From 99ff1fefe54f765e64d1d638f1a99da4ea3634a9 Mon Sep 17 00:00:00 2001 From: Petr Gusev Date: Sat, 20 May 2023 20:04:35 +0400 Subject: [PATCH] abstract_replication_strategy.hh: de-virtualize natural_endpoints_depend_on_token We are going to use this function in vnode_erm::get_natural_endpoints, so for efficiency it's better to have fewer virtual calls. --- locator/abstract_replication_strategy.hh | 3 ++- locator/everywhere_replication_strategy.cc | 4 +++- locator/everywhere_replication_strategy.hh | 2 -- locator/local_strategy.cc | 4 +++- locator/local_strategy.hh | 2 -- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index 6a8a04c3f9..36b36e134d 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -67,6 +67,7 @@ protected: replication_strategy_type _my_type; bool _per_table = false; bool _uses_tablets = false; + bool _natural_endpoints_depend_on_token = true; template void err(const char* fmt, Args&&... args) const { @@ -92,7 +93,7 @@ public: // Evaluates to true iff calculate_natural_endpoints // returns different results for different tokens. - virtual bool natural_endpoints_depend_on_token() const noexcept { return true; } + bool natural_endpoints_depend_on_token() const noexcept { return _natural_endpoints_depend_on_token; } // The returned vector has size O(number of normal token owners), which is O(number of nodes in the cluster). // Note: it is not guaranteed that the function will actually yield. If the complexity of a particular implementation diff --git a/locator/everywhere_replication_strategy.cc b/locator/everywhere_replication_strategy.cc index 43126347c0..9e771eaad2 100644 --- a/locator/everywhere_replication_strategy.cc +++ b/locator/everywhere_replication_strategy.cc @@ -17,7 +17,9 @@ namespace locator { everywhere_replication_strategy::everywhere_replication_strategy(const replication_strategy_config_options& config_options) : - abstract_replication_strategy(config_options, replication_strategy_type::everywhere_topology) {} + abstract_replication_strategy(config_options, replication_strategy_type::everywhere_topology) { + _natural_endpoints_depend_on_token = false; +} future everywhere_replication_strategy::calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const { auto eps = tm.get_all_endpoints(); diff --git a/locator/everywhere_replication_strategy.hh b/locator/everywhere_replication_strategy.hh index a123efbfa1..94152415a4 100644 --- a/locator/everywhere_replication_strategy.hh +++ b/locator/everywhere_replication_strategy.hh @@ -18,8 +18,6 @@ class everywhere_replication_strategy : public abstract_replication_strategy { public: everywhere_replication_strategy(const replication_strategy_config_options& config_options); - virtual bool natural_endpoints_depend_on_token() const noexcept override { return false; } - 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 */ } diff --git a/locator/local_strategy.cc b/locator/local_strategy.cc index b3df8248b5..7fc8504d55 100644 --- a/locator/local_strategy.cc +++ b/locator/local_strategy.cc @@ -15,7 +15,9 @@ namespace locator { local_strategy::local_strategy(const replication_strategy_config_options& config_options) : - abstract_replication_strategy(config_options, replication_strategy_type::local) {} + abstract_replication_strategy(config_options, replication_strategy_type::local) { + _natural_endpoints_depend_on_token = false; +} future local_strategy::calculate_natural_endpoints(const token& t, const token_metadata& tm) const { return make_ready_future(endpoint_set({utils::fb_utilities::get_broadcast_address()})); diff --git a/locator/local_strategy.hh b/locator/local_strategy.hh index be4d2856b7..6e7009f5cb 100644 --- a/locator/local_strategy.hh +++ b/locator/local_strategy.hh @@ -27,8 +27,6 @@ public: virtual ~local_strategy() {}; virtual size_t get_replication_factor(const token_metadata&) const override; - virtual bool natural_endpoints_depend_on_token() const noexcept override { return false; } - 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;