From f1ebd82c5c71ec9fdb616c0906705778b5199900 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Tue, 17 Jan 2023 18:06:13 +0300 Subject: [PATCH] kv/rocksdbstore: apply rocksdb_delete_range_threshold on the fly Plus more effective rm_range_keys implementation when this parameter is set to 0 Signed-off-by: Igor Fedotov (cherry picked from commit 69704fd371cf595489ef7dc0dda718a224a2132a) (cherry picked from commit 592da6e27bcf0ccccf4ed2dc852b199d68657332) --- src/kv/RocksDBStore.cc | 27 ++++++++++++++++++++++----- src/kv/RocksDBStore.h | 8 +++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index dfac6575c13..c95e344e0bc 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -1708,7 +1708,7 @@ void RocksDBStore::RocksDBTransactionImpl::rmkeys_by_prefix(const string &prefix { auto p_iter = db->cf_handles.find(prefix); if (p_iter == db->cf_handles.end()) { - uint64_t cnt = db->delete_range_threshold; + uint64_t cnt = db->get_delete_range_threshold(); bat.SetSavePoint(); auto it = db->get_iterator(prefix); for (it->seek_to_first(); it->valid() && (--cnt) != 0; it->next()) { @@ -1727,7 +1727,7 @@ void RocksDBStore::RocksDBTransactionImpl::rmkeys_by_prefix(const string &prefix } else { ceph_assert(p_iter->second.handles.size() >= 1); for (auto cf : p_iter->second.handles) { - uint64_t cnt = db->delete_range_threshold; + uint64_t cnt = db->get_delete_range_threshold(); bat.SetSavePoint(); auto it = db->new_shard_iterator(cf); for (it->SeekToFirst(); it->Valid() && (--cnt) != 0; it->Next()) { @@ -1748,11 +1748,14 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix, const string &start, const string &end) { - ldout(db->cct, 10) << __func__ << " enter start=" << start + ldout(db->cct, 10) << __func__ + << " enter prefix=" << prefix + << " start=" << start << " end=" << end << dendl; auto p_iter = db->cf_handles.find(prefix); + uint64_t cnt = db->get_delete_range_threshold(); if (p_iter == db->cf_handles.end()) { - uint64_t cnt = db->delete_range_threshold; + uint64_t cnt0 = cnt; bat.SetSavePoint(); auto it = db->get_iterator(prefix); for (it->lower_bound(start); @@ -1760,6 +1763,9 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix, it->next()) { bat.Delete(db->default_cf, combine_strings(prefix, it->key())); } + ldout(db->cct, 15) << __func__ << " count = " + << cnt0 - cnt + << dendl; if (cnt == 0) { ldout(db->cct, 10) << __func__ << " p_iter == end(), resorting to DeleteRange" << dendl; @@ -1770,10 +1776,18 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix, } else { bat.PopSavePoint(); } + } else if (cnt == 0) { + ceph_assert(p_iter->second.handles.size() >= 1); + for (auto cf : p_iter->second.handles) { + ldout(db->cct, 10) << __func__ << " p_iter != end(), resorting to DeleteRange" + << dendl; + bat.DeleteRange(cf, rocksdb::Slice(start), rocksdb::Slice(end)); + } } else { ceph_assert(p_iter->second.handles.size() >= 1); for (auto cf : p_iter->second.handles) { - uint64_t cnt = db->delete_range_threshold; + cnt = db->get_delete_range_threshold(); + uint64_t cnt0 = cnt; bat.SetSavePoint(); rocksdb::Iterator* it = db->new_shard_iterator(cf); ceph_assert(it != nullptr); @@ -1782,6 +1796,9 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix, it->Next()) { bat.Delete(cf, it->key()); } + ldout(db->cct, 10) << __func__ << " count = " + << cnt0 - cnt + << dendl; if (cnt == 0) { ldout(db->cct, 10) << __func__ << " p_iter != end(), resorting to DeleteRange" << dendl; diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 25a2045ffaf..7cc861c0444 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -199,7 +199,10 @@ public: /// compact the underlying rocksdb store bool compact_on_mount; bool disableWAL; - const uint64_t delete_range_threshold; + uint64_t get_delete_range_threshold() const { + return cct->_conf.get_val("rocksdb_delete_range_threshold"); + } + void compact() override; void compact_async() override { @@ -244,8 +247,7 @@ public: compact_queue_stop(false), compact_thread(this), compact_on_mount(false), - disableWAL(false), - delete_range_threshold(cct->_conf.get_val("rocksdb_delete_range_threshold")) + disableWAL(false) {} ~RocksDBStore() override; -- 2.39.5