Problem with state replication of new cache
joc Oct 10, 2005 7:23 AMHi, I'm having a problem with replication if an existing cache.
If I start a cache, and populate it with some values, then I start a long running transaction on that cache. While the transaction is running, another cache is started, and attempts to get the values from the first cache - but seems to fail if the first cache is still in the transaction (?)
Once the transaction of the first cache has completed and been committed, the new value is readable from the second cache, but if it was rolled back, the original value is not readable (just get a NULL).
Im sure theres something I've missed here, but many of the methods in the javadoc have no description of what they actually do so its all rather confusing.
So 2 main questions here really,
1) Is what I described above expected behaviour? I know a long transaction is bad, but it might just happen - and I dont want a new server to be started up and get an empty cache.
2) Is there a way to check if the replication worked ok? I didnt seem to get any exception to say something went wrong, it just carried on as if it worked fine?
I attach a (very rough) example showing the problem below.....
********************************************************
package jbosscachetest;
import java.io.*;
import javax.transaction.*;
import org.jboss.cache.*;
import org.jboss.cache.transaction.*;
public class Example {
boolean sleeping = true;
boolean finished = false;
public static void main(String[] args) {
Example testcase = new Example();
}
public Example() {
Thread coordinator = new Thread(new Runnable()
{
TreeCache tree = createCache();
public void run() {
try {
// Set an initial value
tree.put("/c", "lockMe", "not yet changed");
System.out.println("Tree 1 updated");
// Start up the second server
sleeping = false;
Transaction tx2 = startTransaction();
System.out.println("Thread 1 starting LONG transaction");
// change value inside transaction
tree.put("/c", "lockMe", "this-changed-and-comitted");
_sleep(15000);
tx2.commit();
System.out.println("Finished transaction");
}
catch (Exception ex) {
}
try {
System.out.println("Thread 1 out of transaction - value = " +
tree.get("/c", "lockMe"));
}
catch (CacheException ex1) {
}
_sleep(5000);
tree.stopService();
tree.destroyService();
finished = false;
}
});
coordinator.start();
Thread reader = new Thread(new Runnable()
{
TreeCache tree2 = null;
public void run() {
System.out.println("Thread two woken, creating cache");
tree2 = createCache();
System.out.println("Created second cache - would hope not to see NULL here....");
while (!finished) {
try {
System.out.println("FETCHING - " + tree2.get("/c","lockMe"));
}
catch (CacheException ex) {
System.out.println("EXCEPTION - "+ex);
}
_sleep(1000);
}
tree2.stopService();
tree2.destroyService();
System.out.println("Test finished");
}
});
while (sleeping == true){}
reader.start();
}
public TreeCache createCache() {
TreeCache tree = null;
try {
tree = new TreeCache();
PropertyConfigurator config = new PropertyConfigurator();
config.configure(tree, "META-INF/replSync-service.xml");
tree.setClusterName("demo-cluster");
tree.setFetchStateOnStartup(true);
tree.setInactiveOnStartup(true);
tree.setSyncCommitPhase(true);
tree.setSyncReplTimeout(0);
tree.createService();
tree.startService();
}
catch (Exception ex) {
System.out.println("EXCEPTION-" + ex);
}
return tree;
}
void _sleep(long time) {
Thread.yield();
try {
Thread.sleep(time);
}
catch (InterruptedException e) {}
}
private Transaction startTransaction() throws SystemException,
NotSupportedException {
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
return mgr.getTransaction();
}
}
******************************************
Here's hoping there's a simple solution.... :)
<< JOC >>