summaryrefslogtreecommitdiffstats
path: root/src/kv/RocksDBStore.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/kv/RocksDBStore.cc')
-rw-r--r--src/kv/RocksDBStore.cc92
1 files changed, 90 insertions, 2 deletions
diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc
index ca63ea06484..51d224b67c0 100644
--- a/src/kv/RocksDBStore.cc
+++ b/src/kv/RocksDBStore.cc
@@ -6,6 +6,7 @@
#include <memory>
#include <set>
#include <string>
+#include <string_view>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
@@ -47,6 +48,7 @@ using std::ostream;
using std::pair;
using std::set;
using std::string;
+using std::string_view;
using std::unique_ptr;
using std::vector;
@@ -1992,7 +1994,7 @@ int RocksDBStore::split_key(rocksdb::Slice in, string *prefix, string *key)
// Find separator inside Slice
char* separator = (char*) memchr(in.data(), 0, in.size());
- if (separator == NULL)
+ if (separator == nullptr)
return -EINVAL;
prefix_len = size_t(separator - in.data());
if (prefix_len >= in.size())
@@ -2006,6 +2008,27 @@ int RocksDBStore::split_key(rocksdb::Slice in, string *prefix, string *key)
return 0;
}
+// TODO: deduplicate the code, preferrably by removing the string variant
+int RocksDBStore::split_key(rocksdb::Slice in, string_view *prefix, string_view *key)
+{
+ size_t prefix_len = 0;
+
+ // Find separator inside Slice
+ char* separator = (char*) memchr(in.data(), 0, in.size());
+ if (separator == nullptr)
+ return -EINVAL;
+ prefix_len = size_t(separator - in.data());
+ if (prefix_len >= in.size())
+ return -EINVAL;
+
+ // Fetch prefix and/or key directly from Slice
+ if (prefix)
+ *prefix = string_view(in.data(), prefix_len);
+ if (key)
+ *key = string_view(separator + 1, in.size() - prefix_len - 1);
+ return 0;
+}
+
void RocksDBStore::compact()
{
dout(2) << __func__ << " starting" << dendl;
@@ -2226,7 +2249,13 @@ int RocksDBStore::RocksDBWholeSpaceIteratorImpl::prev()
string RocksDBStore::RocksDBWholeSpaceIteratorImpl::key()
{
string out_key;
- split_key(dbiter->key(), 0, &out_key);
+ split_key(dbiter->key(), nullptr, &out_key);
+ return out_key;
+}
+string_view RocksDBStore::RocksDBWholeSpaceIteratorImpl::key_as_sv()
+{
+ string_view out_key;
+ split_key(dbiter->key(), nullptr, &out_key);
return out_key;
}
pair<string,string> RocksDBStore::RocksDBWholeSpaceIteratorImpl::raw_key()
@@ -2235,6 +2264,12 @@ pair<string,string> RocksDBStore::RocksDBWholeSpaceIteratorImpl::raw_key()
split_key(dbiter->key(), &prefix, &key);
return make_pair(prefix, key);
}
+pair<string_view,string_view> RocksDBStore::RocksDBWholeSpaceIteratorImpl::raw_key_as_sv()
+{
+ string_view prefix, key;
+ split_key(dbiter->key(), &prefix, &key);
+ return make_pair(prefix, key);
+}
bool RocksDBStore::RocksDBWholeSpaceIteratorImpl::raw_key_is_prefixed(const string &prefix) {
// Look for "prefix\0" right in rocksb::Slice
@@ -2267,6 +2302,12 @@ bufferptr RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_ptr()
return bufferptr(val.data(), val.size());
}
+std::string_view RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_sv()
+{
+ rocksdb::Slice val = dbiter->value();
+ return std::string_view{val.data(), val.size()};
+}
+
int RocksDBStore::RocksDBWholeSpaceIteratorImpl::status()
{
return dbiter->status().ok() ? 0 : -1;
@@ -2348,9 +2389,15 @@ public:
string key() override {
return dbiter->key().ToString();
}
+ string_view key_as_sv() override {
+ return dbiter->key().ToStringView();
+ }
std::pair<std::string, std::string> raw_key() override {
return make_pair(prefix, key());
}
+ std::pair<std::string_view, std::string_view> raw_key_as_sv() override {
+ return make_pair(prefix, dbiter->key().ToStringView());
+ }
bufferlist value() override {
return to_bufferlist(dbiter->value());
}
@@ -2358,6 +2405,10 @@ public:
rocksdb::Slice val = dbiter->value();
return bufferptr(val.data(), val.size());
}
+ std::string_view value_as_sv() override {
+ rocksdb::Slice val = dbiter->value();
+ return std::string_view{val.data(), val.size()};
+ }
int status() override {
return dbiter->status().ok() ? 0 : -1;
}
@@ -2668,6 +2719,15 @@ public:
}
}
+ std::string_view key_as_sv() override
+ {
+ if (smaller == on_main) {
+ return main->key_as_sv();
+ } else {
+ return current_shard->second->key_as_sv();
+ }
+ }
+
std::pair<std::string,std::string> raw_key() override
{
if (smaller == on_main) {
@@ -2677,6 +2737,15 @@ public:
}
}
+ std::pair<std::string_view,std::string_view> raw_key_as_sv() override
+ {
+ if (smaller == on_main) {
+ return main->raw_key_as_sv();
+ } else {
+ return { current_shard->first, current_shard->second->key_as_sv() };
+ }
+ }
+
bool raw_key_is_prefixed(const std::string &prefix) override
{
if (smaller == on_main) {
@@ -2695,6 +2764,15 @@ public:
}
}
+ std::string_view value_as_sv() override
+ {
+ if (smaller == on_main) {
+ return main->value_as_sv();
+ } else {
+ return current_shard->second->value_as_sv();
+ }
+ }
+
int status() override
{
//because we already had to inspect key, it must be ok
@@ -3017,9 +3095,15 @@ public:
string key() override {
return iters[0]->key().ToString();
}
+ string_view key_as_sv() override {
+ return iters[0]->key().ToStringView();
+ }
std::pair<std::string, std::string> raw_key() override {
return make_pair(prefix, key());
}
+ std::pair<std::string_view, std::string_view> raw_key_as_sv() override {
+ return make_pair(prefix, iters[0]->key().ToStringView());
+ }
bufferlist value() override {
return to_bufferlist(iters[0]->value());
}
@@ -3027,6 +3111,10 @@ public:
rocksdb::Slice val = iters[0]->value();
return bufferptr(val.data(), val.size());
}
+ std::string_view value_as_sv() override {
+ rocksdb::Slice val = iters[0]->value();
+ return std::string_view{val.data(), val.size()};
+ }
int status() override {
return iters[0]->status().ok() ? 0 : -1;
}