token_metadata: get_endpoint_to_host_id_map_for_reading: restrict to token owners

And verify the they returned host_id isn't null.
Call on_internal_error_noexcept in that case
since all token owners are expected to have their
host_id set. Aborting in testing would help fix
issues in this area.

Fixes scylladb/scylladb#14843
Refs scylladb/scylladb#14793

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2023-07-23 17:50:02 +03:00
parent a4e7f9bed0
commit 44c14f3e2b

View File

@@ -561,7 +561,15 @@ std::unordered_map<inet_address, host_id> token_metadata_impl::get_endpoint_to_h
std::unordered_map<inet_address, host_id> 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;
}