public class BuddyLocker extends BasicLocker
In general, a BuddyLocker can be used whenever the primary (API) locker is in use, and we need to lock a node and release that lock before the primary locker transaction ends. In other words, for this particular lock we don't want to use two-phase locking. To accomplish that we use a separate BuddyLocker instance to hold the lock, while sharing locks with the primary locker. The BuddyLocker can be closed to release this particular lock, without releasing the other locks held by the primary locker.
In particular, a ReadCommittedLocker extends BuddyLocker. The ReadCommittedLocker keeps track of read locks, while its buddy Txn keeps track of write locks. The two lockers must share locks to prevent conflicts.
In addition, a BuddyLocker is used when acquiring a RANGE_INSERT lock. RANGE_INSERT only needs to be held until the point we have inserted the new node into the BIN. A separate locker is therefore used so we can release that lock separately when the insertion into the BIN is complete. But the RANGE_INSERT lock must not conflict with locks held by the primary locker. So a BuddyLocker is used that shares locks with the primary locker.
afterWaiterHook, envImpl, id, lockManager, thread| Modifier | Constructor and Description |
|---|---|
protected |
BuddyLocker(EnvironmentImpl env,
Locker buddy)
Creates a BuddyLocker.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkPreempted(Locker allowPreemptedLocker)
Forwards to the parent buddy locker, so the buddy can check itself and
all of its child buddies.
|
static BuddyLocker |
createBuddyLocker(EnvironmentImpl env,
Locker buddy) |
long |
getLockTimeout()
Returns the lock timeout of the buddy locker, since this locker has no
independent timeout.
|
Transaction |
getTransaction()
Forwards this call to the buddy locker.
|
Txn |
getTxnLocker()
Forwards this call to the buddy locker.
|
long |
getTxnStartMillis()
Returns the buddy locker's start time, since this locker has no
independent timeout.
|
long |
getTxnTimeout()
Returns the transaction timeout of the buddy locker, since this locker
has no independent timeout.
|
boolean |
isLocalWrite()
Consider this locker local-write if its buddy is local-write.
|
boolean |
isReplicated()
Consider this locker replicated if its buddy (Txn) is replicated.
|
boolean |
isTimedOut()
Returns whether the buddy locker is timed out, since this locker has no
independent timeout.
|
void |
releaseNonTxnLocks()
Forwards this call to the base class and to the buddy locker.
|
void |
setLockTimeout(long timeout)
Sets the lock timeout of the buddy locker, since this locker has no
independent timeout.
|
void |
setOnlyAbortable(OperationFailureException cause)
Forwards to the buddy locker, since the buddy may be transactional.
|
void |
setTxnTimeout(long timeout)
Sets the transaction timeout of the buddy locker, since this locker has
no independent timeout.
|
boolean |
sharesLocksWith(Locker other)
Returns whether this locker can share locks with the given locker.
|
addDbCleanup, addLock, checkState, collectStats, createBasicLocker, createBasicLocker, generateId, getWriteLockInfo, getWriteOwnerLocker, isReadCommittedIsolation, isSerializableIsolation, isTransactional, lockingRequired, lockInternal, newNonTxnLocker, nonTxnOperationEnd, operationEnd, preLogWithoutLock, registerCursor, unRegisterCursoraddDeleteInfo, addOpenedDatabase, allowReleaseLockAfterLsnChange, demoteLock, disallowReplicaWrite, dumpLockTable, getDefaultNoWait, getEnvironment, getId, getImportunate, getInitialLockTimeout, getPreemptable, isReadOnly, isReadUncommittedDefault, isRolledBack, isValid, lock, lockAfterLsnChange, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, setClosingLocker, setDefaultNoWait, setImportunate, setPreemptable, setPreempted, toStringprotected BuddyLocker(EnvironmentImpl env, Locker buddy)
public static BuddyLocker createBuddyLocker(EnvironmentImpl env, Locker buddy) throws DatabaseException
DatabaseExceptionpublic Txn getTxnLocker()
getTxnLocker in class BasicLockerpublic Transaction getTransaction()
getTransaction in class Lockerpublic void releaseNonTxnLocks()
throws DatabaseException
releaseNonTxnLocks in class BasicLockerDatabaseExceptionpublic boolean sharesLocksWith(Locker other)
sharesLocksWith in class Lockerpublic long getLockTimeout()
getLockTimeout in class Lockerpublic long getTxnTimeout()
getTxnTimeout in class Lockerpublic void setLockTimeout(long timeout)
setLockTimeout in class Lockertimeout - The timeout value for the transaction lifetime, in
milliseconds. A value of 0 disables timeouts for the transaction.public void setTxnTimeout(long timeout)
setTxnTimeout in class Lockertimeout - The timeout value for the transaction lifetime, in
microseconds. A value of 0 disables timeouts for the transaction.public boolean isTimedOut()
isTimedOut in class Lockerpublic long getTxnStartMillis()
public void setOnlyAbortable(OperationFailureException cause)
setOnlyAbortable in class Lockerpublic void checkPreempted(Locker allowPreemptedLocker) throws OperationFailureException
checkPreempted in class LockerallowPreemptedLocker - 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.OperationFailureExceptionpublic boolean isReplicated()
isReplicated in class Lockerpublic boolean isLocalWrite()
isLocalWrite in class LockerCopyright © 2024. All rights reserved.