Class LockSpace

java.lang.Object
org.apache.derby.impl.services.locks.LockSpace
All Implemented Interfaces:
CompatibilitySpace

final class LockSpace extends Object implements CompatibilitySpace
A LockSpace represents the complete set of locks held within a single compatibility space, broken into groups of locks. A LockSpace contains a HashMap keyed by the group reference, the data for each key is a HashMap of Lock's.

A LockSpace can have an owner (for instance a transaction). Currently, the owner is used by the virtual lock table to find out which transaction a lock belongs to. Some parts of the code also use the owner as a group object which guarantees that the lock is released on a commit or an abort. The owner has no special meaning to the lock manager and can be any object, including null.

  • Field Details

    • groups

      private final HashMap<Object,HashMap<Lock,Lock>> groups
      Map from group references to groups of locks.
    • owner

      private final LockOwner owner
      Reference to the owner of this compatibility space.
    • MAX_CACHED_GROUPS

      private static final int MAX_CACHED_GROUPS
      The maximum number of elements to cache in spareGroups.
      See Also:
    • spareGroups

      private final ArrayDeque<HashMap<Lock,Lock>> spareGroups
      Cached HashMaps for storing lock groups.
    • callbackGroup

      private Object callbackGroup
    • limit

      private int limit
    • nextLimitCall

      private int nextLimitCall
    • callback

      private Limit callback
    • inLimit

      private boolean inLimit
  • Constructor Details

    • LockSpace

      LockSpace(LockOwner owner)
      Creates a new LockSpace instance.
      Parameters:
      owner - an object representing the owner of the compatibility space
  • Method Details

    • getOwner

      public LockOwner getOwner()
      Get the object representing the owner of the compatibility space.
      Specified by:
      getOwner in interface CompatibilitySpace
      Returns:
      the owner of the compatibility space
    • addLock

      protected void addLock(Object group, Lock lock) throws StandardException
      Add a lock to a group.
      Throws:
      StandardException
    • unlockGroup

      void unlockGroup(LockTable lset, Object group)
      Unlock all the locks in a group and then remove the group.
    • getGroupMap

      private HashMap<Lock,Lock> getGroupMap(Object group)
    • saveGroup

      private void saveGroup(HashMap<Lock,Lock> dl)
    • unlockGroup

      void unlockGroup(LockTable lset, Object group, Matchable key)
      Unlock all locks in the group that match the key
    • transfer

      void transfer(Object oldGroup, Object newGroup)
    • mergeGroups

      private void mergeGroups(HashMap<Lock,Lock> from, HashMap<Lock,Lock> into)
    • unlockReference

      int unlockReference(LockTable lset, Lockable ref, Object qualifier, Object group)
    • areLocksHeld

      boolean areLocksHeld(Object group)
      Return true if locks are held in a group
    • areLocksHeld

      boolean areLocksHeld()
      Return true if locks are held in this compatibility space.
      Returns:
      true if locks are held, false otherwise
    • isLockHeld

      boolean isLockHeld(Object group, Lockable ref, Object qualifier)
    • setLimit

      void setLimit(Object group, int limit, Limit callback)
    • clearLimit

      void clearLimit(Object group)
      Clear a limit set by setLimit.
    • deadlockCount

      int deadlockCount(int bail)
      Return a count of the number of locks held by this space. The argument bail indicates at which point the counting should bail out and return the current count. This routine will bail if the count is greater than bail. Thus this routine is intended to for deadlock code to find the space with the fewest number of locks.