From eb678e723b0056554dcfc49d605b732e45eb19ab Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Wed, 10 Aug 2022 23:09:49 +0300 Subject: [PATCH] abstract_replication_strategy: add has_uniform_natural_endpoints So that using calaculate_natural_endpoints can be optimized for strategies that return the same endpoints for all tokens, namely everywhere_replication_strategy and local_strategy. Signed-off-by: Benny Halevy --- locator/abstract_replication_strategy.hh | 4 ++++ locator/everywhere_replication_strategy.hh | 2 ++ locator/local_strategy.hh | 2 ++ 3 files changed, 8 insertions(+) diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index d2eb45d6a5..fdabc8e69c 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -78,6 +78,10 @@ public: const replication_strategy_config_options& config_options, replication_strategy_type my_type); + // Evaluates to true iff calculate_natural_endpoints + // returns different results for different tokens. + virtual bool natural_endpoints_depend_on_token() const noexcept { return true; } + // 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 // is small, that implementation may not yield since by itself it won't cause a reactor stall (assuming practical diff --git a/locator/everywhere_replication_strategy.hh b/locator/everywhere_replication_strategy.hh index cd80502071..d385453793 100644 --- a/locator/everywhere_replication_strategy.hh +++ b/locator/everywhere_replication_strategy.hh @@ -18,6 +18,8 @@ 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 override { /* noop */ } diff --git a/locator/local_strategy.hh b/locator/local_strategy.hh index 6f1bbb2654..5edfe4f024 100644 --- a/locator/local_strategy.hh +++ b/locator/local_strategy.hh @@ -27,6 +27,8 @@ 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 override;