Package org.rocksdb
Class WriteBatch
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.AutoCloseable,WriteBatchInterface
public class WriteBatch extends AbstractWriteBatch
WriteBatch holds a collection of updates to apply atomically to a DB. The updates are applied in the order in which they are added to the WriteBatch. For example, the value of "key" will be "v3" after the following batch is written: batch.put("key", "v1"); batch.remove("key"); batch.put("key", "v2"); batch.put("key", "v3"); Multiple threads can invoke const methods on a WriteBatch without external synchronization, but if any of the threads may call a non-const method, all threads accessing the same WriteBatch must use external synchronization.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWriteBatch.HandlerHandler callback for iterating over the contents of a batch.static classWriteBatch.SavePointA structure for describing the save point in the Write Batch.
-
Field Summary
-
Fields inherited from class org.rocksdb.RocksObject
nativeHandle_
-
Fields inherited from class org.rocksdb.AbstractImmutableNativeReference
owningHandle_
-
-
Constructor Summary
Constructors Constructor Description WriteBatch()Constructs a WriteBatch instance.WriteBatch(byte[] serialized)Constructs a WriteBatch instance from a serialized representation as returned bydata().WriteBatch(int reserved_bytes)Constructs a WriteBatch instance with a given size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]data()Retrieve the serialized version of this batch.protected voiddisposeInternal(long handle)longgetDataSize()Retrieve data size of the batch.WriteBatch.SavePointgetWalTerminationPoint()Gets the WAL termination point.WriteBatchgetWriteBatch()Get the underlying Write Batch.booleanhasBeginPrepare()Returns true if MarkBeginPrepare will be called during Iterate.booleanhasCommit()Returns true if MarkCommit will be called during Iterate.booleanhasDelete()Returns true if Delete will be called during Iterate.booleanhasDeleteRange()Returns true if DeleteRange will be called during Iterate.booleanhasEndPrepare()Returns true if MarkEndPrepare will be called during Iterate.booleanhasMerge()Returns true if Merge will be called during Iterate.booleanhasPut()Returns true if Put will be called during Iterate.booleanhasRollback()Returns true if MarkRollback will be called during Iterate.booleanhasSingleDelete()Returns true if SingleDelete will be called during Iterate.voiditerate(WriteBatch.Handler handler)Support for iterating over the contents of a batch.voidmarkWalTerminationPoint()Marks this point in the WriteBatch as the last record to be inserted into the WAL, provided the WAL is enabled.-
Methods inherited from class org.rocksdb.AbstractWriteBatch
clear, count, delete, delete, deleteRange, deleteRange, 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
-
WriteBatch
public WriteBatch()
Constructs a WriteBatch instance.
-
WriteBatch
public WriteBatch(int reserved_bytes)
Constructs a WriteBatch instance with a given size.- Parameters:
reserved_bytes- reserved size for WriteBatch
-
WriteBatch
public WriteBatch(byte[] serialized)
Constructs a WriteBatch instance from a serialized representation as returned bydata().- Parameters:
serialized- the serialized representation.
-
-
Method Detail
-
iterate
public void iterate(WriteBatch.Handler handler) throws RocksDBException
Support for iterating over the contents of a batch.- Parameters:
handler- A handler that is called back for each update present in the batch- Throws:
RocksDBException- If we cannot iterate over the batch
-
data
public byte[] data() throws RocksDBExceptionRetrieve the serialized version of this batch.- Returns:
- the serialized representation of this write batch.
- Throws:
RocksDBException- if an error occurs whilst retrieving the serialized batch data.
-
getDataSize
public long getDataSize()
Retrieve data size of the batch.- Returns:
- the serialized data size of the batch.
-
hasPut
public boolean hasPut()
Returns true if Put will be called during Iterate.- Returns:
- true if Put will be called during Iterate.
-
hasDelete
public boolean hasDelete()
Returns true if Delete will be called during Iterate.- Returns:
- true if Delete will be called during Iterate.
-
hasSingleDelete
public boolean hasSingleDelete()
Returns true if SingleDelete will be called during Iterate.- Returns:
- true if SingleDelete will be called during Iterate.
-
hasDeleteRange
public boolean hasDeleteRange()
Returns true if DeleteRange will be called during Iterate.- Returns:
- true if DeleteRange will be called during Iterate.
-
hasMerge
public boolean hasMerge()
Returns true if Merge will be called during Iterate.- Returns:
- true if Merge will be called during Iterate.
-
hasBeginPrepare
public boolean hasBeginPrepare()
Returns true if MarkBeginPrepare will be called during Iterate.- Returns:
- true if MarkBeginPrepare will be called during Iterate.
-
hasEndPrepare
public boolean hasEndPrepare()
Returns true if MarkEndPrepare will be called during Iterate.- Returns:
- true if MarkEndPrepare will be called during Iterate.
-
hasCommit
public boolean hasCommit()
Returns true if MarkCommit will be called during Iterate.- Returns:
- true if MarkCommit will be called during Iterate.
-
hasRollback
public boolean hasRollback()
Returns true if MarkRollback will be called during Iterate.- Returns:
- true if MarkRollback will be called during Iterate.
-
getWriteBatch
public WriteBatch getWriteBatch()
Description copied from interface:WriteBatchInterfaceGet the underlying Write Batch.- Specified by:
getWriteBatchin interfaceWriteBatchInterface- Overrides:
getWriteBatchin classAbstractWriteBatch- Returns:
- the underlying WriteBatch.
-
markWalTerminationPoint
public void markWalTerminationPoint()
Marks this point in the WriteBatch as the last record to be inserted into the WAL, provided the WAL is enabled.
-
getWalTerminationPoint
public WriteBatch.SavePoint getWalTerminationPoint()
Gets the WAL termination point. SeemarkWalTerminationPoint()- Returns:
- the WAL termination point
-
disposeInternal
protected final void disposeInternal(long handle)
- Specified by:
disposeInternalin classRocksObject
-
-