]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
kv: implement value_as_ptr() and use it in .get()
authorPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Fri, 4 Dec 2015 13:49:40 +0000 (14:49 +0100)
committerPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Thu, 24 Dec 2015 13:21:08 +0000 (14:21 +0100)
Current .get() methods return values as bufferlists, which are replacing
bufferlists provided by caller. This is particularly inefficient with
MonitorDBStore, because its get() method uses its own temporary bufferlist
which is then appended to bufferlist provided by MonitorDBStore user.
This changeset:
 - adds value_as_ptr() which returns just a bufferptr
 - modifies *DBStore.get() methods to append returned bufferptr to provided
   bufferlist instead of replacing it
 - modifies mondbstore to pass provided bufferlist as target for underlying
   .get() method, instead of providing its own and appending it to one given
   by caller.

This reduces CPU usage of *DBStore.get() methods by up to 5% (particularly
visible with MonitorDBStore, which doesn't use two temporary bufferlists
anymore).

Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
src/kv/KeyValueDB.h
src/kv/LevelDBStore.cc
src/kv/LevelDBStore.h
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h
src/mon/MonitorDBStore.h

index 347169aecb8e4dcf46d54c3b0c4f94960fcb66af..119036d40e4decbabbe5328837f5f15e30204bf4 100644 (file)
@@ -163,6 +163,14 @@ public:
     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();
+      if (bl.length()) {
+        return *bl.buffers().begin();
+      } else {
+        return bufferptr();
+      }
+    }
     virtual int status() = 0;
     virtual ~WholeSpaceIteratorImpl() { }
   };
@@ -223,6 +231,9 @@ public:
     bufferlist value() {
       return generic_iter->value();
     }
+    bufferptr value_as_ptr() {
+      return generic_iter->value_as_ptr();
+    }
     int status() {
       return generic_iter->status();
     }
index 481fbf16d044b4648f4b873c447fa67de9939641..0056c4aa13c90b56a55ca9cbf3305700dd04ce2c 100644 (file)
@@ -272,7 +272,7 @@ int LevelDBStore::get(const string &prefix,
   KeyValueDB::Iterator it = get_iterator(prefix);
   it->lower_bound(key);
   if (it->valid() && it->key() == key) {
-    *value = it->value();
+    value->append(it->value_as_ptr());
   } else {
     r = -ENOENT;
   }
index 6ffcb62da80834aacaa3a59c4197da46ca4babfd..8a201dfa08d563d2c0250795fe5dbdc832c38eb3 100644 (file)
@@ -298,6 +298,12 @@ public:
     bufferlist value() {
       return to_bufferlist(dbiter->value());
     }
+
+    bufferptr value_as_ptr() {
+      leveldb::Slice data = dbiter->value();
+      return bufferptr(data.data(), data.size());
+    }
+
     int status() {
       return dbiter->status().ok() ? 0 : -1;
     }
index 561b065ed9bf9d967ea060e9697804750aff3ebf..b4b9253153454a0e8f6358a235f35869b904c259 100644 (file)
@@ -371,7 +371,7 @@ int RocksDBStore::get(
   KeyValueDB::Iterator it = get_iterator(prefix);
   it->lower_bound(key);
   if (it->valid() && it->key() == key) {
-    *out = it->value();
+    out->append(it->value_as_ptr());
   } else {
     r = -ENOENT;
   }
@@ -589,6 +589,13 @@ bufferlist RocksDBStore::RocksDBWholeSpaceIteratorImpl::value()
 {
   return to_bufferlist(dbiter->value());
 }
+
+bufferptr RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_ptr()
+{
+  rocksdb::Slice val = dbiter->value();
+  return bufferptr(val.data(), val.size());
+}
+
 int RocksDBStore::RocksDBWholeSpaceIteratorImpl::status()
 {
   return dbiter->status().ok() ? 0 : -1;
@@ -601,7 +608,6 @@ string RocksDBStore::past_prefix(const string &prefix)
   return limit;
 }
 
-
 RocksDBStore::WholeSpaceIterator RocksDBStore::_get_iterator()
 {
   return std::shared_ptr<KeyValueDB::WholeSpaceIteratorImpl>(
index 45278e068230d3cbfa5c7583c35bf47f71317f43..9eb2d9db0c0e7edc4b7632b154c627a863a58618 100644 (file)
@@ -192,6 +192,7 @@ public:
     pair<string,string> raw_key();
     bool raw_key_is_prefixed(const string &prefix);
     bufferlist value();
+    bufferptr value_as_ptr();
     int status();
   };
 
index 81016417ec93437a0d33a0493bd8e29741865a4a..6bb35e4e11e854c4029d4c671a6e41201d04da67 100644 (file)
@@ -507,12 +507,7 @@ class MonitorDBStore
   }
 
   int get(const string& prefix, const string& key, bufferlist& bl) {
-    bufferlist outbl;
-    int r = db->get(prefix, key, &outbl);
-    if (!r) {
-      bl.append(outbl);
-    }
-    return r;
+    return db->get(prefix, key, &bl);
   }
 
   int get(const string& prefix, const version_t ver, bufferlist& bl) {