Interface WriteBatchInterface
-
- All Known Implementing Classes:
AbstractWriteBatch,WriteBatch,WriteBatchWithIndex
public interface WriteBatchInterfaceDefines the interface for a Write Batch which holds a collection of updates to apply atomically to a DB.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidclear()Clear all updates buffered in this batchintcount()Returns the number of updates in the batch.voiddelete(byte[] key)If the database contains a mapping for "key", erase it.voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[] key)If column family contains a mapping for "key", erase it.voiddeleteRange(byte[] beginKey, byte[] endKey)Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".voiddeleteRange(ColumnFamilyHandle columnFamilyHandle, byte[] beginKey, byte[] endKey)Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".WriteBatchgetWriteBatch()Get the underlying Write Batch.voidmerge(byte[] key, byte[] value)Merge "value" with the existing value of "key" in the database.voidmerge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Merge "value" with the existing value of "key" in given column family.voidpopSavePoint()Pop the most recent save point.voidput(byte[] key, byte[] value)Store the mapping "key->value" in the database.voidput(java.nio.ByteBuffer key, java.nio.ByteBuffer value)Store the mapping "key->value" within given column family.voidput(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Store the mapping "key->value" within given column family.voidput(ColumnFamilyHandle columnFamilyHandle, java.nio.ByteBuffer key, java.nio.ByteBuffer value)Store the mapping "key->value" within given column family.voidputLogData(byte[] blob)Append a blob of arbitrary size to the records in this batch.voidremove(byte[] key)Deprecated.Usedelete(byte[])voidremove(java.nio.ByteBuffer key)If column family contains a mapping for "key", erase it.voidremove(ColumnFamilyHandle columnFamilyHandle, byte[] key)Deprecated.voidremove(ColumnFamilyHandle columnFamilyHandle, java.nio.ByteBuffer key)If column family contains a mapping for "key", erase it.voidrollbackToSavePoint()Remove all entries in this batch (Put, Merge, Delete, PutLogData) since the most recent call to SetSavePoint() and removes the most recent save point.voidsetMaxBytes(long maxBytes)Set the maximum size of the write batch.voidsetSavePoint()Records the state of the batch for future calls to RollbackToSavePoint().voidsingleDelete(byte[] key)Remove the database entry forkey.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key)Remove the database entry forkey.
-
-
-
Method Detail
-
count
int count()
Returns the number of updates in the batch.- Returns:
- number of items in WriteBatch
-
put
void put(byte[] key, byte[] value) throws RocksDBExceptionStore the mapping "key->value" in the database.
- Parameters:
key- the specified key to be inserted.value- the value associated with the specified key.- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
put
void put(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) throws RocksDBException
Store the mapping "key->value" within given column family.
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- the specified key to be inserted.value- the value associated with the specified key.- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
put
void put(java.nio.ByteBuffer key, java.nio.ByteBuffer value) throws RocksDBExceptionStore the mapping "key->value" within given column family.
- Parameters:
key- the specified key to be inserted. It is using position and limit. Supports direct buffer only.value- the value associated with the specified key. It is using position and limit. Supports direct buffer only.- Throws:
RocksDBException
-
put
void put(ColumnFamilyHandle columnFamilyHandle, java.nio.ByteBuffer key, java.nio.ByteBuffer value) throws RocksDBException
Store the mapping "key->value" within given column family.
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- the specified key to be inserted. It is using position and limit. Supports direct buffer only.value- the value associated with the specified key. It is using position and limit. Supports direct buffer only.- Throws:
RocksDBException
-
merge
void merge(byte[] key, byte[] value) throws RocksDBExceptionMerge "value" with the existing value of "key" in the database. "key->merge(existing, value)"
- Parameters:
key- the specified key to be merged.value- the value to be merged with the current value for the specified key.- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
merge
void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) throws RocksDBException
Merge "value" with the existing value of "key" in given column family. "key->merge(existing, value)"
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- the specified key to be merged.value- the value to be merged with the current value for the specified key.- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
remove
@Deprecated void remove(byte[] key) throws RocksDBExceptionDeprecated.Usedelete(byte[])If the database contains a mapping for "key", erase it. Else do nothing.
- Parameters:
key- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
remove
@Deprecated void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException
Deprecated.If column family contains a mapping for "key", erase it. Else do nothing.
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
delete
void delete(byte[] key) throws RocksDBExceptionIf the database contains a mapping for "key", erase it. Else do nothing.
- Parameters:
key- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
delete
void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException
If column family contains a mapping for "key", erase it. Else do nothing.
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
singleDelete
@Experimental("Performance optimization for a very specific workload") void singleDelete(byte[] key) throws RocksDBException
Remove the database entry forkey. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by callingput(byte[], byte[])multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.- Parameters:
key- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
singleDelete
@Experimental("Performance optimization for a very specific workload") void singleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException
Remove the database entry forkey. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by callingput(byte[], byte[])multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.- Parameters:
columnFamilyHandle- The column family to delete the key fromkey- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
remove
void remove(java.nio.ByteBuffer key) throws RocksDBExceptionIf column family contains a mapping for "key", erase it. Else do nothing.
- Parameters:
key- Key to delete within database. It is using position and limit. Supports direct buffer only.- Throws:
RocksDBException
-
remove
void remove(ColumnFamilyHandle columnFamilyHandle, java.nio.ByteBuffer key) throws RocksDBException
If column family contains a mapping for "key", erase it. Else do nothing.
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- Key to delete within database. It is using position and limit. Supports direct buffer only.- Throws:
RocksDBException
-
deleteRange
void deleteRange(byte[] beginKey, byte[] endKey) throws RocksDBExceptionRemoves the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.- Parameters:
beginKey- First key to delete within database (included)endKey- Last key to delete within database (excluded)- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
deleteRange
void deleteRange(ColumnFamilyHandle columnFamilyHandle, byte[] beginKey, byte[] endKey) throws RocksDBException
Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancebeginKey- First key to delete within database (included)endKey- Last key to delete within database (excluded)- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
putLogData
void putLogData(byte[] blob) throws RocksDBExceptionAppend a blob of arbitrary size to the records in this batch. The blob will be stored in the transaction log but not in any other file. In particular, it will not be persisted to the SST files. When iterating over this WriteBatch, WriteBatch::Handler::LogData will be called with the contents of the blob as it is encountered. Blobs, puts, deletes, and merges will be encountered in the same order in thich they were inserted. The blob will NOT consume sequence number(s) and will NOT increase the count of the batch Example application: add timestamps to the transaction log for use in replication.- Parameters:
blob- binary object to be inserted- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
clear
void clear()
Clear all updates buffered in this batch
-
setSavePoint
void setSavePoint()
Records the state of the batch for future calls to RollbackToSavePoint(). May be called multiple times to set multiple save points.
-
rollbackToSavePoint
void rollbackToSavePoint() throws RocksDBExceptionRemove all entries in this batch (Put, Merge, Delete, PutLogData) since the most recent call to SetSavePoint() and removes the most recent save point.- Throws:
RocksDBException- if there is no previous call to SetSavePoint()
-
popSavePoint
void popSavePoint() throws RocksDBExceptionPop the most recent save point. That is to say that it removes the last save point, which was set bysetSavePoint().- Throws:
RocksDBException- If there is no previous call tosetSavePoint(), an exception withStatus.Code.NotFoundwill be thrown.
-
setMaxBytes
void setMaxBytes(long maxBytes)
Set the maximum size of the write batch.- Parameters:
maxBytes- the maximum size in bytes.
-
getWriteBatch
WriteBatch getWriteBatch()
Get the underlying Write Batch.- Returns:
- the underlying WriteBatch.
-
-