database, treewide: Introduce partition_slice::is_reversed()
Cleanup, reduces noise. Message-Id: <20211014093001.81479-1-tgrabiec@scylladb.com>
This commit is contained in:
committed by
Botond Dénes
parent
cad039421a
commit
cc56a971e8
@@ -66,7 +66,7 @@ public:
|
||||
// The ranges will be returned in forward (increasing) order even if the slice is reversed.
|
||||
static clustering_key_filter_ranges get_ranges(const schema& schema, const query::partition_slice& slice, const partition_key& key) {
|
||||
const query::clustering_row_ranges& ranges = slice.row_ranges(schema, key);
|
||||
if (slice.options.contains(query::partition_slice::option::reversed)) {
|
||||
if (slice.is_reversed()) {
|
||||
return clustering_key_filter_ranges(clustering_key_filter_ranges::reversed{}, ranges);
|
||||
}
|
||||
return clustering_key_filter_ranges(ranges);
|
||||
|
||||
@@ -1385,7 +1385,7 @@ compare_atomic_cell_for_merge(atomic_cell_view left, atomic_cell_view right) {
|
||||
future<std::tuple<lw_shared_ptr<query::result>, cache_temperature>>
|
||||
database::query(schema_ptr s, const query::read_command& cmd, query::result_options opts, const dht::partition_range_vector& ranges,
|
||||
tracing::trace_state_ptr trace_state, db::timeout_clock::time_point timeout) {
|
||||
const auto reversed = cmd.slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto reversed = cmd.slice.is_reversed();
|
||||
if (reversed) {
|
||||
s = s->make_reversed();
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ mutation_source streaming_virtual_table::as_mutation_source() {
|
||||
mutation_reader::forwarding fwd_mr) {
|
||||
|
||||
std::unique_ptr<query::partition_slice> unreversed_slice;
|
||||
const auto reversed = query_slice.options.contains(query::partition_slice::option::reversed);
|
||||
bool reversed = query_slice.is_reversed();
|
||||
if (reversed) {
|
||||
s = s->make_reversed();
|
||||
unreversed_slice = std::make_unique<query::partition_slice>(query::half_reverse_slice(*s, query_slice));
|
||||
|
||||
@@ -437,7 +437,7 @@ flat_mutation_reader_from_mutations(reader_permit permit,
|
||||
const dht::partition_range& pr,
|
||||
const query::partition_slice& query_slice,
|
||||
streamed_mutation::forwarding fwd) {
|
||||
const auto reversed = query_slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto reversed = query_slice.is_reversed();
|
||||
auto slice = reversed
|
||||
? query::half_reverse_slice(*ms.front().schema(), query_slice)
|
||||
: query_slice;
|
||||
@@ -956,7 +956,7 @@ make_flat_mutation_reader_from_fragments(schema_ptr schema, reader_permit permit
|
||||
flat_mutation_reader
|
||||
make_flat_mutation_reader_from_fragments(schema_ptr schema, reader_permit permit, std::deque<mutation_fragment> fragments,
|
||||
const dht::partition_range& pr, const query::partition_slice& query_slice) {
|
||||
const auto reversed = query_slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto reversed = query_slice.is_reversed();
|
||||
if (reversed) {
|
||||
schema = schema->make_reversed();
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ public:
|
||||
|
||||
auto snp_schema = key_and_snp->second->schema();
|
||||
bool digest_requested = _slice.options.contains<query::partition_slice::option::with_digest>();
|
||||
bool is_reversed = _slice.options.contains(query::partition_slice::option::reversed);
|
||||
bool is_reversed = _slice.is_reversed();
|
||||
auto mpsr = make_partition_snapshot_flat_reader_from_snp_schema(is_reversed, _permit, std::move(key_and_snp->first), std::move(cr), std::move(key_and_snp->second), digest_requested, region(), read_section(), mtbl(), streamed_mutation::forwarding::no, *mtbl());
|
||||
mpsr.upgrade_schema(schema());
|
||||
_delegate = std::move(mpsr);
|
||||
@@ -714,7 +714,7 @@ memtable::make_flat_reader(schema_ptr s,
|
||||
tracing::trace_state_ptr trace_state_ptr,
|
||||
streamed_mutation::forwarding fwd,
|
||||
mutation_reader::forwarding fwd_mr) {
|
||||
bool is_reversed = slice.options.contains(query::partition_slice::option::reversed);
|
||||
bool is_reversed = slice.is_reversed();
|
||||
if (query::is_single_partition(range) && !fwd_mr) {
|
||||
const query::ring_position& pos = range.start()->value();
|
||||
auto snp = _read_section(*this, [&] () -> partition_snapshot_ptr {
|
||||
|
||||
@@ -824,7 +824,7 @@ future<std::tuple<foreign_ptr<lw_shared_ptr<query::result>>, cache_temperature>>
|
||||
query::result_options opts,
|
||||
tracing::trace_state_ptr trace_state,
|
||||
db::timeout_clock::time_point timeout) {
|
||||
if (cmd.slice.options.contains(query::partition_slice::option::reversed)) {
|
||||
if (cmd.slice.is_reversed()) {
|
||||
s = s->make_reversed();
|
||||
}
|
||||
return do_query_on_all_shards<data_query_result_builder>(db, s, cmd, ranges, std::move(trace_state), timeout,
|
||||
|
||||
@@ -57,7 +57,7 @@ static sstring cannot_use_reason(can_use cu)
|
||||
|
||||
static bool ring_position_matches(const schema& s, const dht::partition_range& range, const query::partition_slice& slice,
|
||||
const position_view& pos) {
|
||||
const auto is_reversed = slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto is_reversed = slice.is_reversed();
|
||||
|
||||
const auto expected_start = dht::ring_position_view(*pos.partition_key);
|
||||
// If there are no clustering columns or the select is distinct we don't
|
||||
@@ -98,7 +98,7 @@ static bool clustering_position_matches(const schema& s, const query::partition_
|
||||
|
||||
clustering_key_prefix::equality eq(s);
|
||||
|
||||
const auto is_reversed = slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto is_reversed = slice.is_reversed();
|
||||
|
||||
// If the page ended mid-partition the first partition range should start
|
||||
// with the last clustering key (exclusive).
|
||||
|
||||
@@ -244,6 +244,11 @@ public:
|
||||
_partition_row_limit_high_bits = static_cast<uint64_t>(limit >> 32);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool is_reversed() const {
|
||||
return options.contains<query::partition_slice::option::reversed>();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const partition_slice& ps);
|
||||
friend std::ostream& operator<<(std::ostream& out, const specific_ranges& ps);
|
||||
};
|
||||
|
||||
@@ -559,7 +559,7 @@ public:
|
||||
if (!_cells.empty()) {
|
||||
fill_cells(column_kind::regular_column, _in_progress_row->cells());
|
||||
}
|
||||
if (_slice.options.contains(query::partition_slice::option::reversed) &&
|
||||
if (_slice.is_reversed() &&
|
||||
// we always consume whole rows (i.e. `consume_row_end` is always called) when reading in reverse,
|
||||
// even when `consume_row_start` requested to ignore the row. This happens because for reversed reads
|
||||
// skipping is performed in the intermediary reversing data source (not in the reader) and the source
|
||||
@@ -1530,7 +1530,7 @@ private:
|
||||
return _context->skip_to(begin);
|
||||
}
|
||||
bool reversed() const {
|
||||
return _slice.options.contains(query::partition_slice::option::reversed);
|
||||
return _slice.is_reversed();
|
||||
}
|
||||
public:
|
||||
void on_out_of_clustering_range() override {
|
||||
@@ -1684,7 +1684,7 @@ static flat_mutation_reader_v2 make_reader(
|
||||
// but the ranges themselves are not.
|
||||
// FIXME: drop this workaround when callers are fixed to provide the slice
|
||||
// in 'native-reversed' format (if ever).
|
||||
if (slice.get().options.contains(query::partition_slice::option::reversed)) {
|
||||
if (slice.get().is_reversed()) {
|
||||
return make_flat_mutation_reader_v2<mx_sstable_mutation_reader>(
|
||||
std::move(sstable), std::move(schema), std::move(permit), range,
|
||||
legacy_reverse_slice_to_native_reverse_slice(*schema, slice.get()), pc, std::move(trace_state), fwd, fwd_mr, monitor);
|
||||
|
||||
@@ -156,7 +156,7 @@ position_in_partition_view get_slice_upper_bound(const schema& s, const query::p
|
||||
if (ranges.empty()) {
|
||||
return position_in_partition_view::for_static_row();
|
||||
}
|
||||
if (slice.options.contains(query::partition_slice::option::reversed)) {
|
||||
if (slice.is_reversed()) {
|
||||
return position_in_partition_view::for_range_end(ranges.front());
|
||||
}
|
||||
return position_in_partition_view::for_range_end(ranges.back());
|
||||
|
||||
@@ -875,7 +875,7 @@ time_series_sstable_set::create_single_key_sstable_reader(
|
||||
return false;
|
||||
};
|
||||
|
||||
auto reversed = slice.options.contains(query::partition_slice::option::reversed);
|
||||
auto reversed = slice.is_reversed();
|
||||
// Note that `sstable_position_reader_queue` always includes a reader which emits a `partition_start` fragment,
|
||||
// guaranteeing that the reader we return emits it as well; this helps us avoid the problem from #3552.
|
||||
return make_clustering_combined_reader(
|
||||
|
||||
@@ -2108,7 +2108,7 @@ sstable::make_reader(
|
||||
streamed_mutation::forwarding fwd,
|
||||
mutation_reader::forwarding fwd_mr,
|
||||
read_monitor& mon) {
|
||||
const auto reversed = slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto reversed = slice.is_reversed();
|
||||
if (_version >= version_types::mc && (!reversed || (range.is_singular() && !fwd))) {
|
||||
return mx::make_reader(shared_from_this(), std::move(schema), std::move(permit), range, slice, pc, std::move(trace_state), fwd, fwd_mr, mon);
|
||||
}
|
||||
|
||||
4
table.cc
4
table.cc
@@ -180,7 +180,7 @@ table::make_reader(schema_ptr s,
|
||||
}
|
||||
|
||||
const auto bypass_cache = slice.options.contains(query::partition_slice::option::bypass_cache);
|
||||
const auto reversed = slice.options.contains(query::partition_slice::option::reversed);
|
||||
const auto reversed = slice.is_reversed();
|
||||
if (cache_enabled() && !bypass_cache && !(reversed && _config.reversed_reads_auto_bypass_cache())) {
|
||||
// There are two supported methods of performing reversed queries now.
|
||||
// In the old 'inefficient' method the cache/sstable performs a forward query and we wrap the reader in
|
||||
@@ -2083,7 +2083,7 @@ table::mutation_query(schema_ptr s,
|
||||
try {
|
||||
// Un-reverse the schema sent to the coordinator, it expects the
|
||||
// legacy format.
|
||||
auto result_schema = cmd.slice.options.contains(query::partition_slice::option::reversed) ? s->make_reversed() : s;
|
||||
auto result_schema = cmd.slice.is_reversed() ? s->make_reversed() : s;
|
||||
auto rrb = reconcilable_result_builder(*result_schema, cmd.slice, std::move(accounter));
|
||||
auto r = co_await q.consume_page(std::move(rrb), cmd.get_row_limit(), cmd.partition_limit, cmd.timestamp, trace_state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user