Class ContainerShard
- All Implemented Interfaces:
AutoCloseable
,Closeable
BlockAllocator
and independent set of keys. The user of the container should implement a function that
determines which shard should be used. Typically, some sort of hash function that splits
the space of the keys can be applied to partition it into the shards.
Container itself does not provide functionality of that kind and only offers the access to the shards.
The shards are using their own BlockAllocator
, which allows the independent allocation of the
blocks and also allows to remove the shard without knowing of its internal structure. Everything
stored with this allocator can be removed when the allocator is removed.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this entity and all related blocksprotected static ContainerShard
Creates a new shard in the storageProvides information about block allocation within the shardint
getIndex()
Provides a status of this entity<T extends OutputStream>
voidFunction to store the body of the value, using the shard's allocator<T> T
keyFunction
(Function<ContainerShardKeyOperations, T> keyFunction) Executes an operation on the shard's keys catalog.protected static ContainerShard
open
(Container container, int index, ContainerShardDescriptor containerShardDescriptor) Opens a shard of the container<T extends InputStream>
longputValue
(T data) Function to store the body of the value, using the shard's allocatorvoid
remove()
Removes all the data associated with the shardvoid
removeValue
(long id) Function to remove the value from the shard's allocator and free the blocks used by ittoString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Method Details
-
getShardAllocator
-
getDescriptor
-
getIndex
public int getIndex() -
getContainer
-
open
protected static ContainerShard open(Container container, int index, ContainerShardDescriptor containerShardDescriptor) Opens a shard of the container- Parameters:
container
- the parent containerindex
- the index of the shardcontainerShardDescriptor
- the information about properties of the shard (should be retrieved from the underlying media)- Returns:
- the shard object
-
create
Creates a new shard in the storageAs the shard requires its own resources, the
Media.getRootBlockAllocator()
is used to create the obtain them.- Parameters:
container
- the parent containerindex
- the index if the shard- Returns:
- the shard object
-
getBlockAllocation
Provides information about block allocation within the shard- Returns:
- the block allocation
-
putValue
Function to store the body of the value, using the shard's allocator- Type Parameters:
T
- the type of the input stream- Parameters:
data
- the data to be stored- Returns:
- the block index where the data is stored
-
getValue
Function to store the body of the value, using the shard's allocator- Type Parameters:
T
- the type of the output stream- Parameters:
record
- the record information to retrieve the block where the data startsoutputStream
- the stream to put the data to
-
removeValue
public void removeValue(long id) Function to remove the value from the shard's allocator and free the blocks used by it- Parameters:
id
- the block index where the data starts
-
toString
-
remove
public void remove()Removes all the data associated with the shard -
close
public void close()Description copied from interface:Closeable
Closes this entity and all related blocks- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getStatus
Description copied from interface:Closeable
Provides a status of this entity -
keyFunction
Executes an operation on the shard's keys catalog.The function will provide a cached
ContainerShardKeyOperations
if one exists, or create one if cache is depleted.After the operation is over the
CachedCatalogBlockOperations
will be returned to the cache, so it can be reused later.The operation does not do any blocking, for example for write-operations, it should be enforced by the caller.
- Type Parameters:
T
- the result type, e.g.Record
- Parameters:
keyFunction
- that will receive aContainerShardKeyOperations
instance to execute the operation- Returns:
- the result of the function execution
-