com.sleepycat.je.txn
Class Locker

java.lang.Object
  extended by com.sleepycat.je.txn.Locker
Direct Known Subclasses:
BasicLocker, Txn

public abstract class Locker
extends Object

Locker instances are JE's route to locking and transactional support. This class is the abstract base class for BasicLocker, ThreadLocker, Txn and AutoTxn. Locker instances are in fact only a transaction shell to get to the lock manager, and don't guarantee transactional semantics. Txn and AutoTxn instances are both truely transactional, but have different ending behaviors.


Field Summary
protected  boolean defaultNoWait
           
protected  Map deleteInfo
           
protected  EnvironmentImpl envImpl
           
protected  Map handleLockToHandleMap
           
protected  Map handleToHandleLockMap
           
protected  long id
           
protected  LockManager lockManager
           
protected  long lockTimeOutMillis
           
protected  boolean readUncommittedDefault
           
protected  Thread thread
          The thread that created this locker.
 
Constructor Summary
Locker()
          For reading from the log.
Locker(EnvironmentImpl envImpl, boolean readUncommittedDefault, boolean noWait)
          Create a locker id.
 
Method Summary
 void addDeleteInfo(BIN bin, Key deletedKey)
          Add delete information, to be added to the inCompressor queue when the transaction ends.
(package private) abstract  void addLock(Long nodeId, Lock lock, LockType type, LockGrantType grantStatus, MemoryBudget mb)
          Add a lock to set owned by this transaction.
 void addToHandleMaps(Long handleLockId, Database databaseHandle)
          Remember how handle locks and handles match up.
protected abstract  void checkState(boolean ignoreCalledByAbort)
           
abstract  LockStats collectStats(LockStats stats)
          Get lock count, for per transaction lock stats, for internal debugging.
abstract  boolean createdNode(long nodeId)
           
 void demoteLock(long nodeId)
          Revert this lock from a write lock to a read lock.
 void dumpLockTable()
          Dump lock table, for debugging
protected abstract  long generateId(TxnManager txnManager)
          A Locker has to generate its next id.
abstract  boolean getAbortKnownDeleted(long nodeId)
           
abstract  long getAbortLsn(long nodeId)
           
 long getId()
           
 long getLockTimeout()
          Get the lock timeout period for this transaction, in milliseconds
abstract  Txn getTxnLocker()
          Returns the underlying Txn if the locker is transactional, or null if the locker is non-transactional.
(package private)  long getTxnStartMillis()
           
 long getTxnTimeOut()
           
(package private)  Lock getWaitingFor()
           
 boolean isHandleLockTransferrable()
           
abstract  boolean isReadCommittedIsolation()
          Returns whether the isolation level of this locker is read-committed.
 boolean isReadUncommittedDefault()
           
abstract  boolean isSerializableIsolation()
          Returns whether the isolation level of this locker is serializable.
(package private)  boolean isTimedOut()
           
abstract  boolean isTransactional()
          Returns whether this locker is transactional.
abstract  LockResult lock(long nodeId, LockType lockType, DatabaseImpl database)
          Get a lock of the given type on the given nodeId.
abstract  void markDeleteAtTxnEnd(DatabaseImpl db, boolean deleteAtCommit, MemoryBudget mb)
          Database operations like remove and truncate leave behind residual DatabaseImpls that must be purged at transaction commit or abort.
(package private) abstract  void moveWriteToReadLock(long nodeId, Lock lock, MemoryBudget mb)
          A lock is being demoted.
abstract  Locker newNonTxnLocker()
          Creates a fresh non-transactional locker, while retaining any transactional locks held by this locker.
abstract  void operationEnd()
          The equivalent of calling operationEnd(true).
abstract  void operationEnd(boolean operationOK)
          Different types of transactions do different things when the operation ends.
 void operationEnd(OperationStatus status)
          A SUCCESS status equals operationOk.
abstract  void registerCursor(CursorImpl cursor)
          Tell this transaction about a cursor.
 void releaseLock(long nodeId)
          Release the lock on this LN and remove from the transaction's owning set.
abstract  void releaseNonTxnLocks()
          Releases any non-transactional locks held by this locker.
protected  void rememberHandleWriteLock(Long lockId)
          If necessary, remember that this txn once owned a handle lock.
(package private) abstract  void removeLock(long nodeId, Lock lock)
          Remove the lock from the set owned by this transaction.
abstract  void setHandleLockOwner(boolean operationOK, Database dbHandle, boolean dbIsClosing)
          We're at the end of an operation.
 void setLockTimeout(long timeOutMillis)
          Set the lock timeout period for any locks in this transaction, in milliseconds.
(package private)  void setOnlyAbortable()
          Set the state of a transaction to ONLY_ABORTABLE.
 void setTxnTimeout(long timeOutMillis)
          Set the timeout period for this transaction, in milliseconds.
(package private)  void setWaitingFor(Lock lock)
           
 boolean sharesLocksWith(Locker other)
          Returns whether this locker can share locks with the given locker.
 String toString()
           
 void transferHandleLock(Database dbHandle, Locker destLocker, boolean demoteToRead)
           
(package private)  void transferHandleLockToHandle(Database dbHandle)
          The currentTxn passes responsiblity for this db handle lock to a txn owned by the Database object.
abstract  void unRegisterCursor(CursorImpl cursor)
          Remove a cursor from this txn.
(package private)  void unregisterHandle(Database dbHandle)
          Remove this Database from the protected Database handle set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

envImpl

protected EnvironmentImpl envImpl

lockManager

protected LockManager lockManager

id

protected long id

readUncommittedDefault

protected boolean readUncommittedDefault

defaultNoWait

protected boolean defaultNoWait

lockTimeOutMillis

protected long lockTimeOutMillis

deleteInfo

protected Map deleteInfo

handleLockToHandleMap

protected Map handleLockToHandleMap

handleToHandleLockMap

protected Map handleToHandleLockMap

thread

protected Thread thread
The thread that created this locker. Used for debugging, and by the ThreadLocker subclass. Note that thread may be null if the Locker is instantiated by reading the log.

Constructor Detail

Locker

public Locker(EnvironmentImpl envImpl,
              boolean readUncommittedDefault,
              boolean noWait)
       throws DatabaseException
Create a locker id. This constructor is called very often, so it should be as streamlined as possible.

Parameters:
lockManager - lock manager for this environment
readUncommittedDefault - if true, this transaction does read-uncommitted by default
noWait - if true, non-blocking lock requests are used.
Throws:
DatabaseException

Locker

Locker()
For reading from the log.

Method Detail

generateId

protected abstract long generateId(TxnManager txnManager)
A Locker has to generate its next id. Some subtypes, like BasicLocker, have a single id for all instances because they are never used for recovery. Other subtypes ask the txn manager for an id.


getId

public long getId()
Returns:
the transaction's id.

getLockTimeout

public long getLockTimeout()
Get the lock timeout period for this transaction, in milliseconds


setLockTimeout

public void setLockTimeout(long timeOutMillis)
Set the lock timeout period for any locks in this transaction, in milliseconds.


setTxnTimeout

public void setTxnTimeout(long timeOutMillis)
Set the timeout period for this transaction, in milliseconds.


isReadUncommittedDefault

public boolean isReadUncommittedDefault()
Returns:
true if transaction was created with read-uncommitted as a default.

getWaitingFor

Lock getWaitingFor()

setWaitingFor

void setWaitingFor(Lock lock)

setOnlyAbortable

void setOnlyAbortable()
Set the state of a transaction to ONLY_ABORTABLE.


checkState

protected abstract void checkState(boolean ignoreCalledByAbort)
                            throws DatabaseException
Throws:
DatabaseException

lock

public abstract LockResult lock(long nodeId,
                                LockType lockType,
                                DatabaseImpl database)
                         throws DatabaseException
Get a lock of the given type on the given nodeId.

Throws:
DatabaseException

releaseLock

public void releaseLock(long nodeId)
                 throws DatabaseException
Release the lock on this LN and remove from the transaction's owning set.

Throws:
DatabaseException

demoteLock

public void demoteLock(long nodeId)
                throws DatabaseException
Revert this lock from a write lock to a read lock.

Throws:
DatabaseException

isTransactional

public abstract boolean isTransactional()
Returns whether this locker is transactional.


isSerializableIsolation

public abstract boolean isSerializableIsolation()
Returns whether the isolation level of this locker is serializable.


isReadCommittedIsolation

public abstract boolean isReadCommittedIsolation()
Returns whether the isolation level of this locker is read-committed.


getTxnLocker

public abstract Txn getTxnLocker()
Returns the underlying Txn if the locker is transactional, or null if the locker is non-transactional. For a Txn-based locker, this method returns 'this'. For a BuddyLocker, this method may returns the buddy.


newNonTxnLocker

public abstract Locker newNonTxnLocker()
                                throws DatabaseException
Creates a fresh non-transactional locker, while retaining any transactional locks held by this locker. This method is called when the cursor for this locker is cloned.

In general, transactional lockers return 'this' when this method is called, while non-transactional lockers return a new instance.

Throws:
DatabaseException

releaseNonTxnLocks

public abstract void releaseNonTxnLocks()
                                 throws DatabaseException
Releases any non-transactional locks held by this locker. This method is called when the cursor moves to a new position or is closed.

In general, transactional lockers do nothing when this method is called, while non-transactional lockers release all locks as if operationEnd were called.

Throws:
DatabaseException

sharesLocksWith

public boolean sharesLocksWith(Locker other)
Returns whether this locker can share locks with the given locker.

All lockers share locks with a BuddyLocker whose buddy is this locker. To support BuddyLocker when overriding this method, always return true if this implementation (super.sharesLocksWith(...)) returns true.


operationEnd

public abstract void operationEnd()
                           throws DatabaseException
The equivalent of calling operationEnd(true).

Throws:
DatabaseException

operationEnd

public abstract void operationEnd(boolean operationOK)
                           throws DatabaseException
Different types of transactions do different things when the operation ends. Txns do nothing, AutoTxns commit or abort, and BasicLockers and ThreadLockers just release locks.

Parameters:
operationOK - is whether the operation succeeded, since that may impact ending behavior. (i.e for AutoTxn)
Throws:
DatabaseException

setHandleLockOwner

public abstract void setHandleLockOwner(boolean operationOK,
                                        Database dbHandle,
                                        boolean dbIsClosing)
                                 throws DatabaseException
We're at the end of an operation. Move this handle lock to the appropriate owner.

Throws:
DatabaseException

operationEnd

public void operationEnd(OperationStatus status)
                  throws DatabaseException
A SUCCESS status equals operationOk.

Throws:
DatabaseException

registerCursor

public abstract void registerCursor(CursorImpl cursor)
                             throws DatabaseException
Tell this transaction about a cursor.

Throws:
DatabaseException

unRegisterCursor

public abstract void unRegisterCursor(CursorImpl cursor)
                               throws DatabaseException
Remove a cursor from this txn.

Throws:
DatabaseException

getAbortLsn

public abstract long getAbortLsn(long nodeId)
                          throws DatabaseException
Returns:
the abort LSN for this node.
Throws:
DatabaseException

getAbortKnownDeleted

public abstract boolean getAbortKnownDeleted(long nodeId)
                                      throws DatabaseException
Returns:
the knownDeleted bit for this node.
Throws:
DatabaseException

markDeleteAtTxnEnd

public abstract void markDeleteAtTxnEnd(DatabaseImpl db,
                                        boolean deleteAtCommit,
                                        MemoryBudget mb)
                                 throws DatabaseException
Database operations like remove and truncate leave behind residual DatabaseImpls that must be purged at transaction commit or abort.

Throws:
DatabaseException

addDeleteInfo

public void addDeleteInfo(BIN bin,
                          Key deletedKey)
                   throws DatabaseException
Add delete information, to be added to the inCompressor queue when the transaction ends.

Throws:
DatabaseException

addLock

abstract void addLock(Long nodeId,
                      Lock lock,
                      LockType type,
                      LockGrantType grantStatus,
                      MemoryBudget mb)
               throws DatabaseException
Add a lock to set owned by this transaction.

Throws:
DatabaseException

createdNode

public abstract boolean createdNode(long nodeId)
                             throws DatabaseException
Returns:
true if this transaction created this node, for a operation with transactional semantics.
Throws:
DatabaseException

removeLock

abstract void removeLock(long nodeId,
                         Lock lock)
                  throws DatabaseException
Remove the lock from the set owned by this transaction. If specified to LockManager.release, the lock manager will call this when its releasing a lock.

Throws:
DatabaseException

moveWriteToReadLock

abstract void moveWriteToReadLock(long nodeId,
                                  Lock lock,
                                  MemoryBudget mb)
A lock is being demoted. Move it from the write collection into the read collection.


collectStats

public abstract LockStats collectStats(LockStats stats)
                                throws DatabaseException
Get lock count, for per transaction lock stats, for internal debugging.

Throws:
DatabaseException

isTimedOut

boolean isTimedOut()
             throws DatabaseException
Throws:
DatabaseException

getTxnTimeOut

public long getTxnTimeOut()

getTxnStartMillis

long getTxnStartMillis()

unregisterHandle

void unregisterHandle(Database dbHandle)
Remove this Database from the protected Database handle set


addToHandleMaps

public void addToHandleMaps(Long handleLockId,
                            Database databaseHandle)
Remember how handle locks and handles match up.


isHandleLockTransferrable

public boolean isHandleLockTransferrable()
Returns:
true if this txn is willing to give up the handle lock to another txn before this txn ends.

transferHandleLockToHandle

void transferHandleLockToHandle(Database dbHandle)
                          throws DatabaseException
The currentTxn passes responsiblity for this db handle lock to a txn owned by the Database object.

Throws:
DatabaseException

transferHandleLock

public void transferHandleLock(Database dbHandle,
                               Locker destLocker,
                               boolean demoteToRead)
                        throws DatabaseException
Throws:
DatabaseException

rememberHandleWriteLock

protected void rememberHandleWriteLock(Long lockId)
If necessary, remember that this txn once owned a handle lock. Done to make commit optimizations work correctly.


toString

public String toString()
Overrides:
toString in class Object

dumpLockTable

public void dumpLockTable()
                   throws DatabaseException
Dump lock table, for debugging

Throws:
DatabaseException


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