Overview
TheReadOptions structure provides fine-grained control over read operations including point lookups (Get, MultiGet) and scans (iterators). It allows you to configure snapshots, caching behavior, iteration bounds, and performance optimizations.
Constructor
Common Options (Point Lookups & Scans)
Read as of the supplied snapshot (which must belong to the DB and not have been released). If
nullptr, uses an implicit snapshot of the state at the beginning of the read operation.Timestamp of operation. Read returns the latest data visible to the specified timestamp. For iterators,
iter_start_ts is the lower bound (older) and timestamp serves as the upper bound.Lower bound timestamp for iterator. Versions of the same record that fall in the timestamp range will be returned. If
nullptr, only the most recent version visible to timestamp is returned.Deadline for completing an API call (Get/MultiGet/Seek/Next) in microseconds since epoch (e.g.,
env->NowMicros() + timeout). Best efforts - the call may exceed the deadline if there is I/O involved.Timeout for each individual file read request. Unlike
deadline, each read in a MultiGet/Scan can last up to io_timeout microseconds.Specify which cache tier to read from:
kReadAllTier: Read from memtable, block cache, OS cache, or storagekBlockCacheTier: Read only from memtable or block cachekPersistedTier: Read only persisted data (skips memtable when WAL disabled)kMemtableTier: Read only from memtable (for memtable-only iterators)
If true, all data read from underlying storage will be verified against corresponding checksums.
Should data blocks read for this operation be placed in block cache? Set to
false for bulk scans to avoid evicting cached data.Charge the rate limiter at the specified priority. Special value
Env::IO_TOTAL disables rate limiting. The bytes charged may not exactly match file read bytes.Limits the maximum cumulative value size while reading through MultiGet. Once exceeded, remaining keys return with status Aborted.
When the number of merge operands applied exceeds this threshold during a query, returns OK with subcode
kMergeOperandThresholdExceeded. Currently only applies to point lookups.Iterator-Specific Options
RocksDB auto-readahead starts at 8KB and doubles up to 256KB. Use this option for large range scans that need more aggressive readahead. Values > 2MB typically improve performance on spinning disks.
Threshold for keys that can be skipped before failing an iterator seek as incomplete. Default of 0 means never fail.
Smallest key at which the backward iterator can return an entry (inclusive). Once passed,
Valid() returns false. Must have the same prefix as seek target if prefix_extractor is set.Extent up to which the forward iterator can return entries (exclusive). Once reached,
Valid() returns false. If not nullptr, SeekToLast() positions at the first key smaller than this bound.Create a tailing iterator with a view of the complete database, optimized for sequential reads. Can read newly added data after iterator creation.
Enable total order seek regardless of index format (e.g., hash index). When calling
Get(), also skips prefix bloom.When true, uses
total_order_seek = true by default, and RocksDB selectively enables prefix seek mode when it won’t generate different results.Enforce that the iterator only iterates over the same prefix as the seek key. Enables prefix filtering optimizations for both Seek and SeekForPrev.
Keep blocks loaded by the iterator pinned in memory as long as the iterator is not deleted. When enabled with
use_delta_encoding = false, the property rocksdb.iterator.is-key-pinned returns 1.Enable enhancements for prefetching data during sequential reads.
Auto-tune the readahead size during scans based on block cache data and iteration bounds. Requires block cache enabled and either
iterate_upper_bound != nullptr or prefix_same_as_start == true.If enabled, RocksDB prefetches data asynchronously for sequential reads.
When
async_io is set, controls whether to read SST files in multiple levels asynchronously. Helps reduce MultiGet latency by maximizing parallel SST reads.Schedule deletion of obsolete files in background when PurgeObsoleteFile is called in CleanupIteratorState.
DEPRECATED: Skip range tombstone handling in key lookup paths. Only use if the DB never calls
DeleteRange(). Setting to true with DeleteRange in use may serve stale keys.Callback to determine whether relevant keys exist in a table based on table properties. If returns false, the table is not scanned. Only affects iterators.
Iterator may defer loading/preparing values when moving to a different entry. Call
PrepareValue() before accessing values. Only applies to BlobDB large values and multi-CF iterators.EXPERIMENTAL: Long-running iterators release resources as they make progress. Requires non-nullptr
snapshot. Not recommended with user-defined timestamps.Examples
See Also
- WriteOptions - Options for write operations
- Iterator API - Iterator methods and usage
- WriteBatch - Atomic batch writes