From 1e2741d2feea1fdfed1c3f396e3e0e47b7924e61 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Sun, 13 Nov 2022 21:01:05 +0200 Subject: [PATCH] abstract_replication_strategy: recognized_options: return unordered_set An unordered_set is more efficient and there is no need to return an ordered set for this purpose. This change facilitates a follow-up change of adding topology::get_datacenters(), returning an unordered_set of datacenter names. Refs #11987 Signed-off-by: Benny Halevy Closes #12003 --- locator/abstract_replication_strategy.hh | 2 +- locator/everywhere_replication_strategy.hh | 2 +- locator/local_strategy.cc | 2 +- locator/local_strategy.hh | 2 +- locator/network_topology_strategy.cc | 4 ++-- locator/network_topology_strategy.hh | 2 +- locator/simple_strategy.cc | 2 +- locator/simple_strategy.hh | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index d6bfadac65..d4a4f306a2 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -101,7 +101,7 @@ public: virtual inet_address_vector_replica_set get_natural_endpoints(const token& search_token, const effective_replication_map& erm) const; virtual void validate_options() const = 0; - virtual std::optional> recognized_options(const topology&) const = 0; + virtual std::optional> recognized_options(const topology&) 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 diff --git a/locator/everywhere_replication_strategy.hh b/locator/everywhere_replication_strategy.hh index d385453793..f55ca21ddf 100644 --- a/locator/everywhere_replication_strategy.hh +++ b/locator/everywhere_replication_strategy.hh @@ -24,7 +24,7 @@ public: virtual void validate_options() const override { /* noop */ } - std::optional> recognized_options(const topology&) const override { + std::optional> recognized_options(const topology&) const override { // We explicitely allow all options return std::nullopt; } diff --git a/locator/local_strategy.cc b/locator/local_strategy.cc index cd09772d38..c580d13bee 100644 --- a/locator/local_strategy.cc +++ b/locator/local_strategy.cc @@ -24,7 +24,7 @@ future local_strategy::calculate_natural_endpoints(const token& t, void local_strategy::validate_options() const { } -std::optional> local_strategy::recognized_options(const topology&) const { +std::optional> local_strategy::recognized_options(const topology&) const { // LocalStrategy doesn't expect any options. return {}; } diff --git a/locator/local_strategy.hh b/locator/local_strategy.hh index 5edfe4f024..eafd8a875a 100644 --- a/locator/local_strategy.hh +++ b/locator/local_strategy.hh @@ -33,7 +33,7 @@ public: virtual void validate_options() const override; - virtual std::optional> recognized_options(const topology&) const override; + virtual std::optional> recognized_options(const topology&) const override; virtual bool allow_remove_node_being_replaced_from_natural_endpoints() const override { return false; diff --git a/locator/network_topology_strategy.cc b/locator/network_topology_strategy.cc index 3f42aeaab5..53b093c82a 100644 --- a/locator/network_topology_strategy.cc +++ b/locator/network_topology_strategy.cc @@ -266,8 +266,8 @@ void network_topology_strategy::validate_options() const { } } -std::optional> network_topology_strategy::recognized_options(const topology& topology) const { - std::set datacenters; +std::optional> network_topology_strategy::recognized_options(const topology& topology) const { + std::unordered_set datacenters; for (const auto& [dc_name, endpoints] : topology.get_datacenter_endpoints()) { datacenters.insert(dc_name); } diff --git a/locator/network_topology_strategy.hh b/locator/network_topology_strategy.hh index f0cb13431c..b811b805ec 100644 --- a/locator/network_topology_strategy.hh +++ b/locator/network_topology_strategy.hh @@ -49,7 +49,7 @@ protected: virtual void validate_options() const override; - virtual std::optional> recognized_options(const topology&) const override; + virtual std::optional> recognized_options(const topology&) const override; private: // map: data centers -> replication factor diff --git a/locator/simple_strategy.cc b/locator/simple_strategy.cc index 6d5644b853..f0c97b9898 100644 --- a/locator/simple_strategy.cc +++ b/locator/simple_strategy.cc @@ -75,7 +75,7 @@ void simple_strategy::validate_options() const { validate_replication_factor(it->second); } -std::optional>simple_strategy::recognized_options(const topology&) const { +std::optional>simple_strategy::recognized_options(const topology&) const { return {{ "replication_factor" }}; } diff --git a/locator/simple_strategy.hh b/locator/simple_strategy.hh index d6cd4e6c3c..d7f5584dab 100644 --- a/locator/simple_strategy.hh +++ b/locator/simple_strategy.hh @@ -21,7 +21,7 @@ public: virtual ~simple_strategy() {}; virtual size_t get_replication_factor(const token_metadata& tm) const override; virtual void validate_options() const override; - virtual std::optional> recognized_options(const topology&) 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; }