Skip to main content

Overview

The WriteOptions structure controls the behavior of write operations including Put(), Delete(), Merge(), and Write() (WriteBatch). It allows you to configure durability guarantees, write-ahead log behavior, and rate limiting.

Constructor

WriteOptions()
explicit WriteOptions(Env::IOActivity io_activity)
explicit WriteOptions(Env::IOPriority rate_limiter_priority,
                      Env::IOActivity io_activity = Env::IOActivity::kUnknown)

Options

sync
bool
default:"false"
If true, the write will be flushed from the operating system buffer cache (by calling WritableFile::Sync()) before the write is considered complete. Writes will be slower but more durable.
  • sync=false: Similar crash semantics as the write() system call
  • sync=true: Similar crash semantics to write() followed by fdatasync()
If false and the machine crashes, some recent writes may be lost. If only the process crashes (without machine reboot), no writes are lost.
disableWAL
bool
default:"false"
If true, writes will not go to the write-ahead log, and the write may be lost after a crash.Important: The backup engine relies on write-ahead logs. If you disable WAL, you must create backups with flush_before_backup=true to avoid losing unflushed memtable data.
ignore_missing_column_families
bool
default:"false"
If true and user is trying to write to column families that don’t exist (they were dropped), ignore the write instead of returning an error. If there are multiple writes in a WriteBatch, other writes will still succeed.
no_slowdown
bool
default:"false"
If true and the write needs to wait or sleep, fails immediately with Status::Incomplete() instead of blocking.
low_pri
bool
default:"false"
Mark this write request as lower priority if compaction is behind.
  • If no_slowdown = true: Request canceled immediately with Status::Incomplete()
  • If no_slowdown = false: Request will be slowed down (slowdown value determined by RocksDB)
memtable_insert_hint_per_batch
bool
default:"false"
If true, this WriteBatch maintains the last insert positions of each memtable as hints in concurrent writes. Can improve write performance if keys in one WriteBatch are sequential.Ignored in non-concurrent writes (when concurrent_memtable_writes = false).
rate_limiter_priority
Env::IOPriority
default:"Env::IO_TOTAL"
Charge the rate limiter at the specified priority. Special value Env::IO_TOTAL disables charging the rate limiter.Currently covers automatic WAL flushes during live updates when disableWAL = false and manual_wal_flush = false.Only Env::IO_USER and Env::IO_TOTAL are allowed due to implementation constraints.
protection_bytes_per_key
size_t
default:"0"
Number of bytes used to store protection information for each key entry. Currently supported values are zero (disabled) and eight.

Examples

WriteOptions options;
Status s = db->Put(options, "key1", "value");
assert(s.ok());

Durability vs Performance Trade-offs

ConfigurationDurabilityPerformanceUse Case
Default (sync=false, disableWAL=false)GoodGoodStandard operations
sync=trueExcellentLowCritical data that must survive crashes
disableWAL=truePoorExcellentTemporary data, batch loads
sync=true, disableWAL=trueInvalid-Contradictory settings

See Also

Build docs developers (and LLMs) love