From eb9d6df8bf919bf96f744b0326f268ee26acca34 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 13 Apr 2023 10:20:35 +0200 Subject: [PATCH] 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). --- locator/topology.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/locator/topology.cc b/locator/topology.cc index f6f3d8c362..4c3444873a 100644 --- a/locator/topology.cc +++ b/locator/topology.cc @@ -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()