diff --git a/api/api_init.hh b/api/api_init.hh index cff8089a8f..c2065dc28b 100644 --- a/api/api_init.hh +++ b/api/api_init.hh @@ -39,10 +39,7 @@ namespace gms { namespace locator { -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; -using token_metadata2 = generic_token_metadata; +class token_metadata; class shared_token_metadata; class snitch_ptr; diff --git a/cdc/generation.cc b/cdc/generation.cc index 2946872a4e..6a06431283 100644 --- a/cdc/generation.cc +++ b/cdc/generation.cc @@ -192,7 +192,7 @@ bool should_propose_first_generation(const gms::inet_address& me, const gms::gos }) == stop_iteration::no; } -bool is_cdc_generation_optimal(const cdc::topology_description& gen, const locator::token_metadata2& tm) { +bool is_cdc_generation_optimal(const cdc::topology_description& gen, const locator::token_metadata& tm) { if (tm.sorted_tokens().size() != gen.entries().size()) { // We probably have garbage streams from old generations cdc_log.info("Generation size does not match the token ring"); @@ -324,7 +324,7 @@ topology_description limit_number_of_streams_if_needed(topology_description&& de } // Compute a set of tokens that split the token ring into vnodes. -static auto get_tokens(const std::unordered_set& bootstrap_tokens, const locator::token_metadata2_ptr tmptr) { +static auto get_tokens(const std::unordered_set& bootstrap_tokens, const locator::token_metadata_ptr tmptr) { auto tokens = tmptr->sorted_tokens(); auto it = tokens.insert(tokens.end(), bootstrap_tokens.begin(), bootstrap_tokens.end()); std::sort(it, tokens.end()); @@ -352,7 +352,7 @@ static token_range_description create_token_range_description( cdc::topology_description make_new_generation_description( const std::unordered_set& bootstrap_tokens, const noncopyable_function(dht::token)>& get_sharding_info, - const locator::token_metadata2_ptr tmptr) { + const locator::token_metadata_ptr tmptr) { const auto tokens = get_tokens(bootstrap_tokens, tmptr); utils::chunked_vector vnode_descriptions; @@ -378,7 +378,7 @@ db_clock::time_point new_generation_timestamp(bool add_delay, std::chrono::milli } future generation_service::legacy_make_new_generation(const std::unordered_set& bootstrap_tokens, bool add_delay) { - const locator::token_metadata2_ptr tmptr = _token_metadata.get(); + const locator::token_metadata_ptr tmptr = _token_metadata.get(); // Fetch sharding parameters for a node that owns vnode ending with this token // using gossiped application states. diff --git a/cdc/generation.hh b/cdc/generation.hh index d61a800611..71d5a09637 100644 --- a/cdc/generation.hh +++ b/cdc/generation.hh @@ -137,7 +137,7 @@ bool should_propose_first_generation(const gms::inet_address& me, const gms::gos * Checks if the CDC generation is optimal, which is true if its `topology_description` is consistent * with `token_metadata`. */ -bool is_cdc_generation_optimal(const cdc::topology_description& gen, const locator::token_metadata2& tm); +bool is_cdc_generation_optimal(const cdc::topology_description& gen, const locator::token_metadata& tm); /* * Generate a set of CDC stream identifiers such that for each shard @@ -157,7 +157,7 @@ bool is_cdc_generation_optimal(const cdc::topology_description& gen, const locat cdc::topology_description make_new_generation_description( const std::unordered_set& bootstrap_tokens, const noncopyable_function (dht::token)>& get_sharding_info, - const locator::token_metadata2_ptr); + const locator::token_metadata_ptr); db_clock::time_point new_generation_timestamp(bool add_delay, std::chrono::milliseconds ring_delay); diff --git a/cdc/log.hh b/cdc/log.hh index d81f98ea2f..a796729dcd 100644 --- a/cdc/log.hh +++ b/cdc/log.hh @@ -36,10 +36,7 @@ using schema_ptr = seastar::lw_shared_ptr; namespace locator { -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; -using token_metadata2 = generic_token_metadata; +class token_metadata; } // namespace locator diff --git a/cql3/statements/create_keyspace_statement.cc b/cql3/statements/create_keyspace_statement.cc index eb89dd354e..3f5260cda6 100644 --- a/cql3/statements/create_keyspace_statement.cc +++ b/cql3/statements/create_keyspace_statement.cc @@ -253,7 +253,7 @@ create_keyspace_statement::execute(query_processor& qp, service::query_state& st }); } -lw_shared_ptr create_keyspace_statement::get_keyspace_metadata(const locator::token_metadata2& tm) { +lw_shared_ptr create_keyspace_statement::get_keyspace_metadata(const locator::token_metadata& tm) { _attrs->validate(); return _attrs->as_ks_metadata(_name, tm); } diff --git a/cql3/statements/create_keyspace_statement.hh b/cql3/statements/create_keyspace_statement.hh index 533aeeab2c..509c9cb6e6 100644 --- a/cql3/statements/create_keyspace_statement.hh +++ b/cql3/statements/create_keyspace_statement.hh @@ -17,11 +17,7 @@ namespace locator { -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; -using token_metadata2 = generic_token_metadata; - +class token_metadata; }; namespace data_dictionary { @@ -76,7 +72,7 @@ public: virtual future<::shared_ptr> execute(query_processor& qp, service::query_state& state, const query_options& options, std::optional guard) const override; - lw_shared_ptr get_keyspace_metadata(const locator::token_metadata2& tm); + lw_shared_ptr get_keyspace_metadata(const locator::token_metadata& tm); }; std::vector check_against_restricted_replication_strategies( diff --git a/cql3/statements/ks_prop_defs.cc b/cql3/statements/ks_prop_defs.cc index 7120852a45..0739f7a9f8 100644 --- a/cql3/statements/ks_prop_defs.cc +++ b/cql3/statements/ks_prop_defs.cc @@ -20,7 +20,7 @@ namespace statements { static std::map prepare_options( const sstring& strategy_class, - const locator::token_metadata2& tm, + const locator::token_metadata& tm, std::map options, const std::map& old_options = {}) { options.erase(ks_prop_defs::REPLICATION_STRATEGY_CLASS_KEY); @@ -111,13 +111,13 @@ std::optional ks_prop_defs::get_replication_strategy_class() const { return _strategy_class; } -lw_shared_ptr ks_prop_defs::as_ks_metadata(sstring ks_name, const locator::token_metadata2& tm) { +lw_shared_ptr ks_prop_defs::as_ks_metadata(sstring ks_name, const locator::token_metadata& tm) { auto sc = get_replication_strategy_class().value(); return data_dictionary::keyspace_metadata::new_keyspace(ks_name, sc, prepare_options(sc, tm, get_replication_options()), get_boolean(KW_DURABLE_WRITES, true), std::vector{}, get_storage_options()); } -lw_shared_ptr ks_prop_defs::as_ks_metadata_update(lw_shared_ptr old, const locator::token_metadata2& tm) { +lw_shared_ptr ks_prop_defs::as_ks_metadata_update(lw_shared_ptr old, const locator::token_metadata& tm) { std::map options; const auto& old_options = old->strategy_options(); auto sc = get_replication_strategy_class(); diff --git a/cql3/statements/ks_prop_defs.hh b/cql3/statements/ks_prop_defs.hh index 8459997dd0..72b9f86dcd 100644 --- a/cql3/statements/ks_prop_defs.hh +++ b/cql3/statements/ks_prop_defs.hh @@ -26,10 +26,7 @@ namespace gms { } namespace locator { - template - class generic_token_metadata; - using token_metadata = generic_token_metadata; - using token_metadata2 = generic_token_metadata; + class token_metadata; class shared_token_metadata; struct snitch_ptr; class abstract_replication_strategy; @@ -54,8 +51,8 @@ public: std::map get_replication_options() const; std::optional get_replication_strategy_class() const; data_dictionary::storage_options get_storage_options() const; - lw_shared_ptr as_ks_metadata(sstring ks_name, const locator::token_metadata2&); - lw_shared_ptr as_ks_metadata_update(lw_shared_ptr old, const locator::token_metadata2&); + lw_shared_ptr as_ks_metadata(sstring ks_name, const locator::token_metadata&); + lw_shared_ptr as_ks_metadata_update(lw_shared_ptr old, const locator::token_metadata&); #if 0 public KSMetaData asKSMetadataUpdate(KSMetaData old) throws RequestValidationException diff --git a/db/view/view.cc b/db/view/view.cc index f2df589afe..726974fadd 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_metadata2& tm, const sstring& ks_name, +future check_view_build_ongoing(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata& 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_metadata2& tm, const replica::table& t, +future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata& 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 6ee8e9b173..45c9f03f5f 100644 --- a/db/view/view_update_checks.hh +++ b/db/view/view_update_checks.hh @@ -24,15 +24,12 @@ class system_distributed_keyspace; } namespace locator { -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; -using token_metadata2 = generic_token_metadata; +class token_metadata; } namespace db::view { -future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata2& tm, const replica::table& t, +future check_needs_view_update_path(db::system_distributed_keyspace& sys_dist_ks, const locator::token_metadata& tm, const replica::table& t, streaming::stream_reason reason); } diff --git a/db/virtual_tables.cc b/db/virtual_tables.cc index 2089714cef..a1635148fd 100644 --- a/db/virtual_tables.cc +++ b/db/virtual_tables.cc @@ -65,7 +65,7 @@ public: future<> execute(std::function mutation_sink) override { return _ss.get_ownership().then([&, mutation_sink] (std::map ownership) { - const locator::token_metadata2& tm = _ss.get_token_metadata(); + const locator::token_metadata& tm = _ss.get_token_metadata(); _gossiper.for_each_endpoint_state([&] (const gms::inet_address& endpoint, const gms::endpoint_state&) { mutation m(schema(), partition_key::from_single_value(*schema(), data_value(endpoint).serialize_nonnull())); diff --git a/dht/boot_strapper.cc b/dht/boot_strapper.cc index b9fc52a361..0de4e84e0d 100644 --- a/dht/boot_strapper.cc +++ b/dht/boot_strapper.cc @@ -63,7 +63,7 @@ future<> boot_strapper::bootstrap(streaming::stream_reason reason, gms::gossiper } } -std::unordered_set boot_strapper::get_random_bootstrap_tokens(const token_metadata2_ptr tmptr, size_t num_tokens, dht::check_token_endpoint check) { +std::unordered_set boot_strapper::get_random_bootstrap_tokens(const token_metadata_ptr tmptr, size_t num_tokens, dht::check_token_endpoint check) { if (num_tokens < 1) { throw std::runtime_error("num_tokens must be >= 1"); } @@ -77,7 +77,7 @@ std::unordered_set boot_strapper::get_random_bootstrap_tokens(const token return tokens; } -std::unordered_set boot_strapper::get_bootstrap_tokens(const token_metadata2_ptr tmptr, const db::config& cfg, dht::check_token_endpoint check) { +std::unordered_set boot_strapper::get_bootstrap_tokens(const token_metadata_ptr tmptr, const db::config& cfg, dht::check_token_endpoint check) { std::unordered_set initial_tokens; sstring tokens_string = cfg.initial_token(); try { @@ -104,7 +104,7 @@ std::unordered_set boot_strapper::get_bootstrap_tokens(const token_metada return get_random_bootstrap_tokens(tmptr, cfg.num_tokens(), check); } -std::unordered_set boot_strapper::get_random_tokens(const token_metadata2_ptr tmptr, size_t num_tokens) { +std::unordered_set boot_strapper::get_random_tokens(const token_metadata_ptr tmptr, size_t num_tokens) { std::unordered_set tokens; while (tokens.size() < num_tokens) { auto token = dht::token::get_random_token(); diff --git a/dht/boot_strapper.hh b/dht/boot_strapper.hh index 5f88257f05..61ec72f136 100644 --- a/dht/boot_strapper.hh +++ b/dht/boot_strapper.hh @@ -29,9 +29,7 @@ using check_token_endpoint = bool_class; class boot_strapper { using inet_address = gms::inet_address; using token_metadata = locator::token_metadata; - using token_metadata2 = locator::token_metadata2; using token_metadata_ptr = locator::token_metadata_ptr; - using token_metadata2_ptr = locator::token_metadata2_ptr; using token = dht::token; distributed& _db; sharded& _stream_manager; @@ -42,10 +40,10 @@ class boot_strapper { locator::endpoint_dc_rack _dr; /* token of the node being bootstrapped. */ std::unordered_set _tokens; - const locator::token_metadata2_ptr _token_metadata_ptr; + const locator::token_metadata_ptr _token_metadata_ptr; public: boot_strapper(distributed& db, sharded& sm, abort_source& abort_source, - locator::host_id addr, locator::endpoint_dc_rack dr, std::unordered_set tokens, const token_metadata2_ptr tmptr) + locator::host_id addr, locator::endpoint_dc_rack dr, std::unordered_set tokens, const token_metadata_ptr tmptr) : _db(db) , _stream_manager(sm) , _abort_source(abort_source) @@ -62,14 +60,14 @@ public: * otherwise, if num_tokens == 1, pick a token to assume half the load of the most-loaded node. * else choose num_tokens tokens at random */ - static std::unordered_set get_bootstrap_tokens(const token_metadata2_ptr tmptr, const db::config& cfg, check_token_endpoint check); + static std::unordered_set get_bootstrap_tokens(const token_metadata_ptr tmptr, const db::config& cfg, check_token_endpoint check); /** * Same as above but does not consult initialtoken config */ - static std::unordered_set get_random_bootstrap_tokens(const token_metadata2_ptr tmptr, size_t num_tokens, check_token_endpoint check); + static std::unordered_set get_random_bootstrap_tokens(const token_metadata_ptr tmptr, size_t num_tokens, check_token_endpoint check); - static std::unordered_set get_random_tokens(const token_metadata2_ptr tmptr, size_t num_tokens); + static std::unordered_set get_random_tokens(const token_metadata_ptr tmptr, size_t num_tokens); #if 0 public static class StringSerializer implements IVersionedSerializer { @@ -93,7 +91,7 @@ public: #endif private: - const token_metadata2& get_token_metadata() { + const token_metadata& get_token_metadata() { return *_token_metadata_ptr; } }; diff --git a/dht/range_streamer.cc b/dht/range_streamer.cc index f27d3a48e7..37c2e6135b 100644 --- a/dht/range_streamer.cc +++ b/dht/range_streamer.cc @@ -123,14 +123,14 @@ range_streamer::get_all_ranges_with_strict_sources_for(const sstring& keyspace_n auto& strat = erm->get_replication_strategy(); //Active ranges - auto metadata_clone = locator::make_token_metadata2_ptr(get_token_metadata().clone_only_token_map().get0()); - auto range_addresses = strat.get_range_addresses(token_metadata(metadata_clone)).get0(); + auto metadata_clone = get_token_metadata().clone_only_token_map().get0(); + auto range_addresses = strat.get_range_addresses(metadata_clone).get0(); //Pending ranges - metadata_clone->update_topology(_address, _dr); - metadata_clone->update_normal_tokens(_tokens, _address).get(); - auto pending_range_addresses = strat.get_range_addresses(token_metadata(metadata_clone)).get0(); - metadata_clone->clear_gently().get(); + metadata_clone.update_topology(_address, _dr); + metadata_clone.update_normal_tokens(_tokens, _address).get(); + auto pending_range_addresses = strat.get_range_addresses(metadata_clone).get0(); + metadata_clone.clear_gently().get(); //Collects the source that will have its range moved to the new node std::unordered_map> range_sources; diff --git a/dht/range_streamer.hh b/dht/range_streamer.hh index 75ceb1b01b..00c6019f5e 100644 --- a/dht/range_streamer.hh +++ b/dht/range_streamer.hh @@ -37,9 +37,7 @@ class range_streamer { public: using inet_address = gms::inet_address; using token_metadata = locator::token_metadata; - using token_metadata2 = locator::token_metadata2; using token_metadata_ptr = locator::token_metadata_ptr; - using token_metadata2_ptr = locator::token_metadata2_ptr; using stream_plan = streaming::stream_plan; using stream_state = streaming::stream_state; public: @@ -79,7 +77,7 @@ public: } }; - range_streamer(distributed& db, sharded& sm, const token_metadata2_ptr tmptr, abort_source& abort_source, std::unordered_set tokens, + range_streamer(distributed& db, sharded& sm, const token_metadata_ptr tmptr, abort_source& abort_source, std::unordered_set tokens, locator::host_id address, locator::endpoint_dc_rack dr, sstring description, streaming::stream_reason reason, service::frozen_topology_guard topo_guard, std::vector tables = {}) @@ -98,7 +96,7 @@ public: _abort_source.check(); } - range_streamer(distributed& db, sharded& sm, const token_metadata2_ptr tmptr, abort_source& abort_source, + range_streamer(distributed& db, sharded& sm, const token_metadata_ptr tmptr, abort_source& abort_source, locator::host_id address, locator::endpoint_dc_rack dr, sstring description, streaming::stream_reason reason, service::frozen_topology_guard topo_guard, std::vector tables = {}) : range_streamer(db, sm, std::move(tmptr), abort_source, std::unordered_set(), address, std::move(dr), description, reason, std::move(topo_guard), std::move(tables)) { } @@ -147,7 +145,7 @@ private: #endif // Can be called only before stream_async(). - const token_metadata2& get_token_metadata() { + const token_metadata& get_token_metadata() { return *_token_metadata_ptr; } public: @@ -156,7 +154,7 @@ public: private: distributed& _db; sharded& _stream_manager; - token_metadata2_ptr _token_metadata_ptr; + token_metadata_ptr _token_metadata_ptr; abort_source& _abort_source; std::unordered_set _tokens; locator::host_id _address; diff --git a/gms/gossiper.cc b/gms/gossiper.cc index f404b04d28..db346e4a26 100644 --- a/gms/gossiper.cc +++ b/gms/gossiper.cc @@ -2634,7 +2634,7 @@ void gossiper::append_endpoint_state(std::stringstream& ss, const endpoint_state } } -locator::token_metadata2_ptr gossiper::get_token_metadata_ptr() const noexcept { +locator::token_metadata_ptr gossiper::get_token_metadata_ptr() const noexcept { return _shared_token_metadata.get(); } diff --git a/gms/gossiper.hh b/gms/gossiper.hh index 6d6fedd670..dee8d910e9 100644 --- a/gms/gossiper.hh +++ b/gms/gossiper.hh @@ -674,7 +674,7 @@ private: gossip_config _gcfg; // Get features supported by a particular node std::set get_supported_features(inet_address endpoint) const; - locator::token_metadata2_ptr get_token_metadata_ptr() const noexcept; + locator::token_metadata_ptr get_token_metadata_ptr() const noexcept; public: void check_knows_remote_features(std::set& local_features, const std::unordered_map& loaded_peer_features) const; // Get features supported by all the nodes this node knows about diff --git a/locator/abstract_replication_strategy.cc b/locator/abstract_replication_strategy.cc index c173512919..a0ff02d898 100644 --- a/locator/abstract_replication_strategy.cc +++ b/locator/abstract_replication_strategy.cc @@ -19,7 +19,7 @@ namespace locator { -static endpoint_set resolve_endpoints(const host_id_set& host_ids, const token_metadata2& tm) { +static endpoint_set resolve_endpoints(const host_id_set& host_ids, const token_metadata& tm) { endpoint_set result{}; result.reserve(host_ids.size()); for (const auto& host_id: host_ids) { @@ -68,9 +68,9 @@ void abstract_replication_strategy::validate_replication_strategy(const sstring& } } -future abstract_replication_strategy::calculate_natural_ips(const token& search_token, const token_metadata2_ptr& tm) const { - const auto host_ids = co_await calculate_natural_endpoints(search_token, *tm); - co_return resolve_endpoints(host_ids, *tm); +future abstract_replication_strategy::calculate_natural_ips(const token& search_token, const token_metadata& tm) const { + const auto host_ids = co_await calculate_natural_endpoints(search_token, tm); + co_return resolve_endpoints(host_ids, tm); } using strategy_class_registry = class_registry< @@ -87,7 +87,7 @@ inet_address_vector_replica_set vnode_effective_replication_map::get_natural_end return natural_endpoints; } -void maybe_remove_node_being_replaced(const token_metadata2& tm, +void maybe_remove_node_being_replaced(const token_metadata& tm, const abstract_replication_strategy& rs, inet_address_vector_replica_set& natural_endpoints) { if (tm.is_any_node_being_replaced() && @@ -264,10 +264,10 @@ abstract_replication_strategy::get_ranges(locator::host_id ep, token_metadata_pt future abstract_replication_strategy::get_ranges(locator::host_id ep, const token_metadata& tm) const { dht::token_range_vector ret; - if (!tm.get_new()->is_normal_token_owner(ep)) { + if (!tm.is_normal_token_owner(ep)) { co_return ret; } - const auto& sorted_tokens = tm.get_new()->sorted_tokens(); + const auto& sorted_tokens = tm.sorted_tokens(); if (sorted_tokens.empty()) { on_internal_error(rslogger, "Token metadata is empty"); } @@ -279,7 +279,7 @@ abstract_replication_strategy::get_ranges(locator::host_id ep, const token_metad // Using the common path would make the function quadratic in the number of endpoints. should_add = true; } else { - auto eps = co_await calculate_natural_endpoints(tok, *tm.get_new()); + auto eps = co_await calculate_natural_endpoints(tok, tm); should_add = eps.contains(ep); } if (should_add) { @@ -327,7 +327,7 @@ vnode_effective_replication_map::get_primary_ranges_within_dc(inet_address ep) c future> vnode_effective_replication_map::get_range_addresses() const { - const token_metadata2& tm = *_tmptr; + const token_metadata& tm = *_tmptr; std::unordered_map ret; for (auto& t : tm.sorted_tokens()) { dht::token_range_vector ranges = tm.get_primary_ranges_for(t); @@ -342,10 +342,9 @@ vnode_effective_replication_map::get_range_addresses() const { future> abstract_replication_strategy::get_range_addresses(const token_metadata& tm) const { std::unordered_map ret; - auto tm_new = tm.get_new_strong(); - for (auto& t : tm_new->sorted_tokens()) { - dht::token_range_vector ranges = tm_new->get_primary_ranges_for(t); - auto eps = co_await calculate_natural_ips(t, tm_new); + for (auto& t : tm.sorted_tokens()) { + dht::token_range_vector ranges = tm.get_primary_ranges_for(t); + auto eps = co_await calculate_natural_ips(t, tm); for (auto& r : ranges) { ret.emplace(r, eps.get_vector()); } @@ -354,26 +353,26 @@ abstract_replication_strategy::get_range_addresses(const token_metadata& tm) con } future -abstract_replication_strategy::get_pending_address_ranges(const token_metadata2_ptr tmptr, std::unordered_set pending_tokens, locator::host_id pending_address, locator::endpoint_dc_rack dr) const { +abstract_replication_strategy::get_pending_address_ranges(const token_metadata_ptr tmptr, std::unordered_set pending_tokens, locator::host_id pending_address, locator::endpoint_dc_rack dr) const { dht::token_range_vector ret; - auto temp = make_token_metadata2_ptr(co_await tmptr->clone_only_token_map()); - temp->update_topology(pending_address, std::move(dr)); - co_await temp->update_normal_tokens(pending_tokens, pending_address); - for (const auto& t : temp->sorted_tokens()) { - auto eps = co_await calculate_natural_endpoints(t, *temp); + auto temp = co_await tmptr->clone_only_token_map(); + temp.update_topology(pending_address, std::move(dr)); + co_await temp.update_normal_tokens(pending_tokens, pending_address); + for (const auto& t : temp.sorted_tokens()) { + auto eps = co_await calculate_natural_endpoints(t, temp); if (eps.contains(pending_address)) { - dht::token_range_vector r = temp->get_primary_ranges_for(t); + dht::token_range_vector r = temp.get_primary_ranges_for(t); rslogger.debug("get_pending_address_ranges: token={} primary_range={} endpoint={}", t, r, pending_address); ret.insert(ret.end(), r.begin(), r.end()); } } - co_await temp->clear_gently(); + co_await temp.clear_gently(); co_return ret; } static const auto default_replication_map_key = dht::token::from_int64(0); -future calculate_effective_replication_map(replication_strategy_ptr rs, token_metadata2_ptr tmptr) { +future calculate_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr) { replication_map replication_map; ring_mapping pending_endpoints; ring_mapping read_endpoints; @@ -441,11 +440,11 @@ future calculate_effective_replicat } } else if (depend_on_token) { for (const auto &t : sorted_tokens) { - auto eps = co_await rs->calculate_natural_ips(t, tmptr); + auto eps = co_await rs->calculate_natural_ips(t, *tmptr); replication_map.emplace(t, std::move(eps).extract_vector()); } } else { - auto eps = co_await rs->calculate_natural_ips(default_replication_map_key, tmptr); + auto eps = co_await rs->calculate_natural_ips(default_replication_map_key, *tmptr); replication_map.emplace(default_replication_map_key, std::move(eps).extract_vector()); } @@ -512,7 +511,7 @@ vnode_effective_replication_map::~vnode_effective_replication_map() { } effective_replication_map::effective_replication_map(replication_strategy_ptr rs, - token_metadata2_ptr tmptr, + token_metadata_ptr tmptr, size_t replication_factor) noexcept : _rs(std::move(rs)) , _tmptr(std::move(tmptr)) @@ -520,11 +519,11 @@ effective_replication_map::effective_replication_map(replication_strategy_ptr rs , _validity_abort_source(std::make_unique()) { } -vnode_effective_replication_map::factory_key vnode_effective_replication_map::make_factory_key(const replication_strategy_ptr& rs, const token_metadata2_ptr& tmptr) { +vnode_effective_replication_map::factory_key vnode_effective_replication_map::make_factory_key(const replication_strategy_ptr& rs, const token_metadata_ptr& tmptr) { return factory_key(rs->get_type(), rs->get_config_options(), tmptr->get_ring_version()); } -future effective_replication_map_factory::create_effective_replication_map(replication_strategy_ptr rs, token_metadata2_ptr tmptr) { +future effective_replication_map_factory::create_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr) { // lookup key on local shard auto key = vnode_effective_replication_map::make_factory_key(rs, tmptr); auto erm = find_effective_replication_map(key); diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index 99bd927663..dbd35cfe67 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -103,8 +103,8 @@ public: // is small, that implementation may not yield since by itself it won't cause a reactor stall (assuming practical // cluster sizes and number of tokens per node). The caller is responsible for yielding if they call this function // in a loop. - virtual future calculate_natural_endpoints(const token& search_token, const token_metadata2& tm) const = 0; - future calculate_natural_ips(const token& search_token, const token_metadata2_ptr& tm) const; + virtual future calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const = 0; + future calculate_natural_ips(const token& search_token, const token_metadata& tm) const; virtual ~abstract_replication_strategy() {} static ptr_type create_replication_strategy(const sstring& strategy_name, const replication_strategy_config_options& config_options); @@ -119,7 +119,7 @@ public: virtual void validate_options(const gms::feature_service&) const = 0; virtual std::optional> recognized_options(const topology&) const = 0; - virtual size_t get_replication_factor(const token_metadata2& tm) const = 0; + virtual size_t get_replication_factor(const token_metadata& tm) const = 0; // Decide if the replication strategy allow removing the node being // replaced from the natural endpoints when a node is being replaced in the // cluster. LocalStrategy is the not allowed to do so because it always @@ -155,7 +155,7 @@ public: // Caller must ensure that token_metadata will not change throughout the call. future> get_range_addresses(const token_metadata& tm) const; - future get_pending_address_ranges(const token_metadata2_ptr tmptr, std::unordered_set pending_tokens, locator::host_id pending_address, locator::endpoint_dc_rack dr) const; + future get_pending_address_ranges(const token_metadata_ptr tmptr, std::unordered_set pending_tokens, locator::host_id pending_address, locator::endpoint_dc_rack dr) const; }; using ring_mapping = boost::icl::interval_map>; @@ -175,17 +175,17 @@ using mutable_replication_strategy_ptr = seastar::shared_ptr _validity_abort_source; public: - effective_replication_map(replication_strategy_ptr, token_metadata2_ptr, size_t replication_factor) noexcept; + effective_replication_map(replication_strategy_ptr, token_metadata_ptr, size_t replication_factor) noexcept; effective_replication_map(effective_replication_map&&) noexcept = default; virtual ~effective_replication_map() = default; const abstract_replication_strategy& get_replication_strategy() const noexcept { return *_rs; } - const token_metadata2& get_token_metadata() const noexcept { return *_tmptr; } - const token_metadata2_ptr& get_token_metadata_ptr() const noexcept { return _tmptr; } + const token_metadata& get_token_metadata() const noexcept { return *_tmptr; } + const token_metadata_ptr& get_token_metadata_ptr() const noexcept { return _tmptr; } const topology& get_topology() const noexcept { return _tmptr->get_topology(); } size_t get_replication_factor() const noexcept { return _replication_factor; } @@ -255,7 +255,7 @@ protected: } public: virtual ~per_table_replication_strategy() = default; - virtual effective_replication_map_ptr make_replication_map(table_id, token_metadata2_ptr) const = 0; + virtual effective_replication_map_ptr make_replication_map(table_id, token_metadata_ptr) const = 0; }; // Holds the full replication_map resulting from applying the @@ -302,7 +302,7 @@ public: // effective_replication_map std::unique_ptr make_splitter() const override; const dht::sharder& get_sharder(const schema& s) const override; public: - explicit vnode_effective_replication_map(replication_strategy_ptr rs, token_metadata2_ptr tmptr, replication_map replication_map, + explicit vnode_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr, replication_map replication_map, ring_mapping pending_endpoints, ring_mapping read_endpoints, size_t replication_factor) noexcept : effective_replication_map(std::move(rs), std::move(tmptr), replication_factor) , _replication_map(std::move(replication_map)) @@ -357,7 +357,7 @@ private: const inet_address_vector_replica_set& do_get_natural_endpoints(const token& tok, bool is_vnode) const; public: - static factory_key make_factory_key(const replication_strategy_ptr& rs, const token_metadata2_ptr& tmptr); + static factory_key make_factory_key(const replication_strategy_ptr& rs, const token_metadata_ptr& tmptr); const factory_key& get_factory_key() const noexcept { return *_factory_key; @@ -382,7 +382,7 @@ using mutable_vnode_effective_replication_map_ptr = shared_ptr( std::move(rs), std::move(tmptr), std::move(replication_map), @@ -390,7 +390,7 @@ inline mutable_vnode_erm_ptr make_effective_replication_map(replication_strategy } // Apply the replication strategy over the current configuration and the given token_metadata. -future calculate_effective_replication_map(replication_strategy_ptr rs, token_metadata2_ptr tmptr); +future calculate_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr); // Class to hold a coherent view of a keyspace // effective replication map on all shards @@ -478,7 +478,7 @@ public: // vnode_effective_replication_map for the local shard. // // Therefore create should be called first on shard 0, then on all other shards. - future create_effective_replication_map(replication_strategy_ptr rs, token_metadata2_ptr tmptr); + future create_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr); future<> stop() noexcept; @@ -497,7 +497,7 @@ private: friend class vnode_effective_replication_map; }; -void maybe_remove_node_being_replaced(const token_metadata2&, +void maybe_remove_node_being_replaced(const token_metadata&, const abstract_replication_strategy&, inet_address_vector_replica_set& natural_endpoints); diff --git a/locator/everywhere_replication_strategy.cc b/locator/everywhere_replication_strategy.cc index cb25cb5b47..45cb60c27f 100644 --- a/locator/everywhere_replication_strategy.cc +++ b/locator/everywhere_replication_strategy.cc @@ -20,7 +20,7 @@ everywhere_replication_strategy::everywhere_replication_strategy(const replicati _natural_endpoints_depend_on_token = false; } -future everywhere_replication_strategy::calculate_natural_endpoints(const token& search_token, const token_metadata2& tm) const { +future everywhere_replication_strategy::calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const { if (tm.sorted_tokens().empty()) { host_id_set result{host_id_vector_replica_set({host_id{}})}; return make_ready_future(std::move(result)); @@ -29,7 +29,7 @@ future everywhere_replication_strategy::calculate_natural_endpoints return make_ready_future(host_id_set(all_endpoints.begin(), all_endpoints.end())); } -size_t everywhere_replication_strategy::get_replication_factor(const token_metadata2& tm) const { +size_t everywhere_replication_strategy::get_replication_factor(const token_metadata& tm) const { return tm.sorted_tokens().empty() ? 1 : tm.count_normal_token_owners(); } diff --git a/locator/everywhere_replication_strategy.hh b/locator/everywhere_replication_strategy.hh index f6de1823bc..a67c584d2c 100644 --- a/locator/everywhere_replication_strategy.hh +++ b/locator/everywhere_replication_strategy.hh @@ -18,7 +18,7 @@ class everywhere_replication_strategy : public abstract_replication_strategy { public: everywhere_replication_strategy(const replication_strategy_config_options& config_options); - virtual future calculate_natural_endpoints(const token& search_token, const token_metadata2& tm) const override; + virtual future calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const override; virtual void validate_options(const gms::feature_service&) const override { /* noop */ } @@ -27,7 +27,7 @@ public: return std::nullopt; } - virtual size_t get_replication_factor(const token_metadata2& tm) const override; + virtual size_t get_replication_factor(const token_metadata& tm) const override; virtual bool allow_remove_node_being_replaced_from_natural_endpoints() const override { return true; diff --git a/locator/load_sketch.hh b/locator/load_sketch.hh index fb663ad5aa..df4ac4bbfe 100644 --- a/locator/load_sketch.hh +++ b/locator/load_sketch.hh @@ -56,7 +56,7 @@ class load_sketch { } }; std::unordered_map _nodes; - token_metadata2_ptr _tm; + token_metadata_ptr _tm; private: tablet_replica_set get_replicas_for_tablet_load(const tablet_info& ti, const tablet_transition_info* trinfo) const { // We reflect migrations in the load as if they already happened, @@ -65,7 +65,7 @@ private: } public: - load_sketch(token_metadata2_ptr tm) + load_sketch(token_metadata_ptr tm) : _tm(std::move(tm)) { } diff --git a/locator/local_strategy.cc b/locator/local_strategy.cc index a0539b2888..60409235af 100644 --- a/locator/local_strategy.cc +++ b/locator/local_strategy.cc @@ -18,7 +18,7 @@ local_strategy::local_strategy(const replication_strategy_config_options& config _natural_endpoints_depend_on_token = false; } -future local_strategy::calculate_natural_endpoints(const token& t, const token_metadata2& tm) const { +future local_strategy::calculate_natural_endpoints(const token& t, const token_metadata& tm) const { return make_ready_future(host_id_set{host_id{}}); } @@ -30,7 +30,7 @@ std::optional> local_strategy::recognized_options(co return {}; } -size_t local_strategy::get_replication_factor(const token_metadata2&) const { +size_t local_strategy::get_replication_factor(const token_metadata&) const { return 1; } diff --git a/locator/local_strategy.hh b/locator/local_strategy.hh index ffaa18d493..b4b1660e0e 100644 --- a/locator/local_strategy.hh +++ b/locator/local_strategy.hh @@ -25,9 +25,9 @@ class local_strategy : public abstract_replication_strategy { public: local_strategy(const replication_strategy_config_options& config_options); virtual ~local_strategy() {}; - virtual size_t get_replication_factor(const token_metadata2&) const override; + virtual size_t get_replication_factor(const token_metadata&) const override; - virtual future calculate_natural_endpoints(const token& search_token, const token_metadata2& tm) const override; + virtual future calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const override; virtual void validate_options(const gms::feature_service&) const override; diff --git a/locator/network_topology_strategy.cc b/locator/network_topology_strategy.cc index 01e167f048..fc9cd90572 100644 --- a/locator/network_topology_strategy.cc +++ b/locator/network_topology_strategy.cc @@ -160,7 +160,7 @@ class natural_endpoints_tracker { } }; - const token_metadata2& _tm; + const token_metadata& _tm; const topology& _tp; std::unordered_map _dc_rep_factor; @@ -189,7 +189,7 @@ class natural_endpoints_tracker { size_t _dcs_to_fill; public: - natural_endpoints_tracker(const token_metadata2& tm, const std::unordered_map& dc_rep_factor) + natural_endpoints_tracker(const token_metadata& tm, const std::unordered_map& dc_rep_factor) : _tm(tm) , _tp(_tm.get_topology()) , _dc_rep_factor(dc_rep_factor) @@ -239,7 +239,7 @@ public: future network_topology_strategy::calculate_natural_endpoints( - const token& search_token, const token_metadata2& tm) const { + const token& search_token, const token_metadata& tm) const { natural_endpoints_tracker tracker(tm, _dc_rep_factor); @@ -281,14 +281,14 @@ std::optional> network_topology_strategy::recognized return opts; } -effective_replication_map_ptr network_topology_strategy::make_replication_map(table_id table, token_metadata2_ptr tm) const { +effective_replication_map_ptr network_topology_strategy::make_replication_map(table_id table, token_metadata_ptr tm) const { if (!uses_tablets()) { on_internal_error(rslogger, format("make_replication_map() called for table {} but replication strategy not configured to use tablets", table)); } return do_make_replication_map(table, shared_from_this(), std::move(tm), _rep_factor); } -future network_topology_strategy::allocate_tablets_for_new_table(schema_ptr s, token_metadata2_ptr tm) const { +future network_topology_strategy::allocate_tablets_for_new_table(schema_ptr s, token_metadata_ptr tm) const { auto tablet_count = get_initial_tablets(); auto aligned_tablet_count = 1ul << log2ceil(tablet_count); if (tablet_count != aligned_tablet_count) { diff --git a/locator/network_topology_strategy.hh b/locator/network_topology_strategy.hh index 3ce065e98b..b5f1d118ff 100644 --- a/locator/network_topology_strategy.hh +++ b/locator/network_topology_strategy.hh @@ -25,7 +25,7 @@ public: network_topology_strategy( const replication_strategy_config_options& config_options); - virtual size_t get_replication_factor(const token_metadata2&) const override { + virtual size_t get_replication_factor(const token_metadata&) const override { return _rep_factor; } @@ -43,15 +43,15 @@ public: } public: // tablet_aware_replication_strategy - virtual effective_replication_map_ptr make_replication_map(table_id, token_metadata2_ptr) const override; - virtual future allocate_tablets_for_new_table(schema_ptr, token_metadata2_ptr) const override; + virtual effective_replication_map_ptr make_replication_map(table_id, token_metadata_ptr) const override; + virtual future allocate_tablets_for_new_table(schema_ptr, token_metadata_ptr) const override; protected: /** * calculate endpoints in one pass through the tokens by tracking our * progress in each DC, rack etc. */ virtual future calculate_natural_endpoints( - const token& search_token, const token_metadata2& tm) const override; + const token& search_token, const token_metadata& tm) const override; virtual void validate_options(const gms::feature_service&) const override; diff --git a/locator/simple_strategy.cc b/locator/simple_strategy.cc index 22b9f780a7..17730ed2ef 100644 --- a/locator/simple_strategy.cc +++ b/locator/simple_strategy.cc @@ -33,7 +33,7 @@ simple_strategy::simple_strategy(const replication_strategy_config_options& conf } } -future simple_strategy::calculate_natural_endpoints(const token& t, const token_metadata2& tm) const { +future simple_strategy::calculate_natural_endpoints(const token& t, const token_metadata& tm) const { const std::vector& tokens = tm.sorted_tokens(); if (tokens.empty()) { @@ -63,7 +63,7 @@ future simple_strategy::calculate_natural_endpoints(const token& t, co_return endpoints; } -size_t simple_strategy::get_replication_factor(const token_metadata2&) const { +size_t simple_strategy::get_replication_factor(const token_metadata&) const { return _replication_factor; } diff --git a/locator/simple_strategy.hh b/locator/simple_strategy.hh index cb75372048..a4cacccebf 100644 --- a/locator/simple_strategy.hh +++ b/locator/simple_strategy.hh @@ -19,14 +19,14 @@ class simple_strategy : public abstract_replication_strategy { public: simple_strategy(const replication_strategy_config_options& config_options); virtual ~simple_strategy() {}; - virtual size_t get_replication_factor(const token_metadata2& tm) const override; + virtual size_t get_replication_factor(const token_metadata& tm) const override; virtual void validate_options(const gms::feature_service&) const override; virtual std::optional> recognized_options(const topology&) const override; virtual bool allow_remove_node_being_replaced_from_natural_endpoints() const override { return true; } - virtual future calculate_natural_endpoints(const token& search_token, const token_metadata2& tm) const override; + virtual future calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const override; private: size_t _replication_factor = 1; }; diff --git a/locator/tablet_metadata_guard.hh b/locator/tablet_metadata_guard.hh index ca5187d26f..0731ea8faa 100644 --- a/locator/tablet_metadata_guard.hh +++ b/locator/tablet_metadata_guard.hh @@ -45,7 +45,7 @@ public: return _abort_source; } - locator::token_metadata2_ptr get_token_metadata() { + locator::token_metadata_ptr get_token_metadata() { return _erm->get_token_metadata_ptr(); } diff --git a/locator/tablet_replication_strategy.hh b/locator/tablet_replication_strategy.hh index 03257ed0c2..9403cf7c8c 100644 --- a/locator/tablet_replication_strategy.hh +++ b/locator/tablet_replication_strategy.hh @@ -38,13 +38,13 @@ protected: size_t get_initial_tablets() const { return _initial_tablets; } effective_replication_map_ptr do_make_replication_map(table_id, replication_strategy_ptr, - token_metadata2_ptr, + token_metadata_ptr, size_t replication_factor) const; public: /// Generates tablet_map for a new table. /// Runs under group0 guard. - virtual future allocate_tablets_for_new_table(schema_ptr, token_metadata2_ptr) const = 0; + virtual future allocate_tablets_for_new_table(schema_ptr, token_metadata_ptr) const = 0; }; } // namespace locator diff --git a/locator/tablet_sharder.hh b/locator/tablet_sharder.hh index 74a5c1fdd5..b133d272db 100644 --- a/locator/tablet_sharder.hh +++ b/locator/tablet_sharder.hh @@ -17,7 +17,7 @@ namespace locator { /// Implements sharder object which reflects assignment of tablets of a given table to local shards. /// Token ranges which don't have local tablets are reported to belong to shard 0. class tablet_sharder : public dht::sharder { - const token_metadata2& _tm; + const token_metadata& _tm; table_id _table; mutable const tablet_map* _tmap = nullptr; private: @@ -29,7 +29,7 @@ private: } } public: - tablet_sharder(const token_metadata2& tm, table_id table) + tablet_sharder(const token_metadata& tm, table_id table) : _tm(tm) , _table(table) { } diff --git a/locator/tablets.cc b/locator/tablets.cc index 2a145d75fe..ef69433402 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -348,7 +348,7 @@ private: public: tablet_effective_replication_map(table_id table, replication_strategy_ptr rs, - token_metadata2_ptr tmptr, + token_metadata_ptr tmptr, size_t replication_factor) : effective_replication_map(std::move(rs), std::move(tmptr), replication_factor) , _table(table) @@ -480,11 +480,11 @@ public: virtual std::unique_ptr make_splitter() const override { class splitter : public token_range_splitter { - token_metadata2_ptr _tmptr; // To keep the tablet map alive. + token_metadata_ptr _tmptr; // To keep the tablet map alive. const tablet_map& _tmap; std::optional _next; public: - splitter(token_metadata2_ptr tmptr, const tablet_map& tmap) + splitter(token_metadata_ptr tmptr, const tablet_map& tmap) : _tmptr(std::move(tmptr)) , _tmap(tmap) { } @@ -548,7 +548,7 @@ std::unordered_set tablet_aware_replication_strategy::recognized_tablet } effective_replication_map_ptr tablet_aware_replication_strategy::do_make_replication_map( - table_id table, replication_strategy_ptr rs, token_metadata2_ptr tm, size_t replication_factor) const { + table_id table, replication_strategy_ptr rs, token_metadata_ptr tm, size_t replication_factor) const { return seastar::make_shared(table, std::move(rs), std::move(tm), replication_factor); } diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 320ca7ae4b..0b2517e83f 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -27,12 +27,6 @@ namespace locator { static logging::logger tlogger("token_metadata"); -template -inline static constexpr const topology::key_kind kind_for_node_id_type - = std::is_same_v - ? topology::key_kind::inet_address - : topology::key_kind::host_id; - template static void remove_by_value(C& container, V value) { for (auto it = container.begin(); it != container.end();) { @@ -44,7 +38,6 @@ static void remove_by_value(C& container, V value) { } } -template class token_metadata_impl final { private: /** @@ -53,17 +46,17 @@ private: * multiple tokens. Hence, the BiMultiValMap collection. */ // FIXME: have to be BiMultiValMap - std::unordered_map _token_to_endpoint_map; + std::unordered_map _token_to_endpoint_map; // Track the unique set of nodes in _token_to_endpoint_map - std::unordered_set _normal_token_owners; + std::unordered_set _normal_token_owners; - std::unordered_map _bootstrap_tokens; - std::unordered_set _leaving_endpoints; + std::unordered_map _bootstrap_tokens; + std::unordered_set _leaving_endpoints; // The map between the existing node to be replaced and the replacing node - std::unordered_map _replacing_endpoints; + std::unordered_map _replacing_endpoints; - std::optional> _topology_change_info; + std::optional _topology_change_info; std::vector _sorted_tokens; @@ -99,26 +92,26 @@ private: struct shallow_copy {}; public: token_metadata_impl(shallow_copy, const token_metadata_impl& o) noexcept - : _topology(topology::config{}, kind_for_node_id_type) + : _topology(topology::config{}, topology::key_kind::host_id) {} - token_metadata_impl(token_metadata::config cfg) noexcept : _topology(std::move(cfg.topo_cfg), kind_for_node_id_type) {}; + token_metadata_impl(token_metadata::config cfg) noexcept : _topology(std::move(cfg.topo_cfg), topology::key_kind::host_id) {}; token_metadata_impl(const token_metadata_impl&) = delete; // it's too huge for direct copy, use clone_async() token_metadata_impl(token_metadata_impl&&) noexcept = default; const std::vector& sorted_tokens() const; - future<> update_normal_tokens(std::unordered_set tokens, NodeId endpoint); + future<> update_normal_tokens(std::unordered_set tokens, host_id endpoint); const token& first_token(const token& start) const; size_t first_token_index(const token& start) const; - std::optional get_endpoint(const token& token) const; - std::vector get_tokens(const NodeId& addr) const; - const std::unordered_map& get_token_to_endpoint() const { + std::optional get_endpoint(const token& token) const; + std::vector get_tokens(const host_id& addr) const; + const std::unordered_map& get_token_to_endpoint() const { return _token_to_endpoint_map; } - const std::unordered_set& get_leaving_endpoints() const { + const std::unordered_set& get_leaving_endpoints() const { return _leaving_endpoints; } - const std::unordered_map& get_bootstrap_tokens() const { + const std::unordered_map& get_bootstrap_tokens() const { return _bootstrap_tokens; } @@ -138,9 +131,9 @@ public: * * @return The requested range (see the description above) */ - boost::iterator_range::tokens_iterator> ring_range(const token& start) const; + boost::iterator_range ring_range(const token& start) const; - boost::iterator_range::tokens_iterator> ring_range(dht::ring_position_view pos) const; + boost::iterator_range ring_range(dht::ring_position_view pos) const; topology& get_topology() { return _topology; @@ -176,30 +169,30 @@ public: /** @return a copy of the endpoint-to-id map for read-only operations */ std::unordered_map get_endpoint_to_host_id_map_for_reading() const; - void add_bootstrap_token(token t, NodeId endpoint); + void add_bootstrap_token(token t, host_id endpoint); - void add_bootstrap_tokens(std::unordered_set tokens, NodeId endpoint); + void add_bootstrap_tokens(std::unordered_set tokens, host_id endpoint); void remove_bootstrap_tokens(std::unordered_set tokens); - void add_leaving_endpoint(NodeId endpoint); - void del_leaving_endpoint(NodeId endpoint); + void add_leaving_endpoint(host_id endpoint); + void del_leaving_endpoint(host_id endpoint); public: - void remove_endpoint(NodeId endpoint); + void remove_endpoint(host_id endpoint); - bool is_normal_token_owner(NodeId endpoint) const; + bool is_normal_token_owner(host_id endpoint) const; - bool is_leaving(NodeId endpoint) const; + bool is_leaving(host_id endpoint) const; // Is this node being replaced by another node - bool is_being_replaced(NodeId endpoint) const; + bool is_being_replaced(host_id endpoint) const; // Is any node being replaced by another node bool is_any_node_being_replaced() const; - void add_replacing_endpoint(NodeId existing_node, NodeId replacing_node); + void add_replacing_endpoint(host_id existing_node, host_id replacing_node); - void del_replacing_endpoint(NodeId existing_node); + void del_replacing_endpoint(host_id existing_node); public: /** @@ -248,8 +241,8 @@ public: static range interval_to_range(boost::icl::interval::interval_type i); public: - future<> update_topology_change_info(dc_rack_fn& get_dc_rack); - const std::optional>& get_topology_change_info() const { + future<> update_topology_change_info(dc_rack_fn& get_dc_rack); + const std::optional& get_topology_change_info() const { return _topology_change_info; } public: @@ -260,7 +253,7 @@ public: // node that is still joining the cluster, e.g., a node that is still // streaming data before it finishes the bootstrap process and turns into // NORMAL status. - const std::unordered_set& get_all_endpoints() const noexcept { + const std::unordered_set& get_all_endpoints() const noexcept { return _normal_token_owners; } @@ -290,11 +283,11 @@ public: void set_version(token_metadata::version_t version) { if (version <= 0) { on_internal_error(tlogger, - format("token_metadata_impl::set_version: invalid new version {}", version)); + format("token_metadata_impl::set_version: invalid new version {}", version)); } if (version < _version) { on_internal_error(tlogger, - format("token_metadata_impl::set_version: new version can't be smaller than the previous one, " + format("token_metadata_impl::set_version: new version can't be smaller than the previous one, " "new version {}, previous version {}", version, _version)); } _version = version; @@ -303,31 +296,26 @@ public: _version_tracker = std::move(tracker); } - friend class generic_token_metadata; + friend class token_metadata; }; -template -thread_local long token_metadata_impl::_static_ring_version; +thread_local long token_metadata_impl::_static_ring_version; -template -generic_token_metadata::tokens_iterator::tokens_iterator(const token& start, const token_metadata_impl* token_metadata) +token_metadata::tokens_iterator::tokens_iterator(const token& start, const token_metadata_impl* token_metadata) : _token_metadata(token_metadata) { _cur_it = _token_metadata->sorted_tokens().begin() + _token_metadata->first_token_index(start); _remaining = _token_metadata->sorted_tokens().size(); } -template -bool generic_token_metadata::tokens_iterator::operator==(const tokens_iterator& it) const { +bool token_metadata::tokens_iterator::operator==(const tokens_iterator& it) const { return _remaining == it._remaining; } -template -const token& generic_token_metadata::tokens_iterator::operator*() const { +const token& token_metadata::tokens_iterator::operator*() const { return *_cur_it; } -template -typename generic_token_metadata::tokens_iterator& generic_token_metadata::tokens_iterator::operator++() { +token_metadata::tokens_iterator& token_metadata::tokens_iterator::operator++() { ++_cur_it; if (_cur_it == _token_metadata->sorted_tokens().end()) { _cur_it = _token_metadata->sorted_tokens().begin(); @@ -336,22 +324,19 @@ typename generic_token_metadata::tokens_iterator& generic_token_metadata return *this; } -template -host_id generic_token_metadata::get_my_id() const { +host_id token_metadata::get_my_id() const { return get_topology().get_config().this_host_id; } -template inline -boost::iterator_range::tokens_iterator> -token_metadata_impl::ring_range(const token& start) const { - auto begin = typename generic_token_metadata::tokens_iterator(start, this); - auto end = typename generic_token_metadata::tokens_iterator(); +boost::iterator_range +token_metadata_impl::ring_range(const token& start) const { + auto begin = token_metadata::tokens_iterator(start, this); + auto end = token_metadata::tokens_iterator(); return boost::make_iterator_range(begin, end); } -template -future>> token_metadata_impl::clone_async() const noexcept { +future> token_metadata_impl::clone_async() const noexcept { auto ret = co_await clone_only_token_map(); ret->_bootstrap_tokens.reserve(_bootstrap_tokens.size()); for (const auto& p : _bootstrap_tokens) { @@ -365,8 +350,7 @@ future>> token_metadata_impl co_return ret; } -template -future>> token_metadata_impl::clone_only_token_map(bool clone_sorted_tokens) const noexcept { +future> token_metadata_impl::clone_only_token_map(bool clone_sorted_tokens) const noexcept { auto ret = std::make_unique(shallow_copy{}, *this); ret->_token_to_endpoint_map.reserve(_token_to_endpoint_map.size()); for (const auto& p : _token_to_endpoint_map) { @@ -384,8 +368,7 @@ future>> token_metadata_impl co_return ret; } -template -future<> token_metadata_impl::clear_gently() noexcept { +future<> token_metadata_impl::clear_gently() noexcept { co_await utils::clear_gently(_token_to_endpoint_map); co_await utils::clear_gently(_normal_token_owners); co_await utils::clear_gently(_bootstrap_tokens); @@ -397,8 +380,7 @@ future<> token_metadata_impl::clear_gently() noexcept { co_return; } -template -void token_metadata_impl::sort_tokens() { +void token_metadata_impl::sort_tokens() { std::vector sorted; sorted.reserve(_token_to_endpoint_map.size()); @@ -411,28 +393,23 @@ void token_metadata_impl::sort_tokens() { _sorted_tokens = std::move(sorted); } -template -const tablet_metadata& generic_token_metadata::tablets() const { +const tablet_metadata& token_metadata::tablets() const { return _impl->tablets(); } -template -tablet_metadata& generic_token_metadata::tablets() { +tablet_metadata& token_metadata::tablets() { return _impl->tablets(); } -template -void generic_token_metadata::set_tablets(tablet_metadata tm) { +void token_metadata::set_tablets(tablet_metadata tm) { _impl->set_tablets(std::move(tm)); } -template -const std::vector& token_metadata_impl::sorted_tokens() const { +const std::vector& token_metadata_impl::sorted_tokens() const { return _sorted_tokens; } -template -std::vector token_metadata_impl::get_tokens(const NodeId& addr) const { +std::vector token_metadata_impl::get_tokens(const host_id& addr) const { std::vector res; for (auto&& i : _token_to_endpoint_map) { if (i.second == addr) { @@ -443,8 +420,7 @@ std::vector token_metadata_impl::get_tokens(const NodeId& addr) c return res; } -template -future<> token_metadata_impl::update_normal_tokens(std::unordered_set tokens, NodeId endpoint) { +future<> token_metadata_impl::update_normal_tokens(std::unordered_set tokens, host_id endpoint) { if (tokens.empty()) { co_return; } @@ -483,7 +459,7 @@ future<> token_metadata_impl::update_normal_tokens(std::unordered_set(t, endpoint)); + auto prev = _token_to_endpoint_map.insert(std::pair(t, endpoint)); should_sort_tokens |= prev.second; // new token inserted -> sort if (prev.first->second != endpoint) { tlogger.debug("Token {} changing ownership from {} to {}", t, prev.first->second, endpoint); @@ -501,8 +477,7 @@ future<> token_metadata_impl::update_normal_tokens(std::unordered_set -size_t token_metadata_impl::first_token_index(const token& start) const { +size_t token_metadata_impl::first_token_index(const token& start) const { if (_sorted_tokens.empty()) { auto msg = format("sorted_tokens is empty in first_token_index!"); tlogger.error("{}", msg); @@ -516,13 +491,11 @@ size_t token_metadata_impl::first_token_index(const token& start) const } } -template -const token& token_metadata_impl::first_token(const token& start) const { +const token& token_metadata_impl::first_token(const token& start) const { return _sorted_tokens[first_token_index(start)]; } -template -std::optional token_metadata_impl::get_endpoint(const token& token) const { +std::optional token_metadata_impl::get_endpoint(const token& token) const { auto it = _token_to_endpoint_map.find(token); if (it == _token_to_endpoint_map.end()) { return std::nullopt; @@ -531,8 +504,7 @@ std::optional token_metadata_impl::get_endpoint(const token& tok } } -template -void token_metadata_impl::debug_show() const { +void token_metadata_impl::debug_show() const { auto reporter = std::make_shared>(); reporter->set_callback ([reporter, this] { fmt::print("Endpoint -> Token\n"); @@ -547,13 +519,11 @@ void token_metadata_impl::debug_show() const { reporter->arm_periodic(std::chrono::seconds(1)); } -template -void token_metadata_impl::update_host_id(const host_id& host_id, inet_address endpoint) { +void token_metadata_impl::update_host_id(const host_id& host_id, inet_address endpoint) { _topology.add_or_update_endpoint(endpoint, host_id); } -template -host_id token_metadata_impl::get_host_id(inet_address endpoint) const { +host_id token_metadata_impl::get_host_id(inet_address endpoint) const { if (const auto* node = _topology.find_node(endpoint)) [[likely]] { return node->host_id(); } else { @@ -561,8 +531,7 @@ host_id token_metadata_impl::get_host_id(inet_address endpoint) const { } } -template -std::optional token_metadata_impl::get_host_id_if_known(inet_address endpoint) const { +std::optional token_metadata_impl::get_host_id_if_known(inet_address endpoint) const { if (const auto* node = _topology.find_node(endpoint)) [[likely]] { return node->host_id(); } else { @@ -570,8 +539,7 @@ std::optional token_metadata_impl::get_host_id_if_known(inet_ad } } -template -std::optional token_metadata_impl::get_endpoint_for_host_id_if_known(host_id host_id) const { +std::optional token_metadata_impl::get_endpoint_for_host_id_if_known(host_id host_id) const { if (const auto* node = _topology.find_node(host_id)) [[likely]] { return node->endpoint(); } else { @@ -579,8 +547,7 @@ std::optional token_metadata_impl::get_endpoint_for_host_i } } -template -inet_address token_metadata_impl::get_endpoint_for_host_id(host_id host_id) const { +inet_address token_metadata_impl::get_endpoint_for_host_id(host_id host_id) const { if (const auto* node = _topology.find_node(host_id)) [[likely]] { return node->endpoint(); } else { @@ -588,8 +555,7 @@ inet_address token_metadata_impl::get_endpoint_for_host_id(host_id host_ } } -template -std::unordered_map token_metadata_impl::get_endpoint_to_host_id_map_for_reading() const { +std::unordered_map token_metadata_impl::get_endpoint_to_host_id_map_for_reading() const { const auto& nodes = _topology.get_nodes_by_endpoint(); std::unordered_map map; map.reserve(nodes.size()); @@ -607,25 +573,21 @@ std::unordered_map token_metadata_impl::get_endpo return map; } -template -bool token_metadata_impl::is_normal_token_owner(NodeId endpoint) const { +bool token_metadata_impl::is_normal_token_owner(host_id endpoint) const { return _normal_token_owners.contains(endpoint); } -template -void token_metadata_impl::add_bootstrap_token(token t, NodeId endpoint) { +void token_metadata_impl::add_bootstrap_token(token t, host_id endpoint) { std::unordered_set tokens{t}; add_bootstrap_tokens(tokens, endpoint); } -template -boost::iterator_range::tokens_iterator> -token_metadata_impl::ring_range(const dht::ring_position_view start) const { +boost::iterator_range +token_metadata_impl::ring_range(const dht::ring_position_view start) const { return ring_range(start.token()); } -template -void token_metadata_impl::add_bootstrap_tokens(std::unordered_set tokens, NodeId endpoint) { +void token_metadata_impl::add_bootstrap_tokens(std::unordered_set tokens, host_id endpoint) { for (auto t : tokens) { auto old_endpoint = _bootstrap_tokens.find(t); if (old_endpoint != _bootstrap_tokens.end() && (*old_endpoint).second != endpoint) { @@ -640,15 +602,14 @@ void token_metadata_impl::add_bootstrap_tokens(std::unordered_set } } - std::erase_if(_bootstrap_tokens, [endpoint] (const std::pair& n) { return n.second == endpoint; }); + std::erase_if(_bootstrap_tokens, [endpoint] (const std::pair& n) { return n.second == endpoint; }); for (auto t : tokens) { _bootstrap_tokens[t] = endpoint; } } -template -void token_metadata_impl::remove_bootstrap_tokens(std::unordered_set tokens) { +void token_metadata_impl::remove_bootstrap_tokens(std::unordered_set tokens) { if (tokens.empty()) { tlogger.warn("tokens is empty in remove_bootstrap_tokens!"); return; @@ -658,23 +619,19 @@ void token_metadata_impl::remove_bootstrap_tokens(std::unordered_set -bool token_metadata_impl::is_leaving(NodeId endpoint) const { +bool token_metadata_impl::is_leaving(host_id endpoint) const { return _leaving_endpoints.contains(endpoint); } -template -bool token_metadata_impl::is_being_replaced(NodeId endpoint) const { +bool token_metadata_impl::is_being_replaced(host_id endpoint) const { return _replacing_endpoints.contains(endpoint); } -template -bool token_metadata_impl::is_any_node_being_replaced() const { +bool token_metadata_impl::is_any_node_being_replaced() const { return !_replacing_endpoints.empty(); } -template -void token_metadata_impl::remove_endpoint(NodeId endpoint) { +void token_metadata_impl::remove_endpoint(host_id endpoint) { remove_by_value(_bootstrap_tokens, endpoint); remove_by_value(_token_to_endpoint_map, endpoint); _normal_token_owners.erase(endpoint); @@ -684,8 +641,7 @@ void token_metadata_impl::remove_endpoint(NodeId endpoint) { invalidate_cached_rings(); } -template -token token_metadata_impl::get_predecessor(token t) const { +token token_metadata_impl::get_predecessor(token t) const { auto& tokens = sorted_tokens(); auto it = std::lower_bound(tokens.begin(), tokens.end(), t); if (it == tokens.end() || *it != t) { @@ -701,8 +657,7 @@ token token_metadata_impl::get_predecessor(token t) const { } } -template -dht::token_range_vector token_metadata_impl::get_primary_ranges_for(std::unordered_set tokens) const { +dht::token_range_vector token_metadata_impl::get_primary_ranges_for(std::unordered_set tokens) const { dht::token_range_vector ranges; ranges.reserve(tokens.size() + 1); // one of the ranges will wrap for (auto right : tokens) { @@ -715,14 +670,12 @@ dht::token_range_vector token_metadata_impl::get_primary_ranges_for(std: return ranges; } -template -dht::token_range_vector token_metadata_impl::get_primary_ranges_for(token right) const { +dht::token_range_vector token_metadata_impl::get_primary_ranges_for(token right) const { return get_primary_ranges_for(std::unordered_set{right}); } -template boost::icl::interval::interval_type -token_metadata_impl::range_to_interval(range r) { +token_metadata_impl::range_to_interval(range r) { bool start_inclusive = false; bool end_inclusive = false; token start = dht::minimum_token(); @@ -749,9 +702,8 @@ token_metadata_impl::range_to_interval(range r) { } } -template range -token_metadata_impl::interval_to_range(boost::icl::interval::interval_type i) { +token_metadata_impl::interval_to_range(boost::icl::interval::interval_type i) { bool start_inclusive; bool end_inclusive; auto bounds = i.bounds().bits(); @@ -773,8 +725,7 @@ token_metadata_impl::interval_to_range(boost::icl::interval::inte return range({{i.lower(), start_inclusive}}, {{i.upper(), end_inclusive}}); } -template -future<> token_metadata_impl::update_topology_change_info(dc_rack_fn& get_dc_rack) { +future<> token_metadata_impl::update_topology_change_info(dc_rack_fn& get_dc_rack) { if (_bootstrap_tokens.empty() && _leaving_endpoints.empty() && _replacing_endpoints.empty()) { co_await utils::clear_gently(_topology_change_info); _topology_change_info.reset(); @@ -787,7 +738,7 @@ future<> token_metadata_impl::update_topology_change_info(dc_rack_fn> new_normal_tokens; + std::unordered_map> new_normal_tokens; if (!_replacing_endpoints.empty()) { for (const auto& [token, inet_address]: _token_to_endpoint_map) { const auto it = _replacing_endpoints.find(inet_address); @@ -847,21 +798,19 @@ future<> token_metadata_impl::update_topology_change_info(dc_rack_fn>(std::move(target_token_metadata)), - base_token_metadata ? make_lw_shared>(std::move(base_token_metadata)): nullptr, + _topology_change_info.emplace(make_lw_shared(std::move(target_token_metadata)), + base_token_metadata ? make_lw_shared(std::move(base_token_metadata)): nullptr, std::move(all_tokens), _read_new); co_await utils::clear_gently(prev_value); } -template -size_t token_metadata_impl::count_normal_token_owners() const { +size_t token_metadata_impl::count_normal_token_owners() const { return _normal_token_owners.size(); } -template -future<> token_metadata_impl::update_normal_token_owners() { - std::unordered_set eps; +future<> token_metadata_impl::update_normal_token_owners() { + std::unordered_set eps; for (auto [t, ep]: _token_to_endpoint_map) { eps.insert(ep); co_await coroutine::maybe_yield(); @@ -869,25 +818,21 @@ future<> token_metadata_impl::update_normal_token_owners() { _normal_token_owners = std::move(eps); } -template -void token_metadata_impl::add_leaving_endpoint(NodeId endpoint) { +void token_metadata_impl::add_leaving_endpoint(host_id endpoint) { _leaving_endpoints.emplace(endpoint); } -template -void token_metadata_impl::del_leaving_endpoint(NodeId endpoint) { +void token_metadata_impl::del_leaving_endpoint(host_id endpoint) { _leaving_endpoints.erase(endpoint); } -template -void token_metadata_impl::add_replacing_endpoint(NodeId existing_node, NodeId replacing_node) { +void token_metadata_impl::add_replacing_endpoint(host_id existing_node, host_id replacing_node) { tlogger.info("Added node {} as pending replacing endpoint which replaces existing node {}", replacing_node, existing_node); _replacing_endpoints[existing_node] = replacing_node; } -template -void token_metadata_impl::del_replacing_endpoint(NodeId existing_node) { +void token_metadata_impl::del_replacing_endpoint(host_id existing_node) { if (_replacing_endpoints.contains(existing_node)) { tlogger.info("Removed node {} as pending replacing endpoint which replaces existing node {}", _replacing_endpoints[existing_node], existing_node); @@ -895,9 +840,8 @@ void token_metadata_impl::del_replacing_endpoint(NodeId existing_node) { _replacing_endpoints.erase(existing_node); } -template -topology_change_info::topology_change_info(lw_shared_ptr> target_token_metadata_, - lw_shared_ptr> base_token_metadata_, +topology_change_info::topology_change_info(lw_shared_ptr target_token_metadata_, + lw_shared_ptr base_token_metadata_, std::vector all_tokens_, token_metadata::read_new_t read_new_) : target_token_metadata(std::move(target_token_metadata_)) @@ -907,136 +851,96 @@ topology_change_info::topology_change_info(lw_shared_ptr -future<> topology_change_info::clear_gently() { +future<> topology_change_info::clear_gently() { co_await utils::clear_gently(target_token_metadata); co_await utils::clear_gently(base_token_metadata); co_await utils::clear_gently(all_tokens); } -template -generic_token_metadata::generic_token_metadata(std::unique_ptr> impl) +token_metadata::token_metadata(std::unique_ptr impl) : _impl(std::move(impl)) { } -template -template -requires std::is_same_v -generic_token_metadata::generic_token_metadata(std::unique_ptr> impl, - token_metadata2 new_value) - : _impl(std::move(impl)) - , _new_value(make_token_metadata2_ptr(std::move(new_value))) +token_metadata::token_metadata(config cfg) + : _impl(std::make_unique(cfg)) { } -template -template -requires std::is_same_v -generic_token_metadata::generic_token_metadata(token_metadata2_ptr new_value) - : _impl(nullptr) - , _new_value(std::move(new_value)) -{ -} +token_metadata::~token_metadata() = default; -template -generic_token_metadata::generic_token_metadata(config cfg) - : _impl(std::make_unique>(cfg)) -{ - if constexpr (std::is_same_v) { - _new_value = make_token_metadata2_ptr(std::move(cfg)); - } -} +token_metadata::token_metadata(token_metadata&&) noexcept = default; -template -generic_token_metadata::~generic_token_metadata() = default; +token_metadata& token_metadata::token_metadata::operator=(token_metadata&&) noexcept = default; -template -generic_token_metadata::generic_token_metadata(generic_token_metadata&&) noexcept = default; - -template -generic_token_metadata& generic_token_metadata::generic_token_metadata::operator=(generic_token_metadata&&) noexcept = default; - -template const std::vector& -generic_token_metadata::sorted_tokens() const { +token_metadata::sorted_tokens() const { return _impl->sorted_tokens(); } -template future<> -generic_token_metadata::update_normal_tokens(std::unordered_set tokens, NodeId endpoint) { +token_metadata::update_normal_tokens(std::unordered_set tokens, host_id endpoint) { return _impl->update_normal_tokens(std::move(tokens), endpoint); } -template const token& -generic_token_metadata::first_token(const token& start) const { +token_metadata::first_token(const token& start) const { return _impl->first_token(start); } -template size_t -generic_token_metadata::first_token_index(const token& start) const { +token_metadata::first_token_index(const token& start) const { return _impl->first_token_index(start); } -template -std::optional -generic_token_metadata::get_endpoint(const token& token) const { +std::optional +token_metadata::get_endpoint(const token& token) const { return _impl->get_endpoint(token); } -template std::vector -generic_token_metadata::get_tokens(const NodeId& addr) const { +token_metadata::get_tokens(const host_id& addr) const { return _impl->get_tokens(addr); } -template -const std::unordered_map& -generic_token_metadata::get_token_to_endpoint() const { +const std::unordered_map& +token_metadata::get_token_to_endpoint() const { return _impl->get_token_to_endpoint(); } -template -const std::unordered_set& -generic_token_metadata::get_leaving_endpoints() const { +const std::unordered_set& +token_metadata::get_leaving_endpoints() const { return _impl->get_leaving_endpoints(); } -template -const std::unordered_map& -generic_token_metadata::get_bootstrap_tokens() const { +const std::unordered_map& +token_metadata::get_bootstrap_tokens() const { return _impl->get_bootstrap_tokens(); } -template void -generic_token_metadata::update_topology(NodeId ep, std::optional opt_dr, std::optional opt_st, std::optional shard_count) { +token_metadata::update_topology(host_id ep, std::optional opt_dr, std::optional opt_st, std::optional shard_count) { _impl->update_topology(ep, std::move(opt_dr), std::move(opt_st), std::move(shard_count)); } -template -boost::iterator_range::tokens_iterator> -generic_token_metadata::ring_range(const token& start) const { +boost::iterator_range +token_metadata::ring_range(const token& start) const { return _impl->ring_range(start); } -template -boost::iterator_range::tokens_iterator> -generic_token_metadata::ring_range(dht::ring_position_view start) const { +boost::iterator_range +token_metadata::ring_range(dht::ring_position_view start) const { return _impl->ring_range(start); } class token_metadata_ring_splitter : public locator::token_range_splitter { - token_metadata2_ptr _tmptr; - boost::iterator_range _range; + token_metadata_ptr _tmptr; + boost::iterator_range _range; public: - token_metadata_ring_splitter(token_metadata2_ptr tmptr) + token_metadata_ring_splitter(token_metadata_ptr tmptr) : _tmptr(std::move(tmptr)) , _range(_tmptr->sorted_tokens().empty() // ring_range() throws if the ring is empty - ? boost::make_iterator_range(token_metadata2::tokens_iterator(), token_metadata2::tokens_iterator()) + ? boost::make_iterator_range(token_metadata::tokens_iterator(), token_metadata::tokens_iterator()) : _tmptr->ring_range(dht::minimum_token())) { } @@ -1054,239 +958,179 @@ public: } }; -std::unique_ptr make_splitter(token_metadata2_ptr tmptr) { +std::unique_ptr make_splitter(token_metadata_ptr tmptr) { return std::make_unique(std::move(tmptr)); } -template topology& -generic_token_metadata::get_topology() { +token_metadata::get_topology() { return _impl->get_topology(); } -template const topology& -generic_token_metadata::get_topology() const { +token_metadata::get_topology() const { return _impl->get_topology(); } -template void -generic_token_metadata::debug_show() const { +token_metadata::debug_show() const { _impl->debug_show(); } -template void -generic_token_metadata::update_host_id(const host_id& host_id, inet_address endpoint) { +token_metadata::update_host_id(const host_id& host_id, inet_address endpoint) { _impl->update_host_id(host_id, endpoint); } -template host_id -generic_token_metadata::get_host_id(inet_address endpoint) const { +token_metadata::get_host_id(inet_address endpoint) const { return _impl->get_host_id(endpoint); } -template std::optional -generic_token_metadata::get_host_id_if_known(inet_address endpoint) const { +token_metadata::get_host_id_if_known(inet_address endpoint) const { return _impl->get_host_id_if_known(endpoint); } -template -std::optional::inet_address> -generic_token_metadata::get_endpoint_for_host_id_if_known(host_id host_id) const { +std::optional +token_metadata::get_endpoint_for_host_id_if_known(host_id host_id) const { return _impl->get_endpoint_for_host_id_if_known(host_id); } -template -typename generic_token_metadata::inet_address -generic_token_metadata::get_endpoint_for_host_id(host_id host_id) const { +token_metadata::inet_address +token_metadata::get_endpoint_for_host_id(host_id host_id) const { return _impl->get_endpoint_for_host_id(host_id); } -template -host_id_or_endpoint generic_token_metadata::parse_host_id_and_endpoint(const sstring& host_id_string) const { +host_id_or_endpoint token_metadata::parse_host_id_and_endpoint(const sstring& host_id_string) const { auto res = host_id_or_endpoint(host_id_string); res.resolve(*this); return res; } -template std::unordered_map -generic_token_metadata::get_endpoint_to_host_id_map_for_reading() const { +token_metadata::get_endpoint_to_host_id_map_for_reading() const { return _impl->get_endpoint_to_host_id_map_for_reading(); } -template void -generic_token_metadata::add_bootstrap_token(token t, NodeId endpoint) { +token_metadata::add_bootstrap_token(token t, host_id endpoint) { _impl->add_bootstrap_token(t, endpoint); } -template void -generic_token_metadata::add_bootstrap_tokens(std::unordered_set tokens, NodeId endpoint) { +token_metadata::add_bootstrap_tokens(std::unordered_set tokens, host_id endpoint) { _impl->add_bootstrap_tokens(std::move(tokens), endpoint); } -template void -generic_token_metadata::remove_bootstrap_tokens(std::unordered_set tokens) { +token_metadata::remove_bootstrap_tokens(std::unordered_set tokens) { _impl->remove_bootstrap_tokens(std::move(tokens)); } -template void -generic_token_metadata::add_leaving_endpoint(NodeId endpoint) { +token_metadata::add_leaving_endpoint(host_id endpoint) { _impl->add_leaving_endpoint(endpoint); } -template void -generic_token_metadata::del_leaving_endpoint(NodeId endpoint) { +token_metadata::del_leaving_endpoint(host_id endpoint) { _impl->del_leaving_endpoint(endpoint); } -template void -generic_token_metadata::remove_endpoint(NodeId endpoint) { +token_metadata::remove_endpoint(host_id endpoint) { _impl->remove_endpoint(endpoint); _impl->sort_tokens(); } -template bool -generic_token_metadata::is_normal_token_owner(NodeId endpoint) const { +token_metadata::is_normal_token_owner(host_id endpoint) const { return _impl->is_normal_token_owner(endpoint); } -template bool -generic_token_metadata::is_leaving(NodeId endpoint) const { +token_metadata::is_leaving(host_id endpoint) const { return _impl->is_leaving(endpoint); } -template bool -generic_token_metadata::is_being_replaced(NodeId endpoint) const { +token_metadata::is_being_replaced(host_id endpoint) const { return _impl->is_being_replaced(endpoint); } -template bool -generic_token_metadata::is_any_node_being_replaced() const { +token_metadata::is_any_node_being_replaced() const { return _impl->is_any_node_being_replaced(); } -template -void generic_token_metadata::add_replacing_endpoint(NodeId existing_node, NodeId replacing_node) { +void token_metadata::add_replacing_endpoint(host_id existing_node, host_id replacing_node) { _impl->add_replacing_endpoint(existing_node, replacing_node); } -template -void generic_token_metadata::del_replacing_endpoint(NodeId existing_node) { +void token_metadata::del_replacing_endpoint(host_id existing_node) { _impl->del_replacing_endpoint(existing_node); } -template -future> generic_token_metadata::clone_async() const noexcept { - if constexpr (std::is_same_v) { - co_return !holds_alternative(_new_value) - ? generic_token_metadata(co_await _impl->clone_async(), co_await get_new()->clone_async()) - : generic_token_metadata(co_await _impl->clone_async()); - } else { - co_return generic_token_metadata(co_await _impl->clone_async()); - } +future token_metadata::clone_async() const noexcept { + co_return token_metadata(co_await _impl->clone_async()); } -template -future> -generic_token_metadata::clone_only_token_map() const noexcept { - if constexpr (std::is_same_v) { - co_return !holds_alternative(_new_value) - ? generic_token_metadata(co_await _impl->clone_only_token_map(), co_await get_new()->clone_only_token_map()) - : generic_token_metadata(co_await _impl->clone_only_token_map()); - } else { - co_return generic_token_metadata(co_await _impl->clone_only_token_map()); - } +future +token_metadata::clone_only_token_map() const noexcept { + co_return token_metadata(co_await _impl->clone_only_token_map()); } -template -future> -generic_token_metadata::clone_after_all_left() const noexcept { - if constexpr (std::is_same_v) { - co_return !holds_alternative(_new_value) - ? generic_token_metadata(co_await _impl->clone_after_all_left(), co_await get_new()->clone_after_all_left()) - : generic_token_metadata(co_await _impl->clone_after_all_left()); - } else { - co_return generic_token_metadata(co_await _impl->clone_after_all_left()); - } +future +token_metadata::clone_after_all_left() const noexcept { + co_return token_metadata(co_await _impl->clone_after_all_left()); } -template -future<> generic_token_metadata::clear_gently() noexcept { - co_await _impl->clear_gently(); - if constexpr (std::is_same_v) { - if (holds_alternative>(_new_value)) { - co_await get_new()->clear_gently(); - } - } +future<> token_metadata::clear_gently() noexcept { + return _impl->clear_gently(); } -template dht::token_range_vector -generic_token_metadata::get_primary_ranges_for(std::unordered_set tokens) const { +token_metadata::get_primary_ranges_for(std::unordered_set tokens) const { return _impl->get_primary_ranges_for(std::move(tokens)); } -template dht::token_range_vector -generic_token_metadata::get_primary_ranges_for(token right) const { +token_metadata::get_primary_ranges_for(token right) const { return _impl->get_primary_ranges_for(right); } -template boost::icl::interval::interval_type -generic_token_metadata::range_to_interval(range r) { - return token_metadata_impl::range_to_interval(std::move(r)); +token_metadata::range_to_interval(range r) { + return token_metadata_impl::range_to_interval(std::move(r)); } -template range -generic_token_metadata::interval_to_range(boost::icl::interval::interval_type i) { - return token_metadata_impl::interval_to_range(std::move(i)); +token_metadata::interval_to_range(boost::icl::interval::interval_type i) { + return token_metadata_impl::interval_to_range(std::move(i)); } -template future<> -generic_token_metadata::update_topology_change_info(dc_rack_fn& get_dc_rack) { +token_metadata::update_topology_change_info(dc_rack_fn& get_dc_rack) { return _impl->update_topology_change_info(get_dc_rack); } -template -const std::optional>& -generic_token_metadata::get_topology_change_info() const { +const std::optional& +token_metadata::get_topology_change_info() const { return _impl->get_topology_change_info(); } -template token -generic_token_metadata::get_predecessor(token t) const { +token_metadata::get_predecessor(token t) const { return _impl->get_predecessor(t); } -template -const std::unordered_set& -generic_token_metadata::get_all_endpoints() const { +const std::unordered_set& +token_metadata::get_all_endpoints() const { return _impl->get_all_endpoints(); } -template -template -requires std::is_same_v -std::unordered_set generic_token_metadata::get_all_ips() const { +std::unordered_set token_metadata::get_all_ips() const { const auto& host_ids = _impl->get_all_endpoints(); std::unordered_set result; result.reserve(host_ids.size()); @@ -1296,47 +1140,40 @@ std::unordered_set generic_token_metadata::get_all_ip return result; } -template size_t -generic_token_metadata::count_normal_token_owners() const { +token_metadata::count_normal_token_owners() const { return _impl->count_normal_token_owners(); } -template void -generic_token_metadata::set_read_new(read_new_t read_new) { +token_metadata::set_read_new(read_new_t read_new) { _impl->set_read_new(read_new); } -template long -generic_token_metadata::get_ring_version() const { +token_metadata::get_ring_version() const { return _impl->get_ring_version(); } -template void -generic_token_metadata::invalidate_cached_rings() { +token_metadata::invalidate_cached_rings() { _impl->invalidate_cached_rings(); } -template auto -generic_token_metadata::get_version() const -> version_t { +token_metadata::get_version() const -> version_t { return _impl->get_version(); } -template void -generic_token_metadata::set_version(version_t version) { +token_metadata::set_version(version_t version) { _impl->set_version(version); } -template void -generic_token_metadata::set_version_tracker(version_tracker_t tracker) { +token_metadata::set_version_tracker(version_tracker_t tracker) { _impl->set_version_tracker(std::move(tracker)); } -void shared_token_metadata::set(mutable_token_metadata2_ptr tmptr) noexcept { +void shared_token_metadata::set(mutable_token_metadata_ptr tmptr) noexcept { if (_shared->get_ring_version() >= tmptr->get_ring_version()) { on_internal_error(tlogger, format("shared_token_metadata: must not set non-increasing ring_version: {} -> {}", _shared->get_ring_version(), tmptr->get_ring_version())); } @@ -1354,7 +1191,7 @@ void shared_token_metadata::set(mutable_token_metadata2_ptr tmptr) noexcept { void shared_token_metadata::update_fence_version(token_metadata::version_t version) { if (const auto current_version = _shared->get_version(); version > current_version) { - // The generic_token_metadata::version under no circumstance can go backwards. + // The token_metadata::version under no circumstance can go backwards. // Even in case of topology change coordinator moving to another node // this condition must hold, that is why we treat its violation // as an internal error. @@ -1375,7 +1212,7 @@ void shared_token_metadata::update_fence_version(token_metadata::version_t versi tlogger.debug("new fence_version is set, version {}", _fence_version); } -future<> shared_token_metadata::mutate_token_metadata(seastar::noncopyable_function (token_metadata2&)> func) { +future<> shared_token_metadata::mutate_token_metadata(seastar::noncopyable_function (token_metadata&)> func) { auto lk = co_await get_lock(); auto tm = co_await _shared->clone_async(); // bump the token_metadata ring_version @@ -1383,17 +1220,17 @@ future<> shared_token_metadata::mutate_token_metadata(seastar::noncopyable_funct // when the modified token_metadata is committed. tm.invalidate_cached_rings(); co_await func(tm); - set(make_token_metadata2_ptr(std::move(tm))); + set(make_token_metadata_ptr(std::move(tm))); } -future<> shared_token_metadata::mutate_on_all_shards(sharded& stm, seastar::noncopyable_function (token_metadata2&)> func) { +future<> shared_token_metadata::mutate_on_all_shards(sharded& stm, seastar::noncopyable_function (token_metadata&)> func) { auto base_shard = this_shard_id(); assert(base_shard == 0); auto lk = co_await stm.local().get_lock(); - std::vector pending_token_metadata_ptr; + std::vector pending_token_metadata_ptr; pending_token_metadata_ptr.resize(smp::count); - auto tmptr = make_token_metadata2_ptr(co_await stm.local().get()->clone_async()); + auto tmptr = make_token_metadata_ptr(co_await stm.local().get()->clone_async()); auto& tm = *tmptr; // bump the token_metadata ring_version // to invalidate cached token/replication mappings @@ -1404,7 +1241,7 @@ future<> shared_token_metadata::mutate_on_all_shards(sharded future<> { - pending_token_metadata_ptr[this_shard_id()] = make_token_metadata2_ptr(co_await tm.clone_async()); + pending_token_metadata_ptr[this_shard_id()] = make_token_metadata_ptr(co_await tm.clone_async()); }); co_await stm.invoke_on_all([&] (shared_token_metadata& stm) { @@ -1441,8 +1278,7 @@ host_id_or_endpoint::host_id_or_endpoint(const sstring& s, param_type restrict) } } -template -void host_id_or_endpoint::resolve(const generic_token_metadata& tm) { +void host_id_or_endpoint::resolve(const token_metadata& tm) { if (id) { auto endpoint_opt = tm.get_endpoint_for_host_id_if_known(id); if (!endpoint_opt) { @@ -1458,15 +1294,4 @@ void host_id_or_endpoint::resolve(const generic_token_metadata& tm) { } } -template class generic_token_metadata; -template class generic_token_metadata; -template void host_id_or_endpoint::resolve(const token_metadata& tm); -template void host_id_or_endpoint::resolve(const token_metadata2& tm); -template token_metadata2* generic_token_metadata::get_new<>(); -template const token_metadata2* generic_token_metadata::get_new<>() const; -template lw_shared_ptr generic_token_metadata::get_new_strong<>() const; -template generic_token_metadata::generic_token_metadata(std::unique_ptr>, token_metadata2); -template generic_token_metadata::generic_token_metadata(token_metadata2_ptr); -template std::unordered_set generic_token_metadata::get_all_ips<>() const; - } // namespace locator diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index 45752a6f21..e77df66a2d 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -43,10 +43,7 @@ class abstract_replication_strategy; using token = dht::token; -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; -using token_metadata2 = generic_token_metadata; +class token_metadata; class tablet_metadata; struct host_id_or_endpoint { @@ -71,29 +68,14 @@ struct host_id_or_endpoint { // Map the host_id to endpoint based on whichever of them is set, // using the token_metadata - template - void resolve(const generic_token_metadata& tm); + void resolve(const token_metadata& tm); }; -template class token_metadata_impl; -template struct topology_change_info; -class generic_token_metadata_base { -public: - struct config { - topology::config topo_cfg; - }; - using inet_address = gms::inet_address; - using version_t = service::topology::version_t; - using version_tracker_t = utils::phased_barrier::operation; -}; - -template -class generic_token_metadata final: public generic_token_metadata_base { - std::unique_ptr> _impl; - std::variant, lw_shared_ptr> _new_value; +class token_metadata final { + std::unique_ptr _impl; private: friend class token_metadata_ring_splitter; class tokens_iterator { @@ -105,30 +87,31 @@ private: using reference = token&; public: tokens_iterator() = default; - tokens_iterator(const token& start, const token_metadata_impl* token_metadata); + tokens_iterator(const token& start, const token_metadata_impl* token_metadata); bool operator==(const tokens_iterator& it) const; const token& operator*() const; tokens_iterator& operator++(); private: std::vector::const_iterator _cur_it; size_t _remaining = 0; - const token_metadata_impl* _token_metadata = nullptr; + const token_metadata_impl* _token_metadata = nullptr; - friend class token_metadata_impl; + friend class token_metadata_impl; }; public: - generic_token_metadata(config cfg); - explicit generic_token_metadata(std::unique_ptr> impl); - template - requires std::is_same_v - generic_token_metadata(std::unique_ptr> impl, token_metadata2 new_value); - template - requires std::is_same_v - generic_token_metadata(lw_shared_ptr new_value); - generic_token_metadata(generic_token_metadata&&) noexcept; // Can't use "= default;" - hits some static_assert in unique_ptr - generic_token_metadata& operator=(generic_token_metadata&&) noexcept; - ~generic_token_metadata(); + struct config { + topology::config topo_cfg; + }; + using inet_address = gms::inet_address; + using version_t = service::topology::version_t; + using version_tracker_t = utils::phased_barrier::operation; + + token_metadata(config cfg); + explicit token_metadata(std::unique_ptr impl); + token_metadata(token_metadata&&) noexcept; // Can't use "= default;" - hits some static_assert in unique_ptr + token_metadata& operator=(token_metadata&&) noexcept; + ~token_metadata(); const std::vector& sorted_tokens() const; const tablet_metadata& tablets() const; tablet_metadata& tablets(); @@ -138,52 +121,21 @@ public: // // Note: the function is not exception safe! // It must be called only on a temporary copy of the token_metadata - future<> update_normal_tokens(std::unordered_set tokens, NodeId endpoint); + future<> update_normal_tokens(std::unordered_set tokens, host_id endpoint); const token& first_token(const token& start) const; size_t first_token_index(const token& start) const; - std::optional get_endpoint(const token& token) const; - std::vector get_tokens(const NodeId& addr) const; - const std::unordered_map& get_token_to_endpoint() const; - const std::unordered_set& get_leaving_endpoints() const; - const std::unordered_map& get_bootstrap_tokens() const; - - template - requires std::is_same_v - token_metadata2* get_new() { - if (holds_alternative>(_new_value)) { - return get>(_new_value).get(); - } - throw_with_backtrace("no mutable new value"); - } - - template - requires std::is_same_v - const token_metadata2* get_new() const { - if (holds_alternative>(_new_value)) { - return get>(_new_value).get(); - } - if (holds_alternative>(_new_value)) { - return get>(_new_value).get(); - } - throw_with_backtrace("no new value"); - } - - template - requires std::is_same_v - lw_shared_ptr get_new_strong() const { - if (holds_alternative>(_new_value)) { - return get>(_new_value); - } - if (holds_alternative>(_new_value)) { - return get>(_new_value); - } - throw_with_backtrace("no new value"); - } + std::optional get_endpoint(const token& token) const; + std::vector get_tokens(const host_id& addr) const; + const std::unordered_map& get_token_to_endpoint() const; + const std::unordered_set& get_leaving_endpoints() const; + const std::unordered_map& get_bootstrap_tokens() const; /** - * Update or add endpoint given its inet_address and endpoint_dc_rack. + * Update or add a node for a given host_id. + * The other arguments (dc, state, shard_count) are optional, i.e. the corresponding node + * fields won't be updated if std::nullopt is passed. */ - void update_topology(NodeId ep, std::optional opt_dr, std::optional opt_st = std::nullopt, + void update_topology(host_id ep, std::optional opt_dr, std::optional opt_st = std::nullopt, std::optional shard_count = std::nullopt); /** * Creates an iterable range of the sorted tokens starting at the token t @@ -235,39 +187,39 @@ public: /// Returns host_id of the local node. host_id get_my_id() const; - void add_bootstrap_token(token t, NodeId endpoint); + void add_bootstrap_token(token t, host_id endpoint); - void add_bootstrap_tokens(std::unordered_set tokens, NodeId endpoint); + void add_bootstrap_tokens(std::unordered_set tokens, host_id endpoint); void remove_bootstrap_tokens(std::unordered_set tokens); - void add_leaving_endpoint(NodeId endpoint); - void del_leaving_endpoint(NodeId endpoint); + void add_leaving_endpoint(host_id endpoint); + void del_leaving_endpoint(host_id endpoint); - void remove_endpoint(NodeId endpoint); + void remove_endpoint(host_id endpoint); // Checks if the node is part of the token ring. If yes, the node is one of // the nodes that owns the tokens and inside the set _normal_token_owners. - bool is_normal_token_owner(NodeId endpoint) const; + bool is_normal_token_owner(host_id endpoint) const; - bool is_leaving(NodeId endpoint) const; + bool is_leaving(host_id endpoint) const; // Is this node being replaced by another node - bool is_being_replaced(NodeId endpoint) const; + bool is_being_replaced(host_id endpoint) const; // Is any node being replaced by another node bool is_any_node_being_replaced() const; - void add_replacing_endpoint(NodeId existing_node, NodeId replacing_node); + void add_replacing_endpoint(host_id existing_node, host_id replacing_node); - void del_replacing_endpoint(NodeId existing_node); + void del_replacing_endpoint(host_id existing_node); /** * Create a full copy of token_metadata using asynchronous continuations. * The caller must ensure that the cloned object will not change if * the function yields. */ - future clone_async() const noexcept; + future clone_async() const noexcept; /** * Create a copy of TokenMetadata with only tokenToEndpointMap. That is, pending ranges, @@ -275,7 +227,7 @@ public: * The caller must ensure that the cloned object will not change if * the function yields. */ - future clone_only_token_map() const noexcept; + future clone_only_token_map() const noexcept; /** * Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all * current leave operations have finished. @@ -284,7 +236,7 @@ public: * * @return a future holding a new token metadata */ - future clone_after_all_left() const noexcept; + future clone_after_all_left() const noexcept; /** * Gently clear the token_metadata members. @@ -304,16 +256,14 @@ public: static boost::icl::interval::interval_type range_to_interval(range r); static range interval_to_range(boost::icl::interval::interval_type i); - future<> update_topology_change_info(dc_rack_fn& get_dc_rack); + future<> update_topology_change_info(dc_rack_fn& get_dc_rack); - const std::optional>& get_topology_change_info() const; + const std::optional& get_topology_change_info() const; token get_predecessor(token t) const; - const std::unordered_set& get_all_endpoints() const; + const std::unordered_set& get_all_endpoints() const; - template - requires std::is_same_v std::unordered_set get_all_ips() const; /* Returns the number of different endpoints that own tokens in the ring. @@ -334,26 +284,20 @@ public: version_t get_version() const; void set_version(version_t version); - friend class token_metadata_impl; + friend class token_metadata_impl; friend class shared_token_metadata; private: void set_version_tracker(version_tracker_t tracker); }; -extern template class generic_token_metadata; -extern template class generic_token_metadata; -extern template void host_id_or_endpoint::resolve(const token_metadata& tm); -extern template void host_id_or_endpoint::resolve(const token_metadata2& tm); - -template struct topology_change_info { - lw_shared_ptr> target_token_metadata; - lw_shared_ptr> base_token_metadata; + lw_shared_ptr target_token_metadata; + lw_shared_ptr base_token_metadata; std::vector all_tokens; token_metadata::read_new_t read_new; - topology_change_info(lw_shared_ptr> target_token_metadata_, - lw_shared_ptr> base_token_metadata_, + topology_change_info(lw_shared_ptr target_token_metadata_, + lw_shared_ptr base_token_metadata_, std::vector all_tokens_, token_metadata::read_new_t read_new_); future<> clear_gently(); @@ -367,13 +311,8 @@ mutable_token_metadata_ptr make_token_metadata_ptr(Args... args) { return make_lw_shared(std::forward(args)...); } -template -mutable_token_metadata2_ptr make_token_metadata2_ptr(Args... args) { - return make_lw_shared(std::forward(args)...); -} - class shared_token_metadata { - mutable_token_metadata2_ptr _shared; + mutable_token_metadata_ptr _shared; token_metadata_lock_func _lock_func; // We use this barrier during the transition to a new token_metadata version to ensure that the @@ -392,13 +331,13 @@ class shared_token_metadata { // includes its own invocation as an operation in the new phase. utils::phased_barrier _versions_barrier; shared_future<> _stale_versions_in_use{make_ready_future<>()}; - token_metadata2::version_t _fence_version = 0; + token_metadata::version_t _fence_version = 0; public: // used to construct the shared object as a sharded<> instance // lock_func returns semaphore_units<> - explicit shared_token_metadata(token_metadata_lock_func lock_func, token_metadata2::config cfg) - : _shared(make_token_metadata2_ptr(std::move(cfg))) + explicit shared_token_metadata(token_metadata_lock_func lock_func, token_metadata::config cfg) + : _shared(make_token_metadata_ptr(std::move(cfg))) , _lock_func(std::move(lock_func)) { _shared->set_version_tracker(_versions_barrier.start()); @@ -407,18 +346,18 @@ public: shared_token_metadata(const shared_token_metadata& x) = delete; shared_token_metadata(shared_token_metadata&& x) = default; - token_metadata2_ptr get() const noexcept { + token_metadata_ptr get() const noexcept { return _shared; } - void set(mutable_token_metadata2_ptr tmptr) noexcept; + void set(mutable_token_metadata_ptr tmptr) noexcept; future<> stale_versions_in_use() const { return _stale_versions_in_use.get_future(); } - void update_fence_version(token_metadata2::version_t version); - token_metadata2::version_t get_fence_version() const noexcept { + void update_fence_version(token_metadata::version_t version); + token_metadata::version_t get_fence_version() const noexcept { return _fence_version; } @@ -438,7 +377,7 @@ public: // If the functor is successful, the mutated clone // is set back to to the shared_token_metadata, // otherwise, the clone is destroyed. - future<> mutate_token_metadata(seastar::noncopyable_function (token_metadata2&)> func); + future<> mutate_token_metadata(seastar::noncopyable_function (token_metadata&)> func); // mutate_token_metadata_on_all_shards acquires the shared_token_metadata lock, // clones the token_metadata (using clone_async) @@ -450,7 +389,7 @@ public: // otherwise, the clone is destroyed. // // Must be called on shard 0. - static future<> mutate_on_all_shards(sharded& stm, seastar::noncopyable_function (token_metadata2&)> func); + static future<> mutate_on_all_shards(sharded& stm, seastar::noncopyable_function (token_metadata&)> func); }; } diff --git a/locator/token_metadata_fwd.hh b/locator/token_metadata_fwd.hh index 5e67605e3b..07f470bca7 100644 --- a/locator/token_metadata_fwd.hh +++ b/locator/token_metadata_fwd.hh @@ -11,13 +11,9 @@ namespace locator { -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; +class token_metadata; + using token_metadata_ptr = lw_shared_ptr; using mutable_token_metadata_ptr = lw_shared_ptr; -using token_metadata2 = generic_token_metadata; -using token_metadata2_ptr = lw_shared_ptr; -using mutable_token_metadata2_ptr = lw_shared_ptr; } // namespace locator diff --git a/locator/token_range_splitter.hh b/locator/token_range_splitter.hh index 0222f14b0b..ac55d65fd1 100644 --- a/locator/token_range_splitter.hh +++ b/locator/token_range_splitter.hh @@ -40,6 +40,6 @@ public: virtual std::optional next_token() = 0; }; -std::unique_ptr make_splitter(token_metadata2_ptr); +std::unique_ptr make_splitter(token_metadata_ptr); } \ No newline at end of file diff --git a/locator/topology.hh b/locator/topology.hh index 034ac92c44..d9adaf69d7 100644 --- a/locator/topology.hh +++ b/locator/topology.hh @@ -424,7 +424,6 @@ private: return _nodes_by_endpoint; }; - template friend class token_metadata_impl; public: void test_compare_endpoints(const inet_address& address, const inet_address& a1, const inet_address& a2) const; diff --git a/locator/util.cc b/locator/util.cc index 8283cee2ad..1a16fd1313 100644 --- a/locator/util.cc +++ b/locator/util.cc @@ -54,7 +54,7 @@ get_range_to_address_map(locator::effective_replication_map_ptr erm, // Caller is responsible to hold token_metadata valid until the returned future is resolved static future> -get_tokens_in_local_dc(const locator::token_metadata2& tm) { +get_tokens_in_local_dc(const locator::token_metadata& tm) { std::vector filtered_tokens; auto local_dc_filter = tm.get_topology().get_local_dc_filter(); for (auto token : tm.sorted_tokens()) { diff --git a/main.cc b/main.cc index 4ce8097e55..1a01486031 100644 --- a/main.cc +++ b/main.cc @@ -1206,7 +1206,7 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl const auto listen_address = utils::resolve(cfg->listen_address, family).get0(); const auto host_id = initialize_local_info_thread(sys_ks, snitch, listen_address, *cfg, broadcast_addr, broadcast_rpc_addr); - shared_token_metadata::mutate_on_all_shards(token_metadata, [host_id, endpoint = broadcast_addr] (locator::token_metadata2& tm) { + shared_token_metadata::mutate_on_all_shards(token_metadata, [host_id, endpoint = broadcast_addr] (locator::token_metadata& tm) { // Makes local host id available in topology cfg as soon as possible. // Raft topology discard the endpoint-to-id map, so the local id can // still be found in the config. diff --git a/node_ops/node_ops_ctl.hh b/node_ops/node_ops_ctl.hh index e452b90172..6cba6b8cc0 100644 --- a/node_ops/node_ops_ctl.hh +++ b/node_ops/node_ops_ctl.hh @@ -25,10 +25,7 @@ class storage_service; } namespace locator { -template -class generic_token_metadata; -using token_metadata = generic_token_metadata; -using token_metadata2 = generic_token_metadata; +class token_metadata; } class node_ops_info { @@ -139,7 +136,7 @@ public: sstring desc; locator::host_id host_id; // Host ID of the node operand (i.e. added, replaced, or leaving node) gms::inet_address endpoint; // IP address of the node operand (i.e. added, replaced, or leaving node) - lw_shared_ptr tmptr; + lw_shared_ptr tmptr; std::unordered_set sync_nodes; std::unordered_set ignore_nodes; node_ops_cmd_request req; diff --git a/repair/repair.cc b/repair/repair.cc index f59eb4f90d..f64f0feb5f 100644 --- a/repair/repair.cc +++ b/repair/repair.cc @@ -1492,7 +1492,7 @@ std::optional repair::data_sync_repair_task_impl::expected_children_numb return smp::count; } -future<> repair_service::bootstrap_with_repair(locator::token_metadata2_ptr tmptr, std::unordered_set bootstrap_tokens) { +future<> repair_service::bootstrap_with_repair(locator::token_metadata_ptr tmptr, std::unordered_set bootstrap_tokens) { assert(this_shard_id() == 0); using inet_address = gms::inet_address; return seastar::async([this, tmptr = std::move(tmptr), tokens = std::move(bootstrap_tokens)] () mutable { @@ -1531,14 +1531,14 @@ future<> repair_service::bootstrap_with_repair(locator::token_metadata2_ptr tmpt auto replication_factor = erm->get_replication_factor(); //Active ranges - auto metadata_clone = locator::make_token_metadata2_ptr(tmptr->clone_only_token_map().get0()); - auto range_addresses = strat.get_range_addresses(locator::token_metadata(metadata_clone)).get0(); + auto metadata_clone = tmptr->clone_only_token_map().get0(); + auto range_addresses = strat.get_range_addresses(metadata_clone).get0(); //Pending ranges - metadata_clone->update_topology(myid, myloc, locator::node::state::bootstrapping); - metadata_clone->update_normal_tokens(tokens, myid).get(); - auto pending_range_addresses = strat.get_range_addresses(locator::token_metadata(metadata_clone)).get0(); - metadata_clone->clear_gently().get(); + metadata_clone.update_topology(myid, myloc, locator::node::state::bootstrapping); + metadata_clone.update_normal_tokens(tokens, myid).get(); + auto pending_range_addresses = strat.get_range_addresses(metadata_clone).get0(); + metadata_clone.clear_gently().get(); //Collects the source that will have its range moved to the new node std::unordered_map range_sources; @@ -1669,7 +1669,7 @@ future<> repair_service::bootstrap_with_repair(locator::token_metadata2_ptr tmpt }); } -future<> repair_service::do_decommission_removenode_with_repair(locator::token_metadata2_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops) { +future<> repair_service::do_decommission_removenode_with_repair(locator::token_metadata_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops) { assert(this_shard_id() == 0); using inet_address = gms::inet_address; return seastar::async([this, tmptr = std::move(tmptr), leaving_node = std::move(leaving_node), ops] () mutable { @@ -1720,15 +1720,15 @@ future<> repair_service::do_decommission_removenode_with_repair(locator::token_m // Find (for each range) all nodes that store replicas for these ranges as well for (auto& r : ranges) { auto end_token = r.end() ? r.end()->value() : dht::maximum_token(); - auto eps = strat.calculate_natural_ips(end_token, tmptr).get0(); + auto eps = strat.calculate_natural_ips(end_token, *tmptr).get0(); current_replica_endpoints.emplace(r, std::move(eps)); seastar::thread::maybe_yield(); } - auto temp = locator::make_token_metadata2_ptr(tmptr->clone_after_all_left().get0()); + auto temp = tmptr->clone_after_all_left().get0(); // leaving_node might or might not be 'leaving'. If it was not leaving (that is, removenode // command was used), it is still present in temp and must be removed. - if (temp->is_normal_token_owner(leaving_node_id)) { - temp->remove_endpoint(leaving_node_id); + if (temp.is_normal_token_owner(leaving_node_id)) { + temp.remove_endpoint(leaving_node_id); } std::unordered_map range_sources; dht::token_range_vector ranges_for_removenode; @@ -1843,7 +1843,7 @@ future<> repair_service::do_decommission_removenode_with_repair(locator::token_m } } } - temp->clear_gently().get(); + temp.clear_gently().get(); if (reason == streaming::stream_reason::decommission) { container().invoke_on_all([nr_ranges_skipped] (repair_service& rs) { rs.get_metrics().decommission_finished_ranges += nr_ranges_skipped; @@ -1865,13 +1865,13 @@ future<> repair_service::do_decommission_removenode_with_repair(locator::token_m }); } -future<> repair_service::decommission_with_repair(locator::token_metadata2_ptr tmptr) { +future<> repair_service::decommission_with_repair(locator::token_metadata_ptr tmptr) { assert(this_shard_id() == 0); auto my_address = tmptr->get_topology().my_address(); return do_decommission_removenode_with_repair(std::move(tmptr), my_address, {}); } -future<> repair_service::removenode_with_repair(locator::token_metadata2_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops) { +future<> repair_service::removenode_with_repair(locator::token_metadata_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops) { assert(this_shard_id() == 0); return do_decommission_removenode_with_repair(std::move(tmptr), std::move(leaving_node), std::move(ops)).then([this] { rlogger.debug("Triggering off-strategy compaction for all non-system tables on removenode completion"); @@ -1884,7 +1884,7 @@ future<> repair_service::removenode_with_repair(locator::token_metadata2_ptr tmp }); } -future<> repair_service::do_rebuild_replace_with_repair(locator::token_metadata2_ptr tmptr, sstring op, sstring source_dc, streaming::stream_reason reason, std::unordered_set ignore_nodes) { +future<> repair_service::do_rebuild_replace_with_repair(locator::token_metadata_ptr tmptr, sstring op, sstring source_dc, streaming::stream_reason reason, std::unordered_set ignore_nodes) { assert(this_shard_id() == 0); return seastar::async([this, tmptr = std::move(tmptr), source_dc = std::move(source_dc), op = std::move(op), reason, ignore_nodes = std::move(ignore_nodes)] () mutable { auto& db = get_db().local(); @@ -1898,7 +1898,7 @@ future<> repair_service::do_rebuild_replace_with_repair(locator::token_metadata2 } auto& strat = erm->get_replication_strategy(); // Okay to yield since tm is immutable - dht::token_range_vector ranges = strat.get_ranges(myid, locator::token_metadata(tmptr)).get0(); + dht::token_range_vector ranges = strat.get_ranges(myid, tmptr).get0(); auto nr_tables = get_nr_tables(db, keyspace_name); nr_ranges_total += ranges.size() * nr_tables; @@ -1922,7 +1922,7 @@ future<> repair_service::do_rebuild_replace_with_repair(locator::token_metadata2 continue; } auto& strat = erm->get_replication_strategy(); - dht::token_range_vector ranges = strat.get_ranges(myid, locator::token_metadata(tmptr)).get0(); + dht::token_range_vector ranges = strat.get_ranges(myid, *tmptr).get0(); auto& topology = erm->get_token_metadata().get_topology(); std::unordered_map range_sources; auto nr_tables = get_nr_tables(db, keyspace_name); @@ -1931,7 +1931,7 @@ future<> repair_service::do_rebuild_replace_with_repair(locator::token_metadata2 auto& r = *it; seastar::thread::maybe_yield(); auto end_token = r.end() ? r.end()->value() : dht::maximum_token(); - auto neighbors = boost::copy_range>(strat.calculate_natural_ips(end_token, tmptr).get0() | + auto neighbors = boost::copy_range>(strat.calculate_natural_ips(end_token, *tmptr).get0() | boost::adaptors::filtered([myip, &source_dc, &topology, &ignore_nodes] (const gms::inet_address& node) { if (node == myip) { return false; @@ -1969,7 +1969,7 @@ future<> repair_service::do_rebuild_replace_with_repair(locator::token_metadata2 }); } -future<> repair_service::rebuild_with_repair(locator::token_metadata2_ptr tmptr, sstring source_dc) { +future<> repair_service::rebuild_with_repair(locator::token_metadata_ptr tmptr, sstring source_dc) { assert(this_shard_id() == 0); auto op = sstring("rebuild_with_repair"); if (source_dc.empty()) { @@ -1985,7 +1985,7 @@ future<> repair_service::rebuild_with_repair(locator::token_metadata2_ptr tmptr, }); } -future<> repair_service::replace_with_repair(locator::token_metadata2_ptr tmptr, std::unordered_set replacing_tokens, std::unordered_set ignore_nodes) { +future<> repair_service::replace_with_repair(locator::token_metadata_ptr tmptr, std::unordered_set replacing_tokens, std::unordered_set ignore_nodes) { assert(this_shard_id() == 0); auto cloned_tm = co_await tmptr->clone_async(); auto op = sstring("replace_with_repair"); @@ -1994,7 +1994,7 @@ future<> repair_service::replace_with_repair(locator::token_metadata2_ptr tmptr, auto reason = streaming::stream_reason::replace; // update a cloned version of tmptr // no need to set the original version - auto cloned_tmptr = make_token_metadata2_ptr(std::move(cloned_tm)); + auto cloned_tmptr = make_token_metadata_ptr(std::move(cloned_tm)); cloned_tmptr->update_topology(tmptr->get_my_id(), myloc, locator::node::state::replacing); co_await cloned_tmptr->update_normal_tokens(replacing_tokens, tmptr->get_my_id()); co_return co_await do_rebuild_replace_with_repair(std::move(cloned_tmptr), std::move(op), myloc.dc, reason, std::move(ignore_nodes)); diff --git a/repair/row_level.cc b/repair/row_level.cc index 3b3a621edc..63615e6b40 100644 --- a/repair/row_level.cc +++ b/repair/row_level.cc @@ -669,7 +669,7 @@ void flush_rows(schema_ptr s, std::list& rows, lw_shared_ptr last_dk; bool do_small_table_optimization = erm && small_table_optimization; auto* strat = do_small_table_optimization ? &erm->get_replication_strategy() : nullptr; - auto tm = do_small_table_optimization ? erm->get_token_metadata_ptr() : nullptr; + auto* tm = do_small_table_optimization ? &erm->get_token_metadata() : nullptr; auto myip = do_small_table_optimization ? erm->get_topology().my_address() : gms::inet_address(); for (auto& r : rows) { thread::maybe_yield(); @@ -679,7 +679,7 @@ void flush_rows(schema_ptr s, std::list& rows, lw_shared_ptrdk; if (do_small_table_optimization) { // Check if the token is owned by the node - auto eps = strat->calculate_natural_ips(dk.token(), tm).get0(); + auto eps = strat->calculate_natural_ips(dk.token(), *tm).get0(); if (!eps.contains(myip)) { rlogger.trace("master: ignore row, token={}", dk.token()); continue; @@ -1900,7 +1900,7 @@ public: } if (small_table_optimization) { auto& strat = erm.get_replication_strategy(); - auto& tm = erm.get_token_metadata_ptr(); + const auto& tm = erm.get_token_metadata(); std::list tmp; for (auto& row : row_diff) { repair_row r = std::move(row); diff --git a/repair/row_level.hh b/repair/row_level.hh index d82ac83f9b..e21f4df2d2 100644 --- a/repair/row_level.hh +++ b/repair/row_level.hh @@ -138,14 +138,14 @@ public: // The tokens are the tokens assigned to the bootstrap node. // all repair-based node operation entry points must be called on shard 0 - future<> bootstrap_with_repair(locator::token_metadata2_ptr tmptr, std::unordered_set bootstrap_tokens); - future<> decommission_with_repair(locator::token_metadata2_ptr tmptr); - future<> removenode_with_repair(locator::token_metadata2_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops); - future<> rebuild_with_repair(locator::token_metadata2_ptr tmptr, sstring source_dc); - future<> replace_with_repair(locator::token_metadata2_ptr tmptr, std::unordered_set replacing_tokens, std::unordered_set ignore_nodes); + future<> bootstrap_with_repair(locator::token_metadata_ptr tmptr, std::unordered_set bootstrap_tokens); + future<> decommission_with_repair(locator::token_metadata_ptr tmptr); + future<> removenode_with_repair(locator::token_metadata_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops); + future<> rebuild_with_repair(locator::token_metadata_ptr tmptr, sstring source_dc); + future<> replace_with_repair(locator::token_metadata_ptr tmptr, std::unordered_set replacing_tokens, std::unordered_set ignore_nodes); private: - future<> do_decommission_removenode_with_repair(locator::token_metadata2_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops); - future<> do_rebuild_replace_with_repair(locator::token_metadata2_ptr tmptr, sstring op, sstring source_dc, streaming::stream_reason reason, std::unordered_set ignore_nodes); + future<> do_decommission_removenode_with_repair(locator::token_metadata_ptr tmptr, gms::inet_address leaving_node, shared_ptr ops); + future<> do_rebuild_replace_with_repair(locator::token_metadata_ptr tmptr, sstring op, sstring source_dc, streaming::stream_reason reason, std::unordered_set ignore_nodes); // Must be called on shard 0 future<> sync_data_using_repair(sstring keyspace, diff --git a/replica/database.hh b/replica/database.hh index 0d51032835..bff06cbd54 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_metadata2& get_token_metadata() const { return *_shared_token_metadata.get(); } + const locator::token_metadata& get_token_metadata() const { return *_shared_token_metadata.get(); } wasm::manager& wasm() noexcept { return _wasm; } const wasm::manager& wasm() const noexcept { return _wasm; } diff --git a/service/forward_service.cc b/service/forward_service.cc index 44ed7e7ae7..91513a1e6e 100644 --- a/service/forward_service.cc +++ b/service/forward_service.cc @@ -303,7 +303,7 @@ public: } }; -locator::token_metadata2_ptr forward_service::get_token_metadata_ptr() const noexcept { +locator::token_metadata_ptr forward_service::get_token_metadata_ptr() const noexcept { return _shared_token_metadata.get(); } diff --git a/service/forward_service.hh b/service/forward_service.hh index 8bcec3db97..169deb0b63 100644 --- a/service/forward_service.hh +++ b/service/forward_service.hh @@ -159,7 +159,7 @@ private: // Used to execute a `forward_request` on a shard. future execute_on_this_shard(query::forward_request req, std::optional tr_info); - locator::token_metadata2_ptr get_token_metadata_ptr() const noexcept; + locator::token_metadata_ptr get_token_metadata_ptr() const noexcept; void register_metrics(); void init_messaging_service(); diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 9b507a72d0..ee038d3b3d 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -2286,7 +2286,7 @@ bool paxos_response_handler::learned(gms::inet_address ep) { } static inet_address_vector_replica_set -replica_ids_to_endpoints(const locator::token_metadata2& tm, const std::vector& replica_ids) { +replica_ids_to_endpoints(const locator::token_metadata& tm, const std::vector& replica_ids) { inet_address_vector_replica_set endpoints; endpoints.reserve(replica_ids.size()); @@ -2300,7 +2300,7 @@ replica_ids_to_endpoints(const locator::token_metadata2& tm, const std::vector -endpoints_to_replica_ids(const locator::token_metadata2& tm, const inet_address_vector_replica_set& endpoints) { +endpoints_to_replica_ids(const locator::token_metadata& tm, const inet_address_vector_replica_set& endpoints) { std::vector replica_ids; replica_ids.reserve(endpoints.size()); @@ -6545,7 +6545,7 @@ storage_proxy::stop() { return make_ready_future<>(); } -locator::token_metadata2_ptr storage_proxy::get_token_metadata_ptr() const noexcept { +locator::token_metadata_ptr storage_proxy::get_token_metadata_ptr() const noexcept { return _shared_token_metadata.get(); } diff --git a/service/storage_proxy.hh b/service/storage_proxy.hh index 476e1b713f..8d5f517e2b 100644 --- a/service/storage_proxy.hh +++ b/service/storage_proxy.hh @@ -220,7 +220,7 @@ public: return _erm_factory; } - locator::token_metadata2_ptr get_token_metadata_ptr() const noexcept; + locator::token_metadata_ptr get_token_metadata_ptr() const noexcept; query::max_result_size get_max_result_size(const query::partition_slice& slice) const; query::tombstone_limit get_tombstone_limit() const; diff --git a/service/storage_service.cc b/service/storage_service.cc index cf3bd3fc83..d4d46f4aad 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -283,7 +283,7 @@ static future<> set_gossip_tokens(gms::gossiper& g, }); } -static std::unordered_map get_token_to_endpoint(const locator::token_metadata2& tm) { +static std::unordered_map get_token_to_endpoint(const locator::token_metadata& tm) { const auto& map = tm.get_token_to_endpoint(); std::unordered_map result; result.reserve(map.size()); @@ -405,7 +405,7 @@ future<> storage_service::topology_state_load() { co_await _messaging.local().ban_host(locator::host_id{id.uuid()}); } - co_await mutate_token_metadata(seastar::coroutine::lambda([this, &id2ip, &am] (mutable_token_metadata2_ptr tmptr) -> future<> { + co_await mutate_token_metadata(seastar::coroutine::lambda([this, &id2ip, &am] (mutable_token_metadata_ptr tmptr) -> future<> { co_await tmptr->clear_gently(); // drop previous state tmptr->set_version(_topology_state_machine._topology.version); @@ -925,11 +925,11 @@ class topology_coordinator { // True if an ongoing topology change should be rolled back bool _rollback = false; - const locator::token_metadata2& get_token_metadata() const noexcept { + const locator::token_metadata& get_token_metadata() const noexcept { return *_shared_tm.get(); } - locator::token_metadata2_ptr get_token_metadata_ptr() const noexcept { + locator::token_metadata_ptr get_token_metadata_ptr() const noexcept { return _shared_tm.get(); } @@ -1207,7 +1207,7 @@ class topology_coordinator { // If there's a bootstrapping node, its tokens should be included in the new generation. // Pass them and a reference to the bootstrapping node's replica_state through `binfo`. future>> prepare_new_cdc_generation_data( - locator::token_metadata2_ptr tmptr, const group0_guard& guard, std::optional binfo) { + locator::token_metadata_ptr tmptr, const group0_guard& guard, std::optional binfo) { auto get_sharding_info = [&] (dht::token end) -> std::pair { if (binfo && binfo->bootstrap_tokens.contains(end)) { return {binfo->rs.shard_count, binfo->rs.ignore_msb}; @@ -1269,7 +1269,7 @@ class topology_coordinator { // (bootstrapping is quick if there is no data in the cluster, but usually if one has 100 nodes they // have tons of data, so indeed streaming/repair will take much longer (hours/days)). future> prepare_and_broadcast_cdc_generation_data( - locator::token_metadata2_ptr tmptr, group0_guard guard, std::optional binfo) { + locator::token_metadata_ptr tmptr, group0_guard guard, std::optional binfo) { auto [gen_uuid, gen_mutations] = co_await prepare_new_cdc_generation_data(tmptr, guard, binfo); if (gen_mutations.empty()) { @@ -3414,7 +3414,7 @@ future<> storage_service::join_token_ring(sharded future<> { + co_await mutate_token_metadata([this, &bootstrap_tokens] (mutable_token_metadata_ptr tmptr) -> future<> { // This node must know about its chosen tokens before other nodes do // since they may start sending writes to this node after it gossips status = NORMAL. // Therefore, in case we haven't updated _token_metadata with our tokens yet, do it now. @@ -3493,7 +3493,7 @@ future<> storage_service::mark_existing_views_as_built() { }); } -std::unordered_set storage_service::parse_node_list(sstring comma_separated_list, const token_metadata2& tm) { +std::unordered_set storage_service::parse_node_list(sstring comma_separated_list, const token_metadata& tm) { std::vector ignore_nodes_strs = utils::split_comma_separated_list(std::move(comma_separated_list)); std::unordered_set ignore_nodes; for (const sstring& n : ignore_nodes_strs) { @@ -3555,7 +3555,7 @@ future<> storage_service::bootstrap(std::unordered_set& bootstrap_tokens, // When is_repair_based_node_ops_enabled is true, the bootstrap node // will use node_ops_cmd to bootstrap, node_ops_cmd will update the pending ranges. slogger.debug("bootstrap: update pending ranges: endpoint={} bootstrap_tokens={}", get_broadcast_address(), bootstrap_tokens); - mutate_token_metadata([this, &bootstrap_tokens] (mutable_token_metadata2_ptr tmptr) { + mutate_token_metadata([this, &bootstrap_tokens] (mutable_token_metadata_ptr tmptr) { auto endpoint = get_broadcast_address(); tmptr->update_topology(tmptr->get_my_id(), _snitch.local()->get_location(), locator::node::state::bootstrapping); tmptr->add_bootstrap_tokens(bootstrap_tokens, tmptr->get_my_id()); @@ -3650,25 +3650,20 @@ future<> storage_service::handle_state_bootstrap(inet_address endpoint, gms::per // continue. auto tmlock = co_await get_token_metadata_lock(); auto tmptr = co_await get_mutable_token_metadata_ptr(); - auto update_tm = [&](locator::generic_token_metadata& tm, NodeId n, std::optional dc_rack) { - if (tm.is_normal_token_owner(n)) { - // If isLeaving is false, we have missed both LEAVING and LEFT. However, if - // isLeaving is true, we have only missed LEFT. Waiting time between completing - // leave operation and rebootstrapping is relatively short, so the latter is quite - // common (not enough time for gossip to spread). Therefore we report only the - // former in the log. - if (!tm.is_leaving(n)) { - slogger.info("Node {} state jump to bootstrap", n); - } - tm.remove_endpoint(n); - } - - tm.update_topology(n, dc_rack, locator::node::state::bootstrapping); - tm.add_bootstrap_tokens(tokens, n); - }; - const auto dc_rack = get_dc_rack_for(endpoint); const auto host_id = _gossiper.get_host_id(endpoint); - update_tm(*tmptr, host_id, dc_rack); + if (tmptr->is_normal_token_owner(host_id)) { + // If isLeaving is false, we have missed both LEAVING and LEFT. However, if + // isLeaving is true, we have only missed LEFT. Waiting time between completing + // leave operation and rebootstrapping is relatively short, so the latter is quite + // common (not enough time for gossip to spread). Therefore we report only the + // former in the log. + if (!tmptr->is_leaving(host_id)) { + slogger.info("Node {} state jump to bootstrap", host_id); + } + tmptr->remove_endpoint(host_id); + } + tmptr->update_topology(host_id, get_dc_rack_for(endpoint), locator::node::state::bootstrapping); + tmptr->add_bootstrap_tokens(tokens, host_id); tmptr->update_host_id(host_id, endpoint); co_await update_topology_change_info(tmptr, ::format("handle_state_bootstrap {}", endpoint)); @@ -4302,13 +4297,13 @@ future<> storage_service::join_cluster(sharded& co_return co_await join_token_ring(sys_dist_ks, proxy, std::move(initial_contact_nodes), std::move(loaded_endpoints), std::move(loaded_peer_features), get_ring_delay()); } -future<> storage_service::replicate_to_all_cores(mutable_token_metadata2_ptr tmptr) noexcept { +future<> storage_service::replicate_to_all_cores(mutable_token_metadata_ptr tmptr) noexcept { assert(this_shard_id() == 0); slogger.debug("Replicating token_metadata to all cores"); std::exception_ptr ex; - std::vector pending_token_metadata_ptr; + std::vector pending_token_metadata_ptr; pending_token_metadata_ptr.resize(smp::count); std::vector> pending_effective_replication_maps; pending_effective_replication_maps.resize(smp::count); @@ -4339,7 +4334,7 @@ future<> storage_service::replicate_to_all_cores(mutable_token_metadata2_ptr tmp pending_token_metadata_ptr[base_shard] = tmptr; // clone a local copy of updated token_metadata on all other shards co_await smp::invoke_on_others(base_shard, [&, tmptr] () -> future<> { - pending_token_metadata_ptr[this_shard_id()] = make_token_metadata2_ptr(co_await tmptr->clone_async()); + pending_token_metadata_ptr[this_shard_id()] = make_token_metadata_ptr(co_await tmptr->clone_async()); }); // Precalculate new effective_replication_map for all keyspaces @@ -5496,7 +5491,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad slogger.warn("{}", msg); throw std::runtime_error(msg); } - mutate_token_metadata([coordinator, &req, this] (mutable_token_metadata2_ptr tmptr) mutable { + mutate_token_metadata([coordinator, &req, this] (mutable_token_metadata_ptr tmptr) mutable { for (auto& node : req.leaving_nodes) { slogger.info("removenode[{}]: Added node={} as leaving node, coordinator={}", req.ops_uuid, node, coordinator); tmptr->add_leaving_endpoint(tmptr->get_host_id(node)); @@ -5504,7 +5499,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad return update_topology_change_info(tmptr, ::format("removenode {}", req.leaving_nodes)); }).get(); node_ops_insert(ops_uuid, coordinator, std::move(req.ignore_nodes), [this, coordinator, req = std::move(req)] () mutable { - return mutate_token_metadata([this, coordinator, req = std::move(req)] (mutable_token_metadata2_ptr tmptr) mutable { + return mutate_token_metadata([this, coordinator, req = std::move(req)] (mutable_token_metadata_ptr tmptr) mutable { for (auto& node : req.leaving_nodes) { slogger.info("removenode[{}]: Removed node={} as leaving node, coordinator={}", req.ops_uuid, node, coordinator); tmptr->del_leaving_endpoint(tmptr->get_host_id(node)); @@ -5544,7 +5539,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad slogger.warn("{}", msg); throw std::runtime_error(msg); } - mutate_token_metadata([coordinator, &req, this] (mutable_token_metadata2_ptr tmptr) mutable { + mutate_token_metadata([coordinator, &req, this] (mutable_token_metadata_ptr tmptr) mutable { for (auto& node : req.leaving_nodes) { slogger.info("decommission[{}]: Added node={} as leaving node, coordinator={}", req.ops_uuid, node, coordinator); tmptr->add_leaving_endpoint(tmptr->get_host_id(node)); @@ -5552,7 +5547,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad return update_topology_change_info(tmptr, ::format("decommission {}", req.leaving_nodes)); }).get(); node_ops_insert(ops_uuid, coordinator, std::move(req.ignore_nodes), [this, coordinator, req = std::move(req)] () mutable { - return mutate_token_metadata([this, coordinator, req = std::move(req)] (mutable_token_metadata2_ptr tmptr) mutable { + return mutate_token_metadata([this, coordinator, req = std::move(req)] (mutable_token_metadata_ptr tmptr) mutable { for (auto& node : req.leaving_nodes) { slogger.info("decommission[{}]: Removed node={} as leaving node, coordinator={}", req.ops_uuid, node, coordinator); tmptr->del_leaving_endpoint(tmptr->get_host_id(node)); @@ -5605,7 +5600,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad if (!coordinator_host_id) { throw std::runtime_error("Coordinator host_id not found"); } - mutate_token_metadata([coordinator, coordinator_host_id, &req, this] (mutable_token_metadata2_ptr tmptr) mutable { + mutate_token_metadata([coordinator, coordinator_host_id, &req, this] (mutable_token_metadata_ptr tmptr) mutable { for (auto& x: req.replace_nodes) { auto existing_node = x.first; auto replacing_node = x.second; @@ -5631,7 +5626,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad return make_ready_future<>(); }).get(); node_ops_insert(ops_uuid, coordinator, std::move(req.ignore_nodes), [this, coordinator, coordinator_host_id, req = std::move(req)] () mutable { - return mutate_token_metadata([this, coordinator, coordinator_host_id, req = std::move(req)] (mutable_token_metadata2_ptr tmptr) mutable { + return mutate_token_metadata([this, coordinator, coordinator_host_id, req = std::move(req)] (mutable_token_metadata_ptr tmptr) mutable { for (auto& x: req.replace_nodes) { auto existing_node = x.first; auto replacing_node = x.second; @@ -5682,7 +5677,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad if (!coordinator_host_id) { throw std::runtime_error("Coordinator host_id not found"); } - mutate_token_metadata([coordinator, coordinator_host_id, &req, this] (mutable_token_metadata2_ptr tmptr) mutable { + mutate_token_metadata([coordinator, coordinator_host_id, &req, this] (mutable_token_metadata_ptr tmptr) mutable { for (auto& x: req.bootstrap_nodes) { auto& endpoint = x.first; auto tokens = std::unordered_set(x.second.begin(), x.second.end()); @@ -5697,7 +5692,7 @@ future storage_service::node_ops_cmd_handler(gms::inet_ad return update_topology_change_info(tmptr, ::format("bootstrap {}", req.bootstrap_nodes)); }).get(); node_ops_insert(ops_uuid, coordinator, std::move(req.ignore_nodes), [this, coordinator, req = std::move(req)] () mutable { - return mutate_token_metadata([this, coordinator, req = std::move(req)] (mutable_token_metadata2_ptr tmptr) mutable { + return mutate_token_metadata([this, coordinator, req = std::move(req)] (mutable_token_metadata_ptr tmptr) mutable { for (auto& x: req.bootstrap_nodes) { auto& endpoint = x.first; auto tokens = std::unordered_set(x.second.begin(), x.second.end()); @@ -5914,12 +5909,12 @@ storage_service::get_changed_ranges_for_leaving(locator::vnode_effective_replica co_await coroutine::maybe_yield(); } - auto temp = locator::make_token_metadata2_ptr(co_await get_token_metadata_ptr()->clone_after_all_left()); + auto temp = co_await get_token_metadata_ptr()->clone_after_all_left(); // endpoint might or might not be 'leaving'. If it was not leaving (that is, removenode // command was used), it is still present in temp and must be removed. - if (const auto host_id = temp->get_host_id_if_known(endpoint); host_id && temp->is_normal_token_owner(*host_id)) { - temp->remove_endpoint(*host_id); + if (const auto host_id = temp.get_host_id_if_known(endpoint); host_id && temp.is_normal_token_owner(*host_id)) { + temp.remove_endpoint(*host_id); } std::unordered_multimap changed_ranges; @@ -5960,7 +5955,7 @@ storage_service::get_changed_ranges_for_leaving(locator::vnode_effective_replica // E.g. everywhere_replication_strategy co_await coroutine::maybe_yield(); } - co_await temp->clear_gently(); + co_await temp.clear_gently(); co_return changed_ranges; } @@ -6080,7 +6075,7 @@ future<> storage_service::excise(std::unordered_set tokens, inet_address future<> storage_service::leave_ring() { co_await _cdc_gens.local().leave_ring(); co_await _sys_ks.local().set_bootstrap_state(db::system_keyspace::bootstrap_state::NEEDS_BOOTSTRAP); - co_await mutate_token_metadata([this] (mutable_token_metadata2_ptr tmptr) { + co_await mutate_token_metadata([this] (mutable_token_metadata_ptr tmptr) { auto endpoint = get_broadcast_address(); const auto my_id = tmptr->get_my_id(); tmptr->remove_endpoint(my_id); @@ -6242,7 +6237,7 @@ future storage_service::get_token_metadata_lock() // db::schema_tables::do_merge_schema. // // Note: must be called on shard 0. -future<> storage_service::mutate_token_metadata(std::function (mutable_token_metadata2_ptr)> func, acquire_merge_lock acquire_merge_lock) noexcept { +future<> storage_service::mutate_token_metadata(std::function (mutable_token_metadata_ptr)> func, acquire_merge_lock acquire_merge_lock) noexcept { assert(this_shard_id() == 0); std::optional tmlock; @@ -6254,7 +6249,7 @@ future<> storage_service::mutate_token_metadata(std::function (mutable_ co_await replicate_to_all_cores(std::move(tmptr)); } -future<> storage_service::update_topology_change_info(mutable_token_metadata2_ptr tmptr, sstring reason) { +future<> storage_service::update_topology_change_info(mutable_token_metadata_ptr tmptr, sstring reason) { assert(this_shard_id() == 0); try { @@ -6282,7 +6277,7 @@ future<> storage_service::update_topology_change_info(mutable_token_metadata2_pt } future<> storage_service::update_topology_change_info(sstring reason, acquire_merge_lock acquire_merge_lock) { - return mutate_token_metadata([this, reason = std::move(reason)] (mutable_token_metadata2_ptr tmptr) mutable { + return mutate_token_metadata([this, reason = std::move(reason)] (mutable_token_metadata_ptr tmptr) mutable { return update_topology_change_info(std::move(tmptr), std::move(reason)); }, acquire_merge_lock); } @@ -6324,7 +6319,7 @@ future<> storage_service::load_tablet_metadata() { future<> storage_service::snitch_reconfigured() { assert(this_shard_id() == 0); auto& snitch = _snitch.local(); - co_await mutate_token_metadata([&snitch] (mutable_token_metadata2_ptr tmptr) -> future<> { + co_await mutate_token_metadata([&snitch] (mutable_token_metadata_ptr tmptr) -> future<> { // re-read local rack and DC info tmptr->update_topology(tmptr->get_my_id(), snitch->get_location()); return make_ready_future<>(); diff --git a/service/storage_service.hh b/service/storage_service.hh index 6f9d739e5c..5d21f241e6 100644 --- a/service/storage_service.hh +++ b/service/storage_service.hh @@ -113,12 +113,9 @@ private: using endpoint_details = dht::endpoint_details; using boot_strapper = dht::boot_strapper; using token_metadata = locator::token_metadata; - using token_metadata2 = locator::token_metadata2; using shared_token_metadata = locator::shared_token_metadata; using token_metadata_ptr = locator::token_metadata_ptr; - using token_metadata2_ptr = locator::token_metadata2_ptr; using mutable_token_metadata_ptr = locator::mutable_token_metadata_ptr; - using mutable_token_metadata2_ptr = locator::mutable_token_metadata2_ptr; using token_metadata_lock = locator::token_metadata_lock; using application_state = gms::application_state; using inet_address = gms::inet_address; @@ -214,24 +211,24 @@ private: // db::schema_tables::do_merge_schema. // // Note: must be called on shard 0. - future<> mutate_token_metadata(std::function (mutable_token_metadata2_ptr)> func, acquire_merge_lock aml = acquire_merge_lock::yes) noexcept; + future<> mutate_token_metadata(std::function (mutable_token_metadata_ptr)> func, acquire_merge_lock aml = acquire_merge_lock::yes) noexcept; // Update pending ranges locally and then replicate to all cores. // Should be serialized under token_metadata_lock. // Must be called on shard 0. - future<> update_topology_change_info(mutable_token_metadata2_ptr tmptr, sstring reason); + future<> update_topology_change_info(mutable_token_metadata_ptr tmptr, sstring reason); future<> update_topology_change_info(sstring reason, acquire_merge_lock aml = acquire_merge_lock::yes); future<> keyspace_changed(const sstring& ks_name); void register_metrics(); future<> snitch_reconfigured(); - future get_mutable_token_metadata_ptr() noexcept { - return _shared_token_metadata.get()->clone_async().then([] (token_metadata2 tm) { + future get_mutable_token_metadata_ptr() noexcept { + return _shared_token_metadata.get()->clone_async().then([] (token_metadata tm) { // bump the token_metadata ring_version // to invalidate cached token/replication mappings // when the modified token_metadata is committed. tm.invalidate_cached_rings(); - return make_ready_future(make_token_metadata2_ptr(std::move(tm))); + return make_ready_future(make_token_metadata_ptr(std::move(tm))); }); } @@ -258,11 +255,11 @@ public: return _erm_factory; } - token_metadata2_ptr get_token_metadata_ptr() const noexcept { + token_metadata_ptr get_token_metadata_ptr() const noexcept { return _shared_token_metadata.get(); } - const locator::token_metadata2& get_token_metadata() const noexcept { + const locator::token_metadata& get_token_metadata() const noexcept { return *_shared_token_metadata.get(); } @@ -328,7 +325,7 @@ private: public: - static std::unordered_set parse_node_list(sstring comma_separated_list, const locator::token_metadata2& tm); + static std::unordered_set parse_node_list(sstring comma_separated_list, const locator::token_metadata& tm); future<> check_for_endpoint_collision(std::unordered_set initial_contact_nodes, const std::unordered_map& loaded_peer_features); @@ -480,7 +477,7 @@ private: std::optional get_dc_rack_for(inet_address endpoint); private: // Should be serialized under token_metadata_lock. - future<> replicate_to_all_cores(mutable_token_metadata2_ptr tmptr) noexcept; + future<> replicate_to_all_cores(mutable_token_metadata_ptr tmptr) noexcept; sharded& _sys_ks; sharded& _sys_dist_ks; locator::snitch_signal_slot_t _snitch_reconfigure; diff --git a/service/tablet_allocator.cc b/service/tablet_allocator.cc index e66f9127c9..b29e825ede 100644 --- a/service/tablet_allocator.cc +++ b/service/tablet_allocator.cc @@ -199,7 +199,7 @@ class load_balancer { std::optional target_load_sketch; - future get_load_sketch(const token_metadata2_ptr& tm) { + future get_load_sketch(const token_metadata_ptr& tm) { if (!target_load_sketch) { target_load_sketch.emplace(tm); co_await target_load_sketch->populate(id); @@ -255,7 +255,7 @@ class load_balancer { const size_t max_write_streaming_load = 2; const size_t max_read_streaming_load = 4; - token_metadata2_ptr _tm; + token_metadata_ptr _tm; load_balancer_stats_manager& _stats; private: tablet_replica_set get_replicas_for_tablet_load(const tablet_info& ti, const tablet_transition_info* trinfo) const { @@ -290,7 +290,7 @@ private: } public: - load_balancer(token_metadata2_ptr tm, load_balancer_stats_manager& stats) + load_balancer(token_metadata_ptr tm, load_balancer_stats_manager& stats) : _tm(std::move(tm)) , _stats(stats) { } @@ -819,7 +819,7 @@ public: _stopped = true; } - future balance_tablets(token_metadata2_ptr tm) { + future balance_tablets(token_metadata_ptr tm) { load_balancer lb(tm, _load_balancer_stats); co_return co_await lb.make_plan(); } @@ -869,7 +869,7 @@ future<> tablet_allocator::stop() { return impl().stop(); } -future tablet_allocator::balance_tablets(locator::token_metadata2_ptr tm) { +future tablet_allocator::balance_tablets(locator::token_metadata_ptr tm) { return impl().balance_tablets(tm); } diff --git a/service/tablet_allocator.hh b/service/tablet_allocator.hh index 3b90e6d208..4402f40cb1 100644 --- a/service/tablet_allocator.hh +++ b/service/tablet_allocator.hh @@ -90,7 +90,7 @@ public: /// /// The algorithm takes care of limiting the streaming load on the system, also by taking active migrations into account. /// - future balance_tablets(locator::token_metadata2_ptr); + future balance_tablets(locator::token_metadata_ptr); /// Should be called when the node is no longer a leader. void on_leadership_lost(); diff --git a/test/boost/locator_topology_test.cc b/test/boost/locator_topology_test.cc index d6a2a9bc1f..65065087e4 100644 --- a/test/boost/locator_topology_test.cc +++ b/test/boost/locator_topology_test.cc @@ -267,7 +267,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_sketch) { } }); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.update_host_id(host1, ip1); tm.update_host_id(host2, ip2); tm.update_host_id(host3, ip3); @@ -312,7 +312,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_sketch) { std::vector node3_shards(node3_shard_count, 0); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tablet_metadata tab_meta; tablet_map tmap(4); diff --git a/test/boost/network_topology_strategy_test.cc b/test/boost/network_topology_strategy_test.cc index c93ce2d00c..128d1078ff 100644 --- a/test/boost/network_topology_strategy_test.cc +++ b/test/boost/network_topology_strategy_test.cc @@ -72,7 +72,7 @@ static void check_ranges_are_sorted(vnode_effective_replication_map_ptr erm, gms void strategy_sanity_check( replication_strategy_ptr ars_ptr, - const token_metadata2_ptr& tm, + const token_metadata_ptr& tm, const std::map& options) { const network_topology_strategy* nts_ptr = @@ -95,7 +95,7 @@ void strategy_sanity_check( void endpoints_check( replication_strategy_ptr ars_ptr, - const token_metadata2_ptr& tm, + const token_metadata_ptr& tm, const inet_address_vector_replica_set& endpoints, const locator::topology& topo) { @@ -156,7 +156,7 @@ auto d2t = [](double d) -> int64_t { void full_ring_check(const std::vector& ring_points, const std::map& options, replication_strategy_ptr ars_ptr, - locator::token_metadata2_ptr tmptr) { + locator::token_metadata_ptr tmptr) { auto& tm = *tmptr; const auto& topo = tm.get_topology(); strategy_sanity_check(ars_ptr, tmptr, options); @@ -190,7 +190,7 @@ void full_ring_check(const std::vector& ring_points, void full_ring_check(const tablet_map& tmap, const std::map& options, replication_strategy_ptr rs_ptr, - locator::token_metadata2_ptr tmptr) { + locator::token_metadata_ptr tmptr) { auto& tm = *tmptr; const auto& topo = tm.get_topology(); @@ -250,7 +250,7 @@ void simple_test() { }; // Initialize the token_metadata - stm.mutate_token_metadata([&] (token_metadata2& tm) -> future<> { + stm.mutate_token_metadata([&] (token_metadata& tm) -> future<> { auto& topo = tm.get_topology(); for (const auto& [ring_point, endpoint, id] : ring_points) { std::unordered_set tokens; @@ -292,7 +292,7 @@ void simple_test() { // points will be taken from the cache when it shouldn't and the // corresponding check will fail. // - stm.mutate_token_metadata([] (token_metadata2& tm) { + stm.mutate_token_metadata([] (token_metadata& tm) { tm.invalidate_cached_rings(); return make_ready_future<>(); }).get(); @@ -357,7 +357,7 @@ void heavy_origin_test() { } } - stm.mutate_token_metadata([&] (token_metadata2& tm) -> future<> { + stm.mutate_token_metadata([&] (token_metadata& tm) -> future<> { auto& topo = tm.get_topology(); for (const auto& [ring_point, endpoint, id] : ring_points) { topo.add_node(id, endpoint, make_endpoint_dc_rack(endpoint), locator::node::state::normal); @@ -413,7 +413,7 @@ SEASTAR_THREAD_TEST_CASE(NetworkTopologyStrategy_tablets_test) { }; // Initialize the token_metadata - stm.mutate_token_metadata([&] (token_metadata2& tm) -> future<> { + stm.mutate_token_metadata([&] (token_metadata& tm) -> future<> { auto& topo = tm.get_topology(); for (const auto& [ring_point, endpoint, id] : ring_points) { std::unordered_set tokens; @@ -524,7 +524,7 @@ static bool has_sufficient_replicas( } static locator::host_id_set calculate_natural_endpoints( - const token& search_token, const token_metadata2& tm, + const token& search_token, const token_metadata& tm, const locator::topology& topo, const std::unordered_map& datacenters) { // @@ -650,7 +650,7 @@ static void test_equivalence(const shared_token_metadata& stm, const locator::to return std::make_pair(p.first, to_sstring(p.second)); }))); - const token_metadata2& tm = *stm.get(); + const token_metadata& tm = *stm.get(); for (size_t i = 0; i < 1000; ++i) { auto token = dht::token::get_random_token(); auto expected = calculate_natural_endpoints(token, tm, topo, datacenters); @@ -737,7 +737,7 @@ SEASTAR_THREAD_TEST_CASE(testCalculateEndpoints) { } } - stm.mutate_token_metadata([&] (token_metadata2& tm) -> future<> { + stm.mutate_token_metadata([&] (token_metadata& tm) -> future<> { generate_topology(tm.get_topology(), datacenters, nodes); for (auto&& i : endpoint_tokens) { co_await tm.update_normal_tokens(std::move(i.second), i.first); @@ -835,7 +835,7 @@ SEASTAR_THREAD_TEST_CASE(test_topology_compare_endpoints) { semaphore sem(1); shared_token_metadata stm([&sem] () noexcept { return get_units(sem, 1); }, tm_cfg); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { auto& topo = tm.get_topology(); generate_topology(topo, datacenters, nodes); @@ -882,7 +882,7 @@ SEASTAR_THREAD_TEST_CASE(test_topology_tracks_local_node) { BOOST_REQUIRE(stm.get()->get_topology().get_location() == ip1_dc_rack); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.update_host_id(host2, ip2); tm.update_host_id(host1, ip1); // this_node added last on purpose return make_ready_future<>(); @@ -905,7 +905,7 @@ SEASTAR_THREAD_TEST_CASE(test_topology_tracks_local_node) { // Removing local node - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.remove_endpoint(host1); tm.update_host_id(host3, ip3); return make_ready_future<>(); @@ -918,7 +918,7 @@ SEASTAR_THREAD_TEST_CASE(test_topology_tracks_local_node) { // Removing node with no local node - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.remove_endpoint(host2); return make_ready_future<>(); }).get(); @@ -930,7 +930,7 @@ SEASTAR_THREAD_TEST_CASE(test_topology_tracks_local_node) { // Repopulate after clear_gently() - stm.mutate_token_metadata([&] (token_metadata2& tm) -> future<> { + stm.mutate_token_metadata([&] (token_metadata& tm) -> future<> { co_await tm.clear_gently(); tm.update_host_id(host2, ip2); tm.update_host_id(host1, ip1); // this_node added last on purpose @@ -953,7 +953,7 @@ SEASTAR_THREAD_TEST_CASE(test_topology_tracks_local_node) { // get_location() should pick up endpoint_dc_rack from node info - stm.mutate_token_metadata([&] (token_metadata2& tm) -> future<> { + stm.mutate_token_metadata([&] (token_metadata& tm) -> future<> { co_await tm.clear_gently(); tm.get_topology().add_or_update_endpoint(ip1, host1, ip1_dc_rack_v2, node::state::being_decommissioned); }).get(); diff --git a/test/boost/storage_proxy_test.cc b/test/boost/storage_proxy_test.cc index d0d2bb94ad..0006d7604c 100644 --- a/test/boost/storage_proxy_test.cc +++ b/test/boost/storage_proxy_test.cc @@ -41,7 +41,7 @@ SEASTAR_TEST_CASE(test_get_restricted_ranges) { std::vector ring = make_ring(s, 10); - auto check = [&s](locator::token_metadata2_ptr tmptr, dht::partition_range input, + auto check = [&s](locator::token_metadata_ptr tmptr, dht::partition_range input, dht::partition_range_vector expected) { query_ranges_to_vnodes_generator ranges_to_vnodes(locator::make_splitter(tmptr), s, {input}); auto actual = ranges_to_vnodes(1000); @@ -54,7 +54,7 @@ SEASTAR_TEST_CASE(test_get_restricted_ranges) { { // Ring with minimum token - auto tmptr = locator::make_token_metadata2_ptr(locator::token_metadata::config{}); + auto tmptr = locator::make_token_metadata_ptr(locator::token_metadata::config{}); const auto host_id = locator::host_id{utils::UUID(0, 1)}; tmptr->update_topology(host_id, locator::endpoint_dc_rack{"dc1", "rack1"}); tmptr->update_normal_tokens(std::unordered_set({dht::minimum_token()}), host_id).get(); @@ -69,7 +69,7 @@ SEASTAR_TEST_CASE(test_get_restricted_ranges) { } { - auto tmptr = locator::make_token_metadata2_ptr(locator::token_metadata::config{}); + auto tmptr = locator::make_token_metadata_ptr(locator::token_metadata::config{}); const auto id1 = locator::host_id{utils::UUID(0, 1)}; const auto id2 = locator::host_id{utils::UUID(0, 2)}; tmptr->update_topology(id1, locator::endpoint_dc_rack{"dc1", "rack1"}); diff --git a/test/boost/tablets_test.cc b/test/boost/tablets_test.cc index ba56ce3a68..6537e204dd 100644 --- a/test/boost/tablets_test.cc +++ b/test/boost/tablets_test.cc @@ -433,7 +433,7 @@ SEASTAR_TEST_CASE(test_sharder) { auto table1 = table_id(utils::UUID_gen::get_time_UUID()); - token_metadata2 tokm(token_metadata::config{ .topo_cfg{ .this_host_id = h1 } }); + token_metadata tokm(token_metadata::config{ .topo_cfg{ .this_host_id = h1 } }); tokm.get_topology().add_or_update_endpoint(tokm.get_topology().my_address(), h1); std::vector tablet_ids; @@ -591,7 +591,7 @@ SEASTAR_THREAD_TEST_CASE(test_token_ownership_splitting) { // Reflects the plan in a given token metadata as if the migrations were fully executed. static -void apply_plan(token_metadata2& tm, const migration_plan& plan) { +void apply_plan(token_metadata& tm, const migration_plan& plan) { for (auto&& mig : plan.migrations()) { tablet_map& tmap = tm.tablets().get_tablet_map(mig.tablet.table); auto tinfo = tmap.get_tablet_info(mig.tablet.tablet); @@ -611,7 +611,7 @@ tablet_transition_info migration_to_transition_info(const tablet_migration_info& // Reflects the plan in a given token metadata as if the migrations were started but not yet executed. static -void apply_plan_as_in_progress(token_metadata2& tm, const migration_plan& plan) { +void apply_plan_as_in_progress(token_metadata& tm, const migration_plan& plan) { for (auto&& mig : plan.migrations()) { tablet_map& tmap = tm.tablets().get_tablet_map(mig.tablet.table); auto tinfo = tmap.get_tablet_info(mig.tablet.tablet); @@ -626,7 +626,7 @@ void rebalance_tablets(tablet_allocator& talloc, shared_token_metadata& stm) { if (plan.empty()) { break; } - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { apply_plan(tm, plan); return make_ready_future<>(); }).get(); @@ -640,7 +640,7 @@ void rebalance_tablets_as_in_progress(tablet_allocator& talloc, shared_token_met if (plan.empty()) { break; } - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { apply_plan_as_in_progress(tm, plan); return make_ready_future<>(); }).get(); @@ -650,7 +650,7 @@ void rebalance_tablets_as_in_progress(tablet_allocator& talloc, shared_token_met // Completes any in progress tablet migrations. static void execute_transitions(shared_token_metadata& stm) { - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { for (auto&& [tablet, tmap_] : tm.tablets().all_tables()) { auto& tmap = tmap_; for (auto&& [tablet, trinfo]: tmap.transitions()) { @@ -689,7 +689,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_balancing_with_empty_node) { } }); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.update_host_id(host1, ip1); tm.update_host_id(host2, ip2); tm.update_host_id(host3, ip3); @@ -783,7 +783,7 @@ SEASTAR_THREAD_TEST_CASE(test_decommission_rf_met) { } }); - stm.mutate_token_metadata([&](token_metadata2& tm) { + stm.mutate_token_metadata([&](token_metadata& tm) { const unsigned shard_count = 2; tm.update_host_id(host1, ip1); @@ -839,7 +839,7 @@ SEASTAR_THREAD_TEST_CASE(test_decommission_rf_met) { BOOST_REQUIRE(load.get_avg_shard_load(host3) == 0); } - stm.mutate_token_metadata([&](token_metadata2& tm) { + stm.mutate_token_metadata([&](token_metadata& tm) { tm.update_topology(host3, locator::endpoint_dc_rack::default_location, node::state::left); return make_ready_future<>(); }).get(); @@ -885,7 +885,7 @@ SEASTAR_THREAD_TEST_CASE(test_decommission_two_racks) { } }); - stm.mutate_token_metadata([&](token_metadata2& tm) { + stm.mutate_token_metadata([&](token_metadata& tm) { const unsigned shard_count = 1; tm.update_host_id(host1, ip1); @@ -986,7 +986,7 @@ SEASTAR_THREAD_TEST_CASE(test_decommission_rack_load_failure) { } }); - stm.mutate_token_metadata([&](token_metadata2& tm) { + stm.mutate_token_metadata([&](token_metadata& tm) { const unsigned shard_count = 1; tm.update_host_id(host1, ip1); @@ -1060,7 +1060,7 @@ SEASTAR_THREAD_TEST_CASE(test_decommission_rf_not_met) { } }); - stm.mutate_token_metadata([&](token_metadata2& tm) { + stm.mutate_token_metadata([&](token_metadata& tm) { const unsigned shard_count = 2; tm.update_host_id(host1, ip1); @@ -1117,7 +1117,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_balancing_works_with_in_progress_transitions) } }); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.update_host_id(host1, ip1); tm.update_host_id(host2, ip2); tm.update_host_id(host3, ip3); @@ -1186,7 +1186,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_balancer_shuffle_mode) { } }); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.update_host_id(host1, ip1); tm.update_host_id(host2, ip2); tm.update_host_id(host3, ip3); @@ -1249,7 +1249,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_balancing_with_two_empty_nodes) { } }); - stm.mutate_token_metadata([&] (token_metadata2& tm) { + stm.mutate_token_metadata([&] (token_metadata& tm) { tm.update_host_id(host1, ip1); tm.update_host_id(host2, ip2); tm.update_host_id(host3, ip3); @@ -1405,7 +1405,7 @@ SEASTAR_THREAD_TEST_CASE(test_load_balancing_with_random_load) { }); size_t total_tablet_count = 0; - stm.mutate_token_metadata([&](token_metadata2& tm) { + stm.mutate_token_metadata([&](token_metadata& tm) { tablet_metadata tmeta; int i = 0; diff --git a/test/boost/token_metadata_test.cc b/test/boost/token_metadata_test.cc index 5f5454abf1..d7e497f4a2 100644 --- a/test/boost/token_metadata_test.cc +++ b/test/boost/token_metadata_test.cc @@ -28,8 +28,8 @@ namespace { }; } - mutable_token_metadata2_ptr create_token_metadata(host_id this_host_id) { - return make_lw_shared(token_metadata::config { + mutable_token_metadata_ptr create_token_metadata(host_id this_host_id) { + return make_lw_shared(token_metadata::config { topology::config { .this_host_id = this_host_id, .local_dc_rack = get_dc_rack(this_host_id) @@ -38,7 +38,7 @@ namespace { } template - mutable_vnode_erm_ptr create_erm(mutable_token_metadata2_ptr tmptr, replication_strategy_config_options opts = {}) { + mutable_vnode_erm_ptr create_erm(mutable_token_metadata_ptr tmptr, replication_strategy_config_options opts = {}) { dc_rack_fn get_dc_rack_fn = get_dc_rack; tmptr->update_topology_change_info(get_dc_rack_fn).get(); auto strategy = seastar::make_shared(std::move(opts)); diff --git a/test/lib/cql_test_env.cc b/test/lib/cql_test_env.cc index 13f3038796..fe6709eb4d 100644 --- a/test/lib/cql_test_env.cc +++ b/test/lib/cql_test_env.cc @@ -640,7 +640,7 @@ private: host_id = linfo.host_id; _sys_ks.local().save_local_info(std::move(linfo), _snitch.local()->get_location(), my_address, my_address).get(); } - locator::shared_token_metadata::mutate_on_all_shards(_token_metadata, [hostid = host_id, &cfg_in] (locator::token_metadata2& tm) { + locator::shared_token_metadata::mutate_on_all_shards(_token_metadata, [hostid = host_id, &cfg_in] (locator::token_metadata& tm) { auto& topo = tm.get_topology(); topo.set_host_id_cfg(hostid); topo.add_or_update_endpoint(cfg_in.broadcast_address,