change abstract_replication_strategy::get_ranges to not return wrap-arounds
The main motivation behind this change is to make get_ranges() easier for consumers to work with the returned ranges, e.g. binary search to find a range in which a token is contained. In addition, a wrap-around range introduces corner cases, so we should avoid it altogether. Suppose that a node owns three tokens: -5, 6, 8 get_ranges() would return the following ranges: (8, -5], (-5, 6], (6, 8] get_ranges() will now return the following ranges: (-inf, -5], (-5, 6], (6, 8], (8, +inf) Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com> Message-Id: <4bda1428d1ebbe7c8af25aa65119edc5b97bc2eb.1453827605.git.raphaelsc@scylladb.com>
This commit is contained in:
committed by
Tomasz Grabiec
parent
b9ab28a0e6
commit
d54c77d5d0
@@ -123,6 +123,15 @@ abstract_replication_strategy::get_ranges(inet_address ep) const {
|
||||
}
|
||||
prev_tok = tok;
|
||||
}
|
||||
if (!ret.empty()) {
|
||||
// Make ret contain no wrap-around range by unwrapping the first element.
|
||||
auto& r = ret.front();
|
||||
if (r.is_wrap_around(dht::token_comparator())) {
|
||||
auto split_ranges = r.unwrap();
|
||||
r = split_ranges.first;
|
||||
ret.push_back(split_ranges.second);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
replication_strategy_type get_type() const { return _my_type; }
|
||||
|
||||
// get_ranges() returns the list of ranges held by the given endpoint.
|
||||
// The list is sorted, and its elements are non overlapping and non wrap-around.
|
||||
// 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) const;
|
||||
|
||||
@@ -1609,6 +1609,7 @@ public:
|
||||
#endif
|
||||
/**
|
||||
* Get all ranges an endpoint is responsible for (by keyspace)
|
||||
* Replication strategy's get_ranges() guarantees that no wrap-around range is returned.
|
||||
* @param ep endpoint we are interested in.
|
||||
* @return ranges for the specified endpoint.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user