mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-28 10:41:12 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user