Multi-Cluster Proxy: Developer Guide
MultiClusterGigaSpace lets your application reach several clusters through one GigaSpace, and fail over between them when one cluster goes down. It implements the standard GigaSpace interface, so only the bean or factory that creates the GigaSpace changes. Your application code stays the same.
For the full set of options, failure cases, and runnable code, see the example in gs-home/examples/multicluster.
Connect to Each Cluster
Create one ordinary GigaSpace per cluster. The proxy never opens or closes these connections.
SpaceProxyConfigurer eastConfigurer = new SpaceProxyConfigurer("mySpace")
.lookupLocators("east-host:4174")
.lookupGroups("dr-us");
GigaSpace east = new GigaSpaceConfigurer(eastConfigurer).gigaSpace();
SpaceProxyConfigurer westConfigurer = new SpaceProxyConfigurer("mySpace")
.lookupLocators("west-host:4174")
.lookupGroups("dr-emea");
GigaSpace west = new GigaSpaceConfigurer(westConfigurer).gigaSpace();
Check each connection before you combine them, for example with east.count(null). A proxy built on an unreachable cluster fails at its first operation, and the resulting stack trace rarely points to the real cause.
Build the Proxy
MultiClusterGigaSpace proxy = new MultiClusterGigaSpaceConfigurer()
.cluster("us-east", east)
.cluster("us-west", west)
.activeCluster("us-east")
.clusterPriority("us-east", "us-west")
.writeMode(WriteMode.WRITE_SYNC)
.readMode(ReadMode.READ_ROUND_ROBIN)
.gigaSpace();
-
activeClustertakes writes. The first registered cluster is the default. -
clusterPrioritysets the order in which clusters are promoted when the active one fails. -
You can also build the proxy from
SpaceConfigurerinstances, or register clusters at runtime withnew DefaultMultiClusterGigaSpace(name)andregisterCluster(name, space). The example shows both.
Closing the proxy stops its heartbeat scheduler. It does not close your cluster connections, so close those yourself.
Choose the Two Modes
These two settings are the main design decisions.
| Setting | Option | Behavior | Use When |
|---|---|---|---|
writeMode
|
WRITE_ONCE (default) |
Writes go to the active cluster only. | You have a WAN gateway or another way to sync the clusters. |
writeMode
|
WRITE_SYNC
|
Changes go to every cluster and wait for all of them. | You have no gateway and every cluster must hold the data. |
readMode
|
READ_ACTIVE (default) |
Reads go to the active cluster. Read-your-writes is guaranteed. | You need current data and one active site. |
readMode
|
READ_ROUND_ROBIN
|
Reads are spread over healthy clusters. A read can miss the latest write. | You want to spread the read load and accept eventual consistency. |
Both settings can be changed at runtime with proxy.setWriteMode(...) and proxy.setReadMode(...).
Common setups:
-
Active/standby DR
Disaster Recovery. A set of policies and procedures to enable the recovery or continuation of vital technology infrastructure and systems following a natural or human-induced disaster. It ensures business continuity.: WRITE_ONCEwithREAD_ACTIVE. -
Two symmetric sites, no gateway:
WRITE_SYNCwithREAD_ROUND_ROBIN. -
Separate read and write clusters: pin reads with
.readActiveCluster("reader"), or use the read rotation.
Use the Proxy
Your existing GigaSpace code works unchanged:
proxy.write(new Order("o-1", "NEW", 5));
Order order = proxy.readById(Order.class, "o-1");
proxy.change(new IdQuery<>(Order.class, "o-1"), new ChangeSet().set("status", "SHIPPED"));
Some results differ from a single Space
Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model.:
-
countanswers from one cluster, not the sum of all of them. -
clearreturns the total removed across clusters by default. -
Inside a transaction, all operations go to the active cluster.
-
getCluster("us-east")gives you the raw handle for one cluster, for verification or diagnostics.
Failover in Brief
-
If the active cluster fails, the active role moves to the next cluster in
clusterPriority. -
A cluster is marked unhealthy after
failureThresholdfailures (default 3) withinfailureWindow(default 30s). Unhealthy clusters receive no traffic. -
Nothing brings an unhealthy cluster back automatically. Unregister it, register it again when it is ready, then move the active role back with
setActiveCluster(name). -
failoverPolicydecides what happens to the failing operation. The default,AUTO_FAILOVER_NEXT_AVAILABLE, retries it once on another cluster. -
Under
WRITE_SYNC, if only some clusters take a write, you get aPartialWriteException. The cluster that missed it is unregistered so balanced reads cannot return stale data. -
Application errors such as a duplicate ID are thrown to you unchanged. They do not count against cluster health.
The example covers each of these in its own scenario, with the exact failure rules.
Monitor
proxy.addClusterEventListener(event -> {
switch (event.type()) {
case CLUSTER_FAILED -> log.error("{} failed: {}", event.clusterName(), event.cause());
case CLUSTER_RECOVERED -> log.info("{} is answering again", event.clusterName());
case ACTIVE_CLUSTER_CHANGED -> log.warn("active {} -> {}", event.previousActive(), event.clusterName());
default -> { }
}
});
-
Alert on
NoAvailableClusterException. It means the proxy has no cluster left to use. -
proxy.getStats()gives per-cluster operation, failure, and latency counters. -
Set
.jmx(true)on the configurer to expose the proxy through JMX, and give each proxy a distinct.name(...).
Spring
Use MultiClusterGigaSpaceFactoryBean instead of building the proxy by hand. It takes the same settings as the configurer and closes the proxy when the context closes.
Try It and Read More
The example in xap-examples/multicluster runs the proxy end to end against embedded Spaces, or against clusters you already have:
./build.sh run # two embedded spaces, no infrastructure
./build.sh run us=wanSpaceUS@127.0.0.1:4266 emea=wanSpaceEMEA@127.0.0.1:4166
./build.sh probe us=wanSpaceUS@127.0.0.1:4266 # check that a cluster is reachable
You can also have two separate active clusters, one for reads and another for writes.
On Windows, use build.bat with the same commands. The example's README covers its 14 scenarios, which map to each feature in this guide, and explains how to deploy two local clusters to run it against.
In-Memory Data Grid - achieve unparalleled speed, persistence, and accuracy.