sstables: pass ring_position to create_single_key_sstable_reader

instead of partition_range.

It would be best to pass `partition_key` or `decorated_key` here.
However, the implementation of this function needs a `partition_range`
to pass into `sstable_set::select`, and `partition_range` must be
constructed from `ring_position`s. We could create the `ring_position`
internally from the key but that would involve a copy which we want to
avoid.
This commit is contained in:
Kamil Braun
2020-10-08 17:15:38 +02:00
parent 40d8bfa394
commit 68663d0de0
3 changed files with 11 additions and 11 deletions

View File

@@ -474,11 +474,10 @@ public:
// Filter out sstables for reader using bloom filter
static std::vector<shared_sstable>
filter_sstable_for_reader_by_pk(std::vector<shared_sstable>&& sstables, column_family& cf, const schema_ptr& schema,
const dht::partition_range& pr, const key& key) {
const dht::ring_position& pr_key = pr.start()->value();
const dht::ring_position& pos, const key& key) {
auto sstable_has_not_key = [&, cmp = dht::ring_position_comparator(*schema)] (const shared_sstable& sst) {
return cmp(pr_key, sst->get_first_decorated_key()) < 0 ||
cmp(pr_key, sst->get_last_decorated_key()) > 0 ||
return cmp(pos, sst->get_first_decorated_key()) < 0 ||
cmp(pos, sst->get_last_decorated_key()) > 0 ||
!sst->filter_has_key(key);
};
sstables.erase(boost::remove_if(sstables, sstable_has_not_key), sstables.end());
@@ -525,16 +524,16 @@ sstable_set::create_single_key_sstable_reader(
schema_ptr schema,
reader_permit permit,
utils::estimated_histogram& sstable_histogram,
const dht::partition_range& pr,
const dht::ring_position& pos,
const query::partition_slice& slice,
const io_priority_class& pc,
tracing::trace_state_ptr trace_state,
streamed_mutation::forwarding fwd,
mutation_reader::forwarding fwd_mr) const
{
auto& pk = pr.start()->value().key();
auto& pk = pos.key();
auto key = key::from_partition_key(*schema, *pk);
auto selected_sstables = filter_sstable_for_reader_by_pk(select(pr), *cf, schema, pr, key);
auto selected_sstables = filter_sstable_for_reader_by_pk(select({pos}), *cf, schema, pos, key);
auto num_sstables = selected_sstables.size();
if (!num_sstables) {
return make_empty_flat_reader(schema, permit);
@@ -542,8 +541,8 @@ sstable_set::create_single_key_sstable_reader(
auto readers = boost::copy_range<std::vector<flat_mutation_reader>>(
filter_sstable_for_reader_by_ck(std::move(selected_sstables), *cf, schema, slice)
| boost::adaptors::transformed([&] (const shared_sstable& sstable) {
tracing::trace(trace_state, "Reading key {} from sstable {}", pr, seastar::value_of([&sstable] { return sstable->get_filename(); }));
return sstable->read_row_flat(schema, permit, pr.start()->value(), slice, pc, trace_state, fwd);
tracing::trace(trace_state, "Reading key {} from sstable {}", pos, seastar::value_of([&sstable] { return sstable->get_filename(); }));
return sstable->read_row_flat(schema, permit, pos, slice, pc, trace_state, fwd);
})
);

View File

@@ -111,7 +111,7 @@ public:
schema_ptr,
reader_permit,
utils::estimated_histogram&,
const dht::partition_range&, // must be singular
const dht::ring_position&, // must contain a key
const query::partition_slice&,
const io_priority_class&,
tracing::trace_state_ptr,

View File

@@ -89,8 +89,9 @@ table::make_sstable_reader(schema_ptr s,
tracing::trace_state_ptr trace_state,
streamed_mutation::forwarding fwd,
mutation_reader::forwarding fwd_mr) {
assert(pr.is_singular() && pr.start()->value().has_key());
return sstables->create_single_key_sstable_reader(const_cast<column_family*>(this), std::move(s), std::move(permit),
_stats.estimated_sstable_per_read, pr, slice, pc, std::move(trace_state), fwd, fwd_mr);
_stats.estimated_sstable_per_read, pr.start()->value(), slice, pc, std::move(trace_state), fwd, fwd_mr);
});
} else {
return mutation_source([sstables=std::move(sstables)] (