From 9dc155a8efdd0beff82ef59a721209d0734011c5 Mon Sep 17 00:00:00 2001 From: Asias He Date: Tue, 4 Aug 2015 10:17:54 +0800 Subject: [PATCH] token_metadata: Make get_endpoint_for_host_id return optional --- locator/token_metadata.cc | 9 ++++++--- locator/token_metadata.hh | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index a0131f325c..de220214b0 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -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 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& token_metadata::get_endpoint_to_host_id_map_for_reading() const{ diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index 439c5bf2ea..c80517580e 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -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 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& get_endpoint_to_host_id_map_for_reading() const;