com.sleepycat.je.txn
Class LockManager

java.lang.Object
  extended by com.sleepycat.je.txn.LockManager
Direct Known Subclasses:
LatchedLockManager, SyncedLockManager

public abstract class LockManager
extends Object

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


Nested Class Summary
(package private) static class LockManager.LockAttemptResult
          This is just a struct to hold a multi-value return.
 
Field Summary
protected  Latch lockTableLatch
           
(package private) static long TOTAL_LOCK_OVERHEAD
           
 
Constructor Summary
LockManager(EnvironmentImpl envImpl)
           
 
Method Summary
protected abstract  LockManager.LockAttemptResult attemptLock(Long nodeId, Locker locker, LockType type, boolean nonBlockingRequest)
           
protected  LockManager.LockAttemptResult attemptLockInternal(Long nodeId, Locker locker, LockType type, boolean nonBlockingRequest)
           
(package private) abstract  void demote(long nodeId, Locker locker)
          Demote a lock from write to read.
protected  void demoteInternal(long nodeId, Locker locker)
          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)
          Do the real work of dumpLockTableInternal.
 String dumpToString()
           
(package private) abstract  Locker getWriteOwnerLocker(Long nodeId)
           
protected  Locker getWriteOwnerLockerInternal(Long nodeId)
          Do the real work of getWriteOwnerLocker.
(package private) abstract  boolean isLocked(Long nodeId)
          Test the status of the lock on nodeId.
protected  boolean isLockedInternal(Long nodeId)
          Do the real work of isLocked.
(package private) abstract  boolean isOwner(Long nodeId, Locker locker, LockType type)
          Return true if this locker owns this a lock of this type on given node.
protected  boolean isOwnerInternal(Long nodeId, Locker locker, LockType type)
          Do the real work of isOwner.
(package private) abstract  boolean isWaiter(Long nodeId, Locker locker)
          Return true if this locker is waiting on this lock.
protected  boolean isWaiterInternal(Long nodeId, Locker locker)
          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  String makeTimeoutMsg(String lockOrTxn, Locker locker, long nodeId, LockType type, LockGrantType grantType, Lock useLock, long timeout, long start, long now, DatabaseImpl database)
          Create a informative lock or txn timeout message.
protected  String makeTimeoutMsgInternal(String lockOrTxn, Locker locker, long nodeId, LockType type, LockGrantType grantType, Lock useLock, long timeout, long start, long now, DatabaseImpl database)
          Do the real work of creating an lock or txn timeout message.
(package private) abstract  int nOwners(Long nodeId)
          Return the number of owners of this lock.
protected  int nOwnersInternal(Long nodeId)
          Do the real work of nWaiters.
(package private) abstract  int nWaiters(Long nodeId)
          Return the number of waiters for this lock.
protected  int nWaitersInternal(Long nodeId)
          Do the real work of nWaiters.
 boolean release(Lock lock, Locker locker)
          Release a lock and possibly notify any waiters that they have been granted the lock.
 boolean release(long nodeId, Locker locker)
          Release a lock and possibly notify any waiters that they have been granted the lock.
protected abstract  Set releaseAndFindNotifyTargets(long nodeId, Lock lock, Locker locker, boolean removeFromLocker)
          Release the lock, and return the set of new owners to notify, if any.
protected  Set releaseAndFindNotifyTargetsInternal(long nodeId, Lock lock, Locker locker, boolean removeFromLocker)
          Do the real work of releaseAndFindNotifyTargets
(package private) abstract  void transfer(long nodeId, Locker owningLocker, Locker destLocker, boolean demoteToRead)
          Transfer ownership a lock from one locker to another locker.
protected  void transferInternal(long nodeId, Locker owningLocker, Locker destLocker, boolean demoteToRead)
          Do the real work of transfer
(package private) abstract  void transferMultiple(long nodeId, Locker owningLocker, Locker[] destLockers)
          Transfer ownership a lock from one locker to a set of other txns, cloning the lock as necessary.
protected  void transferMultipleInternal(long nodeId, Locker owningLocker, Locker[] destLockers)
          Do the real work of transferMultiple
protected abstract  boolean validateOwnership(Long nodeId, Locker locker, LockType type, boolean flushFromWaiters, MemoryBudget mb)
           
protected  boolean validateOwnershipInternal(Long nodeId, Locker locker, LockType type, boolean flushFromWaiters, MemoryBudget mb)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOTAL_LOCK_OVERHEAD

static final long TOTAL_LOCK_OVERHEAD
See Also:
Constant Field Values

lockTableLatch

protected Latch lockTableLatch
Constructor Detail

LockManager

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

lock

public LockGrantType lock(long nodeId,
                          Locker locker,
                          LockType type,
                          long timeout,
                          boolean nonBlockingRequest,
                          DatabaseImpl database)
                   throws DeadlockException,
                          LockNotGrantedException,
                          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.
LockNotGrantedException - if a non-blocking lock was denied.
DatabaseException

attemptLock

protected abstract LockManager.LockAttemptResult attemptLock(Long nodeId,
                                                             Locker locker,
                                                             LockType type,
                                                             boolean nonBlockingRequest)
                                                      throws DatabaseException
Throws:
DatabaseException

attemptLockInternal

protected LockManager.LockAttemptResult attemptLockInternal(Long nodeId,
                                                            Locker locker,
                                                            LockType type,
                                                            boolean nonBlockingRequest)
                                                     throws DatabaseException
Throws:
DatabaseException

makeTimeoutMsg

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

Throws:
DatabaseException

makeTimeoutMsgInternal

protected String makeTimeoutMsgInternal(String lockOrTxn,
                                        Locker locker,
                                        long nodeId,
                                        LockType type,
                                        LockGrantType grantType,
                                        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

release

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

Parameters:
lock - 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 Set releaseAndFindNotifyTargets(long nodeId,
                                                   Lock lock,
                                                   Locker locker,
                                                   boolean removeFromLocker)
                                            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 Set releaseAndFindNotifyTargetsInternal(long nodeId,
                                                  Lock lock,
                                                  Locker locker,
                                                  boolean removeFromLocker)
                                           throws DatabaseException
Do the real work of releaseAndFindNotifyTargets

Throws:
DatabaseException

transfer

abstract void transfer(long nodeId,
                       Locker owningLocker,
                       Locker destLocker,
                       boolean demoteToRead)
                throws DatabaseException
Transfer ownership a lock from one locker to another locker. We're not sending any notification to the waiters on the lock table, and the past and present owner should be ready for the transfer.

Throws:
DatabaseException

transferInternal

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

Throws:
DatabaseException

transferMultiple

abstract void transferMultiple(long nodeId,
                               Locker owningLocker,
                               Locker[] destLockers)
                        throws DatabaseException
Transfer ownership a lock from one locker to a set of other txns, cloning the lock as necessary. This will always be demoted to read, as we can't have multiple locker owners any other way. We're not sending any notification to the waiters on the lock table, and the past and present owners should be ready for the transfer.

Throws:
DatabaseException

transferMultipleInternal

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

Throws:
DatabaseException

demote

abstract void demote(long nodeId,
                     Locker locker)
              throws DatabaseException
Demote a lock from write to read. Call back to the owning locker to move this to its read collection.

Parameters:
lock - The lock to release. If null, use nodeId to find lock
locker -
Throws:
DatabaseException

demoteInternal

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

Throws:
DatabaseException

isLocked

abstract boolean isLocked(Long nodeId)
                   throws DatabaseException
Test the status of the lock on nodeId. If any transaction holds any lock on it, true is returned. If no transaction holds a lock on it, false is returned. This method is only used by unit tests.

Parameters:
nodeId - The NodeId to check.
Returns:
true if any transaction holds any lock on the nodeid. false if no lock is held by any transaction.
Throws:
DatabaseException

isLockedInternal

protected boolean isLockedInternal(Long nodeId)
Do the real work of isLocked.


isOwner

abstract boolean isOwner(Long nodeId,
                         Locker locker,
                         LockType type)
                  throws DatabaseException
Return true if this locker owns this a lock of this type on given node. This method is only used by unit tests.

Throws:
DatabaseException

isOwnerInternal

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


isWaiter

abstract boolean isWaiter(Long nodeId,
                          Locker locker)
                   throws DatabaseException
Return true if this locker is waiting on this lock. This method is only used by unit tests.

Throws:
DatabaseException

isWaiterInternal

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


nWaiters

abstract int nWaiters(Long nodeId)
               throws DatabaseException
Return the number of waiters for this lock.

Throws:
DatabaseException

nWaitersInternal

protected int nWaitersInternal(Long nodeId)
Do the real work of nWaiters.


nOwners

abstract int nOwners(Long nodeId)
              throws DatabaseException
Return the number of owners of this lock.

Throws:
DatabaseException

nOwnersInternal

protected int nOwnersInternal(Long nodeId)
Do the real work of nWaiters.


getWriteOwnerLocker

abstract Locker getWriteOwnerLocker(Long nodeId)
                             throws DatabaseException
Returns:
the transaction that owns the write lock for this
Throws:
DatabaseException

getWriteOwnerLockerInternal

protected Locker getWriteOwnerLockerInternal(Long nodeId)
                                      throws DatabaseException
Do the real work of getWriteOwnerLocker.

Throws:
DatabaseException

validateOwnership

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

validateOwnershipInternal

protected boolean validateOwnershipInternal(Long nodeId,
                                            Locker locker,
                                            LockType type,
                                            boolean flushFromWaiters,
                                            MemoryBudget mb)
                                     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)
Do the real work of dumpLockTableInternal.


dump

public void dump()
          throws DatabaseException
Debugging

Throws:
DatabaseException

dumpToString

public String dumpToString()
                    throws DatabaseException
Throws:
DatabaseException


Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.