From 5d9bcb45de8c8d71bd24ed857edcbbdd649ec498 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 23 Mar 2023 00:59:36 +0100 Subject: [PATCH] treewide: Use replication_strategy_ptr as a shorter name for abstract_replication_strategy::ptr_type --- locator/abstract_replication_strategy.cc | 8 ++++---- locator/abstract_replication_strategy.hh | 17 ++++++++++------- replica/database.hh | 4 ++-- test/boost/network_topology_strategy_test.cc | 14 +++++++------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/locator/abstract_replication_strategy.cc b/locator/abstract_replication_strategy.cc index 63c5b2dcc3..4b35583483 100644 --- a/locator/abstract_replication_strategy.cc +++ b/locator/abstract_replication_strategy.cc @@ -303,7 +303,7 @@ abstract_replication_strategy::get_pending_address_ranges(const token_metadata_p co_return ret; } -future calculate_effective_replication_map(abstract_replication_strategy::ptr_type rs, token_metadata_ptr tmptr) { +future calculate_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr) { replication_map replication_map; const auto& sorted_tokens = tmptr->sorted_tokens(); @@ -368,7 +368,7 @@ vnode_effective_replication_map::~vnode_effective_replication_map() { } } -effective_replication_map::effective_replication_map(abstract_replication_strategy::ptr_type rs, +effective_replication_map::effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr, size_t replication_factor) noexcept : _rs(std::move(rs)) @@ -376,11 +376,11 @@ effective_replication_map::effective_replication_map(abstract_replication_strate , _replication_factor(replication_factor) { } -vnode_effective_replication_map::factory_key vnode_effective_replication_map::make_factory_key(const abstract_replication_strategy::ptr_type& rs, const token_metadata_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(abstract_replication_strategy::ptr_type rs, token_metadata_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 4d862a815f..090fd89f7e 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -128,6 +128,9 @@ public: future get_pending_address_ranges(const token_metadata_ptr tmptr, std::unordered_set pending_tokens, inet_address pending_address, locator::endpoint_dc_rack dr) const; }; +using replication_strategy_ptr = seastar::shared_ptr; +using mutable_replication_strategy_ptr = seastar::shared_ptr; + /// \brief Represents effective replication (assignment of replicas to keys). /// /// It's a result of application of a given replication strategy instance @@ -140,11 +143,11 @@ public: /// keeping the token metadata version alive and seen as in use. class effective_replication_map { protected: - abstract_replication_strategy::ptr_type _rs; + replication_strategy_ptr _rs; token_metadata_ptr _tmptr; size_t _replication_factor; public: - effective_replication_map(abstract_replication_strategy::ptr_type, token_metadata_ptr, size_t replication_factor) noexcept; + effective_replication_map(replication_strategy_ptr, token_metadata_ptr, size_t replication_factor) noexcept; virtual ~effective_replication_map() = default; const abstract_replication_strategy& get_replication_strategy() const noexcept { return *_rs; } @@ -213,7 +216,7 @@ public: // effective_replication_map inet_address_vector_replica_set get_natural_endpoints_without_node_being_replaced(const token& search_token) const override; inet_address_vector_topology_change get_pending_endpoints(const token& search_token, const sstring& ks_name) const override; public: - explicit vnode_effective_replication_map(abstract_replication_strategy::ptr_type rs, token_metadata_ptr tmptr, replication_map replication_map, size_t replication_factor) noexcept + explicit vnode_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr, replication_map replication_map, size_t replication_factor) noexcept : effective_replication_map(std::move(rs), std::move(tmptr), replication_factor) , _replication_map(std::move(replication_map)) { } @@ -263,7 +266,7 @@ private: dht::token_range_vector do_get_ranges(noncopyable_function consider_range_for_endpoint) const; public: - static factory_key make_factory_key(const abstract_replication_strategy::ptr_type& rs, const token_metadata_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; @@ -288,13 +291,13 @@ using mutable_vnode_effective_replication_map_ptr = shared_ptr( std::move(rs), std::move(tmptr), std::move(replication_map), replication_factor); } // Apply the replication strategy over the current configuration and the given token_metadata. -future calculate_effective_replication_map(abstract_replication_strategy::ptr_type rs, token_metadata_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 @@ -395,7 +398,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(abstract_replication_strategy::ptr_type rs, token_metadata_ptr tmptr); + future create_effective_replication_map(replication_strategy_ptr rs, token_metadata_ptr tmptr); future<> stop() noexcept; diff --git a/replica/database.hh b/replica/database.hh index 9284712599..1c7359edb8 100644 --- a/replica/database.hh +++ b/replica/database.hh @@ -1163,7 +1163,7 @@ public: size_t view_update_concurrency_semaphore_limit; }; private: - locator::abstract_replication_strategy::ptr_type _replication_strategy; + locator::replication_strategy_ptr _replication_strategy; locator::vnode_effective_replication_map_ptr _effective_replication_map; lw_shared_ptr _metadata; config _config; @@ -1200,7 +1200,7 @@ public: * should eventually be refactored. */ const locator::abstract_replication_strategy& get_replication_strategy() const; - locator::abstract_replication_strategy::ptr_type get_replication_strategy_ptr() const { + locator::replication_strategy_ptr get_replication_strategy_ptr() const { return _replication_strategy; } diff --git a/test/boost/network_topology_strategy_test.cc b/test/boost/network_topology_strategy_test.cc index 1190e6b9d2..ffdf8098c8 100644 --- a/test/boost/network_topology_strategy_test.cc +++ b/test/boost/network_topology_strategy_test.cc @@ -71,12 +71,12 @@ static void check_ranges_are_sorted(vnode_effective_replication_map_ptr erm, gms } void strategy_sanity_check( - abstract_replication_strategy::ptr_type ars_ptr, + replication_strategy_ptr ars_ptr, const token_metadata& tm, const std::map& options) { - network_topology_strategy* nts_ptr = - dynamic_cast(ars_ptr.get()); + const network_topology_strategy* nts_ptr = + dynamic_cast(ars_ptr.get()); // // Check that both total and per-DC RFs in options match the corresponding @@ -94,7 +94,7 @@ void strategy_sanity_check( } void endpoints_check( - abstract_replication_strategy::ptr_type ars_ptr, + replication_strategy_ptr ars_ptr, const token_metadata& tm, inet_address_vector_replica_set& endpoints, const locator::topology& topo) { @@ -119,8 +119,8 @@ void endpoints_check( } } - network_topology_strategy* nts_ptr = - dynamic_cast(ars_ptr.get()); + const network_topology_strategy* nts_ptr = + dynamic_cast(ars_ptr.get()); for (auto& rf : dc_rf) { BOOST_CHECK(rf.second == nts_ptr->get_replication_factor(rf.first)); } @@ -145,7 +145,7 @@ auto d2t = [](double d) -> int64_t { */ void full_ring_check(const std::vector& ring_points, const std::map& options, - abstract_replication_strategy::ptr_type ars_ptr, + replication_strategy_ptr ars_ptr, locator::token_metadata_ptr tmptr) { auto& tm = *tmptr; const auto& topo = tm.get_topology();