Package org.rostore.v2.keys
Class KeyBlockOperations
java.lang.Object
org.rostore.v2.keys.KeyBlockOperations
- All Implemented Interfaces:
AutoCloseable,Closeable,Committable
This is a class to manage keys.
It is NOT thread-safe and should be protected in multi-thread environment.
This class organizes the access to the KeyBlockEntry and facilitates its work with VarSizeBlock.
The moves within the key sequence is synchronized with the respective VarSizeBlock and its variants like VarSizeEntry and VarSizeMultiBlock.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this entity and all related blocksvoidcommit()Operation commits all the active blocks.static KeyBlockOperationscreate(BlockAllocator blockAllocator, RecordLengths recordLengths) Creates a new key operations, allocates a new sequence to manage the keys.voiddump()Dumps the content of the key catalog to theSystem.out.A block sequence that underlies this operation's objectgetRecord(byte[] key) Searches for the provided key and return theRecordassociated with it.longThis is first block's index.Provides a status of this entitylist(byte[] startWithKey, byte[] continuationKey, long maxNumber, long maxSize) List the keys managed by this instance.static KeyBlockOperationsload(BlockAllocator blockAllocator, long startIndex, RecordLengths recordLengths) Loads the key operationslongStore the record for specified keyvoidremove()Function removes all the keys from the sequence and remove the sequence itself, freeing all the resourcesbooleanSearches a key and removes the key if found.longremoveIfExpired(int blockIndex) This function is to look up the expired entries and remove themMethods 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
-
Method Details
-
getBlockSequence
A block sequence that underlies this operation's object- Returns:
- the block sequence
-
remove
public void remove()Function removes all the keys from the sequence and remove the sequence itself, freeing all the resources -
dump
public void dump()Dumps the content of the key catalog to theSystem.out. This is for debugging purposes. -
load
public static KeyBlockOperations load(BlockAllocator blockAllocator, long startIndex, RecordLengths recordLengths) Loads the key operations- Parameters:
blockAllocator- the block allocator to allocate new blocks on behalf of the keysstartIndex- the index of the first block in the sequencerecordLengths- the specification of lengths of elements for this class- Returns:
- the key operations object
-
create
Creates a new key operations, allocates a new sequence to manage the keys.In this way created element stays permanently in the underlying storage.
It can be loaded afterwards by
load(BlockAllocator, long, RecordLengths)- Parameters:
blockAllocator- the block allocator to be used to get the new blocksrecordLengths- the length of key entry's elements- Returns:
- the created instance
-
getStartIndex
public long getStartIndex()This is first block's index.- Returns:
- the index of first memory block
-
removeIfExpired
public long removeIfExpired(int blockIndex) This function is to look up the expired entries and remove them- Parameters:
blockIndex- the key block to lookup in- Returns:
- the id of the removed expired entry or
Utils.ID_UNDEFINEDif nothing has been deleted
-
remove
Searches a key and removes the key if found. throwsVersionMismatchExceptionif provided version is not matches to the state in the storage- Parameters:
key- the key to remove- Returns:
trueif the key is removed
-
put
Store the record for specified key- Parameters:
key- the key to storerecord- the record to store- Returns:
- the previous id (if one exists) or
Utils.ID_UNDEFINED
-
list
List the keys managed by this instance.It returns only subset of keys limited by
maxNumberandmaxSize, as well asstartWithKey- Parameters:
startWithKey- the prefix of the keyscontinuationKey- the key to start withmaxNumber- the maximum number of keys to returnmaxSize- the maximum size of keys to return- Returns:
- the list of keys
-
getRecord
Searches for the provided key and return theRecordassociated with it.- Parameters:
key- a key to return- Returns:
- the record if one has been found or
null
-
close
public void close()Description copied from interface:CloseableCloses this entity and all related blocks- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getStatus
Description copied from interface:CloseableProvides a status of this entity -
commit
public void commit()Description copied from interface:CommittableOperation 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
-