Files
scylladb/db/chained_delegating_reader.hh
Avi Kivity fdc1449392 treewide: rename flat_mutation_reader_v2 to mutation_reader
flat_mutation_reader_v2 was introduced in a pair of commits in 2021:

  e3309322c3 "Clone flat_mutation_reader related classes into v2 variants"
  08b5773c12 "Adapt flat_mutation_reader_v2 to the new version of the API"

as a replacement for flat_mutation_reader, using range_tombstone_change
instead of range_tombstone to represent represent range tombstones. See
those commits for more information.

The transition was incremental; the last use of the original
flat_mutation_reader was removed in 2022 in commit

  026f8cc1e7 "db: Use mutation_partition_v2 in mvcc"

In turn, flat_mutation_reader was introduced in 2017 in commit

  748205ca75 "Introduce flat_mutation_reader"

To transition from a mutation_reader that nested rows within
a partition in a separate stream, to a flat reader that streamed
partitions and rows in the same stream.

Here, we reclaim the original name and rename the awkward
flat_mutation_reader_v2 to mutation_reader.

Note that mutation_fragment_v2 remains since we still use the original
for compatibilty, sometimes.

Some notes about the transition:

 - files were also renamed. In one case (flat_mutation_reader_test.cc), the
   rename target already existed, so we rename to
    mutation_reader_another_test.cc.

 - a namespace 'mutation_reader' with two definitions existed (in
   mutation_reader_fwd.hh). Its contents was folded into the mutation_reader
   class. As a result, a few #includes had to be adjusted.

Closes scylladb/scylladb#19356
2024-06-21 07:12:06 +03:00

101 lines
3.1 KiB
C++

/*
* Copyright 2020-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <seastar/core/shared_future.hh>
#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<>();
}
};