]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/kv/KeyValueDB.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / kv / KeyValueDB.h
index 289e562f0d7328e3d765aaef9f01116a013660db..0e4fed97cf4c81ca72d1cb5689eae967b6b8bc31 100644 (file)
@@ -40,24 +40,24 @@ public:
     /// Set Keys
     void set(
       const std::string &prefix,                      ///< [in] Prefix for keys, or CF name
-      const std::map<std::string, bufferlist> &to_set ///< [in] keys/values to set
+      const std::map<std::string, ceph::buffer::list> &to_set ///< [in] keys/values to set
     ) {
-      std::map<std::string, bufferlist>::const_iterator it;
-      for (it = to_set.begin(); it != to_set.end(); ++it)
+      for (auto it = to_set.cbegin(); it != to_set.cend(); ++it)
        set(prefix, it->first, it->second);
     }
 
-    /// Set Keys (via encoded bufferlist)
+    /// Set Keys (via encoded ceph::buffer::list)
     void set(
       const std::string &prefix,      ///< [in] prefix, or CF name
-      bufferlist& to_set_bl           ///< [in] encoded key/values to set
+      ceph::buffer::list& to_set_bl           ///< [in] encoded key/values to set
       ) {
+      using ceph::decode;
       auto p = std::cbegin(to_set_bl);
       uint32_t num;
       decode(num, p);
       while (num--) {
        string key;
-       bufferlist value;
+       ceph::buffer::list value;
        decode(key, p);
        decode(value, p);
        set(prefix, key, value);
@@ -68,21 +68,22 @@ public:
     virtual void set(
       const std::string &prefix,      ///< [in] Prefix or CF for the key
       const std::string &k,          ///< [in] Key to set
-      const bufferlist &bl            ///< [in] Value to set
+      const ceph::buffer::list &bl            ///< [in] Value to set
       ) = 0;
     virtual void set(
       const std::string &prefix,
       const char *k,
       size_t keylen,
-      const bufferlist& bl) {
+      const ceph::buffer::list& bl) {
       set(prefix, string(k, keylen), bl);
     }
 
-    /// Removes Keys (via encoded bufferlist)
+    /// Removes Keys (via encoded ceph::buffer::list)
     void rmkeys(
       const std::string &prefix,     ///< [in] Prefix or CF to search for
-      bufferlist &keys_bl            ///< [in] Keys to remove
+      ceph::buffer::list &keys_bl            ///< [in] Keys to remove
     ) {
+      using ceph::decode;
       auto p = std::cbegin(keys_bl);
       uint32_t num;
       decode(num, p);
@@ -98,8 +99,7 @@ public:
       const std::string &prefix,        ///< [in] Prefix/CF to search for
       const std::set<std::string> &keys ///< [in] Keys to remove
     ) {
-      std::set<std::string>::const_iterator it;
-      for (it = keys.begin(); it != keys.end(); ++it)
+      for (auto it = keys.cbegin(); it != keys.cend(); ++it)
        rmkey(prefix, *it);
     }
 
@@ -141,7 +141,7 @@ public:
     virtual void merge(
       const std::string &prefix,   ///< [in] Prefix/CF ==> MUST match some established merge operator
       const std::string &key,      ///< [in] Key to be merged
-      const bufferlist  &value     ///< [in] value to be merged into key
+      const ceph::buffer::list  &value     ///< [in] value to be merged into key
     ) { ceph_abort_msg("Not implemented"); }
 
     virtual ~TransactionImpl() {}
@@ -151,18 +151,18 @@ public:
   /// create a new instance
   static KeyValueDB *create(CephContext *cct, const std::string& type,
                            const std::string& dir,
-                           map<std::string,std::string> options = {},
+                           std::map<std::string,std::string> options = {},
                            void *p = NULL);
 
   /// test whether we can successfully initialize; may have side effects (e.g., create)
   static int test_init(const std::string& type, const std::string& dir);
   virtual int init(string option_str="") = 0;
-  virtual int open(std::ostream &out, const vector<ColumnFamily>& cfs = {}) = 0;
-  // vector cfs contains column families to be created when db is created.
+  virtual int open(std::ostream &out, const std::vector<ColumnFamily>& cfs = {}) = 0;
+  // std::vector cfs contains column families to be created when db is created.
   virtual int create_and_open(std::ostream &out,
-                             const vector<ColumnFamily>& cfs = {}) = 0;
+                             const std::vector<ColumnFamily>& cfs = {}) = 0;
 
-  virtual int open_read_only(ostream &out, const vector<ColumnFamily>& cfs = {}) {
+  virtual int open_read_only(std::ostream &out, const std::vector<ColumnFamily>& cfs = {}) {
     return -ENOTSUP;
   }
 
@@ -181,26 +181,26 @@ public:
   virtual int get(
     const std::string &prefix,               ///< [in] Prefix/CF for key
     const std::set<std::string> &key,        ///< [in] Key to retrieve
-    std::map<std::string, bufferlist> *out   ///< [out] Key value retrieved
+    std::map<std::string, ceph::buffer::list> *out   ///< [out] Key value retrieved
     ) = 0;
   virtual int get(const std::string &prefix, ///< [in] prefix or CF name
                  const std::string &key,    ///< [in] key
-                 bufferlist *value) {       ///< [out] value
+                 ceph::buffer::list *value) {       ///< [out] value
     std::set<std::string> ks;
     ks.insert(key);
-    std::map<std::string,bufferlist> om;
+    std::map<std::string,ceph::buffer::list> om;
     int r = get(prefix, ks, &om);
     if (om.find(key) != om.end()) {
       *value = std::move(om[key]);
     } else {
-      *value = bufferlist();
+      *value = ceph::buffer::list();
       r = -ENOENT;
     }
     return r;
   }
   virtual int get(const string &prefix,
                  const char *key, size_t keylen,
-                 bufferlist *value) {
+                 ceph::buffer::list *value) {
     return get(prefix, string(key, keylen), value);
   }
 
@@ -215,7 +215,10 @@ public:
     virtual bool valid() = 0;
     virtual int next() = 0;
     virtual std::string key() = 0;
-    virtual bufferlist value() = 0;
+    virtual std::string tail_key() {
+      return "";
+    }
+    virtual ceph::buffer::list value() = 0;
     virtual int status() = 0;
     virtual ~SimplestIteratorImpl() {}
   };
@@ -226,12 +229,12 @@ public:
     virtual int seek_to_last() = 0;
     virtual int prev() = 0;
     virtual std::pair<std::string, std::string> raw_key() = 0;
-    virtual bufferptr value_as_ptr() {
-      bufferlist bl = value();
+    virtual ceph::buffer::ptr value_as_ptr() {
+      ceph::buffer::list bl = value();
       if (bl.length() == 1) {
         return *bl.buffers().begin();
       } else if (bl.length() == 0) {
-        return bufferptr();
+        return ceph::buffer::ptr();
       } else {
        ceph_abort();
       }
@@ -254,13 +257,13 @@ public:
     virtual std::string key() = 0;
     virtual std::pair<std::string,std::string> raw_key() = 0;
     virtual bool raw_key_is_prefixed(const std::string &prefix) = 0;
-    virtual bufferlist value() = 0;
-    virtual bufferptr value_as_ptr() {
-      bufferlist bl = value();
+    virtual ceph::buffer::list value() = 0;
+    virtual ceph::buffer::ptr value_as_ptr() {
+      ceph::buffer::list bl = value();
       if (bl.length()) {
         return *bl.buffers().begin();
       } else {
-        return bufferptr();
+        return ceph::buffer::ptr();
       }
     }
     virtual int status() = 0;
@@ -313,10 +316,10 @@ private:
     std::pair<std::string, std::string> raw_key() override {
       return generic_iter->raw_key();
     }
-    bufferlist value() override {
+    ceph::buffer::list value() override {
       return generic_iter->value();
     }
-    bufferptr value_as_ptr() override {
+    ceph::buffer::ptr value_as_ptr() override {
       return generic_iter->value_as_ptr();
     }
     int status() override {
@@ -364,7 +367,8 @@ public:
   virtual ~KeyValueDB() {}
 
   /// estimate space utilization for a prefix (in bytes)
-  virtual int64_t estimate_prefix_size(const string& prefix) {
+  virtual int64_t estimate_prefix_size(const string& prefix,
+                                      const string& key_prefix) {
     return 0;
   }
 
@@ -408,7 +412,7 @@ public:
     return -EOPNOTSUPP;
   }
 
-  virtual void get_statistics(Formatter *f) {
+  virtual void get_statistics(ceph::Formatter *f) {
     return;
   }
 
@@ -420,6 +424,17 @@ public:
   virtual PerfCounters *get_perf_counters() {
     return nullptr;
   }
+
+  /**
+   * Access implementation specific integral property corresponding
+   * to passed property and prefic.
+   * Return value is true if property is valid for prefix, populates out.
+   */
+  virtual bool get_property(
+    const std::string &property,
+    uint64_t *out) {
+    return false;
+  }
 protected:
   /// List of matching prefixes/ColumnFamilies and merge operators
   std::vector<std::pair<std::string,