Chapter 9. Creating Caches with Data Grid Operator
Use Cache
CRs to add cache configuration with Data Grid Operator and control how Data Grid stores your data.
Creating caches with Data Grid Operator is available as a technology preview.
Technology Preview features or capabilities are not supported with Red Hat production service-level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them for production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
When using Cache
CRs, the following rules apply:
-
Cache
CRs apply to Data Grid service nodes only. -
You can create a single cache for each
Cache
CR. -
If your
Cache
CR contains both a template and an XML configuration, Data Grid Operator uses the template. - If you edit caches in the OpenShift Web Console, the changes are reflected through the user interface but do not take effect on the Data Grid cluster. You cannot edit caches. To change cache configuration, you must first delete the cache through the console or CLI and then re-create the cache.
-
Deleting
Cache
CRs in the OpenShift Web Console does not remove caches from Data Grid clusters. You must delete caches through the console or CLI.
9.1. Adding Credentials for Data Grid Operator
Data Grid Operator must authenticate with Data Grid service clusters to create caches. You add credentials to a secret so that Data Grid Operator can access your cluster when creating caches.
The following procedure explains how to add credentials to a new secret. If you already have a custom secret that contains credentials, you can use that instead of creating a new one.
Procedure
Define a Secret object type that provides valid user credentials for accessing Data Grid service clusters in a
StringData
map.For example, create an
basic-auth.yaml
file that provides credentials for thedeveloper
user as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: v1 stringData: username: developer password: G8ZdJvSaY3lOOwfM kind: Secret metadata: name: basic-auth type: Opaque
apiVersion: v1 stringData: username: developer
1 password: G8ZdJvSaY3lOOwfM
2 kind: Secret metadata: name: basic-auth
3 type: Opaque
Create a secret from the file, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc apply -f basic-auth.yaml
$ oc apply -f basic-auth.yaml
9.1.1. Using Custom Credentials Secrets
Data Grid Operator requires that credentials exist as values for the username
and password
keys in a secret. If you have a custom secret that contains Data Grid credentials, but uses different key names, you can override those names in your Cache
CR.
For example, you have a secret named "my-credentials" that holds a list of Data Grid users and their passwords as follows:
stringData: app_user1: spock app_user1_pw: G8ZdJvSaY3lOOwfM app_user2: jim app_user2_pw: zTzz2gVyyF4JsYsH
stringData:
app_user1: spock
app_user1_pw: G8ZdJvSaY3lOOwfM
app_user2: jim
app_user2_pw: zTzz2gVyyF4JsYsH
Procedure
-
In your
Cache
CR, override custom key names withusername
andpassword
as follows:
spec: adminAuth: username: key: app_user1 name: my-credentials password: key: app_user1_pw name: my-credentials
spec:
adminAuth:
username:
key: app_user1
name: my-credentials
password:
key: app_user1_pw
name: my-credentials
9.2. Creating Data Grid Caches from XML
Complete the following steps to create caches on Data Grid service clusters using valid infinispan.xml
cache definitions.
Prerequisites
- Create a secret that contains valid user credentials for accessing Data Grid clusters.
Procedure
Create a
Cache
CR that contains the XML cache definition you want to create.Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: infinispan.org/v2alpha1 kind: Cache metadata: name: mycachedefinition spec: adminAuth: secretName: basic-auth clusterName: example-infinispan name: mycache template: <infinispan><cache-container><distributed-cache name="mycache" mode="SYNC"><persistence><file-store/></persistence></distributed-cache></cache-container></infinispan>
apiVersion: infinispan.org/v2alpha1 kind: Cache metadata: name: mycachedefinition
1 spec: adminAuth:
2 secretName: basic-auth clusterName: example-infinispan
3 name: mycache
4 template: <infinispan><cache-container><distributed-cache name="mycache" mode="SYNC"><persistence><file-store/></persistence></distributed-cache></cache-container></infinispan>
5 - 1
- Names the
Cache
CR. - 2
- Specifies a secret that provides credentials with
username
andpassword
keys or an override for custom credentials secrets. - 3
- Specifies the name of the target Data Grid cluster where you want Data Grid Operator to create the cache.
- 4
- Names the cache on the Data Grid cluster.
- 5
- Specifies the XML cache definition to create the cache. Note that the
name
attribute is ignored. Onlyspec.name
applies to the resulting cache.
Apply the
Cache
CR, for example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc apply -f mycache.yaml
$ oc apply -f mycache.yaml cache.infinispan.org/mycachedefinition created
9.3. Creating Data Grid Caches from Templates
Complete the following steps to create caches on Data Grid service clusters using cache configuration templates.
Prerequisites
- Create a secret that contains valid user credentials for accessing Data Grid clusters.
- Identify the cache configuration template you want to use for your cache. You can find a list of available configuration templates in Data Grid Console.
Procedure
Create a
Cache
CR that specifies the name of the template you want to use.For example, the following CR creates a cache named "mycache" that uses the
org.infinispan.DIST_SYNC
cache configuration template:Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: infinispan.org/v2alpha1 kind: Cache metadata: name: mycachedefinition spec: adminAuth: secretName: basic-auth clusterName: example-infinispan name: mycache templateName: org.infinispan.DIST_SYNC
apiVersion: infinispan.org/v2alpha1 kind: Cache metadata: name: mycachedefinition
1 spec: adminAuth:
2 secretName: basic-auth clusterName: example-infinispan
3 name: mycache
4 templateName: org.infinispan.DIST_SYNC
5 - 1
- Names the
Cache
CR. - 2
- Specifies a secret that provides credentials with
username
andpassword
keys or an override for custom credentials secrets. - 3
- Specifies the name of the target Data Grid cluster where you want Data Grid Operator to create the cache.
- 4
- Names the Data Grid cache instance.
- 5
- Specifies the
infinispan.org
cache configuration template to create the cache.
Apply the
Cache
CR, for example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc apply -f mycache.yaml
$ oc apply -f mycache.yaml cache.infinispan.org/mycachedefinition created
9.4. Adding Backup Locations to Caches
When you configure Data Grid clusters to perform cross-site replication, you can add backup locations to your cache configurations.
Procedure
Create cache configurations with identical names for each site.
Cache configurations at each site can use different cache modes and backup strategies. Data Grid replicates data based on cache names.
Configure backup locations to go offline automatically with the
take-offline
element.-
Set the amount of time, in milliseconds, before backup locations go offline with the
min-wait
attribute.
-
Set the amount of time, in milliseconds, before backup locations go offline with the
- Define any other valid cache configuration.
Add backup locations to the named cache on all sites in the global cluster.
For example, if you add LON as a backup for NYC you should add NYC as a backup for LON.
The following configuration examples show backup locations for caches:
NYC
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <infinispan> <cache-container> <distributed-cache name="customers"> <encoding media-type="application/x-protostream"/> <backups> <backup site="LON" strategy="SYNC"> <take-offline min-wait="120000"/> </backup> </backups> </distributed-cache> </cache-container> </infinispan>
<infinispan> <cache-container> <distributed-cache name="customers"> <encoding media-type="application/x-protostream"/> <backups> <backup site="LON" strategy="SYNC"> <take-offline min-wait="120000"/> </backup> </backups> </distributed-cache> </cache-container> </infinispan>
LON
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <infinispan> <cache-container> <replicated-cache name="customers"> <encoding media-type="application/x-protostream"/> <backups> <backup site="NYC" strategy="ASYNC" > <take-offline min-wait="120000"/> </backup> </backups> </replicated-cache> </cache-container> </infinispan>
<infinispan> <cache-container> <replicated-cache name="customers"> <encoding media-type="application/x-protostream"/> <backups> <backup site="NYC" strategy="ASYNC" > <take-offline min-wait="120000"/> </backup> </backups> </replicated-cache> </cache-container> </infinispan>
Additional resources
9.4.1. Performance Considerations with Taking Backup Locations Offline
Backup locations can automatically go offline when remote sites become unavailable. This prevents nodes from attempting to replicate data to offline backup locations, which can have a performance impact on your cluster because it results in error.
You can configure how long to wait before backup locations go offline. A good rule of thumb is one or two minutes. However, you should test different wait periods and evaluate their performance impacts to determine the correct value for your deployment.
For instance when OpenShift terminates the site master pod, that backup location becomes unavailable for a short period of time until Data Grid Operator elects a new site master. In this case, if the minimum wait time is not long enough then the backup locations go offline. You then need to bring those backup locations online and perform state transfer operations to ensure the data is in sync.
Likewise, if the minimum wait time is too long, node CPU usage increases from failed backup attempts which can lead to performance degradation.
9.5. Adding Persistent Cache Stores
You can add Single File cache stores to Data Grid service nodes to save data to the persistent volume.
You configure cache stores as part of your Data Grid cache definition with the persistence
element as follows:
<persistence> <file-store/> </persistence>
<persistence>
<file-store/>
</persistence>
Data Grid then creates a Single File cache store, .dat
file, in the /opt/infinispan/server/data
directory.
Procedure
Add a cache store to your cache configurations as follows:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <infinispan> <cache-container> <distributed-cache name="customers" mode="SYNC"> <encoding media-type="application/x-protostream"/> <persistence> <file-store/> </persistence> </distributed-cache> </cache-container> </infinispan>
<infinispan> <cache-container> <distributed-cache name="customers" mode="SYNC"> <encoding media-type="application/x-protostream"/> <persistence> <file-store/> </persistence> </distributed-cache> </cache-container> </infinispan>
Additional resources