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 #12499.

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

Closes #12593
  • Loading branch information
raphaelsc authored and avikivity committed Jan 25, 2023
1 parent bdd4b25 commit 87ee547
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions replica/table.cc
Expand Up @@ -1249,10 +1249,13 @@ void table::set_compaction_strategy(sstables::compaction_strategy_type strategy)
cg.get_backlog_tracker().copy_ongoing_charges(new_bt, move_read_charges);

new_sstables = make_lw_shared<sstables::sstable_set>(new_cs.make_sstable_set(t._schema));
cg.main_sstables()->for_each_sstable([this] (const sstables::shared_sstable& s) {
add_sstable_to_backlog_tracker(new_bt, s);
std::vector<sstables::shared_sstable> new_sstables_for_backlog_tracker;
new_sstables_for_backlog_tracker.reserve(cg.main_sstables()->all()->size());
cg.main_sstables()->for_each_sstable([this, &new_sstables_for_backlog_tracker] (const sstables::shared_sstable& s) {
new_sstables->insert(s);
new_sstables_for_backlog_tracker.push_back(s);
});
new_bt.replace_sstables({}, std::move(new_sstables_for_backlog_tracker));
}

void execute() noexcept {
Expand Down

0 comments on commit 87ee547

Please sign in to comment.