snitch, code: Make get_datacenter() report local dc only

The continuation of the previous patch -- all the code uses
topology::get_datacenter(endpoint) to get peers' dc string. The topology
still uses snitch for that, but it already contains the needed data.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2022-08-25 16:46:08 +03:00
parent 6c6711404f
commit 4206b1f98f
14 changed files with 28 additions and 34 deletions

View File

@@ -37,14 +37,8 @@ sstring production_snitch_base::get_rack() {
return _my_rack;
}
sstring production_snitch_base::get_datacenter(inet_address endpoint) {
if (endpoint == utils::fb_utilities::get_broadcast_address()) {
return _my_dc;
}
return get_endpoint_info(endpoint,
gms::application_state::DC,
default_dc);
sstring production_snitch_base::get_datacenter() {
return _my_dc;
}
void production_snitch_base::set_backreference(snitch_ptr& d) {

View File

@@ -43,7 +43,7 @@ public:
explicit production_snitch_base(snitch_config);
virtual sstring get_rack() override;
virtual sstring get_datacenter(inet_address endpoint) override;
virtual sstring get_datacenter() override;
virtual void set_backreference(snitch_ptr& d) override;
private:

View File

@@ -25,7 +25,7 @@ using inet_address = gms::inet_address;
*/
struct rack_inferring_snitch : public snitch_base {
rack_inferring_snitch(const snitch_config& cfg) {
_my_dc = get_datacenter(utils::fb_utilities::get_broadcast_address());
_my_dc = get_datacenter();
_my_rack = get_rack();
// This snitch is ready on creation
@@ -37,7 +37,8 @@ struct rack_inferring_snitch : public snitch_base {
return std::to_string(uint8_t(endpoint.bytes()[2]));
}
virtual sstring get_datacenter(inet_address endpoint) override {
virtual sstring get_datacenter() override {
auto endpoint = utils::fb_utilities::get_broadcast_address();
return std::to_string(uint8_t(endpoint.bytes()[1]));
}

View File

@@ -22,7 +22,7 @@ namespace locator {
*/
struct simple_snitch : public snitch_base {
simple_snitch(const snitch_config& cfg) {
_my_dc = get_datacenter(utils::fb_utilities::get_broadcast_address());
_my_dc = get_datacenter();
_my_rack = get_rack();
// This snitch is ready on creation
@@ -33,7 +33,7 @@ struct simple_snitch : public snitch_base {
return "rack1";
}
virtual sstring get_datacenter(inet_address endpoint) override {
virtual sstring get_datacenter() override {
return "datacenter1";
}

View File

@@ -66,9 +66,9 @@ public:
virtual sstring get_rack() = 0;
/**
* returns a String representing the datacenter this endpoint belongs to
* returns a String representing the datacenter local node belongs to
*/
virtual sstring get_datacenter(inet_address endpoint) = 0;
virtual sstring get_datacenter() = 0;
/**
* returns whatever info snitch wants to gossip
@@ -299,7 +299,7 @@ public:
//
// Sons have to implement:
// virtual sstring get_rack() = 0;
// virtual sstring get_datacenter(inet_address endpoint) = 0;
// virtual sstring get_datacenter() = 0;
//
virtual std::list<std::pair<gms::application_state, gms::versioned_value>> get_app_states() const override;

View File

@@ -1351,7 +1351,7 @@ sstring topology::get_datacenter() const {
}
sstring topology::get_datacenter(inet_address ep) const {
return i_endpoint_snitch::get_local_snitch_ptr()->get_datacenter(ep);
return get_location(ep).dc;
}
void topology::sort_by_proximity(inet_address address, inet_address_vector_replica_set& addresses) const {