From 41973c5bf79b4c1a4a6c4bc2709810f5aba93501 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 30 Aug 2022 12:33:13 +0300 Subject: [PATCH] topology: Add "enable proximity sorting" bit There's one corner case in nodes sorting by snitch. The simple snitch code overloads the call and doesn't sort anything. The same behavior should be preserved by (future) topology implementation, but it doesn't know the snitch name. To address that the patch adds a boolean switch on topology that's turned off by main code when it sees the snitch is "simple" one. Signed-off-by: Pavel Emelyanov --- locator/simple_snitch.hh | 13 ------------- locator/token_metadata.hh | 6 ++++++ main.cc | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/locator/simple_snitch.hh b/locator/simple_snitch.hh index edb926dc55..0fabdb7a7c 100644 --- a/locator/simple_snitch.hh +++ b/locator/simple_snitch.hh @@ -44,19 +44,6 @@ struct simple_snitch : public snitch_base { virtual int compare_endpoints(inet_address& target, inet_address& a1, inet_address& a2) override { - // - // "Making all endpoints equal ensures we won't change the original - // ordering." - quote from C* code. - // - // Effectively this would return 0 even in the following case: - // - // compare_endpoints(NodeA, NodeA, NodeB) // -1 should be returned - // - // The snitch_base implementation would handle the above case correctly. - // - // I'm leaving the this implementation anyway since it's the C*'s - // implementation and some installations may depend on it. - // return 0; } diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index c7096d2937..d9135b91fe 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -107,6 +107,10 @@ public: void sort_by_proximity(inet_address address, inet_address_vector_replica_set& addresses) const; + void disable_proximity_sorting() noexcept { + _sort_by_proximity = false; + } + private: /** multi-map: DC -> endpoints in that DC */ std::unordered_map current known dc/rack assignment */ std::unordered_map _current_locations; + + bool _sort_by_proximity = true; }; class token_metadata_impl; diff --git a/main.cc b/main.cc index 9d688c8da2..624106daa7 100644 --- a/main.cc +++ b/main.cc @@ -876,6 +876,27 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl // #293 - do not stop anything (unless snitch.on_all(start) fails) stop_snitch->cancel(); + if (snitch.local()->get_name() == "org.apache.cassandra.locator.SimpleSnitch") { + // + // Simple snitch wants sort_by_proximity() not to reorder nodes anyhow + // + // "Making all endpoints equal ensures we won't change the original + // ordering." - quote from C* code. + // + // The snitch_base implementation should handle the above case correctly. + // I'm leaving the this implementation anyway since it's the C*'s + // implementation and some installations may depend on it. + // + token_metadata.invoke_on_all([] (shared_token_metadata& tm) mutable { + const auto& topo = tm.get()->get_topology(); + // There's no real need in mutate_token_metadata here as it just + // sets a single boolean bit on topology object, this change is + // never ever performed again and by this point no code uses neither + // topology nor the token metadata itself + const_cast(topo).disable_proximity_sorting(); + }).get(); + } + static direct_fd_clock fd_clock; static sharded fd; supervisor::notify("starting direct failure detector service");