-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Single Delete
It deletes the most recent version of a key, and whether older versions of the key will come back to life is undefined.
SingleDelete is a new database operation. Similar to Delete()
method, SingleDelete()
removes the database entry for a key. The difference is that a single deletion entry is removed along with the value when the two are lined up in a compaction. A deletion entry is only dropped when compacted to the bottommost level with no data below it. Therefore, SingeDelete has the prerequisites that the key exists and was not overwritten. Returns OK on success, and a non-OK status on error. It is not an error if key did not exist in the database. If a key is overwritten (by calling Put()
multiple times), then the result of calling SingleDelete()
on this key is undefined. SingleDelete()
only behaves correctly if there has been only one Put()
for this key since the previous call to SingleDelete()
for this key. The following code shows how to use SingleDelete
:
std::string value;
rocksdb::Status s;
db->Put(rocksdb::WriteOptions(), "foo", "bar1");
db->SingleDelete(rocksdb::WriteOptions(), "foo");
s = db->Get(rocksdb::ReadOptions(), "foo", &value); // s.IsNotFound()==true
db->Put(rocksdb::WriteOptions(), "foo", "bar2");
db->Put(rocksdb::WriteOptions(), "foo", "bar3");
db->SingleDelete(rocksdb::ReadOptions(), "foo", &value); // Undefined result
SingleDelete
API is also available in WriteBatch
. Actually, DB::SingleDelete()
is implemented by creating a WriteBatch
with only one operation, SingleDelete
, in this batch. The following code snippet shows the basic usage of WriteBatch::SingleDelete()
:
rocksdb::WriteBatch batch;
batch.Put(key1, value);
batch.SingleDelete(key1);
s = db->Write(rocksdb::WriteOptions(), &batch);
- Callers have to ensure that
SingleDelete
only applies to a key having not been deleted usingDelete()
or written usingMerge()
. MixingSingleDelete()
operations withDelete()
andMerge()
can result in undefined behavior (other keys are not affected by this). IfCompactionIterator
sees aSingleDelete
followed by aDelete
for the same user key, an error message will be logged to the LOG file and compaction will fail. -
SingleDelete
is NOT compatible with cuckoo hash tables, which means you should not callSingleDelete
if you setoptions.memtable_factory
withNewHashCuckooRepFactory
- Applications are not encouraged to issue multiple
SingleDelete
for the same key. However, it is possible for compaction to see multiple consecutiveSingleDelete
for the same user key in certain cases, e.g. (when write-prepared transaction is enabled). RocksDB internally is able to handle this case correctly.
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