Class WriteBatchWithIndex
- All Implemented Interfaces:
AutoCloseable,WriteBatchInterface
WriteBatch but with a binary searchable
index built for all the keys inserted.
Calling put, merge, remove or putLogData calls the same function
as with WriteBatch whilst also building an index.
A user can call newIterator() to
create an iterator over the write batch or
newIteratorWithBase(org.rocksdb.RocksIterator)
to get an iterator for the database with Read-Your-Own-Writes like capability
-
Field Summary
Fields inherited from class org.rocksdb.RocksObject
nativeHandle_Fields inherited from class org.rocksdb.AbstractImmutableNativeReference
owningHandle_ -
Constructor Summary
ConstructorsConstructorDescriptionCreates a WriteBatchWithIndex where no bytes are reserved up-front, byte wise comparison is used for fallback key comparisons, and duplicate keys operations are retainedWriteBatchWithIndex(boolean overwriteKey) Creates a WriteBatchWithIndex where no bytes are reserved up-front, byte wise comparison is used for fallback key comparisons, and duplicate key assignment is determined by the constructor argumentWriteBatchWithIndex(AbstractComparator fallbackIndexComparator, int reservedBytes, boolean overwriteKey) Creates a WriteBatchWithIndex -
Method Summary
Modifier and TypeMethodDescriptionprotected final voiddisposeInternal(long handle) byte[]getFromBatch(ColumnFamilyHandle columnFamilyHandle, DBOptions options, byte[] key) Similar toRocksDB.get(ColumnFamilyHandle, byte[])but will only read the key from this batch.byte[]getFromBatch(DBOptions options, byte[] key) Similar toRocksDB.get(byte[])but will only read the key from this batch.byte[]getFromBatchAndDB(RocksDB db, ColumnFamilyHandle columnFamilyHandle, ReadOptions options, byte[] key) Similar toRocksDB.get(ColumnFamilyHandle, byte[])but will also read writes from this batch.byte[]getFromBatchAndDB(RocksDB db, ReadOptions options, byte[] key) Similar toRocksDB.get(byte[])but will also read writes from this batch.Create an iterator of the default column family.newIterator(ColumnFamilyHandle columnFamilyHandle) Create an iterator of a column family.newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle, RocksIterator baseIterator) Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a basenewIteratorWithBase(ColumnFamilyHandle columnFamilyHandle, RocksIterator baseIterator, ReadOptions readOptions) Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a basenewIteratorWithBase(RocksIterator baseIterator) Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a base.newIteratorWithBase(RocksIterator baseIterator, ReadOptions readOptions) Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a base.Methods inherited from class org.rocksdb.AbstractWriteBatch
clear, count, delete, delete, delete, delete, deleteRange, deleteRange, getWriteBatch, merge, merge, popSavePoint, put, put, put, put, putLogData, rollbackToSavePoint, setMaxBytes, setSavePoint, singleDelete, singleDeleteMethods inherited from class org.rocksdb.RocksObject
disposeInternal, getNativeHandleMethods inherited from class org.rocksdb.AbstractImmutableNativeReference
close, disOwnNativeHandle, isOwningHandle
-
Constructor Details
-
WriteBatchWithIndex
public WriteBatchWithIndex()Creates a WriteBatchWithIndex where no bytes are reserved up-front, byte wise comparison is used for fallback key comparisons, and duplicate keys operations are retained -
WriteBatchWithIndex
public WriteBatchWithIndex(boolean overwriteKey) Creates a WriteBatchWithIndex where no bytes are reserved up-front, byte wise comparison is used for fallback key comparisons, and duplicate key assignment is determined by the constructor argument- Parameters:
overwriteKey- if true, overwrite the key in the index when inserting a duplicate key, in this way an iterator will never show two entries with the same key.
-
WriteBatchWithIndex
public WriteBatchWithIndex(AbstractComparator fallbackIndexComparator, int reservedBytes, boolean overwriteKey) Creates a WriteBatchWithIndex- Parameters:
fallbackIndexComparator- We fall back to this comparator to compare keys within a column family if we cannot determine the column family and so look up its comparator.reservedBytes- reserved bytes in underlying WriteBatchoverwriteKey- if true, overwrite the key in the index when inserting a duplicate key, in this way an iterator will never show two entries with the same key.
-
-
Method Details
-
newIterator
Create an iterator of a column family. User can callRocksIteratorInterface.seek(byte[])to search to the next entry of or after a key. Keys will be iterated in the order given by index_comparator. For multiple updates on the same key, each update will be returned as a separate entry, in the order of update time.- Parameters:
columnFamilyHandle- The column family to iterate over- Returns:
- An iterator for the Write Batch contents, restricted to the column family
-
newIterator
Create an iterator of the default column family. User can callRocksIteratorInterface.seek(byte[])to search to the next entry of or after a key. Keys will be iterated in the order given by index_comparator. For multiple updates on the same key, each update will be returned as a separate entry, in the order of update time.- Returns:
- An iterator for the Write Batch contents
-
newIteratorWithBase
public RocksIterator newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle, RocksIterator baseIterator) Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a baseUpdating write batch with the current key of the iterator is not safe. We strongly recommend users not to do it. It will invalidate the current key() and value() of the iterator. This invalidation happens even before the write batch update finishes. The state may recover after Next() is called.
- Parameters:
columnFamilyHandle- The column family to iterate overbaseIterator- The base iterator, e.g.RocksDB.newIterator()- Returns:
- An iterator which shows a view comprised of both the database point-in-time from baseIterator and modifications made in this write batch.
-
newIteratorWithBase
public RocksIterator newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle, RocksIterator baseIterator, ReadOptions readOptions) Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a baseUpdating write batch with the current key of the iterator is not safe. We strongly recommend users not to do it. It will invalidate the current key() and value() of the iterator. This invalidation happens even before the write batch update finishes. The state may recover after Next() is called.
- Parameters:
columnFamilyHandle- The column family to iterate overbaseIterator- The base iterator, e.g.RocksDB.newIterator()readOptions- the read options, or null- Returns:
- An iterator which shows a view comprised of both the database point-in-time from baseIterator and modifications made in this write batch.
-
newIteratorWithBase
Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a base. Operates on the default column family.- Parameters:
baseIterator- The base iterator, e.g.RocksDB.newIterator()- Returns:
- An iterator which shows a view comprised of both the database point-in-time from baseIterator and modifications made in this write batch.
-
newIteratorWithBase
Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a base. Operates on the default column family.- Parameters:
baseIterator- The base iterator, e.g.RocksDB.newIterator()readOptions- the read options, or null- Returns:
- An iterator which shows a view comprised of both the database point-in-time from baseIterator and modifications made in this write batch.
-
getFromBatch
public byte[] getFromBatch(ColumnFamilyHandle columnFamilyHandle, DBOptions options, byte[] key) throws RocksDBException Similar toRocksDB.get(ColumnFamilyHandle, byte[])but will only read the key from this batch.- Parameters:
columnFamilyHandle- The column family to retrieve the value fromoptions- The database options to usekey- The key to read the value for- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- if the batch does not have enough data to resolve Merge operations, MergeInProgress status may be returned.
-
getFromBatch
Similar toRocksDB.get(byte[])but will only read the key from this batch.- Parameters:
options- The database options to usekey- The key to read the value for- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- if the batch does not have enough data to resolve Merge operations, MergeInProgress status may be returned.
-
getFromBatchAndDB
public byte[] getFromBatchAndDB(RocksDB db, ColumnFamilyHandle columnFamilyHandle, ReadOptions options, byte[] key) throws RocksDBException Similar toRocksDB.get(ColumnFamilyHandle, byte[])but will also read writes from this batch.This function will query both this batch and the DB and then merge the results using the DB's merge operator (if the batch contains any merge requests).
Setting
ReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from the batch (the keys in this batch do not yet belong to any snapshot and will be fetched regardless).- Parameters:
db- The Rocks databasecolumnFamilyHandle- The column family to retrieve the value fromoptions- The read options to usekey- The key to read the value for- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- if the value for the key cannot be read
-
getFromBatchAndDB
public byte[] getFromBatchAndDB(RocksDB db, ReadOptions options, byte[] key) throws RocksDBException Similar toRocksDB.get(byte[])but will also read writes from this batch.This function will query both this batch and the DB and then merge the results using the DB's merge operator (if the batch contains any merge requests).
Setting
ReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from the batch (the keys in this batch do not yet belong to any snapshot and will be fetched regardless).- Parameters:
db- The Rocks databaseoptions- The read options to usekey- The key to read the value for- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- if the value for the key cannot be read
-
disposeInternal
protected final void disposeInternal(long handle) - Specified by:
disposeInternalin classRocksObject
-