Class BambooClusterLockServiceImpl
- All Implemented Interfaces:
BambooClusterLockService,com.atlassian.beehive.ClusterLockService,com.atlassian.beehive.core.ManagedClusterLockService
- Since:
- 9.5
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBambooClusterLockServiceImpl(@NotNull BambooClusterLockDao bambooClusterLockDao, @NotNull ClusterNodeHeartbeatDao clusterNodeHeartbeatDao) -
Method Summary
Modifier and TypeMethodDescription@Nullable com.atlassian.beehive.core.ClusterLockStatusgetClusterLockStatusByName(@NotNull String lockName) Returns the cluster lock details for the given name and or null if no such lock has ever been created.static @NotNull StringgetReadLockName(@NotNull String lockName) static @NotNull StringgetReadLockNameForNode(@NotNull String lockName, @NotNull String nodeId) static @NotNull StringgetWriteLockName(@NotNull String lockName) voidlockForReading(@NotNull String lockName, long lockTimeoutSeconds) Locks for READING the lock identified by the given name.voidlockForReading(@NotNull String lockName, @NotNull String nodeId, long lockTimeoutSeconds) voidlockForWriting(@NotNull String lockName, long lockTimeoutSeconds) Locks for WRITING the lock identified by the given name.voidreleaseLock(@NotNull String lockName) Release ownership of a named lock by current cluster node.voidReleases any locks held by the this node.voidreleaseReadLock(@NotNull String lockName) Release READ ownership of a named lock by current cluster node.voidreleaseWriteLock(@NotNull String lockName) Release WRITE ownership of a named lock by current cluster node.voidshutdown()Shuts the service down, stopping all accessory jobs (e..g: lock renewer) for all locks.booleantryAcquireLock(@NotNull String lockName, long lockTimeoutSeconds) Attempts to acquire ownership of a named lock by current cluster node.booleantryAcquireOrExtendWriteLock(@NotNull String lockName, long lockTimeoutSeconds) Attempts to acquire WRITE ownership of a named lock by current cluster node.booleantryAcquireReadLock(@NotNull String lockName, long lockTimeoutSeconds) Attempts to acquire READ ownership of a named lock by current cluster node.booleantryAcquireWriteLock(@NotNull String lockName, long lockTimeoutSeconds) Attempts to acquire WRITE ownership of a named lock by current cluster node.voidunlockForReading(@NotNull String lockName) Unlocks the READING part of the lock identified by the given name.voidunlockForReading(@NotNull String lockName, @NotNull String nodeId) voidunlockForWriting(@NotNull String lockName) Unlocks the WRITING part of the lock identified by the given name.Methods inherited from class com.atlassian.beehive.db.DatabaseClusterLockService
getAllKnownClusterLocks, getLockForName, getStatusesOfAllHeldClusterLocks, resetDatabaseStateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.atlassian.bamboo.beehive.BambooClusterLockService
resetDatabaseStateMethods inherited from interface com.atlassian.beehive.ClusterLockService
getLockForNameMethods inherited from interface com.atlassian.beehive.core.ManagedClusterLockService
getAllKnownClusterLocks, getStatusesOfAllHeldClusterLocks
-
Field Details
-
MULTIPLE_LOCK_NAME_SEPARATOR
- See Also:
-
-
Constructor Details
-
BambooClusterLockServiceImpl
public BambooClusterLockServiceImpl(@NotNull @NotNull BambooClusterLockDao bambooClusterLockDao, @NotNull @NotNull ClusterNodeHeartbeatDao clusterNodeHeartbeatDao)
-
-
Method Details
-
releaseLocksHeldByNode
public void releaseLocksHeldByNode()Description copied from interface:BambooClusterLockServiceReleases any locks held by the this node.- Specified by:
releaseLocksHeldByNodein interfaceBambooClusterLockService
-
tryAcquireLock
Description copied from interface:BambooClusterLockServiceAttempts 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 the specified timeout
- Specified by:
tryAcquireLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the locklockTimeoutSeconds- time (in seconds) after which the lock can be taken over- Returns:
- true if we acquired the lock, false if the locks already has a valid owner.
-
releaseLock
Description copied from interface:BambooClusterLockServiceRelease ownership of a named lock by current cluster node.- Specified by:
releaseLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the lock
-
lockForWriting
Description copied from interface:BambooClusterLockServiceLocks for WRITING the lock identified by the given name. A WRITE lock should be treated as eligible to be acquired when one of the following is true:- It has no node set as an owner of correspondent WRITE lock
- It has no node set as an owner of any correspondent READ locks
- It has nodes set as owners of correspondent READ/WRITE locks, but their last update times are older than the specified time
BambooClusterLockService.tryAcquireWriteLock(String, long).Important: this is a NON-REENTRANT implementation, i.e., if the node tries to acquire a lock that it already owns, then it will not be granted. Rationale: reentrant implementation requires mechanism to track re-entrancies in order to prevent releasing the lock before all operations are completed. It can be considered in the future.
There is no limit for the number of nodes that can acquire READ lock simultaneously, but only one can acquire the correspondent WRITE.
Make sure that
BambooClusterLockService.unlockForWriting(String)is called in a try...finally block.*
- Specified by:
lockForWritingin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the locklockTimeoutSeconds- time (in seconds) after which an existing WRITE lock doesn't block the READ ones anymore
-
unlockForWriting
Description copied from interface:BambooClusterLockServiceUnlocks the WRITING part of the lock identified by the given name.- Specified by:
unlockForWritingin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the lock
-
lockForReading
Description copied from interface:BambooClusterLockServiceLocks for READING the lock identified by the given name. A READ lock should be treated as eligible to be acquired when one of the following is true:- It has no node set as an owner of correspondent WRITE lock
- It has an node set as an owner of correspondent WRITE lock, but its last update time is older than the specified time
BambooClusterLockService.tryAcquireReadLock(String, long).Important: this is a NON-REENTRANT implementation, i.e., if the node tries to acquire a lock that it already owns, then it will not be granted. Rationale: reentrant implementation requires mechanism to track re-entrancies in order to prevent releasing the lock before all operations are completed. It can be considered in the future.
There is no limit for the number of nodes that can acquire READ lock simultaneously, but only one can acquire the correspondent WRITE (see
BambooClusterLockService.lockForWriting(String, long).Make sure that
BambooClusterLockService.unlockForReading(String)is called in a try...finally block.*
- Specified by:
lockForReadingin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the locklockTimeoutSeconds- time (in seconds) after which an existing WRITE lock doesn't block the READ ones anymore
-
lockForReading
-
unlockForReading
Description copied from interface:BambooClusterLockServiceUnlocks the READING part of the lock identified by the given name.- Specified by:
unlockForReadingin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the lock
-
unlockForReading
-
tryAcquireReadLock
Description copied from interface:BambooClusterLockServiceAttempts to acquire READ ownership of a named lock by current cluster node. A READ lock should be treated as eligible to be acquired when one of the following is true:- It has no node set as an owner of correspondent WRITE lock
- It has an node set as an owner of correspondent WRITE lock, but its last update time is older than the specified time
There is no limit for the number of nodes that can acquire READ lock simultaneously, but only one can acquire the correspondent WRITE (see
BambooClusterLockService.tryAcquireWriteLock(String,long).Make sure that
BambooClusterLockService.releaseReadLock(String)is called properly.There is no central entity managing a waiting list and granting permissions based on some criterion. Therefore, clients will be granted or denied immediately and it's up to them to try again.
- Specified by:
tryAcquireReadLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the locklockTimeoutSeconds- time (in seconds) after which an existing WRITE lock doesn't block the READ ones- Returns:
- true if we acquired the READ lock, false otherwise.
-
releaseReadLock
Description copied from interface:BambooClusterLockServiceRelease READ ownership of a named lock by current cluster node.- Specified by:
releaseReadLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the lock
-
tryAcquireWriteLock
Description copied from interface:BambooClusterLockServiceAttempts to acquire WRITE ownership of a named lock by current cluster node. A WRITE lock should be treated as eligible to be acquired when one of the following is true:- It has no node set as an owner of correspondent WRITE lock
- It has no node set as an owner of correspondent READ locks
- It has nodes set as owners of correspondent READ/WRITE locks, but their last update times are older than the specified time
There is no limit for the number of nodes that can acquire READ lock simultaneously, but only one can acquire the correspondent WRITE.
Make sure that
BambooClusterLockService.releaseReadLock(String)is called properly.There is no central entity managing a waiting list and granting permissions based on some criterion. Therefore, clients will be granted or denied immediately and it's up to them to try again.
- Specified by:
tryAcquireWriteLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the locklockTimeoutSeconds- time (in seconds) after which the WRITE lock can be taken over- Returns:
- true if we acquired the WRITE lock, false otherwise.
-
tryAcquireOrExtendWriteLock
public boolean tryAcquireOrExtendWriteLock(@NotNull @NotNull String lockName, long lockTimeoutSeconds) Description copied from interface:BambooClusterLockServiceAttempts to acquire WRITE ownership of a named lock by current cluster node. A WRITE lock should be treated as eligible to be acquired when one of the following is true:- It has no node set as an owner of the correspondent WRITE lock; the exception is if the node already holds the lock, so it will be extended
- It has no node set as an owner of correspondent READ locks
- It has nodes set as owners of correspondent READ/WRITE locks, but their last update times are older than the specified time
There is no limit for the number of nodes that can acquire READ lock simultaneously, but only one can acquire the correspondent WRITE.
Make sure that
BambooClusterLockService.releaseReadLock(String)is called properly.There is no central entity managing a waiting list and granting permissions based on some criterion. Therefore, clients will be granted or denied immediately and it's up to them to try again.
- Specified by:
tryAcquireOrExtendWriteLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the locklockTimeoutSeconds- time (in seconds) after which the WRITE lock can be taken over- Returns:
- true if we acquired the WRITE lock, false otherwise.
-
releaseWriteLock
Description copied from interface:BambooClusterLockServiceRelease WRITE ownership of a named lock by current cluster node.- Specified by:
releaseWriteLockin interfaceBambooClusterLockService- Parameters:
lockName- the globally unique id of the lock
-
getClusterLockStatusByName
@Nullable public @Nullable com.atlassian.beehive.core.ClusterLockStatus getClusterLockStatusByName(@NotNull @NotNull String lockName) Description copied from interface:BambooClusterLockServiceReturns the cluster lock details for the given name and or null if no such lock has ever been created.- Specified by:
getClusterLockStatusByNamein interfaceBambooClusterLockService- 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.
-
shutdown
@PreDestroy public void shutdown()Description copied from interface:BambooClusterLockServiceShuts the service down, stopping all accessory jobs (e..g: lock renewer) for all locks.- Specified by:
shutdownin interfaceBambooClusterLockService- Overrides:
shutdownin classcom.atlassian.beehive.db.DatabaseClusterLockService
-
getReadLockName
-
getReadLockNameForNode
-
getWriteLockName
-