com.sleepycat.je.txn
Class LockManager

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

public abstract class LockManager
extends Object
implements EnvConfigObserver

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


Field Summary
(package private)  Latch[] lockTableLatches
           
(package private)  int nLockTables
           
(package private) static long TOTAL_LOCKIMPL_OVERHEAD
           
(package private) static long TOTAL_THINLOCKIMPL_OVERHEAD
           
 
Constructor Summary
LockManager(EnvironmentImpl envImpl)
           
 
Method Summary
(package private) abstract  LockAttemptResult attemptLock(Long lsn, Locker locker, LockType type, boolean nonBlockingRequest, boolean jumpAheadOfWaiters)
           
(package private)  LockAttemptResult attemptLockInternal(Long lsn, Locker locker, LockType type, boolean nonBlockingRequest, boolean jumpAheadOfWaiters, int lockTableIndex)
           
(package private) abstract  void demote(long lsn, Locker locker)
          Demote a lock from write to read.
(package private)  void demoteInternal(long lsn, Locker locker, int lockTableIndex)
          Do the real work of demote.
 void dump()
          Debugging
(package private) abstract  void dumpLockTable(StatGroup tableStats, boolean clear)
          Dump the lock table to the lock stats.
(package private)  void dumpLockTableInternal(StatGroup tableStats, int i, boolean clear)
          Do the real work of dumpLockTableInternal.
 String dumpToString()
           
 void envConfigUpdate(DbConfigManager configMgr, EnvironmentMutableConfig ignore)
          Process notifications of mutable property changes.
(package private)  int getLockTableIndex(long lsn)
           
(package private)  int getLockTableIndex(Long lsn)
           
abstract  LockType getOwnedLockType(Long lsn, Locker locker)
          Returns the LockType if the given locker owns a lock on the given node, or null if the lock is not owned.
(package private)  LockType getOwnedLockTypeInternal(Long lsn, Locker locker, int lockTableIndex)
           
abstract  Set<LockInfo> getOwners(Long lsn)
          Returns the Lockers that own a lock on the given LSN.
(package private)  Set<LockInfo> getOwnersInternal(Long lsn, int lockTableIndex)
           
 Iterator<ThreadLocker> getThreadLockers(Thread thread)
          Returns an iterator over all thread lockers for the given thread, or an empty iterator if none.
(package private) abstract  Locker getWriteOwnerLocker(Long lsn)
           
(package private)  Locker getWriteOwnerLockerInternal(Long lsn, int lockTableIndex)
          Do the real work of getWriteOwnerLocker.
(package private) abstract  boolean isLocked(Long lsn)
          Test the status of the lock on LSN.
(package private)  boolean isLockedInternal(Long lsn, int lockTableIndex)
          Do the real work of isLocked.
abstract  boolean isLockUncontended(Long lsn)
           
(package private)  boolean isLockUncontendedInternal(Long lsn, int lockTableIndex)
           
(package private) abstract  boolean isOwner(Long lsn, Locker locker, LockType type)
          Return true if this locker owns this a lock of this type on given node.
(package private)  boolean isOwnerInternal(Long lsn, Locker locker, LockType type, int lockTableIndex)
          Do the real work of isOwner.
(package private) abstract  boolean isWaiter(Long lsn, Locker locker)
          Return true if this locker is waiting on this lock.
(package private)  boolean isWaiterInternal(Long lsn, Locker locker, int lockTableIndex)
          Do the real work of isWaiter.
 StatGroup loadStats(StatsConfig config)
           
 LockGrantType lock(long lsn, Locker locker, LockType type, long timeout, boolean nonBlockingRequest, boolean jumpAheadOfWaiters, DatabaseImpl database)
          Attempt to acquire a lock of type on lsn.
 LockStats lockStat(StatsConfig config)
          Statistics
(package private) abstract  Lock lookupLock(Long lsn)
           
(package private)  Lock lookupLockInternal(Long lsn, int lockTableIndex)
           
(package private) abstract  LockConflictException makeTimeoutMsg(boolean isLockNotTxnTimeout, Locker locker, long lsn, LockType type, LockGrantType grantType, Lock useLock, long timeout, long start, long now, DatabaseImpl database)
          Create a informative lock or txn timeout message.
(package private)  LockConflictException makeTimeoutMsgInternal(boolean isLockNotTxnTimeout, Locker locker, long lsn, 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)  LockConflictException newLockNotAvailableException(Locker locker, String msg)
          This method should always be called instead of explicitly creating LockNotAvailableException, to ensure that je.lock.oldLockExceptions is enforced.
(package private) abstract  int nOwners(Long lsn)
          Return the number of owners of this lock.
(package private)  int nOwnersInternal(Long lsn, int lockTableIndex)
          Do the real work of nWaiters.
(package private) abstract  int nWaiters(Long lsn)
          Return the number of waiters for this lock.
(package private)  int nWaitersInternal(Long lsn, int lockTableIndex)
          Do the real work of nWaiters.
 void registerThreadLocker(ThreadLocker locker)
          Called when a ThreadLocker is created.
 boolean release(long lsn, Locker locker)
          Release a lock and possibly notify any waiters that they have been granted the lock.
(package private) abstract  Set<Locker> releaseAndFindNotifyTargets(long lsn, Locker locker)
          Release the lock, and return the set of new owners to notify, if any.
(package private)  Set<Locker> releaseAndFindNotifyTargetsInternal(long lsn, Locker locker, int lockTableIndex)
          Do the real work of releaseAndFindNotifyTargets
(package private) static void setLockTableDump(boolean enable)
          Called when the je.txn.dumpLocks property is changed.
protected abstract  LockAttemptResult stealLock(Long lsn, Locker locker, LockType lockType, MemoryBudget mb)
           
protected  LockAttemptResult stealLockInternal(Long lsn, Locker locker, LockType lockType, MemoryBudget mb, int lockTableIndex)
           
 void unregisterThreadLocker(ThreadLocker locker)
          Called when a ThreadLocker is closed.
(package private) abstract  boolean validateOwnership(Long lsn, Locker locker, LockType type, boolean flushFromWaiters, MemoryBudget mb)
           
(package private)  boolean validateOwnershipInternal(Long lsn, 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

TOTAL_LOCKIMPL_OVERHEAD

static final long TOTAL_LOCKIMPL_OVERHEAD

TOTAL_THINLOCKIMPL_OVERHEAD

static final long TOTAL_THINLOCKIMPL_OVERHEAD

nLockTables

int nLockTables

lockTableLatches

Latch[] lockTableLatches
Constructor Detail

LockManager

public LockManager(EnvironmentImpl envImpl)
Method Detail

envConfigUpdate

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

Specified by:
envConfigUpdate in interface EnvConfigObserver

setLockTableDump

static void setLockTableDump(boolean enable)
Called when the je.txn.dumpLocks property is changed.


getLockTableIndex

int getLockTableIndex(Long lsn)

getLockTableIndex

int getLockTableIndex(long lsn)

lock

public LockGrantType lock(long lsn,
                          Locker locker,
                          LockType type,
                          long timeout,
                          boolean nonBlockingRequest,
                          boolean jumpAheadOfWaiters,
                          DatabaseImpl database)
                   throws LockConflictException,
                          DatabaseException
Attempt to acquire a lock of type on lsn. 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:
lsn - The LSN 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.
jumpAheadOfWaiters - grant the lock before other waiters, if any.
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 because the timeout passed without acquiring the lock or timeout was 0 and the lock was not immediately available.
Throws:
LockConflictException - if lock could not be acquired.
IllegalArgumentException - via db/cursor read/write methods, if non-transactional access to a replicated environment is attempted, and read-uncommitted is not specified.
DatabaseException

getOwners

public abstract Set<LockInfo> getOwners(Long lsn)
Returns the Lockers that own a lock on the given LSN. Note that when this method returns, there is nothing to prevent these lockers from releasing the lock or being closed.


getOwnersInternal

Set<LockInfo> getOwnersInternal(Long lsn,
                                int lockTableIndex)

getOwnedLockType

public abstract LockType getOwnedLockType(Long lsn,
                                          Locker locker)
Returns the LockType if the given locker owns a lock on the given node, or null if the lock is not owned.


getOwnedLockTypeInternal

LockType getOwnedLockTypeInternal(Long lsn,
                                  Locker locker,
                                  int lockTableIndex)

isLockUncontended

public abstract boolean isLockUncontended(Long lsn)

isLockUncontendedInternal

boolean isLockUncontendedInternal(Long lsn,
                                  int lockTableIndex)

lookupLock

abstract Lock lookupLock(Long lsn)
                  throws DatabaseException
Throws:
DatabaseException

lookupLockInternal

Lock lookupLockInternal(Long lsn,
                        int lockTableIndex)

attemptLock

abstract LockAttemptResult attemptLock(Long lsn,
                                       Locker locker,
                                       LockType type,
                                       boolean nonBlockingRequest,
                                       boolean jumpAheadOfWaiters)
                                throws DatabaseException
Throws:
DatabaseException

attemptLockInternal

LockAttemptResult attemptLockInternal(Long lsn,
                                      Locker locker,
                                      LockType type,
                                      boolean nonBlockingRequest,
                                      boolean jumpAheadOfWaiters,
                                      int lockTableIndex)
                                throws DatabaseException
Throws:
DatabaseException

makeTimeoutMsg

abstract LockConflictException makeTimeoutMsg(boolean isLockNotTxnTimeout,
                                              Locker locker,
                                              long lsn,
                                              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

LockConflictException makeTimeoutMsgInternal(boolean isLockNotTxnTimeout,
                                             Locker locker,
                                             long lsn,
                                             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.


newLockNotAvailableException

LockConflictException newLockNotAvailableException(Locker locker,
                                                   String msg)
This method should always be called instead of explicitly creating LockNotAvailableException, to ensure that je.lock.oldLockExceptions is enforced.


release

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

Parameters:
lsn - The LSN 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

abstract Set<Locker> releaseAndFindNotifyTargets(long lsn,
                                                 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

Set<Locker> releaseAndFindNotifyTargetsInternal(long lsn,
                                                Locker locker,
                                                int lockTableIndex)
Do the real work of releaseAndFindNotifyTargets


demote

abstract void demote(long lsn,
                     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 LSN to find lock
locker -
Throws:
DatabaseException

demoteInternal

void demoteInternal(long lsn,
                    Locker locker,
                    int lockTableIndex)
Do the real work of demote.


isLocked

abstract boolean isLocked(Long lsn)
                   throws DatabaseException
Test the status of the lock on LSN. 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:
lsn - The LSN to check.
Returns:
true if any transaction holds any lock on the LSN. false if no lock is held by any transaction.
Throws:
DatabaseException

isLockedInternal

boolean isLockedInternal(Long lsn,
                         int lockTableIndex)
Do the real work of isLocked.


isOwner

abstract boolean isOwner(Long lsn,
                         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

boolean isOwnerInternal(Long lsn,
                        Locker locker,
                        LockType type,
                        int lockTableIndex)
Do the real work of isOwner.


isWaiter

abstract boolean isWaiter(Long lsn,
                          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

boolean isWaiterInternal(Long lsn,
                         Locker locker,
                         int lockTableIndex)
Do the real work of isWaiter.


nWaiters

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

Throws:
DatabaseException

nWaitersInternal

int nWaitersInternal(Long lsn,
                     int lockTableIndex)
Do the real work of nWaiters.


nOwners

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

Throws:
DatabaseException

nOwnersInternal

int nOwnersInternal(Long lsn,
                    int lockTableIndex)
Do the real work of nWaiters.


getWriteOwnerLocker

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

getWriteOwnerLockerInternal

Locker getWriteOwnerLockerInternal(Long lsn,
                                   int lockTableIndex)
Do the real work of getWriteOwnerLocker.


validateOwnership

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

validateOwnershipInternal

boolean validateOwnershipInternal(Long lsn,
                                  Locker locker,
                                  LockType type,
                                  boolean flushFromWaiters,
                                  MemoryBudget mb,
                                  int lockTableIndex)

stealLock

protected abstract LockAttemptResult stealLock(Long lsn,
                                               Locker locker,
                                               LockType lockType,
                                               MemoryBudget mb)
                                        throws DatabaseException
Throws:
DatabaseException

stealLockInternal

protected LockAttemptResult stealLockInternal(Long lsn,
                                              Locker locker,
                                              LockType lockType,
                                              MemoryBudget mb,
                                              int lockTableIndex)
                                       throws DatabaseException
Throws:
DatabaseException

registerThreadLocker

public void registerThreadLocker(ThreadLocker locker)
Called when a ThreadLocker is created.


unregisterThreadLocker

public void unregisterThreadLocker(ThreadLocker locker)
Called when a ThreadLocker is closed.


getThreadLockers

public Iterator<ThreadLocker> getThreadLockers(Thread thread)
Returns an iterator over all thread lockers for the given thread, or an empty iterator if none.


lockStat

public LockStats lockStat(StatsConfig config)
                   throws DatabaseException
Statistics

Throws:
DatabaseException

loadStats

public StatGroup loadStats(StatsConfig config)

dumpLockTable

abstract void dumpLockTable(StatGroup tableStats,
                            boolean clear)
                     throws DatabaseException
Dump the lock table to the lock stats.

Throws:
DatabaseException

dumpLockTableInternal

void dumpLockTableInternal(StatGroup tableStats,
                           int i,
                           boolean clear)
Do the real work of dumpLockTableInternal.


dump

public void dump()
          throws DatabaseException
Debugging

Throws:
DatabaseException

dumpToString

public String dumpToString()
                    throws DatabaseException
Throws:
DatabaseException


Copyright (c) 2004-2012 Oracle. All rights reserved.