From: Joao Eduardo Luis Date: Wed, 27 Feb 2013 18:31:55 +0000 (+0000) Subject: mon: MonitorDBStore: return -ENOENT on get() if key doesn't exist X-Git-Tag: v0.59~72^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cf0d4f8618cbceeed2299661d0dc44a85402b627;p=ceph.git mon: MonitorDBStore: return -ENOENT on get() if key doesn't exist 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 --- diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 7520499ab833..31420360c03d 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -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 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);