]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/KeyValueDB: add bufferlist-based set() and rmkeys() interface
authorSage Weil <sage@redhat.com>
Mon, 19 Oct 2015 18:28:34 +0000 (14:28 -0400)
committerSage Weil <sage@redhat.com>
Mon, 19 Oct 2015 18:37:53 +0000 (14:37 -0400)
Often the caller has an encoded bl and not an STL map/set.

Signed-off-by: Sage Weil <sage@redhat.com>
src/kv/KeyValueDB.h

index 8691694ef3c5d46eba785e6c83770ca1cfb2611c..ccccf06e25dd4f3e35c43e3fa928969384730416 100644 (file)
@@ -10,6 +10,7 @@
 #include <string>
 #include "include/memory.h"
 #include <boost/scoped_ptr.hpp>
+#include "include/encoding.h"
 
 using std::string;
 /**
@@ -31,6 +32,23 @@ public:
        set(prefix, it->first, it->second);
     }
 
+    /// Set Keys (via encoded bufferlist)
+    void set(
+      const std::string &prefix,      ///< [in] prefix
+      bufferlist& to_set_bl     ///< [in] encoded key/values to set
+      ) {
+      bufferlist::iterator p = to_set_bl.begin();
+      uint32_t num;
+      ::decode(num, p);
+      while (num--) {
+       string key;
+       bufferlist value;
+       ::decode(key, p);
+       ::decode(value, p);
+       set(prefix, key, value);
+      }
+    }
+
     /// Set Key
     virtual void set(
       const std::string &prefix,   ///< [in] Prefix for the key
@@ -39,6 +57,21 @@ public:
       ) = 0;
 
 
+    /// Removes Keys (via encoded bufferlist)
+    void rmkeys(
+      const std::string &prefix,   ///< [in] Prefix to search for
+      bufferlist &keys_bl ///< [in] Keys to remove
+    ) {
+      bufferlist::iterator p = keys_bl.begin();
+      uint32_t num;
+      ::decode(num, p);
+      while (num--) {
+       string key;
+       ::decode(key, p);
+       rmkey(prefix, key);
+      }
+    }
+
     /// Removes Keys
     void rmkeys(
       const std::string &prefix,   ///< [in] Prefix to search for