@NotThreadSafe public 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 . |
INVALID_LOCK_ID
Constructor and Description |
---|
DefaultBlockWorker(BlockMasterClientPool blockMasterClientPool,
FileSystemMasterClient fileSystemMasterClient,
Sessions sessions,
BlockStore blockStore,
UfsManager ufsManager)
Constructs a default block worker.
|
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 |
asyncCache(AsyncCacheRequest request)
Submits the async cache request to async cache manager to execute.
|
void |
cache(CacheRequest request)
Submits the cache request to cache manager to execute.
|
void |
cleanupSession(long sessionId)
Cleans up the session.
|
void |
clearMetrics()
Clears the worker metrics.
|
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,
int tier,
String medium,
long initialBytes)
Creates a block in Alluxio managed space.
|
BlockReader |
createBlockReader(BlockReadRequest request)
Creates the block reader to read from Alluxio block or UFS block.
|
BlockWriter |
createBlockWriter(long sessionId,
long blockId)
Creates a
BlockWriter for an existing temporary block which is already created by
BlockWorker.createBlock(long, long, int, java.lang.String, long) . |
BlockReader |
createUfsBlockReader(long sessionId,
long blockId,
long offset,
boolean positionShort,
Protocol.OpenUfsBlockOptions options)
Creates a block reader to read a UFS block starting from given block offset.
|
BlockMeta |
getBlockMeta(long sessionId,
long blockId,
long lockId)
Gets the metadata of a specific block from local storage.
|
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. |
TempBlockMeta |
getTempBlockMeta(long sessionId,
long blockId) |
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 on a block.
|
void |
moveBlock(long sessionId,
long blockId,
int tier)
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.
|
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 |
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.
|
void |
updatePinList(Set<Long> pinnedInodes)
Sets the pinlist for the underlying block store.
|
close, getExecutorService
public DefaultBlockWorker(BlockMasterClientPool blockMasterClientPool, FileSystemMasterClient fileSystemMasterClient, Sessions sessions, BlockStore blockStore, UfsManager ufsManager)
blockMasterClientPool
- a client pool for talking to the block masterfileSystemMasterClient
- a client for talking to the file system mastersessions
- an object for tracking and cleaning up client sessionsblockStore
- an Alluxio block storeufsManager
- ufs managerpublic Set<Class<? extends Server>> getDependencies()
getDependencies
in interface Server<WorkerNetAddress>
public String getName()
getName
in interface Server<WorkerNetAddress>
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>
start
in class AbstractWorker
address
- the start optionsIOException
public void stop() throws IOException
stop
in interface Server<WorkerNetAddress>
stop
in class AbstractWorker
IOException
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
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, int tier, String medium, long initialBytes) throws BlockAlreadyExistsException, WorkerOutOfSpaceException, IOException
BlockWorker
BlockWorker.createBlockWriter(long, long)
to get a writer for writing to the block.
The block will be temporary until it is committed by BlockWorker.commitBlock(long, long, boolean)
.
Throws an 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 createtier
- 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 TempBlockMeta getTempBlockMeta(long sessionId, long blockId)
getTempBlockMeta
in interface BlockWorker
sessionId
- the id of the session to get this fileblockId
- the id of the blockpublic BlockWriter createBlockWriter(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, IOException
BlockWorker
BlockWriter
for an existing temporary block which is already created by
BlockWorker.createBlock(long, long, int, java.lang.String, long)
.createBlockWriter
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)
BlockWorker
BlockWorker.INVALID_LOCK_ID
.lockBlock
in interface BlockWorker
sessionId
- the id of the clientblockId
- the id of the block to be lockedBlockWorker.INVALID_LOCK_ID
if it failed to lockpublic void moveBlock(long sessionId, long blockId, int tier) 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 movetier
- 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 BlockReader createUfsBlockReader(long sessionId, long blockId, long offset, boolean positionShort, Protocol.OpenUfsBlockOptions options) throws BlockDoesNotExistException, IOException
BlockWorker
createUfsBlockReader
in interface BlockWorker
sessionId
- the client session IDblockId
- the ID of the UFS block to readoffset
- the offset within the blockpositionShort
- whether the operation is using positioned read to a small buffer sizeoptions
- the optionsBlockDoesNotExistException
- 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 void asyncCache(AsyncCacheRequest request)
BlockWorker
asyncCache
in interface BlockWorker
request
- the async cache requestpublic void cache(CacheRequest request) throws AlluxioException, IOException
BlockWorker
cache
in interface BlockWorker
request
- the cache requestAlluxioException
IOException
public void updatePinList(Set<Long> pinnedInodes)
BlockWorker
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
sessionId
- the session IDblockId
- the block IDoptions
- the optionsBlockAlreadyExistsException
- if the UFS block already exists in the
UFS block storepublic void closeUfsBlock(long sessionId, long blockId) throws BlockAlreadyExistsException, IOException, WorkerOutOfSpaceException
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 storeBlockDoesNotExistException
- if the UFS block does not exist in the
UFS block storeWorkerOutOfSpaceException
- the the worker does not have enough space to commit the blockIOException
public BlockReader createBlockReader(BlockReadRequest request) throws BlockDoesNotExistException, IOException
BlockWorker
createBlockReader
in interface BlockWorker
request
- the block read requestBlockDoesNotExistException
- if the requested block does not exist in this workerIOException
- if it fails to get block readerpublic void clearMetrics()
BlockWorker
clearMetrics
in interface BlockWorker
public void cleanupSession(long sessionId)
SessionCleanable
cleanupSession
in interface SessionCleanable
sessionId
- the session idCopyright © 2023. All Rights Reserved.