topology: define get_{rack,datacenter} inline

Define get_location() that gets the location
for the local node, and use either this entry point
or get_location(inet_address) to get the respective
dc or rack.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2023-03-01 17:24:43 +02:00
parent fd1a2591b5
commit df1c92649e
2 changed files with 24 additions and 25 deletions

View File

@@ -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) {

View File

@@ -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) {