Skip to content

Commit

Permalink
Merge pull request ceph#4 from branch-predictor/wip-kv
Browse files Browse the repository at this point in the history
kv/LevelDBStore, FileStore, MonDBStore: simpler code for single-key fetches
  • Loading branch information
liewegas committed Oct 23, 2015
2 parents daa4041 + 6b6c5da commit 574f3fc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
19 changes: 19 additions & 0 deletions src/kv/LevelDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ int LevelDBStore::get(
return 0;
}

int LevelDBStore::get(const string &prefix,
const string &key,
bufferlist *value)
{
utime_t start = ceph_clock_now(g_ceph_context);
int r = 0;
KeyValueDB::Iterator it = get_iterator(prefix);
it->lower_bound(key);
if (it->valid() && it->key() == key) {
*value = it->value();
} else {
r = -ENOENT;
}
utime_t lat = ceph_clock_now(g_ceph_context) - start;
logger->inc(l_leveldb_gets);
logger->tinc(l_leveldb_get_latency, lat);
return r;
}

string LevelDBStore::combine_strings(const string &prefix, const string &value)
{
string out = prefix;
Expand Down
4 changes: 4 additions & 0 deletions src/kv/LevelDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ class LevelDBStore : public KeyValueDB {
std::map<string, bufferlist> *out
);

int get(const string &prefix,
const string &key,
bufferlist *value);

class LevelDBWholeSpaceIteratorImpl :
public KeyValueDB::WholeSpaceIteratorImpl {
protected:
Expand Down
12 changes: 5 additions & 7 deletions src/mon/MonitorDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,12 @@ class MonitorDBStore
}

int get(const string& prefix, const string& key, bufferlist& bl) {
set<string> k;
k.insert(key);
map<string,bufferlist> out;

db->get(prefix, k, &out);
if (out.empty())

bufferlist outbl;
db->get(prefix, key, &outbl);
if (outbl.length() == 0)
return -ENOENT;
bl.append(out[key]);
bl.append(outbl);

return 0;
}
Expand Down
11 changes: 5 additions & 6 deletions src/os/DBObjectMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1089,17 +1089,16 @@ DBObjectMap::Header DBObjectMap::_lookup_map_header(
}
}

map<string, bufferlist> out;
set<string> to_get;
to_get.insert(map_header_key(oid));
int r = db->get(HOBJECT_TO_SEQ, to_get, &out);
if (r < 0 || out.empty()) {
bufferlist out;
int r = db->get(HOBJECT_TO_SEQ, map_header_key(oid), &out);
if (r < 0 || out.length()==0) {
delete header;
return Header();
}

Header ret(header, RemoveOnDelete(this));
bufferlist::iterator iter = out.begin()->second.begin();
bufferlist::iterator iter = out.begin();

ret->decode(iter);
{
Mutex::Locker l(cache_lock);
Expand Down

0 comments on commit 574f3fc

Please sign in to comment.