com.sleepycat.je.txn
Class LockManager

java.lang.Object
  extended by com.sleepycat.je.txn.LockManager
All Implemented Interfaces:
EnvConfigObserver
Direct Known Subclasses:
DummyLockManager, LatchedLockManager, SyncedLockManager

public abstract class LockManager
extends java.lang.Object
implements EnvConfigObserver

LockManager manages locks. Note that locks are counted as taking up part of the JE cache;


Field Summary
protected  Latch[] lockTableLatches
           
protected  int nLockTables
           
 
Constructor Summary
LockManager(EnvironmentImpl envImpl)
           
 
Method Summary
protected abstract  com.sleepycat.je.txn.LockAttemptResult attemptLock(java.lang.Long nodeId, Locker locker, LockType type, boolean nonBlockingRequest)
           
protected  com.sleepycat.je.txn.LockAttemptResult attemptLockInternal(java.lang.Long nodeId, Locker locker, LockType type, boolean nonBlockingRequest, int lockTableIndex)
           
protected  void demoteInternal(long nodeId, Locker locker, int lockTableIndex)
          Do the real work of demote.
 void dump()
          Debugging
protected abstract  void dumpLockTable(LockStats stats)
          Dump the lock table to the lock stats.
protected  void dumpLockTableInternal(LockStats stats, int i)
          Do the real work of dumpLockTableInternal.
 java.lang.String dumpToString()
           
 void envConfigUpdate(DbConfigManager configMgr, EnvironmentMutableConfig ignore)
          Process notifications of mutable property changes.
protected  int getLockTableIndex(long nodeId)
           
protected  int getLockTableIndex(java.lang.Long nodeId)
           
protected  Locker getWriteOwnerLockerInternal(java.lang.Long nodeId, int lockTableIndex)
          Do the real work of getWriteOwnerLocker.
protected  boolean isLockedInternal(java.lang.Long nodeId, int lockTableIndex)
          Do the real work of isLocked.
protected  boolean isOwnerInternal(java.lang.Long nodeId, Locker locker, LockType type, int lockTableIndex)
          Do the real work of isOwner.
protected  boolean isWaiterInternal(java.lang.Long nodeId, Locker locker, int lockTableIndex)
          Do the real work of isWaiter.
 LockGrantType lock(long nodeId, Locker locker, LockType type, long timeout, boolean nonBlockingRequest, DatabaseImpl database)
          Attempt to acquire a lock of type on nodeId.
 LockStats lockStat(StatsConfig config)
          Statistics
protected abstract  com.sleepycat.je.txn.Lock lookupLock(java.lang.Long nodeId)
           
protected  com.sleepycat.je.txn.Lock lookupLockInternal(java.lang.Long nodeId, int lockTableIndex)
           
protected abstract  DeadlockException makeTimeoutMsg(java.lang.String lockOrTxn, Locker locker, long nodeId, LockType type, LockGrantType grantType, com.sleepycat.je.txn.Lock useLock, long timeout, long start, long now, DatabaseImpl database)
          Create a informative lock or txn timeout message.
protected  DeadlockException makeTimeoutMsgInternal(java.lang.String lockOrTxn, Locker locker, long nodeId, LockType type, LockGrantType grantType, com.sleepycat.je.txn.Lock useLock, long timeout, long start, long now, DatabaseImpl database)
          Do the real work of creating an lock or txn timeout message.
protected  int nOwnersInternal(java.lang.Long nodeId, int lockTableIndex)
          Do the real work of nWaiters.
protected  int nWaitersInternal(java.lang.Long nodeId, int lockTableIndex)
          Do the real work of nWaiters.
 boolean release(long nodeId, Locker locker)
          Release a lock and possibly notify any waiters that they have been granted the lock.
protected abstract  java.util.Set<Locker> releaseAndFindNotifyTargets(long nodeId, Locker locker)
          Release the lock, and return the set of new owners to notify, if any.
protected  java.util.Set<Locker> releaseAndFindNotifyTargetsInternal(long nodeId, Locker locker, int lockTableIndex)
          Do the real work of releaseAndFindNotifyTargets
protected  void transferInternal(long nodeId, Locker owningLocker, Locker destLocker, boolean demoteToRead, int lockTableIndex)
          Do the real work of transfer
protected  void transferMultipleInternal(long nodeId, Locker owningLocker, Locker[] destLockers, int lockTableIndex)
          Do the real work of transferMultiple
protected abstract  boolean validateOwnership(java.lang.Long nodeId, Locker locker, LockType type, boolean flushFromWaiters, MemoryBudget mb)
           
protected  boolean validateOwnershipInternal(java.lang.Long nodeId, Locker locker, LockType type, boolean flushFromWaiters, MemoryBudget mb, int lockTableIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nLockTables

protected int nLockTables

lockTableLatches

protected Latch[] lockTableLatches
Constructor Detail

LockManager

public LockManager(EnvironmentImpl envImpl)
            throws DatabaseException
Throws:
DatabaseException
Method Detail

envConfigUpdate

public void envConfigUpdate(DbConfigManager configMgr,
                            EnvironmentMutableConfig ignore)
                     throws DatabaseException
Process notifications of mutable property changes.

Specified by:
envConfigUpdate in interface EnvConfigObserver
Throws:
DatabaseException

getLockTableIndex

protected int getLockTableIndex(java.lang.Long nodeId)

getLockTableIndex

protected int getLockTableIndex(long nodeId)

lock

public LockGrantType lock(long nodeId,
                          Locker locker,
                          LockType type,
                          long timeout,
                          boolean nonBlockingRequest,
                          DatabaseImpl database)
                   throws DeadlockException,
                          DatabaseException
Attempt to acquire a lock of type on nodeId. If the lock acquisition would result in a deadlock, throw an exception.
If the requested lock is not currently available, block until it is or until timeout milliseconds have elapsed.
If a lock of type is already held, return EXISTING.
If a WRITE lock is held and a READ lock is requested, return PROMOTION.
If a lock request is for a lock that is not currently held, return either NEW or DENIED depending on whether the lock is granted or not.

Parameters:
nodeId - The NodeId to lock.
locker - The Locker to lock this on behalf of.
type - The lock type requested.
timeout - milliseconds to time out after if lock couldn't be obtained. 0 means block indefinitely. Not used if nonBlockingRequest is true.
nonBlockingRequest - if true, means don't block if lock can't be acquired, and ignore the timeout parameter.
Returns:
a LockGrantType indicating whether the request was fulfilled or not. LockGrantType.NEW means the lock grant was fulfilled and the caller did not previously hold the lock. PROMOTION means the lock was granted and it was a promotion from READ to WRITE. EXISTING means the lock was already granted (not a promotion). DENIED means the lock was not granted either because the timeout passed without acquiring the lock or timeout was -1 and the lock was not immediately available.
Throws:
DeadlockException - if acquiring the lock would result in a deadlock.
DatabaseException

lookupLock

protected abstract com.sleepycat.je.txn.Lock lookupLock(java.lang.Long nodeId)
                                                 throws DatabaseException
Throws:
DatabaseException

lookupLockInternal

protected com.sleepycat.je.txn.Lock lookupLockInternal(java.lang.Long nodeId,
                                                       int lockTableIndex)
                                                throws DatabaseException
Throws:
DatabaseException

attemptLock

protected abstract com.sleepycat.je.txn.LockAttemptResult attemptLock(java.lang.Long nodeId,
                                                                      Locker locker,
                                                                      LockType type,
                                                                      boolean nonBlockingRequest)
                                                               throws DatabaseException
Throws:
DatabaseException

attemptLockInternal

protected com.sleepycat.je.txn.LockAttemptResult attemptLockInternal(java.lang.Long nodeId,
                                                                     Locker locker,
                                                                     LockType type,
                                                                     boolean nonBlockingRequest,
                                                                     int lockTableIndex)
                                                              throws DatabaseException
Throws:
DatabaseException

makeTimeoutMsg

protected abstract DeadlockException makeTimeoutMsg(java.lang.String lockOrTxn,
                                                    Locker locker,
                                                    long nodeId,
                                                    LockType type,
                                                    LockGrantType grantType,
                                                    com.sleepycat.je.txn.Lock useLock,
                                                    long timeout,
                                                    long start,
                                                    long now,
                                                    DatabaseImpl database)
                                             throws DatabaseException
Create a informative lock or txn timeout message.

Throws:
DatabaseException

makeTimeoutMsgInternal

protected DeadlockException makeTimeoutMsgInternal(java.lang.String lockOrTxn,
                                                   Locker locker,
                                                   long nodeId,
                                                   LockType type,
                                                   LockGrantType grantType,
                                                   com.sleepycat.je.txn.Lock useLock,
                                                   long timeout,
                                                   long start,
                                                   long now,
                                                   DatabaseImpl database)
Do the real work of creating an lock or txn timeout message.


release

public boolean release(long nodeId,
                       Locker locker)
                throws DatabaseException
Release a lock and possibly notify any waiters that they have been granted the lock.

Parameters:
nodeId - The node ID of the lock to release.
Returns:
true if the lock is released successfully, false if the lock is not currently being held.
Throws:
DatabaseException

releaseAndFindNotifyTargets

protected abstract java.util.Set<Locker> releaseAndFindNotifyTargets(long nodeId,
                                                                     Locker locker)
                                                              throws DatabaseException
Release the lock, and return the set of new owners to notify, if any.

Returns:
null if the lock does not exist or the given locker was not the owner, a non-empty set if owners should be notified after releasing, an empty set if no notification is required.
Throws:
DatabaseException

releaseAndFindNotifyTargetsInternal

protected java.util.Set<Locker> releaseAndFindNotifyTargetsInternal(long nodeId,
                                                                    Locker locker,
                                                                    int lockTableIndex)
                                                             throws DatabaseException
Do the real work of releaseAndFindNotifyTargets

Throws:
DatabaseException

transferInternal

protected void transferInternal(long nodeId,
                                Locker owningLocker,
                                Locker destLocker,
                                boolean demoteToRead,
                                int lockTableIndex)
                         throws DatabaseException
Do the real work of transfer

Throws:
DatabaseException

transferMultipleInternal

protected void transferMultipleInternal(long nodeId,
                                        Locker owningLocker,
                                        Locker[] destLockers,
                                        int lockTableIndex)
                                 throws DatabaseException
Do the real work of transferMultiple

Throws:
DatabaseException

demoteInternal

protected void demoteInternal(long nodeId,
                              Locker locker,
                              int lockTableIndex)
                       throws DatabaseException
Do the real work of demote.

Throws:
DatabaseException

isLockedInternal

protected boolean isLockedInternal(java.lang.Long nodeId,
                                   int lockTableIndex)
Do the real work of isLocked.


isOwnerInternal

protected boolean isOwnerInternal(java.lang.Long nodeId,
                                  Locker locker,
                                  LockType type,
                                  int lockTableIndex)
Do the real work of isOwner.


isWaiterInternal

protected boolean isWaiterInternal(java.lang.Long nodeId,
                                   Locker locker,
                                   int lockTableIndex)
Do the real work of isWaiter.


nWaitersInternal

protected int nWaitersInternal(java.lang.Long nodeId,
                               int lockTableIndex)
Do the real work of nWaiters.


nOwnersInternal

protected int nOwnersInternal(java.lang.Long nodeId,
                              int lockTableIndex)
Do the real work of nWaiters.


getWriteOwnerLockerInternal

protected Locker getWriteOwnerLockerInternal(java.lang.Long nodeId,
                                             int lockTableIndex)
                                      throws DatabaseException
Do the real work of getWriteOwnerLocker.

Throws:
DatabaseException

validateOwnership

protected abstract boolean validateOwnership(java.lang.Long nodeId,
                                             Locker locker,
                                             LockType type,
                                             boolean flushFromWaiters,
                                             MemoryBudget mb)
                                      throws DatabaseException
Throws:
DatabaseException

validateOwnershipInternal

protected boolean validateOwnershipInternal(java.lang.Long nodeId,
                                            Locker locker,
                                            LockType type,
                                            boolean flushFromWaiters,
                                            MemoryBudget mb,
                                            int lockTableIndex)
                                     throws DatabaseException
Throws:
DatabaseException

lockStat

public LockStats lockStat(StatsConfig config)
                   throws DatabaseException
Statistics

Throws:
DatabaseException

dumpLockTable

protected abstract void dumpLockTable(LockStats stats)
                               throws DatabaseException
Dump the lock table to the lock stats.

Throws:
DatabaseException

dumpLockTableInternal

protected void dumpLockTableInternal(LockStats stats,
                                     int i)
Do the real work of dumpLockTableInternal.


dump

public void dump()
          throws DatabaseException
Debugging

Throws:
DatabaseException

dumpToString

public java.lang.String dumpToString()
                              throws DatabaseException
Throws:
DatabaseException