Repository navigation
os, osd: bring the lightweight OMAP iteration #60278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c740754
f348ea3
87d6447
d4901af
d2531a0
a7c8195
0850828
3c2b4bb
4e1a500
e3df536
cbc771a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which bits are missing for Alien store? Is it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it has some (tiny) features we miss in crimson like |
||
| .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) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| virtual int status() = 0; | ||
| virtual ~SimplestIteratorImpl() {} | ||
| }; | ||
|
|
@@ -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; | ||
|
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) { | ||
|
|
@@ -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() { | ||
|
|
@@ -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; | ||
|
|
@@ -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(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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()) | ||||||||
|
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; | ||||||||
|
|
@@ -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()}; | ||||||||
|
Comment on lines
+2307
to
+2308
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| int RocksDBStore::RocksDBWholeSpaceIteratorImpl::status() | ||||||||
| { | ||||||||
| return dbiter->status().ok() ? 0 : -1; | ||||||||
|
|
@@ -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()}; | ||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
| int status() override { | ||||||||
| return dbiter->status().ok() ? 0 : -1; | ||||||||
| } | ||||||||
|
|
@@ -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) { | ||||||||
|
|
@@ -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) { | ||||||||
|
|
@@ -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 | ||||||||
|
|
@@ -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()}; | ||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
| int status() override { | ||||||||
| return iters[0]->status().ok() ? 0 : -1; | ||||||||
| } | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.