1 9 package org.ozoneDB.core.dr; 10 11 import java.util.HashSet ; 12 13 import org.ozoneDB.DxLib.*; 14 import org.ozoneDB.core.*; 15 import org.ozoneDB.util.*; 16 17 21 public final class EdgeChasing extends DeadlockRecognition { 22 23 protected Env env; 24 25 26 public EdgeChasing( Env _env ) { 27 this.env = _env; 28 } 29 30 31 public Locker detectDeadlock( Locker locker ) { 32 return sendLockMessage( locker, locker, true ); 35 } 36 37 38 42 public Locker sendLockMessage( Locker root, Locker locker, boolean firstLevel ) { 43 HashSet visitingLockers = new HashSet (); 45 return sendLockMessage(root,locker,firstLevel,visitingLockers); 46 } 47 48 52 public Locker sendLockMessage(Locker root,Locker locker,boolean firstLevel,HashSet visitingLockers) { 53 if (!locker.isDeadlocked()) { 54 if (visitingLockers.add(locker)) { 55 try { 56 env.logWriter.newEntry( this, "*** sendLockMessage(): " + locker+", visitingLockers="+visitingLockers+".", LogWriter.DEBUG ); 57 Lockable blocker = locker.blockedBy(); 58 59 if (blocker == null) { 60 return null; 61 } 62 63 try { 64 if (!firstLevel) { 65 if (root == locker) { 66 return null; 67 } 68 69 if (blocker == null) { 70 return null; 71 } 72 } 73 74 80 DxCollection lockers = blocker.allLockers(); 83 Locker deadLockingLocker = null; 84 85 if (lockers != null) { 86 DxIterator it = lockers.iterator(); 87 88 while (it.next() != null) { 89 Locker nextLocker = (Locker)it.object(); 90 if (nextLocker != locker) { 91 if (visitingLockers.contains(nextLocker)) { 92 deadLockingLocker = nextLocker; 93 105 nextLocker.setDeadlocked(true); 106 } else { 107 } 109 112 Locker deadlocker = sendLockMessage(root,nextLocker,false,visitingLockers); 113 114 if (deadlocker!=null) { 116 if (false) { 117 return deadlocker; 118 } else { 119 deadLockingLocker = deadlocker; 120 } 121 } 122 } 123 } 124 } 125 126 return deadLockingLocker; 127 } finally { 128 blocker.unpin(); 129 } 130 } finally { 131 visitingLockers.remove(locker); 132 } 133 } else { 134 if (!locker.isDeadlocked()) { 135 locker.setDeadlocked(true); 136 env.logWriter.newEntry(this,"sendLockMessage(): We are about to visit "+locker+" twice (visitingLockers="+visitingLockers+"). This must not be because we would loop.",LogWriter.ERROR); 137 } else { 138 env.logWriter.newEntry(this,"sendLockMessage(): We were about to visit "+locker+" twice (visitingLockers="+visitingLockers+"), but locker is already deadlocked.",LogWriter.ERROR); 139 } 140 return locker; 141 } 142 } else { 143 return locker; 145 } 146 } 147 148 } 149 | Popular Tags |