Files
scylladb/db/chained_delegating_reader.hh
Kefu Chai ee36358a60 db: remove unused includes
these unused includes are identified by clang-include-cleaner.
after auditing the source files, all of the reports have been
confirmed.

please note, since we have `using seastar::shared_ptr` in
`seastarx.h`, this renders `#include <seastar/core/shared_ptr.hh>`
unnecessary if we don't need the full definition of `seastar::shared_ptr`.

so, in this change, all the unused includes are removed. but there are
some headers which are actually used, while still being identified by
this tool. these includes are marked with "IWYU pragma: keep".

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-10-04 20:48:18 +08:00

99 lines
3.0 KiB
C++

/*
* Copyright 2020-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include "readers/mutation_reader.hh"
// A reader which allows to insert a deferring operation before reading.
// All calls will first wait for a future to resolve, then forward to a given underlying reader.
class chained_delegating_reader : public mutation_reader::impl {
std::unique_ptr<mutation_reader> _underlying;
std::function<future<mutation_reader>()> _populate_reader;
std::function<void()> _on_destroyed;
public:
chained_delegating_reader(schema_ptr s, std::function<future<mutation_reader>()>&& populate, reader_permit permit, std::function<void()> on_destroyed = []{})
: impl(s, std::move(permit))
, _populate_reader(std::move(populate))
, _on_destroyed(std::move(on_destroyed))
{ }
chained_delegating_reader(chained_delegating_reader&& rd) = delete;
~chained_delegating_reader() {
_on_destroyed();
}
virtual future<> fill_buffer() override {
if (!_underlying) {
return _populate_reader().then([this] (mutation_reader&& rd) {
_underlying = std::make_unique<mutation_reader>(std::move(rd));
return fill_buffer();
});
}
if (is_buffer_full()) {
return make_ready_future<>();
}
return _underlying->fill_buffer().then([this] {
_end_of_stream = _underlying->is_end_of_stream();
_underlying->move_buffer_content_to(*this);
});
}
virtual future<> fast_forward_to(position_range pr) override {
if (!_underlying) {
return _populate_reader().then([this, pr = std::move(pr)] (mutation_reader&& rd) mutable {
_underlying = std::make_unique<mutation_reader>(std::move(rd));
return fast_forward_to(pr);
});
}
_end_of_stream = false;
clear_buffer();
return _underlying->fast_forward_to(std::move(pr));
}
virtual future<> next_partition() override {
if (!_underlying) {
return make_ready_future<>();
}
clear_buffer_to_next_partition();
auto f = make_ready_future<>();
if (is_buffer_empty()) {
f = _underlying->next_partition();
}
_end_of_stream = _underlying->is_end_of_stream() && _underlying->is_buffer_empty();
return f;
}
virtual future<> fast_forward_to(const dht::partition_range& pr) override {
if (!_underlying) {
return _populate_reader().then([this, &pr] (mutation_reader&& rd) mutable {
_underlying = std::make_unique<mutation_reader>(std::move(rd));
return fast_forward_to(pr);
});
}
_end_of_stream = false;
clear_buffer();
return _underlying->fast_forward_to(pr);
}
virtual future<> close() noexcept override {
if (_underlying) {
return _underlying->close();
}
return make_ready_future<>();
}
};