diff --git a/api/api-doc/storage_service.json b/api/api-doc/storage_service.json index 76d90a337c..a01a3abbdb 100644 --- a/api/api-doc/storage_service.json +++ b/api/api-doc/storage_service.json @@ -465,7 +465,7 @@ "operations":[ { "method":"GET", - "summary":"Retrieve the mapping of endpoint to host ID", + "summary":"Retrieve the mapping of endpoint to host ID of all nodes that own tokens", "type":"array", "items":{ "type":"mapper" diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 02bfdfaef6..4e11e95390 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -561,7 +561,15 @@ std::unordered_map token_metadata_impl::get_endpoint_to_h std::unordered_map map; map.reserve(nodes.size()); for (const auto& [endpoint, node] : nodes) { - map[endpoint] = node->host_id(); + // Restrict to token-owners + if (!(node->is_normal() || node->is_leaving())) { + continue; + } + if (const auto& host_id = node->host_id()) { + map[endpoint] = host_id; + } else { + on_internal_error_noexcept(tlogger, fmt::format("get_endpoint_to_host_id_map_for_reading: endpoint {} has null host_id", endpoint)); + } } return map; }