[jboss-dev-forums] [Design of JBossCache] - Re: Eager deadlock detection with 2 phase commits

mircea.markus do-not-reply at jboss.com
Tue Jul 21 04:06:10 EDT 2009


Previous design treats the situation in which two replicating transaction are in a deadlock.
Here is an idea for a similar mechanism intended for detecting deadlocks on a local cache.

T1, T2 two transactions running on the same local cache.
T1 has lock on k1 and tries to acquire k2
T2 has lock on k2 and tries to acquire k1

Each thread runs the following algorithm (pseudocode):

lock(int timeout)
  | {
  |   while (currentTime < startTime + timeout)
  |   {
  |      if (acquire(smallTimeout)) break;
  |      testEDD(globalTransaction, key);
  |   }
  | }
  | 
  | 

//will run the same algorithm, by both T1 and T2:
//globalTransaction - this is the tx that couldn't acquire lock in 'smallTimeout'
//key - the key that couldn't be locked by globalTransation

testEDD(globalTransaction, key) :
  | 
  | globalTransaction.setLockIntention(key); //we intend to lock the given key...
  | Object lockOwner = getLockOwner(key);
  | if (isLocallyOriginatedTx(lockOwner)) {
  |   Object keyToBeLocked = lockOwner.getLockIntention();  
  |  if (globalTransaction.ownsLock(keyToBeLocked)) {
  |     //this is a deadlock situation
  |     //use coin toss to determine which tx should rollback!!!
  |     return;
  |   } else {
  |     return; //this will go back to the main loop in 'lock(int timeout)' method
  |   }
  | } 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4244838#4244838

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4244838



More information about the jboss-dev-forums mailing list