Files
scylladb/db/size_estimates_virtual_reader.hh
Michał Chojnowski 55c4b89b88 sstables: make sstable::estimated_keys_for_range asynchronous
Currently, `sstable::estimated_keys_for_range` works by
checking what fraction of Summary is covered by the given
range, and multiplying this fraction to the number of all keys.
Since computing things on Summary doesn't involve I/O (because Summary
is always kept in RAM), this is synchronous.

In a later patch, we will modify `sstable::estimated_keys_for_range`
so that it can deal with sstables that don't have a Summary
(because they use BTI indexes instead of BIG indexes).
In that case, the function is going to compute the relevant fraction
by using the index instead of Summary. This will require making
the function asynchronous. This is what we do in this patch.

(The actual change to the logic of `sstable::estimated_keys_for_range`
will come in the next patch. In this one, we only make it asynchronous).
2025-09-29 13:01:21 +02:00

79 lines
2.4 KiB
C++

/*
* Copyright (C) 2016-present ScyllaDB
*
* Modified by ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include "readers/mutation_reader_fwd.hh"
#include "readers/mutation_reader.hh"
#include "db/system_keyspace.hh"
#include "tracing/trace_state.hh"
namespace replica {
class database;
}
namespace db {
namespace size_estimates {
struct token_range {
bytes start;
bytes end;
};
class size_estimates_mutation_reader final : public mutation_reader::impl {
replica::database& _db;
db::system_keyspace& _sys_ks;
const dht::partition_range* _prange;
const query::partition_slice& _slice;
using ks_range = std::vector<sstring>;
std::optional<ks_range> _keyspaces;
ks_range::const_iterator _current_partition;
streamed_mutation::forwarding _fwd;
mutation_reader_opt _partition_reader;
public:
size_estimates_mutation_reader(replica::database& db, db::system_keyspace& sys_ks, schema_ptr, reader_permit, const dht::partition_range&, const query::partition_slice&, streamed_mutation::forwarding);
virtual future<> fill_buffer() override;
virtual future<> next_partition() override;
virtual future<> fast_forward_to(const dht::partition_range&) override;
virtual future<> fast_forward_to(position_range) override;
virtual future<> close() noexcept override;
private:
future<> get_next_partition();
future<> close_partition_reader() noexcept;
future<std::vector<db::system_keyspace::range_estimates>>
estimates_for_current_keyspace(std::vector<token_range> local_ranges) const;
};
struct virtual_reader {
replica::database& db;
db::system_keyspace& sys_ks;
mutation_reader operator()(schema_ptr schema,
reader_permit permit,
const dht::partition_range& range,
const query::partition_slice& slice,
tracing::trace_state_ptr trace_state,
streamed_mutation::forwarding fwd,
mutation_reader::forwarding fwd_mr) {
return make_mutation_reader<size_estimates_mutation_reader>(db, sys_ks, std::move(schema), std::move(permit), range, slice, fwd);
}
virtual_reader(replica::database& db_, db::system_keyspace& sys_ks_) noexcept : db(db_), sys_ks(sys_ks_) {}
};
future<std::vector<token_range>> test_get_local_ranges(replica::database& db, db::system_keyspace& sys_ks);
} // namespace size_estimates
} // namespace db