token_metadata: Introduce interval_to_range helper

It is used to convert a boost::icl::interval<token> interval back to a
range<token>.
This commit is contained in:
Asias He
2016-12-08 07:28:13 +08:00
parent af3d76e6ac
commit e523803a5d
2 changed files with 24 additions and 0 deletions

View File

@@ -374,6 +374,29 @@ token_metadata::range_to_interval(range<dht::token> r) {
}
}
range<dht::token>
token_metadata::interval_to_range(boost::icl::interval<token>::interval_type i) {
bool start_inclusive;
bool end_inclusive;
auto bounds = i.bounds().bits();
if (bounds == boost::icl::interval_bounds::static_open) {
start_inclusive = false;
end_inclusive = false;
} else if (bounds == boost::icl::interval_bounds::static_left_open) {
start_inclusive = false;
end_inclusive = true;
} else if (bounds == boost::icl::interval_bounds::static_right_open) {
start_inclusive = true;
end_inclusive = false;
} else if (bounds == boost::icl::interval_bounds::static_closed) {
start_inclusive = true;
end_inclusive = true;
} else {
throw std::runtime_error("Invalid boost::icl::interval<token> bounds");
}
return range<dht::token>({{i.lower(), start_inclusive}}, {{i.upper(), end_inclusive}});
}
void token_metadata::set_pending_ranges(const sstring& keyspace_name,
std::unordered_multimap<range<token>, inet_address> new_pending_ranges) {
if (new_pending_ranges.empty()) {

View File

@@ -613,6 +613,7 @@ public:
std::vector<nonwrapping_range<token>> get_primary_ranges_for(token right);
static boost::icl::interval<token>::interval_type range_to_interval(range<dht::token> r);
static range<dht::token> interval_to_range(boost::icl::interval<token>::interval_type i);
private:
std::unordered_multimap<range<token>, inet_address>& get_pending_ranges_mm(sstring keyspace_name);