@NotThreadSafe public final class DefaultBlockWorker extends AbstractWorker implements BlockWorker
BlockMasterSync
(Worker to Master continuous communication)
Logic: DefaultBlockWorker
(Logic for all block related storage operations)Modifier and Type | Class and Description |
---|---|
static class |
DefaultBlockWorker.Metrics
This class contains some metrics related to the block worker.
|
class |
DefaultBlockWorker.StorageChecker
StorageChecker periodically checks the health of each storage path and report missing blocks to
BlockWorker . |
Modifier and Type | Method and Description |
---|---|
void |
abortBlock(long sessionId,
long blockId)
Aborts the temporary block created by the session.
|
void |
accessBlock(long sessionId,
long blockId)
Access the block for a given session.
|
void |
cleanupSession(long sessionId)
Cleans up the session.
|
void |
closeUfsBlock(long sessionId,
long blockId)
Closes a UFS block for a client session.
|
void |
commitBlock(long sessionId,
long blockId,
boolean pinOnCreate)
Commits a block to Alluxio managed space.
|
void |
commitBlockInUfs(long blockId,
long length)
Commits a block in UFS.
|
String |
createBlock(long sessionId,
long blockId,
String tierAlias,
String medium,
long initialBytes)
Creates a block in Alluxio managed space.
|
void |
createBlockRemote(long sessionId,
long blockId,
String tierAlias,
String medium,
long initialBytes)
Creates a block.
|
void |
freeSpace(long sessionId,
long availableBytes,
String tierAlias)
Frees space to make a specific amount of bytes available in a best-effort way in the tier.
|
BlockMeta |
getBlockMeta(long sessionId,
long blockId,
long lockId)
Gets the metadata of a specific block from local storage.
|
BlockStore |
getBlockStore() |
Set<Class<? extends Server>> |
getDependencies() |
FileInfo |
getFileInfo(long fileId)
Gets the file information.
|
String |
getName() |
BlockHeartbeatReport |
getReport()
Gets a report for the periodic heartbeat to master.
|
Map<ServiceType,GrpcService> |
getServices() |
BlockStoreMeta |
getStoreMeta()
Gets the metadata for the entire block store.
|
BlockStoreMeta |
getStoreMetaFull()
Similar as
BlockWorker.getStoreMeta() except that this also contains full blockId
list. |
BlockWriter |
getTempBlockWriterRemote(long sessionId,
long blockId)
Opens a
BlockWriter for an existing temporary block. |
BlockMeta |
getVolatileBlockMeta(long blockId)
Gets the metadata of a block given its blockId or throws IOException.
|
AtomicReference<Long> |
getWorkerId() |
boolean |
hasBlockMeta(long blockId)
Checks if the storage has a given block.
|
long |
lockBlock(long sessionId,
long blockId)
Obtains a read lock the block.
|
long |
lockBlockNoException(long sessionId,
long blockId)
Obtains a read lock the block without throwing an exception.
|
void |
moveBlock(long sessionId,
long blockId,
String tierAlias)
Moves a block from its current location to a target location, currently only tier level moves
are supported.
|
void |
moveBlockToMedium(long sessionId,
long blockId,
String mediumType)
Moves a block from its current location to a target location, with a specific medium type.
|
boolean |
openUfsBlock(long sessionId,
long blockId,
Protocol.OpenUfsBlockOptions options)
Opens a UFS block.
|
String |
readBlock(long sessionId,
long blockId,
long lockId)
Gets the path to the block file in local storage.
|
BlockReader |
readBlockRemote(long sessionId,
long blockId,
long lockId)
Gets the block reader for the block.
|
BlockReader |
readUfsBlock(long sessionId,
long blockId,
long offset)
Gets a block reader to read a UFS block.
|
void |
removeBlock(long sessionId,
long blockId)
Frees a block from Alluxio managed space.
|
void |
requestSpace(long sessionId,
long blockId,
long additionalBytes)
Request an amount of space for a block in its storage directory.
|
void |
sessionHeartbeat(long sessionId)
Handles the heartbeat from a client.
|
void |
start(WorkerNetAddress address)
Runs the block worker.
|
void |
stop()
Stops the block worker.
|
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.
|
void |
updatePinList(Set<Long> pinnedInodes)
Sets the pinlist for the underlying block store.
|
close, getExecutorService
public Set<Class<? extends Server>> getDependencies()
getDependencies
in interface Server<WorkerNetAddress>
public String getName()
getName
in interface Server<WorkerNetAddress>
public BlockStore getBlockStore()
getBlockStore
in interface BlockWorker
public Map<ServiceType,GrpcService> getServices()
getServices
in interface Server<WorkerNetAddress>
public AtomicReference<Long> getWorkerId()
getWorkerId
in interface BlockWorker
public void start(WorkerNetAddress address) throws IOException
start
in interface Server<WorkerNetAddress>
address
- the start optionsIOException
public void stop()
stop
in interface Server<WorkerNetAddress>
public void abortBlock(long sessionId, long blockId) throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException, IOException
BlockWorker
abortBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be abortedBlockAlreadyExistsException
- if blockId already exists in committed blocksBlockDoesNotExistException
- if the temporary block cannot be foundInvalidWorkerStateException
- if blockId does not belong to sessionIdIOException
public void accessBlock(long sessionId, long blockId) throws BlockDoesNotExistException
BlockWorker
accessBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to accessBlockDoesNotExistException
- this exception is not thrown in the tiered block store
implementationpublic void commitBlock(long sessionId, long blockId, boolean pinOnCreate) throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException, IOException, WorkerOutOfSpaceException
BlockWorker
BlockStore.commitBlock(long, long, boolean)
. The block will not be accessible
until BlockMasterClient.commitBlock(long, long, String, String, long, long)
succeeds.commitBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to commitpinOnCreate
- whether to pin block on createBlockAlreadyExistsException
- if blockId already exists in committed blocksBlockDoesNotExistException
- if the temporary block cannot be foundInvalidWorkerStateException
- if blockId does not belong to sessionIdWorkerOutOfSpaceException
- if there is no more space left to hold the blockIOException
public void commitBlockInUfs(long blockId, long length) throws IOException
BlockWorker
commitBlockInUfs
in interface BlockWorker
blockId
- the id of the block to commitlength
- length of the block to commitIOException
public String createBlock(long sessionId, long blockId, String tierAlias, String medium, long initialBytes) throws BlockAlreadyExistsException, WorkerOutOfSpaceException, IOException
BlockWorker
IllegalArgumentException
if the location does not belong to tiered storage.createBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to createtierAlias
- the alias of the tier to place the new block in,
BlockStoreLocation.ANY_TIER
for any tiermedium
- the name of the medium to place the new block ininitialBytes
- the initial amount of bytes to be allocatedBlockAlreadyExistsException
- if blockId already exists, either temporary or committed,
or block in eviction plan already existsWorkerOutOfSpaceException
- if this Store has no more space than the initialBlockSizeIOException
public void createBlockRemote(long sessionId, long blockId, String tierAlias, String medium, long initialBytes) throws BlockAlreadyExistsException, WorkerOutOfSpaceException, IOException
BlockWorker
BlockWorker.getTempBlockWriterRemote(long, long)
to get a writer for writing to the
block. Throws an IllegalArgumentException
if the location does not belong to tiered
storage.createBlockRemote
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be createdtierAlias
- the alias of the tier to place the new block inmedium
- the name of the medium to place the new block ininitialBytes
- the initial amount of bytes to be allocatedBlockAlreadyExistsException
- if blockId already exists, either temporary or committed,
or block in eviction plan already existsWorkerOutOfSpaceException
- if this Store has no more space than the initialBlockSizeIOException
public void freeSpace(long sessionId, long availableBytes, String tierAlias) throws WorkerOutOfSpaceException, BlockDoesNotExistException, IOException, BlockAlreadyExistsException, InvalidWorkerStateException
BlockWorker
WorkerOutOfSpaceException
should be thrown if no space is available.freeSpace
in interface BlockWorker
sessionId
- the session idavailableBytes
- the amount of free space in bytestierAlias
- the alias of the tier to free spaceWorkerOutOfSpaceException
- if there is not enough spaceBlockDoesNotExistException
- if blocks can not be foundBlockAlreadyExistsException
- if blocks to move already exists in destination locationInvalidWorkerStateException
- if blocks to move/evict is uncommittedIOException
public BlockWriter getTempBlockWriterRemote(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, IOException
BlockWorker
BlockWriter
for an existing temporary block. This method is only called from a
data server.
The temporary block must already exist with
#createBlockRemote(long, long, String, long)
.getTempBlockWriterRemote
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be opened for writingBlockDoesNotExistException
- if the block cannot be foundBlockAlreadyExistsException
- if a committed block with the same ID existsInvalidWorkerStateException
- if the worker state is invalidIOException
public BlockHeartbeatReport getReport()
BlockWorker
getReport
in interface BlockWorker
public BlockStoreMeta getStoreMeta()
BlockWorker
getStoreMeta
in interface BlockWorker
public BlockStoreMeta getStoreMetaFull()
BlockWorker
BlockWorker.getStoreMeta()
except that this also contains full blockId
list. This function is expensive.getStoreMetaFull
in interface BlockWorker
public BlockMeta getVolatileBlockMeta(long blockId) throws BlockDoesNotExistException
BlockWorker
getVolatileBlockMeta
in interface BlockWorker
blockId
- the block idBlockDoesNotExistException
- if no BlockMeta
for this blockId is foundpublic BlockMeta getBlockMeta(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException
BlockWorker
Unlike BlockWorker.getVolatileBlockMeta(long)
, this method requires the lock id returned by a
previously acquired BlockWorker.lockBlock(long, long)
.
getBlockMeta
in interface BlockWorker
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 lockIdpublic boolean hasBlockMeta(long blockId)
BlockWorker
hasBlockMeta
in interface BlockWorker
blockId
- the block idpublic long lockBlock(long sessionId, long blockId) throws BlockDoesNotExistException
BlockWorker
lockBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be lockedBlockDoesNotExistException
- if blockId cannot be found, for example, evicted alreadypublic long lockBlockNoException(long sessionId, long blockId)
BlockWorker
BlockLockManager.INVALID_LOCK_ID
.lockBlockNoException
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be lockedBlockLockManager.INVALID_LOCK_ID
if it failed to lockpublic void moveBlock(long sessionId, long blockId, String tierAlias) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, WorkerOutOfSpaceException, IOException
BlockWorker
IllegalArgumentException
if the tierAlias is out of range of
tiered storage.moveBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to movetierAlias
- the alias of the tier to move the block toBlockDoesNotExistException
- if blockId cannot be foundBlockAlreadyExistsException
- if blockId already exists in committed blocks of the
newLocationInvalidWorkerStateException
- if blockId has not been committedWorkerOutOfSpaceException
- if newLocation does not have enough extra space to hold the
blockIOException
public void moveBlockToMedium(long sessionId, long blockId, String mediumType) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, WorkerOutOfSpaceException, IOException
BlockWorker
IllegalArgumentException
if the medium type is not one of the listed medium
types.moveBlockToMedium
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to movemediumType
- the medium type to move toBlockDoesNotExistException
- if blockId cannot be foundBlockAlreadyExistsException
- if blockId already exists in committed blocks of the
newLocationInvalidWorkerStateException
- if blockId has not been committedWorkerOutOfSpaceException
- if newLocation does not have enough extra space to hold the
blockIOException
public String readBlock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException
BlockWorker
readBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to readlockId
- the id of the lock on this blockBlockDoesNotExistException
- if the blockId cannot be found in committed blocks or lockId
cannot be foundInvalidWorkerStateException
- if sessionId or blockId is not the same as that in the
LockRecord of lockIdpublic BlockReader readBlockRemote(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException, IOException
BlockWorker
readBlockRemote
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to readlockId
- the id of the lock on this blockBlockDoesNotExistException
- if lockId is not foundInvalidWorkerStateException
- if sessionId or blockId is not the same as that in the
LockRecord of lockIdIOException
public BlockReader readUfsBlock(long sessionId, long blockId, long offset) throws BlockDoesNotExistException, IOException
BlockWorker
readUfsBlock
in interface BlockWorker
sessionId
- the client session IDblockId
- the ID of the UFS block to readoffset
- the offset within the blockBlockDoesNotExistException
- if the block does not exist in the UFS block storeIOException
public void removeBlock(long sessionId, long blockId) throws InvalidWorkerStateException, BlockDoesNotExistException, IOException
BlockWorker
removeBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be freedInvalidWorkerStateException
- if blockId has not been committedBlockDoesNotExistException
- if block cannot be foundIOException
public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException
BlockWorker
requestSpace
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to allocate space toadditionalBytes
- the amount of bytes to allocateBlockDoesNotExistException
- if blockId can not be found, or some block in eviction plan
cannot be foundWorkerOutOfSpaceException
- if requested space can not be satisfiedIOException
public void unlockBlock(long lockId) throws BlockDoesNotExistException
BlockWorker
unlockBlock
in interface BlockWorker
lockId
- the id of the lock to releaseBlockDoesNotExistException
- if lock id cannot be foundpublic boolean unlockBlock(long sessionId, long blockId)
BlockWorker
unlockBlock
in interface BlockWorker
sessionId
- the session idblockId
- the block idpublic void sessionHeartbeat(long sessionId)
BlockWorker
sessionHeartbeat
in interface BlockWorker
sessionId
- the id of the clientpublic void updatePinList(Set<Long> pinnedInodes)
BlockWorker
PinListSync
.updatePinList
in interface BlockWorker
pinnedInodes
- a set of pinned inodespublic FileInfo getFileInfo(long fileId) throws IOException
BlockWorker
getFileInfo
in interface BlockWorker
fileId
- the file idIOException
public boolean openUfsBlock(long sessionId, long blockId, Protocol.OpenUfsBlockOptions options) throws BlockAlreadyExistsException
BlockWorker
UfsBlockAccessTokenUnavailableException
if the number of concurrent readers
on this block exceeds a threshold.openUfsBlock
in interface BlockWorker
sessionId
- the session IDblockId
- the block IDoptions
- the optionsBlockAlreadyExistsException
- if the UFS block already exists in the
UnderFileSystemBlockStore
public void closeUfsBlock(long sessionId, long blockId) throws BlockAlreadyExistsException, IOException, WorkerOutOfSpaceException
BlockWorker
closeUfsBlock
in interface BlockWorker
sessionId
- the session IDblockId
- the block IDBlockAlreadyExistsException
- if it fails to commit the block to Alluxio block store
because the block exists in the Alluxio block storeWorkerOutOfSpaceException
- the the worker does not have enough space to commit the blockIOException
public void cleanupSession(long sessionId)
SessionCleanable
cleanupSession
in interface SessionCleanable
sessionId
- the session idCopyright © 2023. All Rights Reserved.