Chapter 3. Configuring Data Grid for Cross-Site Replication
Configuring Data Grid to replicate data across sites, you first set up cluster transport so Data Grid clusters can discover each other and site masters can communicate. You then add backup locations to cache definitions in your Data Grid configuration.
3.1. Configuring Cluster Transport for Cross-Site Replication Copy linkLink copied to clipboard!
Add JGroups RELAY2 to your transport layer so that Data Grid clusters can communicate with backup locations.
Procedure
-
Open
infinispan.xml
for editing. Add the RELAY2 protocol to a JGroups stack, for example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure Data Grid cluster transport to use the stack, as in the following example:
<cache-container name="default" statistics="true"> <transport cluster="${cluster.name}" stack="xsite"/> </cache-container>
<cache-container name="default" statistics="true"> <transport cluster="${cluster.name}" stack="xsite"/> </cache-container>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save and close
infinispan.xml
.
3.1.1. JGroups RELAY2 Stacks Copy linkLink copied to clipboard!
Data Grid clusters use JGroups RELAY2 for inter-cluster discovery and communication.
- 1
- Defines a stack named "xsite" that declares which protocols to use for your Data Grid cluster transport.
- 2
- Uses the default JGroups UDP stack for intra-cluster traffic.
- 3
- Adds
RELAY2
to the stack for inter-cluster transport. - 4
- Names the local site. Data Grid replicates data in caches from this site to backup locations.
- 5
- Configures a maximum of 1000 site masters for the local cluster. You should set
max_site_masters
>= the number of nodes in the Data Grid cluster for optimal performance with backup requests. - 6
- Specifies all site names and uses the default JGroups TCP stack for inter-cluster transport.
- 7
- Names each remote site as a backup location.
3.1.2. Custom JGroups RELAY2 Stacks Copy linkLink copied to clipboard!
Example jgroups-relay.xml
3.2. Adding Backup Locations to Caches Copy linkLink copied to clipboard!
Specify the names of remote sites so Data Grid can back up data to those locations.
Procedure
-
Add the
backups
element to your cache definition. Specify the name of each remote site with the
backup
element.As an example, in the LON configuration, specify NYC as the remote site.
- Repeat the preceding steps so that each site is a backup for all other sites. For example, you cannot add LON as a backup for NYC without adding NYC as a backup for LON.
Cache configurations can be different across sites and use different backup strategies. Data Grid replicates data based on cache names.
Example "customers" configuration in LON
<replicated-cache name="customers"> <backups> <backup site="NYC" strategy="ASYNC" /> </backups> </replicated-cache>
<replicated-cache name="customers">
<backups>
<backup site="NYC" strategy="ASYNC" />
</backups>
</replicated-cache>
Example "customers" configuration in NYC
<distributed-cache name="customers"> <backups> <backup site="LON" strategy="SYNC" /> </backups> </replicated-cache>
<distributed-cache name="customers">
<backups>
<backup site="LON" strategy="SYNC" />
</backups>
</replicated-cache>
Reference
3.3. Backing Up to Caches with Different Names Copy linkLink copied to clipboard!
By default, Data Grid replicates data between caches that have the same name.
Procedure
-
Use
backup-for
to replicate data from a remote site into a cache with a different name on the local site.
For example, the following configuration backs up the "customers" cache on LON to the "eu-customers" cache on NYC.
3.4. Verifying Cross-Site Views Copy linkLink copied to clipboard!
After you configure Data Grid for cross-site replication, you should verify that Data Grid clusters successfully form cross-site views.
Procedure
-
Check log messages for
ISPN000439: Received new x-site view
messages.
For example, if the Data Grid cluster in LON has formed a cross-site view with the Data Grid cluster in NYC, it provides the following messages:
INFO [org.infinispan.XSITE] (jgroups-5,${server.hostname}) ISPN000439: Received new x-site view: [NYC] INFO [org.infinispan.XSITE] (jgroups-7,${server.hostname}) ISPN000439: Received new x-site view: [NYC, LON]
INFO [org.infinispan.XSITE] (jgroups-5,${server.hostname}) ISPN000439: Received new x-site view: [NYC]
INFO [org.infinispan.XSITE] (jgroups-7,${server.hostname}) ISPN000439: Received new x-site view: [NYC, LON]
3.5. Configuring Hot Rod Clients for Cross-Site Replication Copy linkLink copied to clipboard!
Configure Hot Rod clients to use Data Grid clusters at different sites.
hotrod-client.properties
Servers at the active site Servers at the backup site
# Servers at the active site
infinispan.client.hotrod.server_list = LON_host1:11222,LON_host2:11222,LON_host3:11222
# Servers at the backup site
infinispan.client.hotrod.cluster.NYC = NYC_hostA:11222,NYC_hostB:11222,NYC_hostC:11222,NYC_hostD:11222
ConfigurationBuilder
ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServers("LON_host1:11222;LON_host2:11222;LON_host3:11222") .addCluster("NYC") .addClusterNodes("NYC_hostA:11222;NYC_hostB:11222;NYC_hostC:11222;NYC_hostD:11222")
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServers("LON_host1:11222;LON_host2:11222;LON_host3:11222")
.addCluster("NYC")
.addClusterNodes("NYC_hostA:11222;NYC_hostB:11222;NYC_hostC:11222;NYC_hostD:11222")
Use the following methods to switch Hot Rod clients to the default cluster or to a cluster at a different site:
-
RemoteCacheManager.switchToDefaultCluster()
-
RemoteCacheManager.switchToCluster(${site.name})