Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/common/ceph_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,23 @@ class coarse_mono_clock {
}
};

// Please note time_guard is not thread safety -- multiple threads
// updating same diff_accumulator can corrupt it.
template <class ClockT = mono_clock>
Comment thread
rzarzynski marked this conversation as resolved.
Resolved
class time_guard {
const typename ClockT::time_point start;
timespan& diff_accumulator;

public:
time_guard(timespan& diff_accumulator)
: start(ClockT::now()),
diff_accumulator(diff_accumulator) {
}
~time_guard() {
diff_accumulator += ClockT::now() - start;
}
};

namespace time_detail {
// So that our subtractions produce negative spans rather than
// arithmetic underflow.
Expand Down
17 changes: 15 additions & 2 deletions src/crimson/os/alienstore/alien_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,21 @@ auto AlienStore::omap_get_values(CollectionRef ch,
return do_with_op_gate(omap_values_t{}, [=, this] (auto &values) {
return tp->submit(ch->get_cid().hash_to_shard(tp->size()), [=, this, &values] {
auto c = static_cast<AlienCollection*>(ch.get());
return store->omap_get_values(c->collection, oid, start,
reinterpret_cast<map<string, bufferlist>*>(&values));
return store->omap_iterate(
c->collection, oid,
ObjectStore::omap_iter_seek_t{
.seek_position = start.value_or(std::string{}),
// FIXME: classical OSDs begins iteration from LOWER_BOUND
// (or UPPER_BOUND if filter_prefix > start). However, these
// bits are not implemented yet
Comment on lines 436 to 438

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bits are missing for Alien store? Is it PrimaryLogPG::do_osd_ops usage of omap_iterate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it has some (tiny) features we miss in crimson like filter_prefix support.

.seek_type = ObjectStore::omap_iter_seek_t::UPPER_BOUND
},
[&values]
(std::string_view key, std::string_view value) mutable {
values[std::string{key}].append(value);
// FIXME: there is limit on number of entries yet
return ObjectStore::omap_iter_ret_t::NEXT;
});
}).then([&values] (int r)
-> read_errorator::future<std::tuple<bool, omap_values_t>> {
if (r == -ENOENT) {
Expand Down
22 changes: 22 additions & 0 deletions src/kv/KeyValueDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <map>
#include <optional>
#include <string>
#include <string_view>
#include <boost/scoped_ptr.hpp>
#include "include/encoding.h"
#include "common/Formatter.h"
Expand Down Expand Up @@ -205,6 +206,10 @@ class KeyValueDB {
return "";
}
virtual ceph::buffer::list value() = 0;
// When valid() returns true, value returned as string-view
// is guaranteed to be valid until iterator is moved to another
// position; that is until call to next() / seek_to_first() / etc.
virtual std::string_view value_as_sv() = 0;

@rzarzynski rzarzynski Oct 12, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to drop old variants ultimately. Please note that doing the memcpy here results in more fragmentation of bufferlist at the Message layer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keys should undergo exactly the same expansion procedure.

There is a problem with string_view lifetime. It should be clearly stated for how long the value existence is guaranteed.
For RocksDB that would be until next seek/bound/next call, I am reasonably sure.
For MemStore and KStore it should be checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MemStore stores OMAP simply as map<string, bl> so it should be good till modification. Ideally we would hide the new variants from users and only let ObjectStores to use them.

virtual int status() = 0;
virtual ~SimplestIteratorImpl() {}
};
Expand All @@ -214,7 +219,12 @@ class KeyValueDB {
virtual ~IteratorImpl() {}
virtual int seek_to_last() = 0;
virtual int prev() = 0;
// When valid() returns true, key returned as string-view
// is guaranteed to be valid until iterator is moved to another
// position; that is until call to next() / seek_to_first() / etc.
virtual std::string_view key_as_sv() = 0;
Comment thread
rzarzynski marked this conversation as resolved.
Resolved
virtual std::pair<std::string, std::string> raw_key() = 0;
virtual std::pair<std::string_view, std::string_view> raw_key_as_sv() = 0;
virtual ceph::buffer::ptr value_as_ptr() {
ceph::buffer::list bl = value();
if (bl.length() == 1) {
Expand All @@ -241,7 +251,9 @@ class KeyValueDB {
virtual int next() = 0;
virtual int prev() = 0;
virtual std::string key() = 0;
virtual std::string_view key_as_sv() = 0;
virtual std::pair<std::string,std::string> raw_key() = 0;
virtual std::pair<std::string_view, std::string_view> raw_key_as_sv() = 0;
virtual bool raw_key_is_prefixed(const std::string &prefix) = 0;
virtual ceph::buffer::list value() = 0;
virtual ceph::buffer::ptr value_as_ptr() {
Expand All @@ -252,6 +264,7 @@ class KeyValueDB {
return ceph::buffer::ptr();
}
}
virtual std::string_view value_as_sv() = 0;
virtual int status() = 0;
virtual size_t key_size() {
return 0;
Expand Down Expand Up @@ -309,15 +322,24 @@ class KeyValueDB {
std::string key() override {
return generic_iter->key();
}
std::string_view key_as_sv() override {
return generic_iter->key_as_sv();
}
std::pair<std::string, std::string> raw_key() override {
return generic_iter->raw_key();
}
std::pair<std::string_view, std::string_view> raw_key_as_sv() override {
return generic_iter->raw_key_as_sv();
}
ceph::buffer::list value() override {
return generic_iter->value();
}
ceph::buffer::ptr value_as_ptr() override {
return generic_iter->value_as_ptr();
}
std::string_view value_as_sv() override {
return generic_iter->value_as_sv();
}
int status() override {
return generic_iter->status();
}
Expand Down
92 changes: 90 additions & 2 deletions src/kv/RocksDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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())
Expand All @@ -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())
Comment thread
rzarzynski marked this conversation as resolved.
Resolved
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;
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()};
Comment on lines +2307 to +2308

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rocksdb::Slice val = dbiter->value();
return std::string_view{val.data(), val.size()};
return dbiter->value().ToStringView();

}

int RocksDBStore::RocksDBWholeSpaceIteratorImpl::status()
{
return dbiter->status().ok() ? 0 : -1;
Expand Down Expand Up @@ -2348,16 +2389,26 @@ class CFIteratorImpl : public KeyValueDB::IteratorImpl {
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());
}
bufferptr value_as_ptr() override {
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()};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return std::string_view{val.data(), val.size()};
return val.ToStringView();

}
int status() override {
return dbiter->status().ok() ? 0 : -1;
}
Expand Down Expand Up @@ -2668,6 +2719,15 @@ class WholeMergeIteratorImpl : public KeyValueDB::WholeSpaceIteratorImpl {
}
}

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) {
Expand All @@ -2677,6 +2737,15 @@ class WholeMergeIteratorImpl : public KeyValueDB::WholeSpaceIteratorImpl {
}
}

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) {
Expand All @@ -2695,6 +2764,15 @@ class WholeMergeIteratorImpl : public KeyValueDB::WholeSpaceIteratorImpl {
}
}

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
Expand Down Expand Up @@ -3017,16 +3095,26 @@ class ShardMergeIteratorImpl : public KeyValueDB::IteratorImpl {
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());
}
bufferptr value_as_ptr() override {
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()};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return std::string_view{val.data(), val.size()};
return val.ToStringView();

}
int status() override {
return iters[0]->status().ok() ? 0 : -1;
}
Expand Down
4 changes: 4 additions & 0 deletions src/kv/RocksDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,13 @@ class RocksDBStore : public KeyValueDB {
int next() override;
int prev() override;
std::string key() override;
std::string_view key_as_sv() override;
std::pair<std::string,std::string> raw_key() override;
std::pair<std::string_view,std::string_view> raw_key_as_sv() override;
bool raw_key_is_prefixed(const std::string &prefix) override;
ceph::bufferlist value() override;
ceph::bufferptr value_as_ptr() override;
std::string_view value_as_sv() override;
int status() override;
size_t key_size() override;
size_t value_size() override;
Expand Down Expand Up @@ -413,6 +416,7 @@ class RocksDBStore : public KeyValueDB {
}

static int split_key(rocksdb::Slice in, std::string *prefix, std::string *key);
static int split_key(rocksdb::Slice in, std::string_view *prefix, std::string_view *key);

static std::string past_prefix(const std::string &prefix);

Expand Down
5 changes: 5 additions & 0 deletions src/os/DBObjectMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ bufferlist DBObjectMap::DBObjectMapIteratorImpl::value()
return cur_iter->value();
}

std::string_view DBObjectMap::DBObjectMapIteratorImpl::value_as_sv()
{
return cur_iter->value_as_sv();
}

int DBObjectMap::DBObjectMapIteratorImpl::status()
{
return r;
Expand Down
2 changes: 2 additions & 0 deletions src/os/DBObjectMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class DBObjectMap : public ObjectMap {
int next() override { ceph_abort(); return 0; }
std::string key() override { ceph_abort(); return ""; }
ceph::buffer::list value() override { ceph_abort(); return ceph::buffer::list(); }
std::string_view value_as_sv() override { ceph_abort(); return std::string_view(); }
int status() override { return 0; }
};

Expand Down Expand Up @@ -431,6 +432,7 @@ class DBObjectMap : public ObjectMap {
int next() override;
std::string key() override;
ceph::buffer::list value() override;
std::string_view value_as_sv() override;
int status() override;

bool on_parent() {
Expand Down
Loading