locator: topology: Fix get_location(ep) for local node

topology config may designate a different node than
get_broadcast_address() as local node. In particular, some tests don't
designate any node as the local node, which leads to logic errors
where current get_location(ep) for ep which happens to have the
address 127.0.0.1 returns location of the first node in _nodes rather
than ep.

Fix by looking up in _nodes first and fall back to local node if it's
equal to configured local node (if any).
This commit is contained in:
Tomasz Grabiec
2023-04-13 10:20:35 +02:00
parent 0a675291dd
commit eb9d6df8bf

View File

@@ -443,12 +443,16 @@ bool topology::has_endpoint(inet_address ep) const
}
const endpoint_dc_rack& topology::get_location(const inet_address& ep) const {
if (ep == utils::fb_utilities::get_broadcast_address()) {
return get_location();
}
if (auto node = find_node(ep)) {
return node->dc_rack();
}
// We should do the following check after lookup in nodes.
// In tests, there may be no config for local node, so fall back to get_location()
// only if no mapping is found. Otherwise, get_location() will return empty location
// from config or random node, neither of which is correct.
if (ep == _cfg.this_endpoint) {
return get_location();
}
// FIXME -- this shouldn't happen. After topology is stable and is
// correctly populated with endpoints, this should be replaced with
// on_internal_error()