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 Details

    • getAllHeldClusterLocks

      @Nonnull List<ClusterLockStatus> 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

      @Nullable ClusterLockStatus getClusterLockStatusByName(@Nonnull String lockName)
      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

      boolean tryAcquireLock(@Nonnull String lockName)
      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:
      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

      void insertEmptyClusterLock(@Nonnull String lockName)
      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

      void unlock(@Nonnull String lockName)
      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 by IllegalMonitorStateException. 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

      void renewLease(@Nonnull String lockName)
      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 by IllegalMonitorStateException.
      Parameters:
      lockName - The lock identifier