]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: MonitorDBStore: return -ENOENT on get() if key doesn't exist
authorJoao Eduardo Luis <joao.luis@inktank.com>
Wed, 27 Feb 2013 18:31:55 +0000 (18:31 +0000)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Wed, 27 Feb 2013 18:50:16 +0000 (18:50 +0000)
And adjust version_t get(string,string) so that, in case of -ENOENT, it
returns 0 (when a key doesn't exist, assumes its value is zero), and make
sure it asserts in all other negative return values.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/mon/MonitorDBStore.h

index 7520499ab833b14cdd9f901d56a3944e03c33b78..31420360c03d5c5815e4ad53a88083aa95341629 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "include/assert.h"
 #include "common/Formatter.h"
+#include "common/errno.h"
 
 class MonitorDBStore
 {
@@ -368,8 +369,9 @@ class MonitorDBStore
     map<string,bufferlist> out;
 
     db->get(prefix, k, &out);
-    if (!out.empty())
-      bl.append(out[key]);
+    if (out.empty())
+      return -ENOENT;
+    bl.append(out[key]);
 
     return 0;
   }
@@ -382,10 +384,19 @@ class MonitorDBStore
 
   version_t get(const string& prefix, const string& key) {
     bufferlist bl;
-    get(prefix, key, bl);
-    if (!bl.length()) // if key does not exist, assume its value is 0
-      return 0;
+    int err = get(prefix, key, bl);
+    if (err < 0) {
+      if (err == -ENOENT) // if key doesn't exist, assume its value is 0
+        return 0;
+      // we're not expecting any other negative return value, and we can't
+      // just return a negative value if we're returning a version_t
+      generic_dout(0) << "MonitorDBStore::get() error obtaining"
+                      << " (" << prefix << ":" << key << "): "
+                      << cpp_strerror(err) << dendl;
+      assert(0 == "error obtaining key");
+    }
 
+    assert(bl.length());
     version_t ver;
     bufferlist::iterator p = bl.begin();
     ::decode(ver, p);