Chapter 11. Replicated cache with unshared (local) datastore
In this example, we'll run 2 nodes again, but this time, instead of sharing the same datastore, each node has its own datastore. The configuration is in file jboss-cache/output/etc/META-INF/node{1,2}.xml . We'll look at node1.xml:
<attribute name="CacheLoaderClass">org.jboss.cache.loader.bdbje.BdbjeCacheLoader</attribute>
<attribute name="CacheLoaderConfig">
location=c:\\tmp\\node1
</attribute>
<attribute name="CacheLoaderShared">false</attribute>
<attribute name="CacheLoaderPreload">/</attribute>
<attribute name="CacheLoaderFetchTransientState">false</attribute>
<attribute name="CacheLoaderFetchPersistentState">true</attribute>
Again, we use the Sleepycat CacheLoader implementation in CacheLoaderClass . The CacheLoaderConfig points to c:\tmp\node1 . This is the directory in which the Sleepycat DB for node1 will reside. File node2.xml has a configuration that points to c:\tmp\node2 , so we have 2 different unshared datastores. Note that, of course, we still have the same filesystem in our case, because we run the 2 nodes on the same machine. In practice those two directories would reside on two different machines, and each machine would run one JBossCache process. Note that the 2 directories have to exis
To create an unshared datastore, we set the CacheLoaderShared attribute to false .
The example can be run by again opening 2 shells, and running 2 ANT targets (here we show the target for node1):
bela@laptop /cygdrive/c/jboss-cache
$ ./build.sh run.demo.unshared.node2
Buildfile: build.xml
init:
compile:
run.demo.unshared.node2:
[java] ** node loaded: /a
[java] ** node loaded: /a/a2
...
The run.demo.unshared.node2 target runs node2, which will have its own store located at c:\tmp\node2 (shown above). Whenever a change is made on either of the 2 nodes, it is replicated to the other node, and persisted in both local datastores. You can kill and restart a node, or even both nodes, and the data will still be available due to the persistent backend store(s).