Chapter 3. Creating Data Grid Services
Data Grid services are stateful applications that provide flexible and robust in-memory data storage.
3.1. Cache Service
Cache service provides a volatile, low-latency data store that dramatically increases application response rates.
Cache service nodes:
- Synchronously distribute data across the cluster to ensure consistency.
- Maintain single copies of cache entries to reduce size.
- Store cache entries off-heap and use eviction for JVM efficiency.
- Ensure data consistency with a default partition handling configuration.
You can create multiple cache definitions with Cache service but only as copies of the default configuration.
If you update Cache service nodes with the Infinispan CR or update the version, you lose all data in the cache.
3.1.1. Cache Configuration
Cache service nodes use the following cache configuration:
<distributed-cache name="default" 1 mode="SYNC" 2 owners="1"> 3 <memory> <off-heap eviction="MEMORY" 4 strategy="REMOVE"/> 5 </memory> <partition-handling when-split="ALLOW_READ_WRITES" 6 merge-policy="REMOVE_ALL"/> 7 </distributed-cache>
- 1
- Names the cache instance as "default".
- 2
- Uses synchronous distribution for storing data across the cluster.
- 3
- Configures one replica for each cache entry across the cluster.
- 4
- Stores cache entries as bytes in native memory (off-heap).
- 5
- Removes old entries to make space when adding new entries.
- 6
- Specifies a conflict resolution strategy that allows read and write operations for cache entries even if segment owners are in different partitions.
- 7
- Specifies a merge policy that removes entries from the cache when Data Grid detects conflicts.
3.2. Data Grid Service
Data Grid service provides a configurable Data Grid server distribution for OpenShift.
- Use with advanced capabilities like cross-site replication as well as indexing and querying.
Remotely access Data Grid service clusters from Hot Rod or REST clients and dynamically create caches using any Data Grid cache mode and configuration.
NoteData Grid does not provide default caches for Data Grid service nodes. However, you can use cache configuration templates to get started.
3.3. Creating Data Grid Services
Define the .spec.service.type
resource to create Cache service and Data Grid service nodes with Data Grid Operator.
By default, Data Grid Operator creates Data Grid clusters configured as a Cache service.
Procedure
-
Specify the service type for Data Grid clusters with
spec.service.type
in your Infinispan CR and then apply the changes.
For example, create Data Grid service clusters as follows:
spec: ... service: type: DataGrid
You cannot change .spec.service.type
after you create Data Grid clusters.
For example, if you create a cluster of Cache service nodes, you cannot change the service type to Data Grid service. In this case you must create a new cluster with Data Grid service nodes in a different OpenShift namespace.
3.3.1. Cache Service Resources
apiVersion: infinispan.org/v1 kind: Infinispan metadata: name: example-rhdatagrid 1 spec: replicas: 4 2 service: type: Cache 3 security: endpointSecretName: endpoint-identities 4 endpointEncryption: 5 type: secret certSecretName: tls-secret container: 6 extraJvmOpts: "-XX:NativeMemoryTracking=summary" cpu: "2000m" memory: 1Gi logging: 7 categories: org.infinispan: trace org.jgroups: trace expose: 8 type: LoadBalancer
- 1
- Names the Data Grid cluster.
- 2
- Specifies the number of nodes in the cluster.
- 3
- Creates Cache service clusters.
- 4
- Adds an authentication secret with user credentials.
- 5
- Adds a custom encryption secret for secure connections.
- 6
- Allocates resources to nodes.
- 7
- Configures logging.
- 8
- Configures services for external traffic.
3.3.2. Data Grid Service Resources
apiVersion: infinispan.org/v1 kind: Infinispan metadata: name: example-rhdatagrid 1 spec: replicas: 6 2 service: type: DataGrid 3 container: storage: 2Gi 4 sites: 5 local: expose: type: LoadBalancer locations: - name: azure url: openshift://api.azure.host:6443 secretName: azure-identities - name: aws url: openshift://api.aws.host:6443 secretName: aws-identities security: endpointSecretName: endpoint-identities 6 endpointEncryption: 7 type: secret certSecretName: tls-secret container: 8 extraJvmOpts: "-XX:NativeMemoryTracking=summary" cpu: "1000m" memory: 1Gi logging: 9 categories: org.infinispan: debug org.jgroups: debug expose: 10 type: LoadBalancer
- 1
- Names the Data Grid cluster.
- 2
- Specifies the number of nodes in the cluster.
- 3
- Creates Data Grid service clusters.
- 4
- Configures size of the persistent volume.
- 5
- Provides connection information for backup locations.
- 6
- Adds an authentication secret with user credentials.
- 7
- Adds a custom encryption secret for secure connections.
- 8
- Allocates resources to nodes.
- 9
- Configures logging.
- 10
- Configures services for external traffic.