Overview
TheWriteOptions 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
Options
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 thewrite()system callsync=true: Similar crash semantics towrite()followed byfdatasync()
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.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.
If true and the write needs to wait or sleep, fails immediately with
Status::Incomplete() instead of blocking.Mark this write request as lower priority if compaction is behind.
- If
no_slowdown = true: Request canceled immediately withStatus::Incomplete() - If
no_slowdown = false: Request will be slowed down (slowdown value determined by RocksDB)
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).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.Number of bytes used to store protection information for each key entry. Currently supported values are zero (disabled) and eight.
Examples
Durability vs Performance Trade-offs
| Configuration | Durability | Performance | Use Case |
|---|---|---|---|
Default (sync=false, disableWAL=false) | Good | Good | Standard operations |
sync=true | Excellent | Low | Critical data that must survive crashes |
disableWAL=true | Poor | Excellent | Temporary data, batch loads |
sync=true, disableWAL=true | Invalid | - | Contradictory settings |
See Also
- ReadOptions - Options for read operations
- WriteBatch - Atomic batch writes
- FlushOptions - Options for manual flush operations