Skip to content

Commit

Permalink
table: Fix quadratic behavior when inserting sstables into tracker on…
Browse files Browse the repository at this point in the history
… schema change

Each time backlog tracker is informed about a new or old sstable, it
will recompute the static part of backlog which complexity is
proportional to the total number of sstables.
On schema change, we're calling backlog_tracker::replace_sstables()
for each existing sstable, therefore it produces O(N ^ 2) complexity.

Fixes scylladb#12499.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>

Closes scylladb#12593

(cherry picked from commit 87ee547)
Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
  • Loading branch information
raphaelsc committed Feb 7, 2023
1 parent 5c9ecd5 commit 47dcfd8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion replica/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1135,10 +1135,12 @@ void table::set_compaction_strategy(sstables::compaction_strategy_type strategy)
_compaction_strategy.get_backlog_tracker().transfer_ongoing_charges(new_cs.get_backlog_tracker(), move_read_charges);

auto new_sstables = new_cs.make_sstable_set(_schema);
std::vector<sstables::shared_sstable> new_sstables_for_backlog_tracker;
_main_sstables->for_each_sstable([&] (const sstables::shared_sstable& s) {
add_sstable_to_backlog_tracker(new_cs.get_backlog_tracker(), s);
new_sstables.insert(s);
new_sstables_for_backlog_tracker.push_back(s);
});
new_cs.get_backlog_tracker().replace_sstables({}, std::move(new_sstables_for_backlog_tracker));

// now exception safe:
_compaction_strategy = std::move(new_cs);
Expand Down

0 comments on commit 47dcfd8

Please sign in to comment.