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 TypeMethodDescriptionvoidTries to acquire a lock for a transaction.booleanTries to acquire a lock for a transaction.default voidDiscard any local record of held locks, without touching ZooKeeper.booleanisAcquired(UUID theTxId) default booleanWhether this process holds the lock for any transaction, by its own records.voidRelease a lock for a transaction.voidRelease all locks for transactions that have been acquired.default booleanreleaseIfHeld(UUID theTxId) Release the lock for a transaction if it is still held.
-
Method Details
-
acquire
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
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
Release a lock for a transaction.- Parameters:
theTxId-- Throws:
Exception
-
releaseIfHeld
Release the lock for a transaction if it is still held. A concurrent rollback may have released it already, andrelease(java.util.UUID)throwsIllegalMonitorStateExceptiononce 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
- Returns:
- true if a lock for the specific transaction is acquired by any thread/process.
- Throws:
IOException
-
releaseAll
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.
-