@NotThreadSafe public final class DefaultStorageDir extends Object implements StorageDir
StorageDirView
, this space will be reflected as:
- committed for user I/Os
- available for internal I/Os.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 . |
long |
getReservedBytes() |
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
TempBlockMeta 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,
long reservedBytes,
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, long reservedBytes, String dirPath, String dirMedium) throws BlockAlreadyExistsException, IOException, WorkerOutOfSpaceException, InvalidPathException
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 laterreservedBytes
- the amount of reserved space for internal managementdirPath
- 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
InvalidPathException
public long getCapacityBytes()
StorageDir
StorageDir
in bytes, which is a constant once this
StorageDir
has been initialized.getCapacityBytes
in interface StorageDir
StorageDir
in bytespublic long getAvailableBytes()
StorageDir
StorageDir
in bytes. This value equals the
total capacity of this StorageDir
, minus the used bytes by committed blocks and temp
blocks.getAvailableBytes
in interface StorageDir
public long getCommittedBytes()
StorageDir
getCommittedBytes
in interface StorageDir
public String getDirPath()
getDirPath
in interface StorageDir
public String getDirMedium()
getDirMedium
in interface StorageDir
public StorageTier getParentTier()
StorageDir
StorageTier
containing this StorageDir
.getParentTier
in interface StorageDir
StorageTier
public int getDirIndex()
StorageDir
StorageTier
.getDirIndex
in interface StorageDir
public List<Long> getBlockIds()
StorageDir
getBlockIds
in interface StorageDir
public List<BlockMeta> getBlocks()
StorageDir
getBlocks
in interface StorageDir
public boolean hasBlockMeta(long blockId)
StorageDir
hasBlockMeta
in interface StorageDir
blockId
- the block idpublic boolean hasTempBlockMeta(long blockId)
StorageDir
hasTempBlockMeta
in interface StorageDir
blockId
- the block idpublic BlockMeta getBlockMeta(long blockId) throws BlockDoesNotExistException
StorageDir
BlockMeta
from this storage dir by its block id.getBlockMeta
in interface StorageDir
blockId
- the block idBlockMeta
of the given block or nullBlockDoesNotExistException
- if no block is foundpublic TempBlockMeta getTempBlockMeta(long blockId)
StorageDir
TempBlockMeta
from this storage dir by its block id.getTempBlockMeta
in interface StorageDir
blockId
- the block idTempBlockMeta
of the given block or nullpublic void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException
StorageDir
addBlockMeta
in interface StorageDir
blockMeta
- the metadata of the blockWorkerOutOfSpaceException
- when not enough space to hold blockBlockAlreadyExistsException
- if blockId already existspublic void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException
StorageDir
addTempBlockMeta
in interface StorageDir
tempBlockMeta
- the metadata of a temp block to addWorkerOutOfSpaceException
- when not enough space to hold blockBlockAlreadyExistsException
- if blockId already existspublic void removeBlockMeta(BlockMeta blockMeta) throws BlockDoesNotExistException
StorageDir
removeBlockMeta
in interface StorageDir
blockMeta
- the metadata of the blockBlockDoesNotExistException
- if no block is foundpublic void removeTempBlockMeta(TempBlockMeta tempBlockMeta) throws BlockDoesNotExistException
StorageDir
removeTempBlockMeta
in interface StorageDir
tempBlockMeta
- the metadata of the temp block to removeBlockDoesNotExistException
- if no temp block is foundpublic void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize) throws InvalidWorkerStateException
StorageDir
resizeTempBlockMeta
in interface StorageDir
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)
StorageDir
cleanupSessionTempBlocks
in interface StorageDir
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
StorageDir
, an empty list
is returned if the session has no temporary blocks in this StorageDir
.getSessionTempBlocks
in interface StorageDir
sessionId
- the id of the sessionStorageDir
public BlockStoreLocation toBlockStoreLocation()
toBlockStoreLocation
in interface StorageDir
public long getReservedBytes()
getReservedBytes
in interface StorageDir
Copyright © 2023. All Rights Reserved.