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:
Botond Dénes
2018-02-27 16:22:48 +02:00
committed by Avi Kivity
parent 76e6423910
commit ee307751e6
2 changed files with 4 additions and 4 deletions

View File

@@ -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) {

View File

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