1 8 9 package com.sleepycat.je.txn; 10 11 import java.util.Set ; 12 13 import com.sleepycat.je.DatabaseException; 14 import com.sleepycat.je.LockStats; 15 import com.sleepycat.je.dbi.DatabaseImpl; 16 import com.sleepycat.je.dbi.EnvironmentImpl; 17 import com.sleepycat.je.dbi.MemoryBudget; 18 19 23 public class SyncedLockManager extends LockManager { 24 25 public SyncedLockManager(EnvironmentImpl envImpl) 26 throws DatabaseException { 27 28 super(envImpl); 29 } 30 31 34 protected LockAttemptResult attemptLock(Long nodeId, 35 Locker locker, 36 LockType type, 37 boolean nonBlockingRequest) 38 throws DatabaseException { 39 40 int lockTableIndex = getLockTableIndex(nodeId); 41 synchronized(lockTableLatches[lockTableIndex]) { 42 return attemptLockInternal(nodeId, locker, type, 43 nonBlockingRequest, lockTableIndex); 44 } 45 } 46 47 50 protected String makeTimeoutMsg(String lockOrTxn, 51 Locker locker, 52 long nodeId, 53 LockType type, 54 LockGrantType grantType, 55 Lock useLock, 56 long timeout, 57 long start, 58 long now, 59 DatabaseImpl database) { 60 61 int lockTableIndex = getLockTableIndex(nodeId); 62 synchronized(lockTableLatches[lockTableIndex]) { 63 return makeTimeoutMsgInternal(lockOrTxn, locker, nodeId, type, 64 grantType, useLock, timeout, 65 start, now, database); 66 } 67 } 68 69 72 protected Set releaseAndFindNotifyTargets(long nodeId, 73 Lock lock, 74 Locker locker, 75 boolean removeFromLocker) 76 throws DatabaseException { 77 78 long nid = nodeId; 79 if (nid == -1) { 80 nid = lock.getNodeId().longValue(); 81 } 82 int lockTableIndex = getLockTableIndex(nid); 83 synchronized(lockTableLatches[lockTableIndex]) { 84 return releaseAndFindNotifyTargetsInternal 85 (nodeId, lock, locker, removeFromLocker, lockTableIndex); 86 } 87 } 88 89 92 void transfer(long nodeId, 93 Locker owningLocker, 94 Locker destLocker, 95 boolean demoteToRead) 96 throws DatabaseException { 97 98 int lockTableIndex = getLockTableIndex(nodeId); 99 synchronized(lockTableLatches[lockTableIndex]) { 100 transferInternal(nodeId, owningLocker, destLocker, 101 demoteToRead, lockTableIndex); 102 } 103 } 104 105 108 void transferMultiple(long nodeId, 109 Locker owningLocker, 110 Locker[] destLockers) 111 throws DatabaseException { 112 113 int lockTableIndex = getLockTableIndex(nodeId); 114 synchronized(lockTableLatches[lockTableIndex]) { 115 transferMultipleInternal(nodeId, owningLocker, 116 destLockers, lockTableIndex); 117 } 118 } 119 120 123 void demote(long nodeId, Locker locker) 124 throws DatabaseException { 125 126 int lockTableIndex = getLockTableIndex(nodeId); 127 synchronized(lockTableLatches[lockTableIndex]) { 128 demoteInternal(nodeId, locker, lockTableIndex); 129 } 130 } 131 132 135 boolean isLocked(Long nodeId) { 136 137 int lockTableIndex = getLockTableIndex(nodeId); 138 synchronized(lockTableLatches[lockTableIndex]) { 139 return isLockedInternal(nodeId, lockTableIndex); 140 } 141 } 142 143 146 boolean isOwner(Long nodeId, Locker locker, LockType type) { 147 148 int lockTableIndex = getLockTableIndex(nodeId); 149 synchronized(lockTableLatches[lockTableIndex]) { 150 return isOwnerInternal(nodeId, locker, type, lockTableIndex); 151 } 152 } 153 154 157 boolean isWaiter(Long nodeId, Locker locker) { 158 159 int lockTableIndex = getLockTableIndex(nodeId); 160 synchronized(lockTableLatches[lockTableIndex]) { 161 return isWaiterInternal(nodeId, locker, lockTableIndex); 162 } 163 } 164 165 168 int nWaiters(Long nodeId) { 169 170 int lockTableIndex = getLockTableIndex(nodeId); 171 synchronized(lockTableLatches[lockTableIndex]) { 172 return nWaitersInternal(nodeId, lockTableIndex); 173 } 174 } 175 176 179 int nOwners(Long nodeId) { 180 181 int lockTableIndex = getLockTableIndex(nodeId); 182 synchronized(lockTableLatches[lockTableIndex]) { 183 return nOwnersInternal(nodeId, lockTableIndex); 184 } 185 } 186 187 190 Locker getWriteOwnerLocker(Long nodeId) 191 throws DatabaseException { 192 193 int lockTableIndex = getLockTableIndex(nodeId); 194 synchronized(lockTableLatches[lockTableIndex]) { 195 return getWriteOwnerLockerInternal(nodeId, lockTableIndex); 196 } 197 } 198 199 202 protected boolean validateOwnership(Long nodeId, 203 Locker locker, 204 LockType type, 205 boolean flushFromWaiters, 206 MemoryBudget mb) 207 throws DatabaseException { 208 209 int lockTableIndex = getLockTableIndex(nodeId); 210 synchronized(lockTableLatches[lockTableIndex]) { 211 return validateOwnershipInternal 212 (nodeId, locker, type, flushFromWaiters, mb, lockTableIndex); 213 } 214 } 215 216 219 protected void dumpLockTable(LockStats stats) 220 throws DatabaseException { 221 222 for (int i = 0; i < nLockTables; i++) { 223 synchronized(lockTableLatches[i]) { 224 dumpLockTableInternal(stats, i); 225 } 226 } 227 } 228 } 229 | Popular Tags |