repair: do not pass erm to flush_rows_in_working_row_buf when unnecessary

When small_table_optimization isn't enabled, flush_rows_in_working_row_buf
does not access erm. Add small_table_optimization_params containing erm and
pass it only when small_table_optimization is enabled.

This is safe as erm is kept by shard_repair_task_impl.

(cherry picked from commit e56bb5b6e2)
This commit is contained in:
Aleksandra Martyniuk
2025-02-04 11:42:03 +01:00
parent fb2c46dfbe
commit 4115f6f367
2 changed files with 18 additions and 11 deletions

View File

@@ -1385,13 +1385,17 @@ public:
public:
// Must run inside a seastar thread
void flush_rows_in_working_row_buf(locator::effective_replication_map_ptr erm, bool small_table_optimization) {
void flush_rows_in_working_row_buf(std::optional<small_table_optimization_params> small_table_optimization) {
if (_dirty_on_master) {
_dirty_on_master = is_dirty_on_master::no;
} else {
return;
}
flush_rows(_schema, _working_row_buf, _repair_writer, erm, small_table_optimization, this);
if (small_table_optimization) {
flush_rows(_schema, _working_row_buf, _repair_writer, small_table_optimization, this);
} else {
flush_rows(_schema, _working_row_buf, _repair_writer);
}
}
private:
@@ -1933,14 +1937,13 @@ public:
}
};
void flush_rows(schema_ptr s, std::list<repair_row>& rows, lw_shared_ptr<repair_writer>& writer, locator::effective_replication_map_ptr erm, bool small_table_optimization, repair_meta* rm) {
void flush_rows(schema_ptr s, std::list<repair_row>& rows, lw_shared_ptr<repair_writer>& writer, std::optional<small_table_optimization_params> small_table_optimization, repair_meta* rm) {
auto cmp = position_in_partition::tri_compare(*s);
lw_shared_ptr<mutation_fragment> last_mf;
lw_shared_ptr<const decorated_key_with_hash> last_dk;
bool do_small_table_optimization = erm && small_table_optimization;
const auto* tm = do_small_table_optimization ? &erm->get_token_metadata() : nullptr;
const auto* tm = small_table_optimization ? &small_table_optimization->erm->get_token_metadata() : nullptr;
if (do_small_table_optimization && rm) {
if (small_table_optimization && rm) {
const auto* tmptr = rm->get_tm_for_small_table_optimization_check(tm).get();
if (tmptr) {
tm = tmptr;
@@ -1953,10 +1956,10 @@ void flush_rows(schema_ptr s, std::list<repair_row>& rows, lw_shared_ptr<repair_
continue;
}
const auto& dk = r.get_dk_with_hash()->dk;
if (do_small_table_optimization) {
if (small_table_optimization) {
// Check if the token is owned by the node
auto eps = erm->get_replication_strategy().calculate_natural_endpoints(dk.token(), *tm).get();
if (!eps.contains(erm->get_topology().my_host_id())) {
auto eps = small_table_optimization->erm->get_replication_strategy().calculate_natural_endpoints(dk.token(), *tm).get();
if (!eps.contains(small_table_optimization->erm->get_topology().my_host_id())) {
rlogger.trace("master: ignore row, token={}", dk.token());
continue;
}
@@ -2937,7 +2940,7 @@ private:
throw;
}
}
master.flush_rows_in_working_row_buf(get_erm(), _small_table_optimization);
master.flush_rows_in_working_row_buf(_small_table_optimization ? std::make_optional(small_table_optimization_params{ .erm = get_erm() }) : std::nullopt);
return op_status::next_step;
}

View File

@@ -42,6 +42,10 @@ namespace gms {
class gossiper;
}
struct small_table_optimization_params {
locator::effective_replication_map_ptr erm;
};
class repair_meta;
using repair_meta_ptr = shared_ptr<repair_meta>;
@@ -279,4 +283,4 @@ future<> repair_cf_range_row_level(repair::shard_repair_task_impl& shard_task,
future<std::list<repair_row>> to_repair_rows_list(repair_rows_on_wire rows,
schema_ptr s, uint64_t seed, repair_master is_master,
reader_permit permit, repair_hasher hasher);
void flush_rows(schema_ptr s, std::list<repair_row>& rows, lw_shared_ptr<repair_writer>& writer, locator::effective_replication_map_ptr erm = {}, bool small_table_optimization = false, repair_meta* rm = nullptr);
void flush_rows(schema_ptr s, std::list<repair_row>& rows, lw_shared_ptr<repair_writer>& writer, std::optional<small_table_optimization_params> small_table_optimization = std::nullopt, repair_meta* rm = nullptr);