@NotThreadSafe public final class StorageDir extends Object
Modifier and Type | Method and Description |
---|---|
void |
addBlockMeta(BlockMeta blockMeta)
Adds the metadata of a new block into this storage dir.
|
void |
addTempBlockMeta(TempBlockMeta tempBlockMeta)
Adds the metadata of a new block into this storage dir.
|
void |
cleanupSessionTempBlocks(long sessionId,
List<Long> tempBlockIds)
Cleans up the temp block metadata for each block id passed in.
|
long |
getAvailableBytes()
Gets the total available capacity of this
StorageDir in bytes. |
List<Long> |
getBlockIds()
Returns the list of block ids in this dir.
|
BlockMeta |
getBlockMeta(long blockId)
Gets the
BlockMeta from this storage dir by its block id. |
List<BlockMeta> |
getBlocks()
Returns the list of blocks stored in this dir.
|
long |
getCapacityBytes()
Gets the total capacity of this
StorageDir in bytes, which is a constant once this
StorageDir has been initialized. |
long |
getCommittedBytes()
Gets the total size of committed blocks in this StorageDir in bytes.
|
int |
getDirIndex()
Returns the zero-based index of this dir in its parent
StorageTier . |
String |
getDirMedium() |
String |
getDirPath() |
StorageTier |
getParentTier()
Returns the
StorageTier containing this StorageDir . |
List<TempBlockMeta> |
getSessionTempBlocks(long sessionId)
Gets the temporary blocks associated with a session in this
StorageDir , an empty list
is returned if the session has no temporary blocks in this StorageDir . |
TempBlockMeta |
getTempBlockMeta(long blockId)
Gets the
BlockMeta from this storage dir by its block id. |
boolean |
hasBlockMeta(long blockId)
Checks if a block is in this storage dir.
|
boolean |
hasTempBlockMeta(long blockId)
Checks if a temp block is in this storage dir.
|
static StorageDir |
newStorageDir(StorageTier tier,
int dirIndex,
long capacityBytes,
String dirPath,
String dirMedium)
Factory method to create
StorageDir . |
void |
removeBlockMeta(BlockMeta blockMeta)
Removes a block from this storage dir.
|
void |
removeTempBlockMeta(TempBlockMeta tempBlockMeta)
Removes a temp block from this storage dir.
|
void |
resizeTempBlockMeta(TempBlockMeta tempBlockMeta,
long newSize)
Changes the size of a temp block.
|
BlockStoreLocation |
toBlockStoreLocation() |
public static StorageDir newStorageDir(StorageTier tier, int dirIndex, long capacityBytes, String dirPath, String dirMedium) throws BlockAlreadyExistsException, IOException, WorkerOutOfSpaceException
StorageDir
.
It will load metadata of existing committed blocks in the dirPath specified. Only files with
directory depth 1 under dirPath and whose file name can be parsed into long
will be
considered as existing committed blocks, these files will be preserved, others files or
directories will be deleted.tier
- the StorageTier
this dir belongs todirIndex
- the index of this dir in its tiercapacityBytes
- the initial capacity of this dir, can not be modified laterdirPath
- filesystem path of this dir for actual storagedirMedium
- the medium type of the storage dirStorageDir
BlockAlreadyExistsException
- when metadata of existing committed blocks already existsWorkerOutOfSpaceException
- when metadata can not be added due to limited left spaceIOException
public long getCapacityBytes()
StorageDir
in bytes, which is a constant once this
StorageDir
has been initialized.StorageDir
in bytespublic long getAvailableBytes()
StorageDir
in bytes. This value equals the
total capacity of this StorageDir
, minus the used bytes by committed blocks and temp
blocks.public long getCommittedBytes()
public String getDirPath()
public String getDirMedium()
public StorageTier getParentTier()
StorageTier
containing this StorageDir
.StorageTier
public int getDirIndex()
StorageTier
.public List<Long> getBlockIds()
public List<BlockMeta> getBlocks()
public boolean hasBlockMeta(long blockId)
blockId
- the block idpublic boolean hasTempBlockMeta(long blockId)
blockId
- the block idpublic BlockMeta getBlockMeta(long blockId) throws BlockDoesNotExistException
BlockMeta
from this storage dir by its block id.blockId
- the block idBlockMeta
of the given block or nullBlockDoesNotExistException
- if no block is foundpublic TempBlockMeta getTempBlockMeta(long blockId)
BlockMeta
from this storage dir by its block id.blockId
- the block idTempBlockMeta
of the given block or nullpublic void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException
blockMeta
- the metadata of the blockBlockAlreadyExistsException
- if blockId already existsWorkerOutOfSpaceException
- when not enough space to hold blockpublic void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException
tempBlockMeta
- the metadata of a temp block to addBlockAlreadyExistsException
- if blockId already existsWorkerOutOfSpaceException
- when not enough space to hold blockpublic void removeBlockMeta(BlockMeta blockMeta) throws BlockDoesNotExistException
blockMeta
- the metadata of the blockBlockDoesNotExistException
- if no block is foundpublic void removeTempBlockMeta(TempBlockMeta tempBlockMeta) throws BlockDoesNotExistException
tempBlockMeta
- the metadata of the temp block to removeBlockDoesNotExistException
- if no temp block is foundpublic void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize) throws InvalidWorkerStateException
tempBlockMeta
- the metadata of the temp block to resizenewSize
- the new size after change in bytesInvalidWorkerStateException
- when newSize is smaller than oldSizepublic void cleanupSessionTempBlocks(long sessionId, List<Long> tempBlockIds)
sessionId
- the id of the client associated with the temporary blockstempBlockIds
- the list of temporary blocks to clean up, non temporary blocks or
nonexistent blocks will be ignoredpublic List<TempBlockMeta> getSessionTempBlocks(long sessionId)
StorageDir
, an empty list
is returned if the session has no temporary blocks in this StorageDir
.sessionId
- the id of the sessionStorageDir
public BlockStoreLocation toBlockStoreLocation()
Copyright © 2023. All Rights Reserved.