public interface BlockStore extends SessionCleanable, Closeable
Modifier and Type | Method and Description |
---|---|
void |
abortBlock(long sessionId,
long blockId)
Aborts a temporary block.
|
void |
accessBlock(long sessionId,
long blockId)
Notifies the block store that a block was accessed so the block store could update accordingly
the registered listeners such as evictor and allocator on block access.
|
boolean |
checkStorage()
Checks storage health.
|
void |
cleanupSession(long sessionId)
Cleans up the data associated with a specific session (typically a dead session).
|
void |
commitBlock(long sessionId,
long blockId,
boolean pinOnCreate)
Commits a temporary block to the local store.
|
long |
commitBlockLocked(long sessionId,
long blockId,
boolean pinOnCreate)
Similar to
commitBlock(long, long, boolean) . |
TempBlockMeta |
createBlock(long sessionId,
long blockId,
AllocateOptions options)
Creates the metadata of a new block and assigns a temporary path (e.g., a subdir of the final
location named after session id) to store its data.
|
void |
freeSpace(long sessionId,
long minContigiousBytes,
long minAvailableBytes,
BlockStoreLocation location)
Frees space to make a specific amount of bytes available in the location.
|
BlockMeta |
getBlockMeta(long sessionId,
long blockId,
long lockId)
Gets the metadata of a specific block from local storage.
|
BlockReader |
getBlockReader(long sessionId,
long blockId,
long lockId)
Creates a reader of an existing block to read data from this block.
|
BlockStoreMeta |
getBlockStoreMeta()
Gets the metadata of the entire store in a snapshot.
|
BlockStoreMeta |
getBlockStoreMetaFull()
Similar as
getBlockStoreMeta() except that this includes
more information about the block store (e.g. |
BlockWriter |
getBlockWriter(long sessionId,
long blockId)
Creates a writer to write data to a temp block.
|
TempBlockMeta |
getTempBlockMeta(long sessionId,
long blockId)
Gets the temp metadata of a specific block from local storage.
|
BlockMeta |
getVolatileBlockMeta(long blockId)
Gets the metadata of a block given its block id or throws
BlockDoesNotExistException . |
boolean |
hasBlockMeta(long blockId)
Checks if the storage has a given block.
|
long |
lockBlock(long sessionId,
long blockId)
Locks an existing block and guards subsequent reads on this block.
|
long |
lockBlockNoException(long sessionId,
long blockId)
Locks an existing block and guards subsequent reads on this block.
|
void |
moveBlock(long sessionId,
long blockId,
AllocateOptions moveOptions)
Moves an existing block to a new location.
|
void |
moveBlock(long sessionId,
long blockId,
BlockStoreLocation oldLocation,
AllocateOptions moveOptions)
Moves an existing block to a new location.
|
void |
registerBlockStoreEventListener(BlockStoreEventListener listener)
Registers a
BlockStoreEventListener to this block store. |
void |
removeBlock(long sessionId,
long blockId)
Removes an existing block.
|
void |
removeBlock(long sessionId,
long blockId,
BlockStoreLocation location)
Removes an existing block.
|
void |
requestSpace(long sessionId,
long blockId,
long additionalBytes)
Requests to increase the size of a temp block.
|
void |
unlockBlock(long lockId)
Releases an acquired block lock based on a lockId (returned by
lockBlock(long, long) . |
boolean |
unlockBlock(long sessionId,
long blockId)
Releases an acquired block lock based on a session id and block id.
|
void |
updatePinnedInodes(Set<Long> inodes)
Update the pinned inodes.
|
long lockBlock(long sessionId, long blockId) throws BlockDoesNotExistException
sessionId
- the id of the session to lock this blockblockId
- the id of the block to lockBlockDoesNotExistException
- if block id can not be found, for example, evicted alreadylong lockBlockNoException(long sessionId, long blockId)
BlockLockManager.INVALID_LOCK_ID
.sessionId
- the id of the session to lock this blockblockId
- the id of the block to lockBlockLockManager.INVALID_LOCK_ID
if it failed to lockvoid unlockBlock(long lockId) throws BlockDoesNotExistException
lockBlock(long, long)
.lockId
- the id of the lock returned by lockBlock(long, long)
BlockDoesNotExistException
- if lockId can not be foundboolean unlockBlock(long sessionId, long blockId)
sessionId
- the id of the session to lock this blockblockId
- the id of the block to lockTempBlockMeta createBlock(long sessionId, long blockId, AllocateOptions options) throws BlockAlreadyExistsException, WorkerOutOfSpaceException, IOException
BlockStoreLocation.anyTier()
, or
BlockStoreLocation.anyDirInTier(String)
.
Before commit, all the data written to this block will be stored in the temp path and the block is only "visible" to its writer client.
sessionId
- the id of the sessionblockId
- the id of the block to createoptions
- allocation optionsIllegalArgumentException
- if location does not belong to tiered storageBlockAlreadyExistsException
- if block id already exists, either temporary or committed,
or block in eviction plan already existsWorkerOutOfSpaceException
- if this Store has no more space than the initialBlockSizeIOException
BlockMeta getVolatileBlockMeta(long blockId) throws BlockDoesNotExistException
BlockDoesNotExistException
.
This method does not require a lock id so the block is possible to be moved or removed after it
returns.blockId
- the block idBlockDoesNotExistException
- if no BlockMeta for this block id is foundBlockMeta getBlockMeta(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException
This method requires the lock id returned by a previously acquired
lockBlock(long, long)
.
sessionId
- the id of the session to get this fileblockId
- the id of the blocklockId
- the id of the lockBlockDoesNotExistException
- if the block id can not be found in committed blocks or
lockId can not be foundInvalidWorkerStateException
- if session id or block id is not the same as that in the
LockRecord of lockId@Nullable TempBlockMeta getTempBlockMeta(long sessionId, long blockId)
sessionId
- the id of the session to get this fileblockId
- the id of the blockvoid commitBlock(long sessionId, long blockId, boolean pinOnCreate) throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException, IOException, WorkerOutOfSpaceException
sessionId
- the id of the sessionblockId
- the id of a temp blockpinOnCreate
- whether to pin block on createBlockAlreadyExistsException
- if block id already exists in committed blocksBlockDoesNotExistException
- if the temporary block can not be foundInvalidWorkerStateException
- if block id does not belong to session idWorkerOutOfSpaceException
- if there is no more space left to hold the blockIOException
long commitBlockLocked(long sessionId, long blockId, boolean pinOnCreate) throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException, IOException, WorkerOutOfSpaceException
commitBlock(long, long, boolean)
. It returns the block locked,
so the caller is required to explicitly unlock the block.sessionId
- the id of the sessionblockId
- the id of a temp blockpinOnCreate
- whether to pin block on createBlockAlreadyExistsException
- if block id already exists in committed blocksBlockDoesNotExistException
- if the temporary block can not be foundInvalidWorkerStateException
- if block id does not belong to session idWorkerOutOfSpaceException
- if there is no more space left to hold the blockIOException
void abortBlock(long sessionId, long blockId) throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException, IOException
sessionId
- the id of the sessionblockId
- the id of a temp blockBlockAlreadyExistsException
- if block id already exists in committed blocksBlockDoesNotExistException
- if the temporary block can not be foundInvalidWorkerStateException
- if block id does not belong to session idIOException
void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException
sessionId
- the id of the session to request spaceblockId
- the id of the temp blockadditionalBytes
- the amount of more space to request in bytes, never be less than 0BlockDoesNotExistException
- if block id can not be found, or some block in eviction plan
cannot be foundWorkerOutOfSpaceException
- if requested space can not be satisfiedIOException
BlockWriter getBlockWriter(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, IOException
sessionId
- the id of the session to get the writerblockId
- the id of the temp blockBlockWriter
instance on this blockBlockDoesNotExistException
- if the block can not be foundBlockAlreadyExistsException
- if a committed block with the same ID existsInvalidWorkerStateException
- if the worker state is invalidIOException
BlockReader getBlockReader(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException, IOException
This operation requires the lock id returned by a previously acquired
lockBlock(long, long)
.
sessionId
- the id of the session to get the readerblockId
- the id of an existing blocklockId
- the id of the lock returned by lockBlock(long, long)
BlockReader
instance on this blockBlockDoesNotExistException
- if lockId is not foundInvalidWorkerStateException
- if session id or block id is not the same as that in the
LockRecord of lockIdIOException
void moveBlock(long sessionId, long blockId, AllocateOptions moveOptions) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, WorkerOutOfSpaceException, IOException
sessionId
- the id of the session to move a blockblockId
- the id of an existing blockmoveOptions
- the options for moveIllegalArgumentException
- if newLocation does not belong to the tiered storageBlockDoesNotExistException
- if block id can not be foundBlockAlreadyExistsException
- if block id already exists in committed blocks of the
newLocationInvalidWorkerStateException
- if block id has not been committedWorkerOutOfSpaceException
- if newLocation does not have enough extra space to hold the
blockIOException
void moveBlock(long sessionId, long blockId, BlockStoreLocation oldLocation, AllocateOptions moveOptions) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, WorkerOutOfSpaceException, IOException
sessionId
- the id of the session to remove a blockblockId
- the id of an existing blockoldLocation
- the location of the sourcemoveOptions
- the options for moveIllegalArgumentException
- if newLocation does not belong to the tiered storageBlockDoesNotExistException
- if block id can not be foundBlockAlreadyExistsException
- if block id already exists in committed blocks of the
newLocationInvalidWorkerStateException
- if block id has not been committedWorkerOutOfSpaceException
- if newLocation does not have enough extra space to hold the
blockIOException
void removeBlock(long sessionId, long blockId) throws InvalidWorkerStateException, BlockDoesNotExistException, IOException
sessionId
- the id of the session to remove a blockblockId
- the id of an existing blockInvalidWorkerStateException
- if block id has not been committedBlockDoesNotExistException
- if block can not be foundIOException
void removeBlock(long sessionId, long blockId, BlockStoreLocation location) throws InvalidWorkerStateException, BlockDoesNotExistException, IOException
sessionId
- the id of the session to move a blockblockId
- the id of an existing blocklocation
- the location of the blockInvalidWorkerStateException
- if block id has not been committedBlockDoesNotExistException
- if block can not be foundIOException
void accessBlock(long sessionId, long blockId) throws BlockDoesNotExistException
sessionId
- the id of the session to access a blockblockId
- the id of an accessed blockBlockDoesNotExistException
- if the block id is not foundBlockStoreMeta getBlockStoreMeta()
BlockStoreMeta getBlockStoreMetaFull()
getBlockStoreMeta()
except that this includes
more information about the block store (e.g. blockId list). This is an expensive operation.boolean hasBlockMeta(long blockId)
blockId
- the block idvoid cleanupSession(long sessionId)
cleanupSession
in interface SessionCleanable
sessionId
- the session idvoid freeSpace(long sessionId, long minContigiousBytes, long minAvailableBytes, BlockStoreLocation location) throws WorkerOutOfSpaceException, BlockDoesNotExistException, IOException
sessionId
- the session idminContigiousBytes
- the minimum amount of contigious free space in bytesminAvailableBytes
- the maximum amount of free space in byteslocation
- the location to free spaceWorkerOutOfSpaceException
- if there is not enough space to fulfill minimum requirementBlockDoesNotExistException
- if blocks in EvictionPlan
can not be foundIOException
void registerBlockStoreEventListener(BlockStoreEventListener listener)
BlockStoreEventListener
to this block store.listener
- the listener to those eventsvoid updatePinnedInodes(Set<Long> inodes)
inodes
- a set of inodes that are currently pinnedboolean checkStorage()
Copyright © 2023. All Rights Reserved.