@ThreadSafe public final class BlockLockManager extends Object
Modifier and Type | Field and Description |
---|---|
static long |
INVALID_LOCK_ID
Invalid lock ID.
|
Constructor and Description |
---|
BlockLockManager()
Constructs a new
BlockLockManager . |
Modifier and Type | Method and Description |
---|---|
void |
cleanupSession(long sessionId)
Cleans up the locks currently hold by a specific session.
|
Set<Long> |
getLockedBlocks()
Gets a set of currently locked blocks.
|
long |
lockBlock(long sessionId,
long blockId,
BlockLockType blockLockType)
Locks a block.
|
void |
unlockBlock(long lockId)
Releases the lock with the specified lock id.
|
boolean |
unlockBlock(long sessionId,
long blockId)
Releases the lock with the specified session and block id.
|
boolean |
unlockBlockNoException(long lockId)
Releases the lock with the specified lock id.
|
void |
validate()
Checks the internal state of the manager to make sure invariants hold.
|
void |
validateLock(long sessionId,
long blockId,
long lockId)
Validates the lock is hold by the given session for the given block.
|
public static final long INVALID_LOCK_ID
public BlockLockManager()
BlockLockManager
.public long lockBlock(long sessionId, long blockId, BlockLockType blockLockType)
PropertyKey.WORKER_TIERED_STORE_BLOCK_LOCKS
are already in use and no lock has
been allocated for the specified block, this method will need to wait until a lock can be
acquired from the lock pool.sessionId
- the session idblockId
- the block idblockLockType
- BlockLockType.READ
or BlockLockType.WRITE
public boolean unlockBlockNoException(long lockId)
lockId
- the id of the lock to releasepublic void unlockBlock(long lockId) throws BlockDoesNotExistException
lockId
- the id of the lock to releaseBlockDoesNotExistException
- if lock id cannot be foundpublic boolean unlockBlock(long sessionId, long blockId)
sessionId
- the session idblockId
- the block idpublic void validateLock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException
sessionId
- the session idblockId
- the block idlockId
- the lock idBlockDoesNotExistException
- when no lock record can be found for lock idInvalidWorkerStateException
- when session id or block id is not consistent with that
in the lock record for lock idpublic void cleanupSession(long sessionId)
sessionId
- the id of the session to cleanuppublic Set<Long> getLockedBlocks()
public void validate()
Copyright © 2023. All Rights Reserved.