com.sleepycat.je.txn
Class BuddyLocker

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

public class BuddyLocker
extends BasicLocker

Extends BasicLocker to share locks with another specific locker.

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 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.


Field Summary
 
Fields inherited from class com.sleepycat.je.txn.Locker
defaultNoWait, deleteInfo, envImpl, id, lockManager, readUncommittedDefault, thread
 
Constructor Summary
protected BuddyLocker(EnvironmentImpl env, Locker buddy)
          Creates a BuddyLocker.
 
Method Summary
 void checkPreempted(Locker allowPreemptedLocker)
          Forwards to the parent buddy locker, so the buddy can check itself and all of its child buddies.
(package private)  void close()
          Should be called by all subclasses when the locker is no longer used.
static BuddyLocker createBuddyLocker(EnvironmentImpl env, Locker buddy)
           
(package private)  Locker getBuddy()
          Returns the buddy locker.
 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 getTxnTimeout()
          Returns the transaction timeout of the buddy locker, since this locker has no independent timeout.
 boolean isReplicationDefined()
          Consider this locker replication-defined if its buddy (Txn) is replication-defined.
 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.
 
Methods inherited from class com.sleepycat.je.txn.BasicLocker
addLock, checkState, collectStats, createBasicLocker, createBasicLocker, createdNode, generateId, getWriteLockInfo, getWriteOwnerLocker, isReadCommittedIsolation, isSerializableIsolation, isTransactional, lockingRequired, lockInternal, markDeleteAtTxnEnd, moveWriteToReadLock, newNonTxnLocker, nonTxnOperationEnd, operationEnd, preLogWithoutLock, registerCursor, removeLock, unRegisterCursor
 
Methods inherited from class com.sleepycat.je.txn.Locker
addBuddy, addDeleteInfo, addOpenedDatabase, allowReleaseLockAfterLsnChange, demoteLock, disallowReplicaWrite, dumpLockTable, getDefaultNoWait, getEnvironment, getId, getImportunate, getInitialLockTimeout, getPreemptable, getTxnStartMillis, getWaitingFor, isPreempted, isReadUncommittedDefault, isRolledBack, isValid, lock, lockAfterLsnChange, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, removeBuddy, setAllowMultithreadedAccess, setClosingLocker, setImportunate, setPreemptable, setPreempted, setWaitingFor, throwIfPreempted, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BuddyLocker

protected BuddyLocker(EnvironmentImpl env,
                      Locker buddy)
Creates a BuddyLocker.

Method Detail

createBuddyLocker

public static BuddyLocker createBuddyLocker(EnvironmentImpl env,
                                            Locker buddy)
                                     throws DatabaseException
Throws:
DatabaseException

close

void close()
Description copied from class: Locker
Should be called by all subclasses when the locker is no longer used. For Txns and auto Txns this is at commit or abort. For non-transactional lockers it is at operationEnd.

Overrides:
close in class Locker

getBuddy

Locker getBuddy()
Returns the buddy locker.


getTxnLocker

public Txn getTxnLocker()
Forwards this call to the buddy locker. This object itself is never transactional but the buddy may be.

Overrides:
getTxnLocker in class BasicLocker

getTransaction

public Transaction getTransaction()
Forwards this call to the buddy locker. This object itself is never transactional but the buddy may be.

Overrides:
getTransaction in class Locker

releaseNonTxnLocks

public void releaseNonTxnLocks()
                        throws DatabaseException
Forwards this call to the base class and to the buddy locker.

Overrides:
releaseNonTxnLocks in class BasicLocker
Throws:
DatabaseException

sharesLocksWith

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

Overrides:
sharesLocksWith in class Locker

getLockTimeout

public long getLockTimeout()
Returns the lock timeout of the buddy locker, since this locker has no independent timeout.

Overrides:
getLockTimeout in class Locker

getTxnTimeout

public long getTxnTimeout()
Returns the transaction timeout of the buddy locker, since this locker has no independent timeout.

Overrides:
getTxnTimeout in class Locker

setLockTimeout

public void setLockTimeout(long timeout)
Sets the lock timeout of the buddy locker, since this locker has no independent timeout.

Overrides:
setLockTimeout in class Locker
Parameters:
timeout - The timeout value for the transaction lifetime, in milliseconds. A value of 0 disables timeouts for the transaction.

setTxnTimeout

public void setTxnTimeout(long timeout)
Sets the transaction timeout of the buddy locker, since this locker has no independent timeout.

Overrides:
setTxnTimeout in class Locker
Parameters:
timeout - The timeout value for the transaction lifetime, in microseconds. A value of 0 disables timeouts for the transaction.

isTimedOut

public boolean isTimedOut()
Returns whether the buddy locker is timed out, since this locker has no independent timeout.

Overrides:
isTimedOut in class Locker

setOnlyAbortable

public void setOnlyAbortable(OperationFailureException cause)
Forwards to the buddy locker, since the buddy may be transactional.

Overrides:
setOnlyAbortable in class Locker

checkPreempted

public void checkPreempted(Locker allowPreemptedLocker)
                    throws OperationFailureException
Forwards to the parent buddy locker, so the buddy can check itself and all of its child buddies.

Overrides:
checkPreempted in class Locker
Parameters:
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.
Throws:
OperationFailureException

isReplicationDefined

public boolean isReplicationDefined()
Consider this locker replication-defined if its buddy (Txn) is replication-defined.

Overrides:
isReplicationDefined in class Locker


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