-
Notifications
You must be signed in to change notification settings - Fork 6.3k
SeekForPrev
Start from 4.13, Rocksdb added Iterator::SeekForPrev()
. This new API will seek to the last key that is less than or equal to the target key, in contrast with Seek()
.
// Suppose we have keys "a1", "a3", "b1", "b2", "c2", "c4".
auto iter = db->NewIterator(ReadOptions());
iter->Seek("a1"); // iter->Key() == "a1";
iter->Seek("a3"); // iter->Key() == "a3";
iter->SeekForPrev("c4"); // iter->Key() == "c4";
iter->SeekForPrev("c3"); // iter->Key() == "c2";
Basically, the behavior of SeekForPrev() is like the code snippet below:
Seek(target);
if (!Valid()) {
SeekToLast();
} else if (key() > target) {
Prev();
}
In fact, this API serves more than this code snippet. One typical example is, suppose we have keys, "a1", "a3", "a5", "b1" and enable prefix_extractor which take the first byte as prefix. If we want to get the last key less than or equal to "a6". The code above without SeekForPrev() doesn't work. Since after Seek("a6")
and Prev()
, the iterator will enter the invalid state. But now, what you need is just a call, SeekForPrev("a6")
and get "a5".
Also, SeekForPrev() API serves internally to support Prev()
in prefix mode. Now, Next()
and Prev()
could both be mixed in prefix mode. Thanks to SeekForPrev()!
Contents
- RocksDB Wiki
- Overview
- RocksDB FAQ
- Terminology
- Requirements
- Contributors' Guide
- Release Methodology
- RocksDB Users and Use Cases
- RocksDB Public Communication and Information Channels
-
Basic Operations
- Iterator
- Prefix seek
- SeekForPrev
- Tailing Iterator
- Compaction Filter
- Multi Column Family Iterator (Experimental)
- Read-Modify-Write (Merge) Operator
- Column Families
- Creating and Ingesting SST files
- Single Delete
- Low Priority Write
- Time to Live (TTL) Support
- Transactions
- Snapshot
- DeleteRange
- Atomic flush
- Read-only and Secondary instances
- Approximate Size
- User-defined Timestamp
- Wide Columns
- BlobDB
- Online Verification
- Options
- MemTable
- Journal
- Cache
- Write Buffer Manager
- Compaction
- SST File Formats
- IO
- Compression
- Full File Checksum and Checksum Handoff
- Background Error Handling
- Huge Page TLB Support
- Tiered Storage (Experimental)
- Logging and Monitoring
- Known Issues
- Troubleshooting Guide
- Tests
- Tools / Utilities
-
Implementation Details
- Delete Stale Files
- Partitioned Index/Filters
- WritePrepared-Transactions
- WriteUnprepared-Transactions
- How we keep track of live SST files
- How we index SST
- Merge Operator Implementation
- RocksDB Repairer
- Write Batch With Index
- Two Phase Commit
- Iterator's Implementation
- Simulation Cache
- [To Be Deprecated] Persistent Read Cache
- DeleteRange Implementation
- unordered_write
- Extending RocksDB
- RocksJava
- Lua
- Performance
- Projects Being Developed
- Misc