Overview
TheWriteBatch class holds a collection of updates to apply atomically to a database. All updates are applied in the order they are added to the WriteBatch. WriteBatch supports Put, Delete, Merge, and DeleteRange operations.
Constructor
size_t
default:"0"
Number of bytes to pre-allocate for the batch. Useful for avoiding reallocations when batch size is known.
size_t
default:"0"
Maximum size of the batch in bytes. If 0, no limit is enforced.
size_t
default:"0"
Number of bytes used to store protection information for each key entry. Currently supported values are zero (disabled) and eight.
Write Operations
Put
Store the mapping “key->value” in the database.ColumnFamilyHandle*
Target column family. If
nullptr, uses the default column family.const Slice&
The key to store. When user-defined timestamp is enabled,
key should point to a contiguous buffer with timestamp appended after user key.const Slice&
User-defined timestamp for the key.
const Slice&
The value to associate with the key.
TimedPut (Experimental)
Stores the mapping “key->value” with a specified write time.uint64_t
Unix timestamp indicating when the write occurred.
PutEntity
Store wide column entities.Delete
Erase a key from the database.SingleDelete
See DB::SingleDelete() for semantics and constraints.DeleteRange
Delete a range of keys [begin_key, end_key).const Slice&
Start of the range (inclusive).
const Slice&
End of the range (exclusive).
Merge
Merge “value” with the existing value of “key” using the merge operator.Utility Methods
Clear
resize() on the string buffer, so allocated memory capacity may not be freed.
Count
GetDataSize
Data
SetMaxBytes
Save Points
Save points allow you to rollback portions of a WriteBatch.SetSavePoint
RollbackToSavePoint(). May be called multiple times.
RollbackToSavePoint
SetSavePoint() and removes that save point. Returns Status::NotFound() if no save point exists.
PopSavePoint
Status::NotFound() if no save point exists.
Content Queries
Query what types of operations are in the batch:Iteration
Handler
Implement aWriteBatch::Handler to iterate over the contents of a batch:
Iterate
Examples
Thread Safety
Multiple threads can invoke const methods on a WriteBatch without external synchronization. However, if any thread may call a non-const method, all threads accessing the same WriteBatch must use external synchronization.See Also
- WriteOptions - Options for write operations
- ReadOptions - Options for read operations
- DB Write Methods - Database write operations