From 74aa7afc719e517dbed300f802c1bc2dafe43ee0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 10 Aug 2014 14:00:11 -0700 Subject: [PATCH] mon/MonitorDBStore: add get_{keys,bytes}() accounting to Transaction Signed-off-by: Sage Weil (cherry picked from commit fd421b26748e872ddf8e0f068dda2106853edff1) --- src/mon/MonitorDBStore.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 88c4f9366ef3c..1576db77d3c3d 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -87,6 +87,9 @@ class MonitorDBStore struct Transaction { list ops; + uint64_t bytes, keys; + + Transaction() : bytes(0), keys(0) {} enum { OP_PUT = 1, @@ -96,6 +99,8 @@ class MonitorDBStore void put(string prefix, string key, bufferlist& bl) { ops.push_back(Op(OP_PUT, prefix, key, bl)); + ++keys; + bytes += prefix.length() + key.length() + bl.length(); } void put(string prefix, version_t ver, bufferlist& bl) { @@ -112,6 +117,8 @@ class MonitorDBStore void erase(string prefix, string key) { ops.push_back(Op(OP_ERASE, prefix, key)); + ++keys; + bytes += prefix.length() + key.length(); } void erase(string prefix, version_t ver) { @@ -129,14 +136,20 @@ class MonitorDBStore } void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); + ENCODE_START(2, 1, bl); ::encode(ops, bl); + ::encode(bytes, bl); + ::encode(keys, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START(1, bl); + DECODE_START(2, bl); ::decode(ops, bl); + if (struct_v >= 2) { + ::decode(bytes, bl); + ::decode(keys, bl); + } DECODE_FINISH(bl); } @@ -153,6 +166,8 @@ class MonitorDBStore void append(Transaction& other) { ops.splice(ops.end(), other.ops); + keys += other.keys; + bytes += other.bytes; } void append_from_encoded(bufferlist& bl) { @@ -169,6 +184,12 @@ class MonitorDBStore bool size() { return ops.size(); } + uint64_t get_keys() const { + return keys; + } + uint64_t get_bytes() const { + return bytes; + } void dump(ceph::Formatter *f, bool dump_val=false) const { f->open_object_section("transaction"); @@ -218,6 +239,8 @@ class MonitorDBStore f->close_section(); } f->close_section(); + f->dump_unsigned("num_keys", keys); + f->dump_unsigned("num_bytes", bytes); f->close_section(); } }; -- 2.39.5