Package org.rostore.v2.catalog
Class CachedCatalogBlockOperations
java.lang.Object
org.rostore.v2.catalog.CachedCatalogBlockOperations
- All Implemented Interfaces:
AutoCloseable,Closeable,Committable
This class extends
CatalogBlockOperations by caching some subset
of the catalog in memory. It will make operations faster, but also
would make some operation less fault-tolerant.
When the catalog is created, a min and max size of the cache is provided. if the internal cache become bigger than the given maximum, then the entries are written to the catalog. If the cache size is lower than the minimum, the values are extracted form the catalog.
-
Constructor Summary
ConstructorsConstructorDescriptionCachedCatalogBlockOperations(CatalogBlockOperations catalogBlockOperations, int minCacheSize, int maxCacheSize) Creates a cached version with theCatalogBlockOperationsbackend -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(CatalogBlockIndices catalogBlockIndices, boolean rebalance) This is a version ofCatalogBlockOperations.add(CatalogBlockIndices, boolean)with the cachevoidclose()Returns all the entries from the cache back to catalog and closes it.voidcommit()Operation commits all the active blocks.voiddump()extractIndex(int blockNumber, boolean rebalance) This is the version ofCatalogBlockOperations.extractIndex(long, boolean)that uses internal cachelongCatalog 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 operationslongProvides the number of blocks in the cachegetMedia()Provides the parent medialongProvides a number of free blocks in the underlyingBlockIndexSequence.longGives the index of the first block of the sequence where the data associated with catalog is stored.Provides a status of this entityvoiditerateAll(Consumer<CatalogBlockIndices> consumer) Iterates all blocks in the catalog, inclusive those from the cachevoidremove(CatalogBlockIndices catalogBlockIndices, boolean rebalance) This is a version ofCatalogBlockOperations.remove(CatalogBlockIndices, boolean)with the cacheMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Constructor Details
-
CachedCatalogBlockOperations
public CachedCatalogBlockOperations(CatalogBlockOperations catalogBlockOperations, int minCacheSize, int maxCacheSize) Creates a cached version with theCatalogBlockOperationsbackend- Parameters:
catalogBlockOperations- the backing catalog opsminCacheSize- the minimum size of the cachemaxCacheSize- the maximum size of the cache
-
-
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
-
getCachedBlockNumber
public long getCachedBlockNumber()Provides the number of blocks in the cache- Returns:
- the cache size
-
getBlockProvider
A block provider that is used to manage the blocks in this catalog operations- Returns:
- the block provider
-
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 is the version ofCatalogBlockOperations.extractIndex(long, boolean)that uses internal cache- Parameters:
blockNumber- the number of blocks to extractrebalance- indicates if rebalance should be executed- Returns:
- the indices that has been extracted
-
add
This is a version ofCatalogBlockOperations.add(CatalogBlockIndices, boolean)with the cacheWith regards to rebalance, see
BlockSequence.rebalance()- Parameters:
catalogBlockIndices- the set of blocksrebalance- indicates if the rebalance should be executed
-
remove
This is a version ofCatalogBlockOperations.remove(CatalogBlockIndices, boolean)with the cacheWith regards to rebalance, see
BlockSequence.rebalance()- Parameters:
catalogBlockIndices- the set of blocksrebalance- indicates if the rebalance should be executed
-
close
public void close()Returns all the entries from the cache back to catalog and closes it.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein 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:
commitin interfaceCommittable
-
dump
public void dump() -
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
-
getMedia
Provides the parent media- Returns:
- the parent media
-
iterateAll
Iterates all blocks in the catalog, inclusive those from the cache- Parameters:
consumer- the consumer to consume all the blocks
-