diff --git a/locator/simple_strategy.cc b/locator/simple_strategy.cc index ca149f057b..72732c8ce1 100644 --- a/locator/simple_strategy.cc +++ b/locator/simple_strategy.cc @@ -24,10 +24,11 @@ std::vector simple_strategy::calculate_natural_endpoints(const tok auto it = tokens.begin() + _token_metadata.first_token_index(t); auto c = tokens.size(); - while(endpoints.size() < replicas && c) { - inet_address ep = _token_metadata.get_endpoint(*(it++)); - if (std::find(endpoints.begin(), endpoints.end(), ep) == endpoints.end()) { - endpoints.push_back(ep); + while (endpoints.size() < replicas && c) { + auto ep = _token_metadata.get_endpoint(*(it++)); + assert(ep); + if (std::find(endpoints.begin(), endpoints.end(), *ep) == endpoints.end()) { + endpoints.push_back(*ep); } c--; // wrap around diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 32d0e27efb..1fb61c939a 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -3,6 +3,7 @@ */ #include "token_metadata.hh" +#include namespace locator { @@ -104,9 +105,13 @@ const token& token_metadata::first_token(const token& start) { return _sorted_tokens[first_token_index(start)]; } -inet_address token_metadata::get_endpoint(const token& token) const { +std::experimental::optional token_metadata::get_endpoint(const token& token) const { auto it = _token_to_endpoint_map.find(token); - assert (it != _token_to_endpoint_map.end()); - return it->second; + if (it == _token_to_endpoint_map.end()) { + return std::experimental::nullopt; + } else { + return it->second; + } } + } diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index 33898c71d0..49f766b403 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -10,6 +10,7 @@ #include "gms/inet_address.hh" #include "dht/i_partitioner.hh" #include "utils/UUID.hh" +#include namespace locator { @@ -47,7 +48,7 @@ public: void update_normal_tokens(std::unordered_map>& endpoint_tokens); const token& first_token(const token& start); size_t first_token_index(const token& start); - inet_address get_endpoint(const token& token) const; + std::experimental::optional get_endpoint(const token& token) const; }; }