Class ContainerShardKeyOperations

java.lang.Object
org.rostore.v2.container.ContainerShardKeyOperations
All Implemented Interfaces:
AutoCloseable, Closeable, Committable

public class ContainerShardKeyOperations extends Object implements Committable
Encapsulates the operation context on the shard level.

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 Details

    • ContainerShardKeyOperations

      public ContainerShardKeyOperations(ContainerShard containerShard)
      Creates an instance for the shard's operations.
  • Method Details

    • getBlockSequence

      public BlockSequence getBlockSequence()
      The sequence of the blocks that manages the shard's keys
      Returns:
    • putKey

      public long putKey(byte[] key, Record record)
      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

      public KeyList listKeys(byte[] startWithKey, byte[] continuationKey, int maxNumber, int maxSize)
    • getKey

      public Record getKey(byte[] key)
      Executes an operation to find a key
      Parameters:
      key - a key to be found
      Returns:
      the Record associated with the key or null 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

      public boolean removeKey(byte[] key, Record record)
      Removes a key from the shard
      Parameters:
      key - a key to rmeove
      record - the metadata to be used
      Returns:
      true if deletion happened or false otherwise
    • dump

      public void dump()
    • close

      public void close()
      Closes this entity and all related blocks
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getStatus

      public Status getStatus()
      Provides a status of this entity
      Specified by:
      getStatus in interface Closeable
      Returns:
      the status
    • 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 interface Committable