diff --git a/HISTORY.md b/HISTORY.md index 4632e387c..3b959335c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,7 @@ ### Public API Change * Options::max_bytes_for_level_multiplier is now a double along with all getters and setters. * Support dynamically change `delayed_write_rate` and `max_total_wal_size` options via SetDBOptions(). +* Introduce DB::DeleteRange for optimized deletion of large ranges of contiguous keys. ### New Features * Add avoid_flush_during_shutdown option, which speeds up DB shutdown by not flushing unpersisted data (i.e. with disableWAL = true). Unpersisted data will be lost. The options is dynamically changeable via SetDBOptions(). diff --git a/db/db_impl.cc b/db/db_impl.cc index b930a68ba..273bb3a93 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -5845,6 +5845,14 @@ Status DB::SingleDelete(const WriteOptions& opt, return Write(opt, &batch); } +Status DB::DeleteRange(const WriteOptions& opt, + ColumnFamilyHandle* column_family, + const Slice& begin_key, const Slice& end_key) { + WriteBatch batch; + batch.DeleteRange(column_family, begin_key, end_key); + return Write(opt, &batch); +} + Status DB::Merge(const WriteOptions& opt, ColumnFamilyHandle* column_family, const Slice& key, const Slice& value) { WriteBatch batch; diff --git a/include/rocksdb/db.h b/include/rocksdb/db.h index f3c2924ba..419acd8a5 100644 --- a/include/rocksdb/db.h +++ b/include/rocksdb/db.h @@ -235,6 +235,25 @@ class DB { return SingleDelete(options, DefaultColumnFamily(), key); } + // Removes the database entries in the range ["begin_key", "end_key"), i.e., + // including "begin_key" and excluding "end_key". Returns OK on success, and + // a non-OK status on error. It is not an error if no keys exist in the range + // ["begin_key", "end_key"). + // + // This feature is currently an experimental performance optimization for + // deleting very large ranges of contiguous keys. Invoking it many times or on + // small ranges may severely degrade read performance; in particular, the + // resulting performance can be worse than calling Delete() for each key in + // the range. Note also the degraded read performance affects keys outside the + // deleted ranges, and affects database operations involving scans, like flush + // and compaction. + // + // Consider setting ReadOptions::ignore_range_deletions = true to speed + // up reads for key(s) that are known to be unaffected by range deletions. + virtual Status DeleteRange(const WriteOptions& options, + ColumnFamilyHandle* column_family, + const Slice& begin_key, const Slice& end_key); + // Merge the database entry for "key" with "value". Returns OK on success, // and a non-OK status on error. The semantics of this operation is // determined by the user provided merge_operator when opening DB.