@ThreadSafe public final class BlockLockManager extends Object
Constructor and Description |
---|
BlockLockManager()
Constructs a new
BlockLockManager . |
Modifier and Type | Method and Description |
---|---|
BlockLock |
acquireBlockLock(long sessionId,
long blockId,
BlockLockType blockLockType)
Locks a block.
|
boolean |
checkLock(long sessionId,
long blockId,
long lockId)
Validates the lock is hold by the given session for the given block.
|
void |
cleanupSession(long sessionId)
Cleans up the locks currently hold by a specific session.
|
Set<Long> |
getLockedBlocks()
Gets a snapshot of currently locked blocks.
|
Optional<BlockLock> |
tryAcquireBlockLock(long sessionId,
long blockId,
BlockLockType blockLockType,
long time,
TimeUnit unit)
Tries to lock a block within the given time.
|
void |
validate()
Checks the internal state of the manager to make sure invariants hold.
|
public BlockLockManager()
BlockLockManager
.public BlockLock acquireBlockLock(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 Optional<BlockLock> tryAcquireBlockLock(long sessionId, long blockId, BlockLockType blockLockType, long time, TimeUnit unit)
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
time
- the maximum time to wait for the lockunit
- the time unit of the time
argumentpublic boolean checkLock(long sessionId, long blockId, long lockId)
sessionId
- the session idblockId
- the block idlockId
- the 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.