mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 01:20:39 +00:00
token_metadata: Make get_endpoint_for_host_id return optional
This commit is contained in:
@@ -182,14 +182,17 @@ utils::UUID token_metadata::get_host_id(inet_address endpoint) {
|
||||
return _endpoint_to_host_id_map.at(endpoint);
|
||||
}
|
||||
|
||||
gms::inet_address token_metadata::get_endpoint_for_host_id(UUID host_id) {
|
||||
std::experimental::optional<inet_address> token_metadata::get_endpoint_for_host_id(UUID host_id) {
|
||||
auto beg = _endpoint_to_host_id_map.cbegin();
|
||||
auto end = _endpoint_to_host_id_map.cend();
|
||||
auto it = std::find_if(beg, end, [host_id] (auto x) {
|
||||
return x.second == host_id;
|
||||
});
|
||||
assert(it != end);
|
||||
return (*it).first;
|
||||
if (it == end) {
|
||||
return {};
|
||||
} else {
|
||||
return (*it).first;
|
||||
}
|
||||
}
|
||||
|
||||
const std::unordered_map<inet_address, utils::UUID>& token_metadata::get_endpoint_to_host_id_map_for_reading() const{
|
||||
|
||||
@@ -420,7 +420,7 @@ public:
|
||||
UUID get_host_id(inet_address endpoint);
|
||||
|
||||
/** Return the end-point for a unique host ID */
|
||||
inet_address get_endpoint_for_host_id(UUID host_id);
|
||||
std::experimental::optional<inet_address> get_endpoint_for_host_id(UUID host_id);
|
||||
|
||||
/** @return a copy of the endpoint-to-id map for read-only operations */
|
||||
const std::unordered_map<inet_address, utils::UUID>& get_endpoint_to_host_id_map_for_reading() const;
|
||||
|
||||
Reference in New Issue
Block a user