Class CatalogBlockOperations

java.lang.Object
org.rostore.v2.catalog.CatalogBlockOperations
All Implemented Interfaces:
AutoCloseable, Closeable, Committable

public class CatalogBlockOperations extends Object implements Committable
This is the major class to manage a catalog of blocks. This catalogs stores in a sequence of blocks the references to other blocks. Can be used for example, to store a set of blocks for the secondary block allocator or any other purpose of the persistent set of blocks.

Has to be closed at the end

The provided block provider should be processed independently

  • Method Details

    • getSequenceIndexFreeBlockNumber

      public long getSequenceIndexFreeBlockNumber()
      Provides a number of free blocks in the underlying BlockIndexSequence. It is not the same as the free blocks that might be managed by the catalog itself.
      Returns:
      the number of free blocks
    • getBlockProvider

      public BlockProvider getBlockProvider()
      A block provider that is used to manage the blocks in this catalog operations
      Returns:
      the block provider
    • getStartIndex

      public long getStartIndex()
      Gives the index of the first block of the sequence where the data associated with catalog is stored.

      It is enough to store this index somewhere to be able to restore the whole catalog

      Returns:
      the first block index of this catalog
    • iterateAll

      public void iterateAll(Consumer<CatalogBlockIndices> entryConsumer)
      A function will iteratively provide all block indices in the catalog
      Parameters:
      entryConsumer - a consumer that would have to accept all the blocks
    • load

      public static CatalogBlockOperations load(BlockProvider blockProvider, long startIndex)
      Loads an instance of the catalog based on the index of the first block (given by getStartIndex()).
      Parameters:
      blockProvider - the block provider to be used by the object
      startIndex - the index of the first block
      Returns:
      an instance of the catalog transaction
    • create

      public static CatalogBlockOperations create(BlockProvider blockProvider, CatalogBlockIndices catalogBlockIndices)
      Creates a new catalog.

      After the catalog is created it can be stored just by storing getStartIndex(), and the next time it can be reinitialized by load(BlockProvider, long)

      As the catalogs might participate in the allocators, they usually would require to hold some free blocks to cover the internal allocation cycles, that's why the method requires a set of blocks to initialize a new catalog.

      Parameters:
      blockProvider - the block provider to be used
      catalogBlockIndices - this is the initial set of blocks that should be reserved for the underlying block sequence
      Returns:
      an instance of the catalog
    • create

      public static CatalogBlockOperations create(BlockProvider blockProvider)
      Creates a new catalog.

      After the catalog is created it can be stored just by storing getStartIndex(), and the next time it can be reinitialized by load(BlockProvider, long)

      Parameters:
      blockProvider - the block provider to be used
      Returns:
      an instance of the catalog
    • dump

      public void dump()
    • getAddedNumber

      public long getAddedNumber()
      Catalog counts and persists internally the total number of blocks in the catalog.
      Returns:
      the total number of blocks in the catalog
    • extractIndex

      public CatalogBlockIndices extractIndex(long number, boolean rebalance)
      This function will extract the requested number of blocks from the catalog. It iterates from the bottom - up. And adds the blocks found in the catalog, remove them from the catalog and add them to the returned CatalogBlockIndices.

      Note that if the catalog will be empty at some point, it will return less blocks than requested.

      With regards to rebalance, see BlockSequence.rebalance()

      Parameters:
      number - the requested number of blocks
      rebalance - indicates if the rebalance should be executed
      Returns:
      the set blocks that was available
    • add

      public void add(CatalogBlockIndices catalogBlockIndices, boolean rebalance)
      Adds a set of blocks to the catalog.

      With regards to rebalance, see BlockSequence.rebalance()

      Parameters:
      catalogBlockIndices - the set of blocks
      rebalance - indicates if the rebalance should be executed
    • remove

      public void remove(CatalogBlockIndices catalogBlockIndices, boolean rebalance)
      Removes a set of blocks from the catalog.

      If some blocks won't found in the catalog - it would throw an exception.

      With regards to rebalance, see BlockSequence.rebalance()

      Parameters:
      catalogBlockIndices - the set of blocks
      rebalance - indicates if the rebalance should be executed
    • add

      public void add(long startIndex, long stopIndex, boolean rebalance)
      Adds a set of blocks from the range - to the catalog.

      With regards to rebalance, see BlockSequence.rebalance()

      Parameters:
      startIndex - the first block index to add
      stopIndex - the last block index to add
      rebalance - indicates if the rebalance should be executed
    • remove

      public void remove(long startIndex, long stopIndex, boolean rebalance)
      Removes a set of blocks from the range - from the catalog.

      If some blocks won't found in the catalog - it would throw an exception.

      With regards to rebalance, see BlockSequence.rebalance()

      Parameters:
      startIndex - the first block index to remove
      stopIndex - the last block index to remove
      rebalance - indicates if the rebalance should be executed
    • close

      public void close()
      Closes the catalog and frees the sequence, blocks still needs to be committed/closed by the usage of getBlockProvider()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getStatus

      public Status getStatus()
      Description copied from interface: Closeable
      Provides a status of this entity
      Specified by:
      getStatus in interface Closeable
      Returns:
      the status
    • commit

      public void commit()
      Commit all the active blocks from the associated container
      Specified by:
      commit in interface Committable