token_metadata: make get_host_id() and get_endpoint_for_host() const
Signed-off-by: Botond Dénes <bdenes@scylladb.com> Message-Id: <febcb558848f8e06661bba592263e55e3192ed47.1519741336.git.bdenes@scylladb.com>
This commit is contained in:
@@ -215,14 +215,14 @@ void token_metadata::update_host_id(const UUID& host_id, inet_address endpoint)
|
||||
_endpoint_to_host_id_map[endpoint] = host_id;
|
||||
}
|
||||
|
||||
utils::UUID token_metadata::get_host_id(inet_address endpoint) {
|
||||
utils::UUID token_metadata::get_host_id(inet_address endpoint) const {
|
||||
if (!_endpoint_to_host_id_map.count(endpoint)) {
|
||||
throw std::runtime_error(sprint("host_id for endpoint %s is not found", endpoint));
|
||||
}
|
||||
return _endpoint_to_host_id_map.at(endpoint);
|
||||
}
|
||||
|
||||
std::experimental::optional<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) const {
|
||||
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) {
|
||||
|
||||
@@ -467,10 +467,10 @@ public:
|
||||
void update_host_id(const UUID& host_id, inet_address endpoint);
|
||||
|
||||
/** Return the unique host ID for an end-point. */
|
||||
UUID get_host_id(inet_address endpoint);
|
||||
UUID get_host_id(inet_address endpoint) const;
|
||||
|
||||
/** Return the end-point for a unique host ID */
|
||||
std::experimental::optional<inet_address> get_endpoint_for_host_id(UUID host_id);
|
||||
std::experimental::optional<inet_address> get_endpoint_for_host_id(UUID host_id) const;
|
||||
|
||||
/** @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