diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 3331283a0c..73f1078073 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -2,6 +2,7 @@ * Copyright (C) 2015 Cloudius Systems, Ltd. */ +#include "utils/UUID.hh" #include "token_metadata.hh" #include @@ -160,5 +161,25 @@ 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) { + assert(_endpoint_to_host_id_map.count(endpoint)); + return _endpoint_to_host_id_map.at(endpoint); +} + +gms::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; +} + +const auto& token_metadata::get_endpoint_to_host_id_map_for_reading() { + return _endpoint_to_host_id_map; +} + + } diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index a1df113809..0b851fb8c4 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -252,50 +252,17 @@ public: * @param endpoint */ void update_host_id(const UUID& host_id, inet_address endpoint); -#if 0 + /** Return the unique host ID for an end-point. */ - public UUID getHostId(InetAddress endpoint) - { - lock.readLock().lock(); - try - { - return _endpoint_to_host_id_map.get(endpoint); - } - finally - { - lock.readLock().unlock(); - } - } + UUID get_host_id(inet_address endpoint); /** Return the end-point for a unique host ID */ - public InetAddress getEndpointForHostId(UUID hostId) - { - lock.readLock().lock(); - try - { - return _endpoint_to_host_id_map.inverse().get(hostId); - } - finally - { - lock.readLock().unlock(); - } - } + inet_address get_endpoint_for_host_id(UUID host_id); /** @return a copy of the endpoint-to-id map for read-only operations */ - public Map getEndpointToHostIdMapForReading() - { - lock.readLock().lock(); - try - { - Map readMap = new HashMap(); - readMap.putAll(_endpoint_to_host_id_map); - return readMap; - } - finally - { - lock.readLock().unlock(); - } - } + const auto& get_endpoint_to_host_id_map_for_reading(); + +#if 0 @Deprecated public void addBootstrapToken(Token token, InetAddress endpoint)