Merge pull request #9411 from ceph/wip-rocksdb-perf

os/RocksDBStore: use effective Get API instead of iterator api

Reviewed-by: Sage Weil <sage@redhat.com>
Reviewed-by: Mark Nelson <mnelson@redhat.com>
This commit is contained in:
Yuri Weinstein 2016-07-18 16:28:21 -07:00 committed by GitHub
commit 88e6244e30
2 changed files with 28 additions and 27 deletions

View File

@ -247,15 +247,13 @@ int LevelDBStore::get(
std::map<string, bufferlist> *out)
{
utime_t start = ceph_clock_now(g_ceph_context);
KeyValueDB::Iterator it = get_iterator(prefix);
for (std::set<string>::const_iterator i = keys.begin();
i != keys.end();
++i) {
it->lower_bound(*i);
if (it->valid() && it->key() == *i) {
out->insert(make_pair(*i, it->value()));
} else if (!it->valid())
break;
i != keys.end(); ++i) {
std::string value;
std::string bound = combine_strings(prefix, *i);
auto status = db->Get(leveldb::ReadOptions(), leveldb::Slice(bound), &value);
if (status.ok())
(*out)[*i].append(value);
}
utime_t lat = ceph_clock_now(g_ceph_context) - start;
logger->inc(l_leveldb_gets);
@ -264,16 +262,18 @@ int LevelDBStore::get(
}
int LevelDBStore::get(const string &prefix,
const string &key,
bufferlist *value)
const string &key,
bufferlist *out)
{
assert(value && (value->length() == 0));
assert(out && (out->length() == 0));
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->append(it->value_as_ptr());
string value, k;
leveldb::Status s;
k = combine_strings(prefix, key);
s = db->Get(leveldb::ReadOptions(), leveldb::Slice(k), &value);
if (s.ok()) {
out->append(value);
} else {
r = -ENOENT;
}

View File

@ -475,21 +475,20 @@ void RocksDBStore::RocksDBTransactionImpl::merge(
}
}
//gets will bypass RocksDB row cache, since it uses iterator
int RocksDBStore::get(
const string &prefix,
const std::set<string> &keys,
std::map<string, bufferlist> *out)
{
utime_t start = ceph_clock_now(g_ceph_context);
KeyValueDB::Iterator it = get_iterator(prefix);
for (std::set<string>::const_iterator i = keys.begin();
i != keys.end();
++i) {
it->lower_bound(*i);
if (it->valid() && it->key() == *i) {
out->insert(make_pair(*i, it->value()));
} else if (!it->valid())
break;
i != keys.end(); ++i) {
std::string value;
std::string bound = combine_strings(prefix, *i);
auto status = db->Get(rocksdb::ReadOptions(), rocksdb::Slice(bound), &value);
if (status.ok())
(*out)[*i].append(value);
}
utime_t lat = ceph_clock_now(g_ceph_context) - start;
logger->inc(l_rocksdb_gets);
@ -505,10 +504,12 @@ int RocksDBStore::get(
assert(out && (out->length() == 0));
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) {
out->append(it->value_as_ptr());
string value, k;
rocksdb::Status s;
k = combine_strings(prefix, key);
s = db->Get(rocksdb::ReadOptions(), rocksdb::Slice(k), &value);
if (s.ok()) {
out->append(value);
} else {
r = -ENOENT;
}