com.sleepycat.je.txn
Class ThinLockImpl

java.lang.Object
  extended by com.sleepycat.je.txn.LockInfo
      extended by com.sleepycat.je.txn.ThinLockImpl
All Implemented Interfaces:
java.lang.Cloneable

public class ThinLockImpl
extends LockInfo

Implements a lightweight Lock with no waiters and only a single Owner. If, during an operation (lock, transfer, or transferMultiple) more than one owner or waiter is required, then this will mutate to a LockImpl, perform the requested operation, and return the new LockImpl to the caller. public for Sizeof.


Field Summary
 
Fields inherited from class com.sleepycat.je.txn.LockInfo
locker, lockType
 
Constructor Summary
ThinLockImpl()
          Create a Lock.
 
Method Summary
 void demote(Locker locker)
          Downgrade a write lock to a read lock.
 void flushWaiter(Locker locker, MemoryBudget mb, int lockTableIndex)
          Remove this locker from the waiter list.
 java.util.Set<LockInfo> getOwnersClone()
          Get a new Set of the owners.
 java.util.List<LockInfo> getWaitersListClone()
          Get a list of waiters for debugging and error messages.
 Locker getWriteOwnerLocker()
          Return the locker that has a write ownership on this lock.
 boolean isOwnedWriteLock(Locker locker)
          Return true if locker is an owner of this Lock and this is a write lock.
 boolean isOwner(Locker locker, LockType lockType)
          Return true if locker is an owner of this Lock for lockType, false otherwise.
 boolean isThin()
           
 boolean isWaiter(Locker locker)
          Return true if locker is a waiter on this Lock.
 com.sleepycat.je.txn.LockAttemptResult lock(LockType requestType, Locker locker, boolean nonBlockingRequest, MemoryBudget mb, int lockTableIndex)
          Attempts to acquire the lock and returns the LockGrantType.
 int nOwners()
           
 int nWaiters()
           
 java.util.Set<Locker> release(Locker locker, MemoryBudget mb, int lockTableIndex)
          Releases a lock and moves the next waiter(s) to the owners.
 java.lang.String toString()
          Debug dumper.
 com.sleepycat.je.txn.Lock transfer(java.lang.Long nodeId, Locker currentLocker, Locker destLocker, MemoryBudget mb, int lockTableIndex)
          Transfer a lock from one transaction to another.
 com.sleepycat.je.txn.Lock transferMultiple(java.lang.Long nodeId, Locker currentLocker, Locker[] destLockers, MemoryBudget mb, int lockTableIndex)
          Transfer a lock from one transaction to many others.
 
Methods inherited from class com.sleepycat.je.txn.LockInfo
clone, dump, getDeadlockStackTrace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThinLockImpl

public ThinLockImpl()
Create a Lock. Public for Sizeof.

Method Detail

getWaitersListClone

public java.util.List<LockInfo> getWaitersListClone()
Get a list of waiters for debugging and error messages.


flushWaiter

public void flushWaiter(Locker locker,
                        MemoryBudget mb,
                        int lockTableIndex)
Remove this locker from the waiter list.


getOwnersClone

public java.util.Set<LockInfo> getOwnersClone()
Get a new Set of the owners.


isOwner

public boolean isOwner(Locker locker,
                       LockType lockType)
Return true if locker is an owner of this Lock for lockType, false otherwise. This method is only used by unit tests.


isOwnedWriteLock

public boolean isOwnedWriteLock(Locker locker)
Return true if locker is an owner of this Lock and this is a write lock.


isWaiter

public boolean isWaiter(Locker locker)
Return true if locker is a waiter on this Lock. This method is only used by unit tests.


nWaiters

public int nWaiters()

nOwners

public int nOwners()

lock

public com.sleepycat.je.txn.LockAttemptResult lock(LockType requestType,
                                                   Locker locker,
                                                   boolean nonBlockingRequest,
                                                   MemoryBudget mb,
                                                   int lockTableIndex)
                                            throws DatabaseException
Attempts to acquire the lock and returns the LockGrantType. Assumes we hold the lockTableLatch when entering this method.

Throws:
DatabaseException

release

public java.util.Set<Locker> release(Locker locker,
                                     MemoryBudget mb,
                                     int lockTableIndex)
Releases a lock and moves the next waiter(s) to the owners.

Returns:
- null if we were not the owner, - a non-empty set if owners should be notified after releasing, - an empty set if no notification is required.

demote

public void demote(Locker locker)
Downgrade a write lock to a read lock.


transfer

public com.sleepycat.je.txn.Lock transfer(java.lang.Long nodeId,
                                          Locker currentLocker,
                                          Locker destLocker,
                                          MemoryBudget mb,
                                          int lockTableIndex)
                                   throws DatabaseException
Transfer a lock from one transaction to another. Make sure that this destination locker is only present as a single reader or writer.

Throws:
DatabaseException

transferMultiple

public com.sleepycat.je.txn.Lock transferMultiple(java.lang.Long nodeId,
                                                  Locker currentLocker,
                                                  Locker[] destLockers,
                                                  MemoryBudget mb,
                                                  int lockTableIndex)
                                           throws DatabaseException
Transfer a lock from one transaction to many others. Only really needed for case where a write handle lock is being transferred to multiple read handles.

Throws:
DatabaseException

getWriteOwnerLocker

public Locker getWriteOwnerLocker()
Return the locker that has a write ownership on this lock. If no write owner exists, return null.


isThin

public boolean isThin()

toString

public java.lang.String toString()
Debug dumper.

Overrides:
toString in class LockInfo