streaming: replace reverse iterators with reverse view in sstables scan

Use a reverse view over the SSTables vector instead of reverse iterators.
This avoids awkward rbegin/rend usage and the mental overhead of tracking
inverted sort order. With a view, we can use standard begin/end iteration
while preserving the intended scan direction.
This commit is contained in:
Ernest Zaslavsky
2025-11-25 16:52:42 +02:00
parent 68dcd1b1b2
commit f925ed176b

View File

@@ -358,7 +358,8 @@ future<std::vector<tablet_sstable_collection>> tablet_sstable_streamer::get_ssta
co_return std::move(tablets_sstables);
}
// sstables are sorted by first key in reverse order.
auto sstable_it = sstables.rbegin();
auto reversed_sstables = sstables | std::views::reverse;
auto sstable_it = reversed_sstables.cbegin();
for (auto& [tablet_range, sstables_fully_contained, sstables_partially_contained] : tablets_sstables) {
auto sstable_token_range = [] (const sstables::shared_sstable& sst) {
@@ -370,11 +371,11 @@ future<std::vector<tablet_sstable_collection>> tablet_sstable_streamer::get_ssta
auto exhausted = [&tablet_range] (const sstables::shared_sstable& sst) {
return tablet_range.before(sst->get_last_decorated_key().token(), dht::token_comparator{});
};
while (sstable_it != sstables.rend() && exhausted(*sstable_it)) {
while (sstable_it != reversed_sstables.cend() && exhausted(*sstable_it)) {
sstable_it++;
}
for (auto sst_it = sstable_it; sst_it != sstables.rend(); sst_it++) {
for (auto sst_it = sstable_it; sst_it != reversed_sstables.cend(); sst_it++) {
auto sst_token_range = sstable_token_range(*sst_it);
// sstables are sorted by first key, so should skip this SSTable since it