Class ContainerShardKeyOperations
- All Implemented Interfaces:
AutoCloseable
,Closeable
,Committable
Every key read/write/delete operation should be executed over this class.
The objects of this class are not thread safe and have a state, so it should be created just one type of this operation object for every parallel process.
Once the key-access operation is over, the object can be reused in another process, but during the process should be exactly one process waiting for it.
The key-read operations can be executed in parallel as many as needed.
The key-write or key-delete operations should not be executed in parallel.
The mechanism to for separating the blocking write and non-blocking read operation should be implemented on the caller side.
-
Constructor Summary
ConstructorDescriptionContainerShardKeyOperations
(ContainerShard containerShard) Creates an instance for the shard's operations. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this entity and all related blocksvoid
commit()
Operation commits all the active blocks.void
dump()
The sequence of the blocks that manages the shard's keysgetKey
(byte[] key) Executes an operation to find a keyProvides a status of this entitylistKeys
(byte[] startWithKey, byte[] continuationKey, int maxNumber, int maxSize) long
Create or update the provided key with the parameter from the provided record.boolean
Removes a key from the shardlong
removeKeyIfExpired
(int keyBlockSequenceIndex) The operation is executed in the clean-up cycle.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Constructor Details
-
ContainerShardKeyOperations
Creates an instance for the shard's operations.
-
-
Method Details
-
getBlockSequence
The sequence of the blocks that manages the shard's keys- Returns:
-
putKey
Create or update the provided key with the parameter from the provided record.Operation will execute the validation for the legitimacy of the update.
If the TTL of the record would be higher than the one configured for the container, the TTL in the Record will be corrected.
- Parameters:
record
- the data to be stored with the key- Returns:
- the id that has been stored before with the key or
Utils.ID_UNDEFINED
-
listKeys
-
getKey
Executes an operation to find a key- Parameters:
key
- a key to be found- Returns:
- the
Record
associated with the key ornull
if the key has not been found
-
removeKeyIfExpired
public long removeKeyIfExpired(int keyBlockSequenceIndex) The operation is executed in the clean-up cycle.It will search for the expired records on the block of the sequence and remove it if one found. In the later case the id of the entry is returned. If nothing is found
Utils.ID_UNDEFINED
is returned.- Parameters:
keyBlockSequenceIndex
-- Returns:
- an id associated with the deleted entry or
Utils.ID_UNDEFINED
if nothing is found.
-
removeKey
Removes a key from the shard- Parameters:
key
- a key to rmeoverecord
- the metadata to be used- Returns:
true
if deletion happened orfalse
otherwise
-
dump
public void dump() -
close
public void close()Closes this entity and all related blocks- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getStatus
Provides a status of this entity -
commit
public void commit()Operation commits all the active blocks. It will mark the block to be garbage-collected, the data from the associated physical block will be flushed to the persistent storage.- Specified by:
commit
in interfaceCommittable
-