From: Sage Weil Date: Tue, 12 Nov 2019 20:46:13 +0000 (-0600) Subject: mon/MonitorDBStore: better size estimation for Transaction X-Git-Tag: v15.1.0~620^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5103b2563db771eb2f3d4a37f51c8eb40b4e188f;p=ceph.git mon/MonitorDBStore: better size estimation for Transaction Signed-off-by: Sage Weil --- diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 9a47f58282ff..9b980808aa95 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) {