From f74eedce7d42d391dfc6f5d07a7bfa7cd614609d Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Sat, 8 Aug 2015 18:22:05 +0300 Subject: [PATCH] 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 --- locator/abstract_replication_strategy.cc | 18 ++++++++++++++++++ locator/abstract_replication_strategy.hh | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/locator/abstract_replication_strategy.cc b/locator/abstract_replication_strategy.cc index 64f2e45db8..3dfb28b25b 100644 --- a/locator/abstract_replication_strategy.cc +++ b/locator/abstract_replication_strategy.cc @@ -73,4 +73,22 @@ abstract_replication_strategy::get_cached_endpoints() { return _cached_endpoints; } +std::vector> +abstract_replication_strategy::get_ranges(inet_address ep) { + std::vector> 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::bound(prev_tok, false), + range::bound(tok, true)); + break; + } + } + prev_tok = tok; + } + return ret; +} + } // namespace locator diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index d72c34e45a..1c599972ba 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -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> get_ranges(inet_address ep); }; }