mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-20 00:20:47 +00:00
locator: Return optional for token_metadata::get_endpoint
This commit is contained in:
@@ -24,10 +24,11 @@ std::vector<inet_address> 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
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
#include "token_metadata.hh"
|
||||
#include <experimental/optional>
|
||||
|
||||
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<inet_address> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "gms/inet_address.hh"
|
||||
#include "dht/i_partitioner.hh"
|
||||
#include "utils/UUID.hh"
|
||||
#include <experimental/optional>
|
||||
|
||||
namespace locator {
|
||||
|
||||
@@ -47,7 +48,7 @@ public:
|
||||
void update_normal_tokens(std::unordered_map<inet_address, std::unordered_set<token>>& 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<inet_address> get_endpoint(const token& token) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user