]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonitorDBStore: add get_{keys,bytes}() accounting to Transaction
authorSage Weil <sage@redhat.com>
Sun, 10 Aug 2014 21:00:11 +0000 (14:00 -0700)
committerSage Weil <sage@redhat.com>
Fri, 3 Oct 2014 17:12:30 +0000 (10:12 -0700)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit fd421b26748e872ddf8e0f068dda2106853edff1)

src/mon/MonitorDBStore.h

index 88c4f9366ef3c797ed4b8adadfba02c669e28ce8..1576db77d3c3d87545eb03769afb43729e9533a0 100644 (file)
@@ -87,6 +87,9 @@ class MonitorDBStore
 
   struct Transaction {
     list<Op> 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();
     }
   };