Merge 'token_metadata::get_endpoint_to_host_id_map_for_reading: restrict to token owners' from Benny Halevy

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

Closes #14844

* github.com:scylladb/scylladb:
  api: storage_service: improve description of /storage_service/host_id
  token_metadata: get_endpoint_to_host_id_map_for_reading: restrict to token owners
This commit is contained in:
Botond Dénes
2023-08-23 13:55:14 +03:00
2 changed files with 10 additions and 2 deletions

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;
}