From 8257986468220dcbdac3da004e0309f10306a431 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Fri, 10 Mar 2017 14:10:47 +0800 Subject: [PATCH] kv/rocksdb: add option to control whether enable DeleteRange API Signed-off-by: Haomai Wang --- src/common/config_opts.h | 1 + src/kv/RocksDBStore.cc | 14 +++++++++++++- src/kv/RocksDBStore.h | 4 +++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 2aa4f283b7eb9..491322fd5c227 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -918,6 +918,7 @@ OPTION(rocksdb_perf, OPT_BOOL, false) // Enabling this will have 5-10% impact on OPTION(rocksdb_collect_compaction_stats, OPT_BOOL, false) //For rocksdb, this behavior will be an overhead of 5%~10%, collected only rocksdb_perf is enabled. OPTION(rocksdb_collect_extended_stats, OPT_BOOL, false) //For rocksdb, this behavior will be an overhead of 5%~10%, collected only rocksdb_perf is enabled. OPTION(rocksdb_collect_memory_stats, OPT_BOOL, false) //For rocksdb, this behavior will be an overhead of 5%~10%, collected only rocksdb_perf is enabled. +OPTION(rocksdb_enable_rmrange, OPT_BOOL, false) // see https://github.com/facebook/rocksdb/blob/master/include/rocksdb/db.h#L253 // rocksdb options that will be used for omap(if omap_backend is rocksdb) OPTION(filestore_rocksdb_options, OPT_STR, "") diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 0d102c6e6d04d..dd0895adf5768 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -619,7 +619,19 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix, const string &start, const string &end) { - bat.DeleteRange(combine_strings(prefix, start), combine_strings(prefix, end)); + if (db->enable_rmrange) { + bat.DeleteRange(combine_strings(prefix, start), combine_strings(prefix, end)); + } else { + auto it = db->get_iterator(prefix); + it->lower_bound(start); + while (it->valid()) { + if (it->key() >= end) { + break; + } + bat.Delete(combine_strings(prefix, it->key())); + it->next(); + } + } } void RocksDBStore::RocksDBTransactionImpl::merge( diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index ef81df324961b..4d25408a5f004 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -102,6 +102,7 @@ public: /// compact the underlying rocksdb store bool compact_on_mount; bool disableWAL; + bool enable_rmrange; void compact() override; int tryInterpret(const string key, const string val, rocksdb::Options &opt); @@ -135,7 +136,8 @@ public: compact_queue_stop(false), compact_thread(this), compact_on_mount(false), - disableWAL(false) + disableWAL(false), + enable_rmrange(cct->_conf->rocksdb_enable_rmrange) {} ~RocksDBStore() override; -- 2.39.5