From 36a211eff7b10df36427643ab4d17e355e66289c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 12 Nov 2019 14:46:13 -0600 Subject: [PATCH] mon/MonitorDBStore: better size estimation for Transaction Signed-off-by: Sage Weil (cherry picked from commit 5103b2563db771eb2f3d4a37f51c8eb40b4e188f) --- src/mon/MonitorDBStore.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 9a47f58282ffb..9b980808aa959 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -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& ls) { ls.push_back(new Op); // we get coverage here from the Transaction instances @@ -118,7 +126,7 @@ class MonitorDBStore list 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) { -- 2.39.5