Class CatalogBlockOperations
- All Implemented Interfaces:
AutoCloseable
,Closeable
,Committable
Has to be closed at the end
The provided block provider should be processed independently
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(long startIndex, long stopIndex, boolean rebalance) Adds a set of blocks from the range - to the catalog.void
add
(CatalogBlockIndices catalogBlockIndices, boolean rebalance) Adds a set of blocks to the catalog.void
close()
Closes the catalog and frees the sequence, blocks still needs to be committed/closed by the usage ofgetBlockProvider()
void
commit()
Commit all the active blocks from the associated containerstatic CatalogBlockOperations
create
(BlockProvider blockProvider) Creates a new catalog.static CatalogBlockOperations
create
(BlockProvider blockProvider, CatalogBlockIndices catalogBlockIndices) Creates a new catalog.void
dump()
extractIndex
(long number, boolean rebalance) This function will extract the requested number of blocks from the catalog.long
Catalog counts and persists internally the total number of blocks in the catalog.A block provider that is used to manage the blocks in this catalog operationslong
Provides a number of free blocks in the underlyingBlockIndexSequence
.long
Gives the index of the first block of the sequence where the data associated with catalog is stored.Provides a status of this entityvoid
iterateAll
(Consumer<CatalogBlockIndices> entryConsumer) A function will iteratively provide all block indices in the catalogstatic CatalogBlockOperations
load
(BlockProvider blockProvider, long startIndex) Loads an instance of the catalog based on the index of the first block (given bygetStartIndex()
).void
remove
(long startIndex, long stopIndex, boolean rebalance) Removes a set of blocks from the range - from the catalog.void
remove
(CatalogBlockIndices catalogBlockIndices, boolean rebalance) Removes a set of blocks from the catalog.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
-
Method Details
-
getSequenceIndexFreeBlockNumber
public long getSequenceIndexFreeBlockNumber()Provides a number of free blocks in the underlyingBlockIndexSequence
. It is not the same as the free blocks that might be managed by the catalog itself.- Returns:
- the number of free blocks
-
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
A function will iteratively provide all block indices in the catalog- Parameters:
entryConsumer
- a consumer that would have to accept all the blocks
-
load
Loads an instance of the catalog based on the index of the first block (given bygetStartIndex()
).- Parameters:
blockProvider
- the block provider to be used by the objectstartIndex
- 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 byload(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 usedcatalogBlockIndices
- this is the initial set of blocks that should be reserved for the underlying block sequence- Returns:
- an instance of the catalog
-
create
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 byload(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
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 returnedCatalogBlockIndices
.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 blocksrebalance
- indicates if the rebalance should be executed- Returns:
- the set blocks that was available
-
add
Adds a set of blocks to the catalog.With regards to rebalance, see
BlockSequence.rebalance()
- Parameters:
catalogBlockIndices
- the set of blocksrebalance
- indicates if the rebalance should be executed
-
remove
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 blocksrebalance
- 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 addstopIndex
- the last block index to addrebalance
- 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 removestopIndex
- the last block index to removerebalance
- 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 ofgetBlockProvider()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getStatus
Description copied from interface:Closeable
Provides a status of this entity -
commit
public void commit()Commit all the active blocks from the associated container- Specified by:
commit
in interfaceCommittable
-