Package org.rocksdb
Class WriteBatchWithIndex
- java.lang.Object
-
- org.rocksdb.AbstractNativeReference
-
- org.rocksdb.AbstractImmutableNativeReference
-
- org.rocksdb.RocksObject
-
- org.rocksdb.AbstractWriteBatch
-
- org.rocksdb.WriteBatchWithIndex
-
- All Implemented Interfaces:
java.lang.AutoCloseable,WriteBatchInterface
public class WriteBatchWithIndex extends AbstractWriteBatch
Similar toWriteBatchbut with a binary searchable index built for all the keys inserted. Calling put, merge, remove or putLogData calls the same function as withWriteBatchwhilst also building an index. A user can callnewIterator()to create an iterator over the write batch ornewIteratorWithBase(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
Constructors Constructor Description WriteBatchWithIndex()Creates a WriteBatchWithIndex where no bytes are reserved up-front, bytewise 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, bytewise 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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.WBWIRocksIteratornewIterator()Create an iterator of the default column family.WBWIRocksIteratornewIterator(ColumnFamilyHandle columnFamilyHandle)Create an iterator of a column family.RocksIteratornewIteratorWithBase(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 base Updating write batch with the current key of the iterator is not safe.RocksIteratornewIteratorWithBase(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 base Updating write batch with the current key of the iterator is not safe.RocksIteratornewIteratorWithBase(RocksIterator baseIterator)Provides Read-Your-Own-Writes like functionality by creating a new Iterator that will useWBWIRocksIteratoras a delta and baseIterator as a base.RocksIteratornewIteratorWithBase(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, deleteRange, deleteRange, getWriteBatch, merge, merge, popSavePoint, put, put, put, put, putLogData, remove, remove, remove, remove, rollbackToSavePoint, setMaxBytes, setSavePoint, singleDelete, singleDelete
-
Methods inherited from class org.rocksdb.RocksObject
disposeInternal, getNativeHandle
-
Methods inherited from class org.rocksdb.AbstractImmutableNativeReference
close, disOwnNativeHandle, isOwningHandle
-
Methods inherited from class org.rocksdb.AbstractNativeReference
dispose, finalize
-
-
-
-
Constructor Detail
-
WriteBatchWithIndex
public WriteBatchWithIndex()
Creates a WriteBatchWithIndex where no bytes are reserved up-front, bytewise 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, bytewise 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 fallback to this comparator to compare keys within a column family if we cannot determine the column family and so look up it's 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 Detail
-
newIterator
public WBWIRocksIterator newIterator(ColumnFamilyHandle columnFamilyHandle)
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
public WBWIRocksIterator 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 base Updating write batch with the current key of the iterator is not safe. We strongly recommand 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 base Updating write batch with the current key of the iterator is not safe. We strongly recommand 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
public RocksIterator newIteratorWithBase(RocksIterator baseIterator)
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-timefrom baseIterator and modifications made in this write batch.
-
newIteratorWithBase
public RocksIterator 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. 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-timefrom 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
public byte[] getFromBatch(DBOptions options, byte[] key) throws RocksDBException
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). SettingReadOptions.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). SettingReadOptions.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
-
-