diff --git a/locator/topology.cc b/locator/topology.cc index 2398b844a1..8a76e068b8 100644 --- a/locator/topology.cc +++ b/locator/topology.cc @@ -137,27 +137,6 @@ const endpoint_dc_rack& topology::get_location(const inet_address& ep) const { return endpoint_dc_rack::default_location; } -// FIXME -- both methods below should rather return data from the -// get_location() result, but to make it work two things are to be fixed: -// - topology should be aware of internal-ip conversions -// - topology should be pre-populated with data loaded from system ks - -sstring topology::get_rack() const { - return get_rack(utils::fb_utilities::get_broadcast_address()); -} - -sstring topology::get_rack(inet_address ep) const { - return get_location(ep).rack; -} - -sstring topology::get_datacenter() const { - return get_datacenter(utils::fb_utilities::get_broadcast_address()); -} - -sstring topology::get_datacenter(inet_address ep) const { - return get_location(ep).dc; -} - void topology::sort_by_proximity(inet_address address, inet_address_vector_replica_set& addresses) const { if (_sort_by_proximity) { std::sort(addresses.begin(), addresses.end(), [this, &address](inet_address& a1, inet_address& a2) { diff --git a/locator/topology.hh b/locator/topology.hh index 9f315ca320..e38adda02b 100644 --- a/locator/topology.hh +++ b/locator/topology.hh @@ -20,6 +20,7 @@ #include "locator/types.hh" #include "inet_address_vectors.hh" +#include "utils/fb_utilities.hh" using namespace seastar; @@ -71,11 +72,30 @@ public: return _datacenters; } + // Get dc/rack location of the local node + const endpoint_dc_rack& get_location() const noexcept { + return get_location(utils::fb_utilities::get_broadcast_address()); + } + // Get dc/rack location of a node identified by endpoint const endpoint_dc_rack& get_location(const inet_address& ep) const; - sstring get_rack() const; - sstring get_rack(inet_address ep) const; - sstring get_datacenter() const; - sstring get_datacenter(inet_address ep) const; + + // Get datacenter of the local node + const sstring& get_datacenter() const noexcept { + return get_location().dc; + } + // Get datacenter of a node identified by endpoint + const sstring& get_datacenter(inet_address ep) const { + return get_location(ep).dc; + } + + // Get rack of the local node + const sstring& get_rack() const noexcept { + return get_location().rack; + } + // Get rack of a node identified by endpoint + const sstring& get_rack(inet_address ep) const { + return get_location(ep).rack; + } auto get_local_dc_filter() const noexcept { return [ this, local_dc = get_datacenter() ] (inet_address ep) {