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 <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2022-08-30 12:33:13 +03:00
parent b6fdea9a79
commit 41973c5bf7
3 changed files with 27 additions and 13 deletions

View File

@@ -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;
}

View File

@@ -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<sstring,
@@ -121,6 +125,8 @@ private:
/** reverse-lookup map: endpoint -> current known dc/rack assignment */
std::unordered_map<inet_address, endpoint_dc_rack> _current_locations;
bool _sort_by_proximity = true;
};
class token_metadata_impl;

21
main.cc
View File

@@ -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<locator::topology&>(topo).disable_proximity_sorting();
}).get();
}
static direct_fd_clock fd_clock;
static sharded<direct_failure_detector::failure_detector> fd;
supervisor::notify("starting direct failure detector service");