Interface InterProcessTxLock

All Known Implementing Classes:
NonReentrantMutex

public interface InterProcessTxLock
Similar to an InterProcessLock, but we track the locks with specific transaction ids.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    acquire(UUID theTxId)
    Tries to acquire a lock for a transaction.
    boolean
    acquire(UUID theTxId, long theTime, TimeUnit theTimeUnit)
    Tries to acquire a lock for a transaction.
    default void
    Discard any local record of held locks, without touching ZooKeeper.
    boolean
    isAcquired(UUID theTxId)
     
    default boolean
    Whether this process holds the lock for any transaction, by its own records.
    void
    release(UUID theTxId)
    Release a lock for a transaction.
    void
    Release all locks for transactions that have been acquired.
    default boolean
    Release the lock for a transaction if it is still held.
  • Method Details

    • acquire

      void acquire(UUID theTxId) throws Exception
      Tries to acquire a lock for a transaction. Each call to acquire for a transaction should be balanced with a call to release with the same transaction id. This method blocks until it is able to obtain the lock.
      Parameters:
      theTxId -
      Throws:
      Exception
    • acquire

      boolean acquire(UUID theTxId, long theTime, TimeUnit theTimeUnit) throws Exception
      Tries to acquire a lock for a transaction. Each call to acquire for a transaction should be balanced with a call to release with the same transaction id. This method blocks until the timeout is reached.
      Parameters:
      theTxId -
      theTime -
      theTimeUnit -
      Returns:
      Throws:
      Exception
    • release

      void release(UUID theTxId) throws Exception
      Release a lock for a transaction.
      Parameters:
      theTxId -
      Throws:
      Exception
    • releaseIfHeld

      default boolean releaseIfHeld(UUID theTxId) throws Exception
      Release the lock for a transaction if it is still held. A concurrent rollback may have released it already, and release(java.util.UUID) throws IllegalMonitorStateException once it is gone.

      The default implementation is not an atomic check-and-release

      Returns:
      true if the lock was held and is now released
      Throws:
      Exception
    • isAcquired

      boolean isAcquired(UUID theTxId) throws IOException
      Returns:
      true if a lock for the specific transaction is acquired by any thread/process.
      Throws:
      IOException
    • releaseAll

      void releaseAll() throws Exception
      Release all locks for transactions that have been acquired.
      Throws:
      Exception
    • invalidateAll

      default void invalidateAll()
      Discard any local record of held locks, without touching ZooKeeper.

      Called when this node's ZooKeeper session is lost. Lock nodes are ephemeral, so the session ending is itself the release -- unlike releaseAll(), there is nothing left to delete.

      The default does nothing. Implementations that cache lock state must override it.

    • isHeldInProcess

      default boolean isHeldInProcess()
      Whether this process holds the lock for any transaction, by its own records. The default reports false; implementations that record locks must override it.