-
1. Re: Synchronous replication does NOT block the caller
ben.wang May 17, 2005 10:53 AM (in response to akinf)Please desribe in details which case in the tutorial that you have gone through? It should block.
-Ben -
2. Re: Synchronous replication does NOT block the caller
akinf May 18, 2005 1:47 AM (in response to akinf)Thank you for your reply
In the treecache tutorial , on replication section it writes:
Replication can be synchronous or asynchronous . Use of either one of the options is application dependent. Synchronous replication blocks the caller (e.g. on a put()) until the modifications have been replicated successfully to all nodes in a cluster. ......
Also jbosscache examples includes a unittest to test concurrent puts
public void testConcurrentPuts() throws Exception {
initCaches(TreeCache.REPL_SYNC);
cache1.setSyncCommitPhase(true);
Thread t1=new Thread("Thread1") {
Transaction tx;
public void run() {
try {
tx=beginTransaction();
cache1.put("/bela/ban", "name", "Bela Ban");
_pause(2000); // Thread2 will be blocked until we commit
tx.commit();
System.out.println("[Thread1] ** LOCK INFO cache1: " + cache1.printLockInfo());
System.out.println("[Thread1] ** LOCK INFO cache2: " + cache2.printLockInfo());
}
catch(Throwable ex) {
ex.printStackTrace();
t1_ex=ex;
}
}
};
Thread t2=new Thread("Thread2") {
Transaction tx;
public void run() {
try {
_pause(1000); // give Thread1 time to acquire the lock
tx=beginTransaction();
System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
cache1.put("/bela/ban", "name", "Michelle Ban");
System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
tx.commit();
System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
}
catch(Throwable ex) {
ex.printStackTrace();
t2_ex=ex;
}
}
};
// Let the game start
t1.start();
t2.start();
// Wait for threads to die
t1.join();
t2.join();
if(t1_ex != null)
fail("Thread1 failed: " + t1_ex);
if(t2_ex != null)
fail("Thread2 failed: " + t2_ex);
assertEquals("Michelle Ban", cache1.get("/bela/ban", "name"));
}
This test is ok when running in the same jvm.ie Thread2 is blocked until
first thread commits. But we need this behaviour for two threads running in different jvms.Bu it failed.