Package com.atlassian.beehive.db.spi
Interface ClusterLockDao
public interface ClusterLockDao
Provides access to the Cluster Lock DB table.
Clustered applications need to implement this DAO in order to be able to use the
DatabaseClusterLockService.-
Method Summary
Modifier and TypeMethodDescriptionReturns lock details for all cluster locks being held by any cluster node.getClusterLockStatusByName(String lockName) Returns the cluster lock details for the given name, or null if no such lock has ever been created.voidinsertEmptyClusterLock(String lockName) Attempts to insert an "unlocked" DB row for the named lock.voidReleases any locks held by the this node.voidrenewLease(String lockName) Prolong the lock's lease, assuming it has current node set as the owner(but regardless of time passed since previous renewal).booleantryAcquireLock(String lockName) Attempts to acquire ownership of a named lock by current cluster node.voidUnlock the named lock, if this node still holds the lock.
-
Method Details
-
getAllHeldClusterLocks
Returns lock details for all cluster locks being held by any cluster node.- Returns:
- a list of cluster lock details for all locks held by any node, or an empty list if no such locks exist.
-
getClusterLockStatusByName
Returns the cluster lock details for the given name, or null if no such lock has ever been created.- Parameters:
lockName- the globally unique id of the lock- Returns:
- the cluster lock details for the given name, or null if no such lock has ever been created.
-
tryAcquireLock
Attempts to acquire ownership of a named lock by current cluster node. A lock should be treated as eligible to be acquired when one of the following is true:- It has no node set as an owner
- It has the current node set as an owner
- It has an other node set as an owner, but its last update time is older than
LockExpiryConfiguration.getExpiryPeriodDurationSeconds()from current db time
- Parameters:
lockName- the globally unique id of the lock- Returns:
- true if we acquired the lock, false if the the locks already has a valid owner.
-
insertEmptyClusterLock
Attempts to insert an "unlocked" DB row for the named lock. (That is, the "locked by" column should be NULL).You can assume that the lock name is not null. This insert should only insert a single row for the given lock name (which will never be null). This is expected to be achieved simply by putting a unique constraint on the LOCK_NAME column.
If the row already exists, then this method must catch the unique constraint violation and terminate normally. All other SQL errors should be thrown as a RuntimeException of some kind.
- Parameters:
lockName- the lock identifier
-
unlock
Unlock the named lock, if this node still holds the lock. If for some reason we no longer hold the lock then we should not unlock it, just report it byIllegalMonitorStateException. Failure to perform the unlock because of enviromental problems should result with exception, to allow retries.- Parameters:
lockName- the lock identifier
-
releaseLocksHeldByNode
void releaseLocksHeldByNode()Releases any locks held by the this node.- Since:
- 1.0
-
renewLease
Prolong the lock's lease, assuming it has current node set as the owner(but regardless of time passed since previous renewal). If lock being no longer owned by this node is detected, it should be reported byIllegalMonitorStateException.- Parameters:
lockName- The lock identifier
-