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 import com.sleepycat.je.latch.Latch; 19 20 23 public class LatchedLockManager extends LockManager { 24 25 public LatchedLockManager(EnvironmentImpl envImpl) 26 throws DatabaseException { 27 super(envImpl); 28 } 29 30 33 protected LockAttemptResult attemptLock(Long nodeId, 34 Locker locker, 35 LockType type, 36 boolean nonBlockingRequest) 37 throws DatabaseException { 38 39 int lockTableIndex = getLockTableIndex(nodeId); 40 Latch latch = lockTableLatches[lockTableIndex]; 41 latch.acquire(); 42 try { 43 return attemptLockInternal(nodeId, locker, type, 44 nonBlockingRequest, lockTableIndex); 45 } finally { 46 latch.release(); 47 } 48 } 49 50 53 protected String makeTimeoutMsg(String lockOrTxn, 54 Locker locker, 55 long nodeId, 56 LockType type, 57 LockGrantType grantType, 58 Lock useLock, 59 long timeout, 60 long start, 61 long now, 62 DatabaseImpl database) 63 throws DatabaseException { 64 65 int lockTableIndex = getLockTableIndex(nodeId); 66 Latch latch = lockTableLatches[lockTableIndex]; 67 latch.acquire(); 68 try { 69 return makeTimeoutMsgInternal(lockOrTxn, locker, 70 nodeId, type, grantType, 71 useLock, timeout, start, now, 72 database); 73 } finally { 74 latch.release(); 75 } 76 } 77 78 81 protected Set releaseAndFindNotifyTargets(long nodeId, 82 Lock lock, 83 Locker locker, 84 boolean removeFromLocker) 85 throws DatabaseException { 86 87 long nid = nodeId; 88 if (nid == -1) { 89 nid = lock.getNodeId().longValue(); 90 } 91 int lockTableIndex = getLockTableIndex(nid); 92 Latch latch = lockTableLatches[lockTableIndex]; 93 latch.acquire(); 94 try { 95 return releaseAndFindNotifyTargetsInternal 96 (nodeId, lock, locker, removeFromLocker, lockTableIndex); 97 } finally { 98 latch.release(); 99 } 100 } 101 102 105 void transfer(long nodeId, 106 Locker owningLocker, 107 Locker destLocker, 108 boolean demoteToRead) 109 throws DatabaseException { 110 111 int lockTableIndex = getLockTableIndex(nodeId); 112 Latch latch = lockTableLatches[lockTableIndex]; 113 latch.acquire(); 114 try { 115 transferInternal(nodeId, owningLocker, destLocker, 116 demoteToRead, lockTableIndex); 117 } finally { 118 latch.release(); 119 } 120 } 121 122 125 void transferMultiple(long nodeId, 126 Locker owningLocker, 127 Locker [] destLockers) 128 throws DatabaseException { 129 130 int lockTableIndex = getLockTableIndex(nodeId); 131 Latch latch = lockTableLatches[lockTableIndex]; 132 latch.acquire(); 133 try { 134 transferMultipleInternal(nodeId, owningLocker, 135 destLockers, lockTableIndex); 136 } finally { 137 latch.release(); 138 } 139 } 140 141 144 void demote(long nodeId, Locker locker) 145 throws DatabaseException { 146 147 int lockTableIndex = getLockTableIndex(nodeId); 148 Latch latch = lockTableLatches[lockTableIndex]; 149 latch.acquire(); 150 try { 151 demoteInternal(nodeId, locker, lockTableIndex); 152 } finally { 153 latch.release(); 154 } 155 } 156 157 160 boolean isLocked(Long nodeId) 161 throws DatabaseException { 162 163 int lockTableIndex = getLockTableIndex(nodeId); 164 Latch latch = lockTableLatches[lockTableIndex]; 165 latch.acquire(); 166 try { 167 return isLockedInternal(nodeId, lockTableIndex); 168 } finally { 169 latch.release(); 170 } 171 } 172 173 176 boolean isOwner(Long nodeId, Locker locker, LockType type) 177 throws DatabaseException { 178 179 int lockTableIndex = getLockTableIndex(nodeId); 180 Latch latch = lockTableLatches[lockTableIndex]; 181 latch.acquire(); 182 try { 183 return isOwnerInternal(nodeId, locker, type, lockTableIndex); 184 } finally { 185 latch.release(); 186 } 187 } 188 189 192 boolean isWaiter(Long nodeId, Locker locker) 193 throws DatabaseException { 194 195 int lockTableIndex = getLockTableIndex(nodeId); 196 Latch latch = lockTableLatches[lockTableIndex]; 197 latch.acquire(); 198 try { 199 return isWaiterInternal(nodeId, locker, lockTableIndex); 200 } finally { 201 latch.release(); 202 } 203 } 204 205 208 int nWaiters(Long nodeId) 209 throws DatabaseException { 210 211 int lockTableIndex = getLockTableIndex(nodeId); 212 Latch latch = lockTableLatches[lockTableIndex]; 213 latch.acquire(); 214 try { 215 return nWaitersInternal(nodeId, lockTableIndex); 216 } finally { 217 latch.release(); 218 } 219 } 220 221 224 int nOwners(Long nodeId) 225 throws DatabaseException { 226 227 int lockTableIndex = getLockTableIndex(nodeId); 228 Latch latch = lockTableLatches[lockTableIndex]; 229 latch.acquire(); 230 try { 231 return nOwnersInternal(nodeId, lockTableIndex); 232 } finally { 233 latch.release(); 234 } 235 } 236 237 240 Locker getWriteOwnerLocker(Long nodeId) 241 throws DatabaseException { 242 243 int lockTableIndex = getLockTableIndex(nodeId); 244 Latch latch = lockTableLatches[lockTableIndex]; 245 latch.acquire(); 246 try { 247 return getWriteOwnerLockerInternal(nodeId, lockTableIndex); 248 } finally { 249 latch.release(); 250 } 251 } 252 253 256 protected boolean validateOwnership(Long nodeId, 257 Locker locker, 258 LockType type, 259 boolean flushFromWaiters, 260 MemoryBudget mb) 261 throws DatabaseException { 262 263 int lockTableIndex = getLockTableIndex(nodeId); 264 Latch latch = lockTableLatches[lockTableIndex]; 265 latch.acquire(); 266 try { 267 return validateOwnershipInternal 268 (nodeId, locker, type, flushFromWaiters, mb, lockTableIndex); 269 } finally { 270 latch.release(); 271 } 272 } 273 274 277 protected void dumpLockTable(LockStats stats) 278 throws DatabaseException { 279 280 for (int i = 0; i < nLockTables; i++) { 281 lockTableLatches[i].acquire(); 282 try { 283 dumpLockTableInternal(stats, i); 284 } finally { 285 lockTableLatches[i].release(); 286 } 287 } 288 } 289 } 290 | Popular Tags |