]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonitorDBStore: better size estimation for Transaction
authorSage Weil <sage@redhat.com>
Tue, 12 Nov 2019 20:46:13 +0000 (14:46 -0600)
committerDan van der Ster <daniel.vanderster@cern.ch>
Thu, 5 Mar 2020 20:10:39 +0000 (21:10 +0100)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 5103b2563db771eb2f3d4a37f51c8eb40b4e188f)

src/mon/MonitorDBStore.h

index 9a47f58282ffb38eee18d9218c00344161aadbf7..9b980808aa959fd21cc9f98bd0dc7af0040ee915 100644 (file)
@@ -106,6 +106,14 @@ class MonitorDBStore
       }
     }
 
+    int approx_size() const {
+      return 6 + 1 +
+       4 + prefix.size() +
+       4 + key.size() +
+       4 + endkey.size() +
+       4 + bl.length();
+    }
+
     static void generate_test_instances(list<Op*>& ls) {
       ls.push_back(new Op);
       // we get coverage here from the Transaction instances
@@ -118,7 +126,7 @@ class MonitorDBStore
     list<Op> ops;
     uint64_t bytes, keys;
 
-    Transaction() : bytes(0), keys(0) {}
+    Transaction() : bytes(6 + 4 + 8*2), keys(0) {}
 
     enum {
       OP_PUT   = 1,
@@ -130,7 +138,7 @@ class MonitorDBStore
     void put(const string& prefix, const string& key, const bufferlist& bl) {
       ops.push_back(Op(OP_PUT, prefix, key, bl));
       ++keys;
-      bytes += prefix.length() + key.length() + bl.length();
+      bytes += ops.back().approx_size();
     }
 
     void put(const string& prefix, version_t ver, const bufferlist& bl) {
@@ -149,7 +157,7 @@ class MonitorDBStore
     void erase(const string& prefix, const string& key) {
       ops.push_back(Op(OP_ERASE, prefix, key));
       ++keys;
-      bytes += prefix.length() + key.length();
+      bytes += ops.back().approx_size();
     }
 
     void erase(const string& prefix, version_t ver) {
@@ -162,7 +170,7 @@ class MonitorDBStore
                     const string& end) {
       ops.push_back(Op(OP_ERASE_RANGE, prefix, begin, end));
       ++keys;
-      bytes += prefix.length() + begin.length() + end.length();
+      bytes += ops.back().approx_size();
     }
 
     void compact_prefix(const string& prefix) {