JBoss EAP 7's infinispan CLI command to insert remote store cache
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.x
- Infinispan subsystem
Issue
How to create a cache store in a cache in Infinispan's subsystem?
[standalone@localhost:9990 /] /subsystem=infinispan/cache-container=web/invalidation-cache=acache/store=remote:add(cache=myTestCache, remote-servers=[remote-rhdg-server1]) <----------------------------------------------- does not have it
{
"outcome" => "failed",
"failure-description" => "WFLYCTL0158: Operation handler failed: org.jboss.msc.service.DuplicateServi
ceException: Service org.wildfly.clustering.infinispan.cache.store.web.acache is already registered",
"rolled-back" => true
}
Following on the CLI command for externalization on Externalize EAP 7 HTTP Sessions To RHDG 8
Resolution
There are two options to execute this, via batch or cli command with --admin-only/allow resource service reload, described below:
/subsystem=infinispan/cache-container=web/invalidation-cache=acache/store=remote:add(cache=myTestCache1, remote-servers=[remote-rhdg-server]) {allow-resource-service-restart=true}
Or one needs to boot the server in admin-only mode (i.e. no runtime), e.g.:
./bin/standalone.sh -c standalone-ha.xml --admin-only
Batch command to add a socket, a rhdg cache container, and a invalidation cache, invcache:
batch
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-rhdg-server:add(host=127.0.0.1,port=11222)
/subsystem=infinispan/remote-cache-container=rhdgcc:add(default-remote-cluster=data-grid-cluster,\
properties={infinispan.client.hotrod.sasl_mechanism=SCRAM-SHA-512,infinispan.client.hotrod.auth_username=rhdgadmin,infinispan.client.hotrod.auth_password=password@2,infinispan.client.hotrod.auth_realm=default})
/subsystem=infinispan/remote-cache-container=rhdgcc/remote-cluster=data-grid-cluster:add(socket-bindings=[remote-rhdg-server])
run-batch
batch
/subsystem=infinispan/cache-container=web/invalidation-cache=invcache:add()
/subsystem=infinispan/cache-container=web/invalidation-cache=invcache/store=hotrod:add( remote-cache-container=rhdgcc,\
fetch-state=false,\
purge=false,\
passivation=false,\
shared=true)
/subsystem=infinispan/cache-container=web/invalidation-cache=invcache/component=transaction:add(mode=BATCH)
/subsystem=infinispan/cache-container=web/invalidation-cache=invcache/component=locking:add(isolation=REPEATABLE_READ)
/subsystem=infinispan/cache-container=web:write-attribute(name=default-cache,value=invcache)
run-batch
Root Cause
A cache can only have one single store=* resource. Adding a store to a cache that already contains a store, will first auto-remove the old store, and therefore will delete the previous one. One can, however, modify the existing remote store via write-attribute operations.
Also, technically, all caches contain a store resource, which might be store=none, if no store was initially defined.
Usage of remote-store cache vs hotrod-store remote-cache-container:
| Type of cache | Behavior |
|---|---|
| store=remote | uses a reference to a remote-cache-container, whereas store=remote contains the configuration for the remote infinispan cluster directly. |
| store=hotrod | auto-provisions a cache on the remote infinispan cluster, whereas store=remote requires the cache on the remote infinispan cluster to be created manually. |
See below the differences comparatively (configuration file):
hotrod-store remote-cache-container:
<cache-container name="web" default-cache="infinispan" modules="org.wildfly.clustering.web.infinispan">
<transport lock-timeout="60000"/>
<invalidation-cache name="infinispan">
<locking isolation="REPEATABLE_READ"/>
<transaction mode="BATCH"/>
<hotrod-store remote-cache-container="rhdg" fetch-state="false" passivation="false" purge="false" shared="true"/>
</invalidation-cache>
...
<remote-cache-container name="rhdg" default-remote-cluster="data-grid-cluster">
<property name="infinispan.client.hotrod.use_auth">true</property>
<property name="infinispan.client.hotrod.sasl_properties.javax.security.sasl.qop">auth</property>
<property name="infinispan.client.hotrod.sasl_mechanism">SCRAM-SHA-512</property>
<property name="infinispan.client.hotrod.auth_username">developer</property>
<property name="infinispan.client.hotrod.auth_server_name">eap-infinispan</property>
<property name="infinispan.client.hotrod.auth_password">Cx2ak@E9fGcaSfs4</property>
<property name="infinispan.client.hotrod.use_ssl">false</property>
<property name="infinispan.client.hotrod.auth_realm">default</property>
<remote-clusters>
<remote-cluster name="data-grid-cluster" socket-bindings="remote-rhdg-server"/>
</remote-clusters>
</remote-cache-container>
remote-store cache
<invalidation-cache name="rhdg">
<locking isolation="REPEATABLE_READ"/>
<transaction mode="BATCH"/>
<remote-store cache="myTestCache" socket-timeout="60000" remote-servers="remote-rhdg-server" passivation="false" purge="false" shared="true"> <!-- remote-servers must match the socket binding below -->
<property name="infinispan.client.hotrod.auth_username">rhdgadmin</property>
<property name="infinispan.client.hotrod.auth_password">password@2</property> <!-- must match the password above -->
<property name="infinispan.client.hotrod.auth_realm">default</property>
<property name="infinispan.client.hotrod.sasl_mechanism">SCRAM-SHA-512</property>
</remote-store>
</invalidation-cache>
Diagnostic Steps
The successful execution of the scrip above will be as below:
$ ./bin/jboss-cli.sh -c --file=actions.cli
The batch executed successfully
process-state: reload-required
The batch executed successfully
process-state: reload-required
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.