@ThreadSafe public class HeapBlockMetaStore extends Object implements BlockMetaStore
BlockMetaStore.Block, BlockMetaStore.Factory
Modifier and Type | Field and Description |
---|---|
TwoKeyConcurrentMap<Long,Long,Block.BlockLocation,Map<Long,Block.BlockLocation>> |
mBlockLocations |
Map<Long,Block.BlockMeta> |
mBlocks |
Constructor and Description |
---|
HeapBlockMetaStore()
constructor a HeapBlockStore.
|
Modifier and Type | Method and Description |
---|---|
void |
addLocation(long blockId,
Block.BlockLocation location)
Adds a new block location.
|
void |
clear()
Removes all metadata from the block store.
|
void |
close()
Closes the block store and releases all resources.
|
Optional<Block.BlockMeta> |
getBlock(long id) |
CloseableIterator<BlockMetaStore.Block> |
getCloseableIterator()
Gets a
CloseableIterator over the blocks. |
List<Block.BlockLocation> |
getLocations(long blockid)
Gets locations for a block.
|
void |
putBlock(long id,
Block.BlockMeta meta)
Adds block metadata to the block store.
|
void |
removeBlock(long id)
Removes a block, or does nothing if the block does not exist.
|
void |
removeLocation(long blockId,
long workerId)
Removes a block location.
|
long |
size() |
public final Map<Long,Block.BlockMeta> mBlocks
public final TwoKeyConcurrentMap<Long,Long,Block.BlockLocation,Map<Long,Block.BlockLocation>> mBlockLocations
public Optional<Block.BlockMeta> getBlock(long id)
getBlock
in interface BlockMetaStore
id
- a block idpublic void putBlock(long id, Block.BlockMeta meta)
BlockMetaStore
putBlock
in interface BlockMetaStore
id
- the block idmeta
- the block metadatapublic void removeBlock(long id)
BlockMetaStore
removeBlock
in interface BlockMetaStore
id
- a block id to removepublic CloseableIterator<BlockMetaStore.Block> getCloseableIterator()
BlockMetaStore
CloseableIterator
over the blocks.
The iterator must be closed properly.
One option is to follow the below idiom:
try (CloseableIterator<Block> iter =
mBlockStore.getCloseableIterator()) {
while (iter.hasNext()) {
// take the element and perform operations
}
}
If the iterator must be passed to other methods,
it must be closed at the end of operation or on exceptions.
Otherwise there can be a leak!getCloseableIterator
in interface BlockMetaStore
CloseableIterator
over the blockspublic void clear()
BlockMetaStore
clear
in interface BlockMetaStore
public void close()
BlockMetaStore
close
in interface BlockMetaStore
public long size()
size
in interface BlockMetaStore
public List<Block.BlockLocation> getLocations(long blockid)
BlockMetaStore
getLocations
in interface BlockMetaStore
blockid
- a block idpublic void addLocation(long blockId, Block.BlockLocation location)
BlockMetaStore
addLocation
in interface BlockMetaStore
blockId
- a block idlocation
- a block locationpublic void removeLocation(long blockId, long workerId)
BlockMetaStore
removeLocation
in interface BlockMetaStore
blockId
- a block idworkerId
- a worker idCopyright © 2023. All Rights Reserved.