Skip to content

Commit

Permalink
replica: Add compaction_strategy_state to compaction group
Browse files Browse the repository at this point in the history
The state is not wired anywhere yet. It will replice the ones
stored in compaction strategies themselves. Therefore, allowing
each compaction group to have its own state.

Signed-off-by: Raphael S. Carvalho <[email protected]>
  • Loading branch information
raphaelsc committed Mar 27, 2023
1 parent 25f73a4 commit ee89ff2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions replica/compaction_group.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "database_fwd.hh"
#include "compaction/compaction_descriptor.hh"
#include "compaction/compaction_backlog_manager.hh"
#include "compaction/compaction_strategy_state.hh"
#include "sstables/sstable_set.hh"

#pragma once
Expand All @@ -35,6 +36,7 @@ class compaction_group {
std::unique_ptr<table_state> _table_state;
// Tokens included in this compaction_groups
dht::token_range _token_range;
compaction::compaction_strategy_state _compaction_strategy_state;
// Holds list of memtables for this group
lw_shared_ptr<memtable_list> _memtables;
// SSTable set which contains all non-maintenance sstables
Expand Down Expand Up @@ -79,6 +81,8 @@ public:
return _token_range;
}

void set_compaction_strategy_state(compaction::compaction_strategy_state compaction_strategy_state) noexcept;

lw_shared_ptr<memtable_list>& memtables() noexcept;
size_t memtable_count() const noexcept;
// Returns minimum timestamp from memtable list
Expand Down
13 changes: 12 additions & 1 deletion replica/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,10 @@ unsigned table::estimate_pending_compactions() const {
}), unsigned(0));
}

void compaction_group::set_compaction_strategy_state(compaction::compaction_strategy_state compaction_strategy_state) noexcept {
_compaction_strategy_state = std::move(compaction_strategy_state);
}

void table::set_compaction_strategy(sstables::compaction_strategy_type strategy) {
tlogger.debug("Setting compaction strategy of {}.{} to {}", _schema->ks_name(), _schema->cf_name(), sstables::compaction_strategy::name(strategy));
auto new_cs = make_compaction_strategy(strategy, _schema->compaction_strategy_options());
Expand All @@ -1299,10 +1303,15 @@ void table::set_compaction_strategy(sstables::compaction_strategy_type strategy)
table& t;
compaction_group& cg;
compaction_backlog_tracker new_bt;
compaction::compaction_strategy_state new_cs_state;
lw_shared_ptr<sstables::sstable_set> new_sstables;

compaction_group_sstable_set_updater(table& t, compaction_group& cg, sstables::compaction_strategy& new_cs)
: t(t), cg(cg), new_bt(new_cs.make_backlog_tracker()) {}
: t(t)
, cg(cg)
, new_bt(new_cs.make_backlog_tracker())
, new_cs_state(compaction::compaction_strategy_state::make(new_cs)) {
}

void prepare(sstables::compaction_strategy& new_cs) {
auto move_read_charges = new_cs.type() == t._compaction_strategy.type();
Expand All @@ -1321,6 +1330,7 @@ void table::set_compaction_strategy(sstables::compaction_strategy_type strategy)
void execute() noexcept {
t._compaction_manager.register_backlog_tracker(cg.as_table_state(), std::move(new_bt));
cg.set_main_sstables(std::move(new_sstables));
cg.set_compaction_strategy_state(std::move(new_cs_state));
}
};
std::vector<compaction_group_sstable_set_updater> cg_sstable_set_updaters;
Expand Down Expand Up @@ -1443,6 +1453,7 @@ compaction_group::compaction_group(table& t, dht::token_range token_range)
: _t(t)
, _table_state(std::make_unique<table_state>(t, *this))
, _token_range(std::move(token_range))
, _compaction_strategy_state(compaction::compaction_strategy_state::make(_t._compaction_strategy))
, _memtables(_t._config.enable_disk_writes ? _t.make_memtable_list(*this) : _t.make_memory_only_memtable_list())
, _main_sstables(make_lw_shared<sstables::sstable_set>(t._compaction_strategy.make_sstable_set(t.schema())))
, _maintenance_sstables(t.make_maintenance_sstable_set())
Expand Down

0 comments on commit ee89ff2

Please sign in to comment.