public class WriteBatchWithIndex extends AbstractWriteBatch
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
nativeHandle_
owningHandle_
Constructor and Description |
---|
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(AbstractComparator fallbackIndexComparator,
int reservedBytes,
boolean overwriteKey)
Creates a WriteBatchWithIndex
|
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
|
Modifier and Type | Method and Description |
---|---|
protected void |
disposeInternal(long handle) |
byte[] |
getFromBatch(ColumnFamilyHandle columnFamilyHandle,
DBOptions options,
byte[] key)
Similar to
RocksDB.get(ColumnFamilyHandle, byte[]) but will only
read the key from this batch. |
byte[] |
getFromBatch(DBOptions options,
byte[] key)
Similar to
RocksDB.get(byte[]) but will only
read the key from this batch. |
byte[] |
getFromBatchAndDB(RocksDB db,
ColumnFamilyHandle columnFamilyHandle,
ReadOptions options,
byte[] key)
Similar to
RocksDB.get(ColumnFamilyHandle, byte[]) but will also
read writes from this batch. |
byte[] |
getFromBatchAndDB(RocksDB db,
ReadOptions options,
byte[] key)
Similar to
RocksDB.get(byte[]) but will also
read writes from this batch. |
WBWIRocksIterator |
newIterator()
Create an iterator of the default column family.
|
WBWIRocksIterator |
newIterator(ColumnFamilyHandle columnFamilyHandle)
Create an iterator of a column family.
|
RocksIterator |
newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle,
RocksIterator baseIterator)
Provides Read-Your-Own-Writes like functionality by
creating a new Iterator that will use
WBWIRocksIterator
as a delta and baseIterator as a base |
RocksIterator |
newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle,
RocksIterator baseIterator,
ReadOptions readOptions)
Provides Read-Your-Own-Writes like functionality by
creating a new Iterator that will use
WBWIRocksIterator
as a delta and baseIterator as a base |
RocksIterator |
newIteratorWithBase(RocksIterator baseIterator)
Provides Read-Your-Own-Writes like functionality by
creating a new Iterator that will use
WBWIRocksIterator
as a delta and baseIterator as a base. |
RocksIterator |
newIteratorWithBase(RocksIterator baseIterator,
ReadOptions readOptions)
Provides Read-Your-Own-Writes like functionality by
creating a new Iterator that will use
WBWIRocksIterator
as a delta and baseIterator as a base. |
clear, count, delete, delete, delete, delete, deleteRange, deleteRange, getWriteBatch, merge, merge, popSavePoint, put, put, put, put, putLogData, rollbackToSavePoint, setMaxBytes, setSavePoint, singleDelete, singleDelete
disposeInternal, getNativeHandle
close, disOwnNativeHandle, isOwningHandle
public WriteBatchWithIndex()
public WriteBatchWithIndex(boolean overwriteKey)
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.public WriteBatchWithIndex(AbstractComparator fallbackIndexComparator, int reservedBytes, boolean overwriteKey)
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.public WBWIRocksIterator newIterator(ColumnFamilyHandle columnFamilyHandle)
RocksIteratorInterface.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.columnFamilyHandle
- The column family to iterate overpublic WBWIRocksIterator newIterator()
RocksIteratorInterface.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.public RocksIterator newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle, RocksIterator baseIterator)
WBWIRocksIterator
as a delta and baseIterator as a base
Updating 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.
columnFamilyHandle
- The column family to iterate overbaseIterator
- The base iterator,
e.g. RocksDB.newIterator()
public RocksIterator newIteratorWithBase(ColumnFamilyHandle columnFamilyHandle, RocksIterator baseIterator, ReadOptions readOptions)
WBWIRocksIterator
as a delta and baseIterator as a base
Updating 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.
columnFamilyHandle
- The column family to iterate overbaseIterator
- The base iterator,
e.g. RocksDB.newIterator()
readOptions
- the read options, or nullpublic RocksIterator newIteratorWithBase(RocksIterator baseIterator)
WBWIRocksIterator
as a delta and baseIterator as a base. Operates on the default column
family.baseIterator
- The base iterator,
e.g. RocksDB.newIterator()
public RocksIterator newIteratorWithBase(RocksIterator baseIterator, ReadOptions readOptions)
WBWIRocksIterator
as a delta and baseIterator as a base. Operates on the default column
family.baseIterator
- The base iterator,
e.g. RocksDB.newIterator()
readOptions
- the read options, or nullpublic byte[] getFromBatch(ColumnFamilyHandle columnFamilyHandle, DBOptions options, byte[] key) throws RocksDBException
RocksDB.get(ColumnFamilyHandle, byte[])
but will only
read the key from this batch.columnFamilyHandle
- The column family to retrieve the value fromoptions
- The database options to usekey
- The key to read the value forRocksDBException
- if the batch does not have enough data to resolve
Merge operations, MergeInProgress status may be returned.public byte[] getFromBatch(DBOptions options, byte[] key) throws RocksDBException
RocksDB.get(byte[])
but will only
read the key from this batch.options
- The database options to usekey
- The key to read the value forRocksDBException
- if the batch does not have enough data to resolve
Merge operations, MergeInProgress status may be returned.public byte[] getFromBatchAndDB(RocksDB db, ColumnFamilyHandle columnFamilyHandle, ReadOptions options, byte[] key) throws RocksDBException
RocksDB.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).
db
- The Rocks databasecolumnFamilyHandle
- The column family to retrieve the value fromoptions
- The read options to usekey
- The key to read the value forRocksDBException
- if the value for the key cannot be readpublic byte[] getFromBatchAndDB(RocksDB db, ReadOptions options, byte[] key) throws RocksDBException
RocksDB.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).
db
- The Rocks databaseoptions
- The read options to usekey
- The key to read the value forRocksDBException
- if the value for the key cannot be readprotected final void disposeInternal(long handle)
disposeInternal
in class RocksObject