RocksDB-Sharp

Read & Write Options

ReadOptions and WriteOptions are per-call options. You can keep singletons around and re-use them, or build new ones on the fly.

If you pass null (or omit the parameter), the call uses internal defaults — a fresh ReadOptions() and WriteOptions().


ReadOptions

ReadOptions controls a single Get, MultiGet, or NewIterator call. It carries snapshot pinning, iterate bounds, and a handful of performance knobs.

var ro = new ReadOptions()
    .SetSnapshot(snap)
    .SetFillCache(false)
    .SetIterateLowerBound("user:")
    .SetIterateUpperBound("user;");
Setter What it does
SetSnapshot(Snapshot) Pin the read to a specific snapshot. See Snapshots.
SetVerifyChecksums(bool) Verify SST/block checksums on read.
SetFillCache(bool) If false, blocks read by this call won't pollute the block cache. Useful for large scans.
SetIterateLowerBound(...) Skip SST files / blocks below this key in iterators.
SetIterateUpperBound(...) Skip SST files / blocks at or above this key in iterators.
SetPrefixSameAsStart(bool) Constrain prefix-seek iterators to a single prefix bucket.
SetTotalOrderSeek(bool) Force a CF with a prefix_extractor to scan across prefixes.
SetTailing(bool) Tailing iterator that follows new writes.
SetReadTier(int) 0=any tier, 1=block cache + memtable, 2=memtable only, 3=persisted tier only.
SetReadaheadSize(ulong) Read-ahead size for iterator scans.
SetAutoReadaheadSize(bool) Auto-tuned readahead.
SetAsyncIO(bool) Allow async I/O for iterator scans.
SetPinData(bool) Pin iterator values in the block cache.
SetBackgroundPurgeOnIteratorCleanup(bool) Move iterator cleanup off the request thread.

Upstream reference: include/rocksdb/options.h, Iterator wiki.

Examples

// A bounded range scan that doesn't pollute the block cache:
var ro = new ReadOptions()
    .SetIterateLowerBound("events:2026-05-")
    .SetIterateUpperBound("events:2026-06-")
    .SetFillCache(false);

using var it = db.NewIterator(readOptions: ro);
// Read at a specific snapshot:
using var snap = db.CreateSnapshot();
var ro = new ReadOptions().SetSnapshot(snap);
string v = db.Get("k", readOptions: ro);

WriteOptions

WriteOptions controls durability and WAL behaviour for a single Put, Merge, Remove, or Write call.

var sync = new WriteOptions().SetSync(true);
db.Put("k", "v", writeOptions: sync);
Setter What it does
SetSync(bool) true blocks until the WAL is fsynced. Far slower, much safer on crash.
DisableWal(int) 1 = skip the WAL entirely for this write. Faster but not crash-safe.

For knobs that aren't exposed on the C# WriteOptions class — ignore_missing_column_families, no_slowdown, low_pri, memtable_insert_hint_per_batch — drop down to the native layer and call the matching rocksdb_writeoptions_* setter directly on the Handle.

Upstream reference: WriteOptions in options.h.

Examples

// Fully durable write:
var sync = new WriteOptions().SetSync(true);
db.Put("ledger:42", "...", writeOptions: sync);

// Throw-away analytics CF — speed over durability:
var nowal = new WriteOptions().DisableWal(1);
db.Put("metric:cpu", "..", writeOptions: nowal);
DisableWal voids crash safety

Writes with DisableWal(1) are only durable once the next MemTable flush hits disk. A process crash in between loses every WAL-skipped write since the last flush. Use only for ephemeral / re-computable data, or pair with explicit db.Flush(...).

Sync per batch, not per put

The cost of Sync(true) is per fsync, not per key. If you need durability, batch many keys into a single WriteBatch and sync that — orders of magnitude faster than syncing every Put.

Referenced by

© 2026 RocksDB-Sharp. All rights reserved.