replication: add get_ranges() function

This patch adds a method get_ranges() to replication-strategy.
It returns the list of token ranges held by the given endpoint.

It will be used by the replication code, which needs to know
in particular which token ranges are held by *this* node.

This function is the analogue of Origin's getAddressRanges().get(endpoint).
As in Origin, also here the implementation is not meant to be efficient,
and will not be used in the fast path.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
This commit is contained in:
Nadav Har'El
2015-08-08 18:22:05 +03:00
committed by Avi Kivity
parent f3107c7869
commit f74eedce7d
2 changed files with 23 additions and 0 deletions

View File

@@ -73,4 +73,22 @@ abstract_replication_strategy::get_cached_endpoints() {
return _cached_endpoints;
}
std::vector<range<token>>
abstract_replication_strategy::get_ranges(inet_address ep) {
std::vector<range<token>> ret;
auto prev_tok = _token_metadata.sorted_tokens().back();
for (auto tok : _token_metadata.sorted_tokens()) {
for (inet_address a : calculate_natural_endpoints(tok)) {
if (a == ep) {
ret.emplace_back(
range<token>::bound(prev_tok, false),
range<token>::bound(tok, true));
break;
}
}
prev_tok = tok;
}
return ret;
}
} // namespace locator

View File

@@ -77,6 +77,11 @@ public:
virtual size_t get_replication_factor() const = 0;
uint64_t get_cache_hits_count() const { return _cache_hits_count; }
replication_strategy_type get_type() const { return _my_type; }
// get_ranges() returns the list of ranges held by the given endpoint.
// It the analogue of Origin's getAddressRanges().get(endpoint).
// This function is not efficient, and not meant for the fast path.
std::vector<range<token>> get_ranges(inet_address ep);
};
}