mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-24 18:40:38 +00:00
sstables: dowithify non dowithed code
Technically speaking, the current code is not wrong. However, it was written before we had do_with, and I ended up dowithing it while chasing our erratic bug under the suspicion that this code could somehow be related with our bug. Turns out it isn't, but now that I went through the trouble of dowithing it - and since do_with is easier to reason about and guarantee liveness, let's go with this option. Signed-off-by: Glauber Costa <glommer@cloudius-systems.com> Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
This commit is contained in:
committed by
Avi Kivity
parent
3d24d49971
commit
8a6f362ef8
@@ -389,19 +389,19 @@ future<> write(file_writer& out, disk_array<Size, Members>& arr) {
|
||||
|
||||
template <typename Size, typename Key, typename Value>
|
||||
future<> parse(random_access_reader& in, Size& len, std::unordered_map<Key, Value>& map) {
|
||||
auto count = make_lw_shared<Size>();
|
||||
auto eos = [len, count] { return len == *count; };
|
||||
return do_until(eos, [len, count, &in, &map] {
|
||||
struct kv {
|
||||
Key key;
|
||||
Value value;
|
||||
};
|
||||
++*count;
|
||||
return do_with(Size(), [&in, len, &map] (Size& count) {
|
||||
auto eos = [len, &count] { return len == count++; };
|
||||
return do_until(eos, [len, &in, &map] {
|
||||
struct kv {
|
||||
Key key;
|
||||
Value value;
|
||||
};
|
||||
|
||||
auto el = std::make_unique<kv>();
|
||||
auto f = parse(in, el->key, el->value);
|
||||
return f.then([el = std::move(el), &map] {
|
||||
map.emplace(el->key, el->value);
|
||||
return do_with(kv(), [&in, &map] (auto& el) {
|
||||
return parse(in, el.key, el.value).then([&el, &map] {
|
||||
map.emplace(el.key, el.value);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user