From e50dbef3e288672774be06656608791872fd1f03 Mon Sep 17 00:00:00 2001 From: Petr Gusev Date: Mon, 6 Nov 2023 18:23:02 +0400 Subject: [PATCH] database: get_token_metadata -> new token_metadata database::get_token_metadata() is switched to token_metadata2. get_all_ips method is added to the host_id-based token_metadata, since its convenient and will be used in several places. It returns all current nodes converted to inet_address by means of the topology contained within token_metadata. hint_sender::can_send: if the node has already left the cluster we may not find its host_id. This case is handled in the same way as if it's not a normal token owner - we simply send a hint to all replicas. --- db/hints/internal/hint_sender.cc | 4 +++- db/view/view.cc | 4 ++-- db/view/view_update_checks.hh | 2 +- repair/repair.cc | 2 +- replica/database.hh | 2 +- tombstone_gc.cc | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/db/hints/internal/hint_sender.cc b/db/hints/internal/hint_sender.cc index abd2b9c690..561a3a5677 100644 --- a/db/hints/internal/hint_sender.cc +++ b/db/hints/internal/hint_sender.cc @@ -101,7 +101,9 @@ bool hint_sender::can_send() noexcept { return true; } else { if (!_state.contains(state::ep_state_left_the_ring)) { - _state.set_if(!_shard_manager.local_db().get_token_metadata().is_normal_token_owner(end_point_key())); + const auto& tm = _shard_manager.local_db().get_token_metadata(); + const auto host_id = tm.get_host_id_if_known(end_point_key()); + _state.set_if(!host_id || !tm.is_normal_token_owner(*host_id)); } // send the hints out if the destination Node is part of the ring - we will send to all new replicas in this case return _state.contains(state::ep_state_left_the_ring); diff --git a/db/view/view.cc b/db/view/view.cc index 726974fadd..f2df589afe 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -2573,7 +2573,7 @@ update_backlog node_update_backlog::add_fetch(unsigned shard, update_backlog bac return std::max(backlog, _max.load(std::memory_order_relaxed)); } -future check_view_build_ongoing(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata& tm, const sstring& ks_name, +future check_view_build_ongoing(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata2& tm, const sstring& ks_name, const sstring& cf_name) { using view_statuses_type = std::unordered_map; return sys_dist_ks.view_status(ks_name, cf_name).then([&tm] (view_statuses_type&& view_statuses) { @@ -2584,7 +2584,7 @@ future check_view_build_ongoing(db::system_distributed_keyspace& sys_dist_ }); } -future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata& tm, const replica::table& t, +future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata2& tm, const replica::table& t, streaming::stream_reason reason) { if (is_internal_keyspace(t.schema()->ks_name())) { return make_ready_future(false); diff --git a/db/view/view_update_checks.hh b/db/view/view_update_checks.hh index ccb3eacafa..6ee8e9b173 100644 --- a/db/view/view_update_checks.hh +++ b/db/view/view_update_checks.hh @@ -32,7 +32,7 @@ using token_metadata2 = generic_token_metadata; namespace db::view { -future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata& tm, const replica::table& t, +future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata2& tm, const replica::table& t, streaming::stream_reason reason); } diff --git a/repair/repair.cc b/repair/repair.cc index 6edaabd09d..f59eb4f90d 100644 --- a/repair/repair.cc +++ b/repair/repair.cc @@ -1237,7 +1237,7 @@ future<> repair::user_requested_repair_task_impl::run() { participants = get_hosts_participating_in_repair(germs->get(), keyspace, ranges, data_centers, hosts, ignore_nodes).get(); } if (needs_flush_before_repair) { - auto waiting_nodes = db.get_token_metadata().get_all_endpoints(); + auto waiting_nodes = db.get_token_metadata().get_all_ips(); std::erase_if(waiting_nodes, [&] (const auto& addr) { return ignore_nodes.contains(addr); }); diff --git a/replica/database.hh b/replica/database.hh index bff06cbd54..da6827b76a 100644 --- a/replica/database.hh +++ b/replica/database.hh @@ -1561,7 +1561,7 @@ public: } const locator::shared_token_metadata& get_shared_token_metadata() const { return _shared_token_metadata; } - const locator::token_metadata& get_token_metadata() const { return *_shared_token_metadata.get(); } + const locator::token_metadata2& get_token_metadata() const { return *_shared_token_metadata.get()->get_new(); } wasm::manager& wasm() noexcept { return _wasm; } const wasm::manager& wasm() const noexcept { return _wasm; } diff --git a/tombstone_gc.cc b/tombstone_gc.cc index 93744f60d9..2bed1374cd 100644 --- a/tombstone_gc.cc +++ b/tombstone_gc.cc @@ -181,7 +181,7 @@ static bool needs_repair_before_gc(const replica::database& db, sstring ks_name) auto& ks = db.find_keyspace(ks_name); auto& rs = ks.get_replication_strategy(); bool needs_repair = rs.get_type() != locator::replication_strategy_type::local - && rs.get_replication_factor(*db.get_token_metadata().get_new()) != 1; + && rs.get_replication_factor(db.get_token_metadata()) != 1; return needs_repair; }