|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.txn.Locker
public abstract class Locker
Locker instances are JE's route to locking and transactional support. This class is the abstract base class for BasicLocker, ThreadLocker, Txn, MasterTxn and ReadonlyTxn. Locker instances are in fact only a transaction shell to get to the lock manager, and don't guarantee transactional semantics. Txn (includes Txns marked autoTxn) MasterTxn and ReadonlyTxn instances are truly transactional. They have potentially different transaction begin and end behaviors.
Field Summary | |
---|---|
protected boolean |
defaultNoWait
|
protected Map<Long,BINReference> |
deleteInfo
|
protected EnvironmentImpl |
envImpl
|
protected Map<Long,Set<Database>> |
handleLockToHandleMap
|
protected Map<Database,Long> |
handleToHandleLockMap
|
protected long |
id
|
protected LockManager |
lockManager
|
protected boolean |
readUncommittedDefault
|
protected Thread |
thread
The thread that created this locker. |
Constructor Summary | |
---|---|
(package private) |
Locker()
For reading from the log. |
protected |
Locker(EnvironmentImpl envImpl,
boolean readUncommittedDefault,
boolean noWait,
long mandatedId)
Create a locker id. |
Method Summary | |
---|---|
(package private) void |
addBuddy(BuddyLocker buddy)
By default the set of buddy lockers is not maintained. |
void |
addDeleteInfo(BIN bin,
Key deletedKey)
Add delete information, to be added to the inCompressor queue when the transaction ends. |
protected abstract void |
addLock(Long nodeId,
LockType type,
LockGrantType grantStatus)
Add a lock to set owned by this transaction. |
void |
addToHandleMaps(Long handleLockId,
Database databaseHandle)
Remember how handle locks and handles match up. |
(package private) void |
checkPreempted(Locker allowPreemptedLocker)
Called when obtaining a lock to cause a LockPreemptedException to be thrown if a lock was preempted earlier. |
protected abstract void |
checkState(boolean ignoreCalledByAbort)
|
(package private) void |
close()
Should be called by all subclasses when the locker is no longer used. |
abstract StatGroup |
collectStats()
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,
long mandatedId)
A Locker has to generate its next id. |
abstract long |
getAbortLsn(long nodeId)
|
boolean |
getDefaultNoWait()
|
long |
getId()
|
boolean |
getImportunate()
Get the state of a transaction's IMPORTUNATE bit. |
protected long |
getInitialLockTimeout()
|
long |
getLockTimeout()
Get the lock timeout period for this locker, in milliseconds WARNING: Be sure to always access the timeout with this accessor, since it is overridden in BuddyLocker. |
boolean |
getPreemptable()
Returns whether my locks can be stolen/preemted. |
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()
Get the transaction timeout period for this locker, in milliseconds public for jca/ra/JELocalTransaction. |
(package private) Lock |
getWaitingFor()
|
abstract WriteLockInfo |
getWriteLockInfo(long nodeId)
|
boolean |
isHandleLockTransferrable()
|
(package private) boolean |
isPreempted()
For unit testing. |
abstract boolean |
isReadCommittedIsolation()
Returns whether the isolation level of this locker is read-committed. |
boolean |
isReadUncommittedDefault()
|
boolean |
isReplicationDefined()
Used for debugging checks to ensure that replication-defined lockers are used for accessing replicated databases. |
boolean |
isRolledBack()
|
abstract boolean |
isSerializableIsolation()
Returns whether the isolation level of this locker is serializable. |
boolean |
isTimedOut()
|
abstract boolean |
isTransactional()
Returns whether this locker is transactional. |
LockResult |
lock(long nodeId,
LockType lockType,
boolean noWait,
DatabaseImpl database)
Request a blocking or non-blocking lock of the given type on the given nodeId. |
abstract boolean |
lockingRequired()
Returns true if locking is required for this Locker. |
(package private) abstract LockResult |
lockInternal(long nodeId,
LockType lockType,
boolean noWait,
DatabaseImpl database)
Abstract method to a blocking or non-blocking lock of the given type on the given nodeId. |
abstract void |
markDeleteAtTxnEnd(DatabaseImpl db,
boolean deleteAtCommit)
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)
A lock is being demoted. |
abstract Locker |
newNonTxnLocker()
Creates a fresh non-transactional locker, while retaining any transactional locks held by this locker. |
LockResult |
nonBlockingLock(long nodeId,
LockType lockType,
DatabaseImpl database)
Request a non-blocking lock of the given type on the given nodeId. |
abstract void |
nonTxnOperationEnd()
Releases locks and closes the locker at the end of a non-transactional cursor operation. |
void |
openCursorHook()
Overridden to perform actions in a non-transactional cursor when it is opened, for example, ReplicaThreadLocker performs consistency checks. |
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. |
boolean |
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. |
(package private) void |
removeBuddy(BuddyLocker buddy)
By default the set of buddy lockers is not maintained. |
(package private) abstract void |
removeLock(long nodeId)
Remove the lock from the set owned by this transaction. |
void |
setClosingLocker(Locker closingLocker)
This method is called to set the closingLocker when a cursor has been duplicated prior to being moved. |
abstract void |
setHandleLockOwner(boolean operationOK,
Database dbHandle,
boolean dbIsClosing)
We're at the end of an operation. |
void |
setImportunate(boolean importunate)
Set the state of a transaction's IMPORTUNATE bit. |
void |
setLockTimeout(long timeout)
Set the lock timeout period for any locks in this transaction, in milliseconds. |
void |
setOnlyAbortable(OperationFailureException cause)
Set the state of a transaction to abort-only. |
void |
setPreemptable(boolean preemptable)
Allows/disallows my locks from being stolen/preemted. |
void |
setPreempted()
Called when a lock is stolen from this locker by the HA replayer. |
void |
setTxnTimeout(long timeout)
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. |
(package private) void |
throwIfPreempted(Locker allowPreemptedLocker)
Called by checkPreempted to cause a LockPreemptedException to be thrown if a lock was preempted earlier. |
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 |
---|
protected EnvironmentImpl envImpl
protected LockManager lockManager
protected long id
protected boolean readUncommittedDefault
protected boolean defaultNoWait
protected Map<Long,BINReference> deleteInfo
protected Map<Long,Set<Database>> handleLockToHandleMap
protected Map<Database,Long> handleToHandleLockMap
protected Thread thread
Constructor Detail |
---|
protected Locker(EnvironmentImpl envImpl, boolean readUncommittedDefault, boolean noWait, long mandatedId)
lockManager
- lock manager for this environmentreadUncommittedDefault
- if true, this transaction does
read-uncommitted by defaultnoWait
- if true, non-blocking lock requests are used.Locker()
Method Detail |
---|
protected long getInitialLockTimeout()
protected abstract long generateId(TxnManager txnManager, long mandatedId)
public long getId()
public boolean getDefaultNoWait()
public long getLockTimeout()
public void setLockTimeout(long timeout)
timeout
- The timeout value for the transaction lifetime, in
milliseconds. A value of 0 disables timeouts for the transaction.
IllegalArgumentException
- via Transaction.setLockTimeoutpublic void setTxnTimeout(long timeout)
timeout
- The timeout value for the transaction lifetime, in
microseconds. A value of 0 disables timeouts for the transaction.
IllegalArgumentException
- via Transaction.setLockTimeoutpublic boolean isReadUncommittedDefault()
Lock getWaitingFor()
void setWaitingFor(Lock lock)
public void setOnlyAbortable(OperationFailureException cause)
public void setImportunate(boolean importunate)
public boolean getImportunate()
public void setPreemptable(boolean preemptable)
public boolean getPreemptable()
public void setPreempted()
void checkPreempted(Locker allowPreemptedLocker) throws OperationFailureException
allowPreemptedLocker
- is a locker that is being closed as the
result of a cursor move operation. If the operation is successful then
allowPreemptedLocker will be closed, and the fact that a lock has been
stolen from allowPreemptedLocker can be ignored.
OperationFailureException
final void throwIfPreempted(Locker allowPreemptedLocker) throws OperationFailureException
OperationFailureException
checkPreempted(com.sleepycat.je.txn.Locker)
final boolean isPreempted()
public void setClosingLocker(Locker closingLocker)
closingLocker
- the old locker that will be closed if the new
cursor (using this locker) is moved successfully.protected abstract void checkState(boolean ignoreCalledByAbort) throws DatabaseException
DatabaseException
public void openCursorHook()
public boolean isReplicationDefined()
abstract LockResult lockInternal(long nodeId, LockType lockType, boolean noWait, DatabaseImpl database) throws LockConflictException, DatabaseException
nodeId
- is the node to lock.lockType
- is the type of lock to request.noWait
- is true to override the defaultNoWait setting. If true,
or if defaultNoWait is true, throws LockNotAvailableException if the
lock cannot be granted without waiting.database
- is the database containing nodeId.
LockConflictException
- if a blocking lock could not be acquired.
DatabaseException
public LockResult lock(long nodeId, LockType lockType, boolean noWait, DatabaseImpl database) throws LockNotAvailableException, LockConflictException
nodeId
- is the node to lock.lockType
- is the type of lock to request.noWait
- is true to override the defaultNoWait setting. If true,
or if defaultNoWait is true, throws LockNotAvailableException if the
lock cannot be granted without waiting.database
- is the database containing nodeId.
LockNotAvailableException
- if a non-blocking lock was denied.
LockConflictException
- if a blocking lock could not be acquired.public LockResult nonBlockingLock(long nodeId, LockType lockType, DatabaseImpl database)
Unlike lock(), this method returns LockGrantType.DENIED if the lock is denied rather than throwing LockNotAvailableException. This method should therefore not be used as the final lock for a user operation, since in that case LockNotAvailableException should be thrown for a denied lock. It is normally used only to probe for a lock internally, and other recourse is taken if the lock is denied.
nodeId
- is the node to lock.lockType
- is the type of lock to request.database
- is the database containing nodeId.public boolean releaseLock(long nodeId) throws DatabaseException
DatabaseException
public void demoteLock(long nodeId) throws DatabaseException
DatabaseException
public abstract boolean isTransactional()
public abstract boolean isSerializableIsolation()
public abstract boolean isReadCommittedIsolation()
public abstract Txn getTxnLocker()
public abstract Locker newNonTxnLocker() throws DatabaseException
This method must return a locker that shares locks with this locker, e.g., a ThreadLocker.
In general, transactional lockers return 'this' when this method is called, while non-transactional lockers return a new instance.
DatabaseException
public abstract void releaseNonTxnLocks() throws DatabaseException
In general, transactional lockers do nothing when this method is called, while non-transactional lockers release all locks as if operationEnd were called.
DatabaseException
public abstract void nonTxnOperationEnd() throws DatabaseException
DatabaseException
void addBuddy(BuddyLocker buddy)
void removeBuddy(BuddyLocker buddy)
public boolean sharesLocksWith(Locker other)
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.
public final void operationEnd() throws DatabaseException
DatabaseException
public final void operationEnd(OperationStatus status) throws DatabaseException
DatabaseException
public abstract void operationEnd(boolean operationOK) throws DatabaseException
operationOK
- is whether the operation succeeded, since
that may impact ending behavior. (i.e for an auto Txn)
DatabaseException
void close() throws DatabaseException
DatabaseException
public abstract void setHandleLockOwner(boolean operationOK, Database dbHandle, boolean dbIsClosing) throws DatabaseException
DatabaseException
public abstract void registerCursor(CursorImpl cursor)
public abstract void unRegisterCursor(CursorImpl cursor)
public abstract boolean lockingRequired()
public abstract long getAbortLsn(long nodeId)
public abstract WriteLockInfo getWriteLockInfo(long nodeId)
public abstract void markDeleteAtTxnEnd(DatabaseImpl db, boolean deleteAtCommit) throws DatabaseException
DatabaseException
public void addDeleteInfo(BIN bin, Key deletedKey)
protected abstract void addLock(Long nodeId, LockType type, LockGrantType grantStatus) throws DatabaseException
DatabaseException
public abstract boolean createdNode(long nodeId)
abstract void removeLock(long nodeId) throws DatabaseException
DatabaseException
abstract void moveWriteToReadLock(long nodeId, Lock lock)
public abstract StatGroup collectStats() throws DatabaseException
DatabaseException
public boolean isTimedOut()
public long getTxnTimeout()
long getTxnStartMillis()
public boolean isRolledBack()
void unregisterHandle(Database dbHandle)
public void addToHandleMaps(Long handleLockId, Database databaseHandle)
public boolean isHandleLockTransferrable()
void transferHandleLockToHandle(Database dbHandle) throws DatabaseException
DatabaseException
public void transferHandleLock(Database dbHandle, Locker destLocker, boolean demoteToRead) throws DatabaseException
DatabaseException
public String toString()
toString
in class Object
public void dumpLockTable() throws DatabaseException
DatabaseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |