]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/KeyValueDB: New estimate_range_size function
authorAdam Kupczyk <akupczyk@ibm.com>
Tue, 1 Jul 2025 11:23:28 +0000 (11:23 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Mon, 1 Jun 2026 16:14:02 +0000 (16:14 +0000)
Taking estimate_prefix_size to another level.
Makes possible detailed inspection of db size.
Used primarily for bisecting key range.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/kv/KeyValueDB.h
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index 68f07394eaa7342e525c7c0c1d66e73452c1f11f..0583107cf5032e6ab227f95200f3841fac0ed0c2 100644 (file)
@@ -410,6 +410,13 @@ public:
                                       const std::string& key_prefix) {
     return 0;
   }
+  /// estimate space utilization for a specified range (in bytes)
+  virtual int64_t estimate_range_size(
+    const std::string& prefix,
+    const std::string& key_from,
+    const std::string& key_to) {
+      return 0;
+  };
 
   /// compact the underlying store
   virtual void compact() {}
index 9783020126965259d87f4b676c6fadc513c40e6d..a51968b7036aea9829b0f3a8fb85bb15fd9b148a 100644 (file)
@@ -1433,6 +1433,36 @@ int64_t RocksDBStore::estimate_prefix_size(const string& prefix,
   return size;
 }
 
+int64_t RocksDBStore::estimate_range_size(
+  const string& prefix,
+  const string& key_from,
+  const string& key_to)
+{
+  // The default mode is to derive estimates based on
+  // sst files alone (INCLUDE_FILES).
+  // This gives an irritating result when a batch of keys is
+  // just commited but estimate keeps showing 0.
+  rocksdb::DB::SizeApproximationFlags flags(
+    rocksdb::DB::SizeApproximationFlags::INCLUDE_FILES |
+    rocksdb::DB::SizeApproximationFlags::INCLUDE_MEMTABLES);
+  uint64_t size = 0;
+  auto p_iter = cf_handles.find(prefix);
+  if (p_iter != cf_handles.end()) {
+    for (const auto cf : p_iter->second.handles) {
+      uint64_t s = 0;
+      rocksdb::Range r(key_from, key_to);
+      db->GetApproximateSizes(cf, &r, 1, &s, flags);
+      size += s;
+    }
+  } else {
+    string start = combine_strings(prefix , key_from);
+    string limit = combine_strings(prefix , key_to);
+    rocksdb::Range r(start, limit);
+    db->GetApproximateSizes(default_cf, &r, 1, &size, flags);
+  }
+  return size;
+}
+
 void RocksDBStore::get_statistics(Formatter *f)
 {
   if (!cct->_conf->rocksdb_perf)  {
index c0cab4cfbcf60a224b40aae311d821018927c233..a32cc71b0c8d846de44244116d07db4882aedc5f 100644 (file)
@@ -291,6 +291,9 @@ public:
 
   int64_t estimate_prefix_size(const std::string& prefix,
                               const std::string& key_prefix) override;
+  int64_t estimate_range_size(const std::string& prefix,
+                              const std::string& key_from,
+                              const std::string& key_to) override;
   struct RocksWBHandler;
   class RocksDBTransactionImpl : public KeyValueDB::TransactionImpl {
   public: