diff --git a/locator/abstract_replication_strategy.cc b/locator/abstract_replication_strategy.cc index c314aa7b45..a29b2c9c68 100644 --- a/locator/abstract_replication_strategy.cc +++ b/locator/abstract_replication_strategy.cc @@ -156,8 +156,12 @@ dht::token_range_vector effective_replication_map::do_get_ranges(noncopyable_function should_add_range) const { dht::token_range_vector ret; const auto& tm = *_tmptr; - auto prev_tok = tm.sorted_tokens().back(); - for (const auto& tok : tm.sorted_tokens()) { + const auto& sorted_tokens = tm.sorted_tokens(); + if (sorted_tokens.empty()) { + on_internal_error(rslogger, "Token metadata is empty"); + } + auto prev_tok = sorted_tokens.back(); + for (const auto& tok : sorted_tokens) { if (should_add_range(get_natural_endpoints(tok))) { insert_token_range_to_sorted_container_while_unwrapping(prev_tok, tok, ret); } @@ -183,8 +187,12 @@ future abstract_replication_strategy::get_ranges(inet_address ep, token_metadata_ptr tmptr) const { dht::token_range_vector ret; const auto& tm = *tmptr; - auto prev_tok = tm.sorted_tokens().back(); - for (auto tok : tm.sorted_tokens()) { + const auto& sorted_tokens = tm.sorted_tokens(); + if (sorted_tokens.empty()) { + on_internal_error(rslogger, "Token metadata is empty"); + } + auto prev_tok = sorted_tokens.back(); + for (auto tok : sorted_tokens) { for (inet_address a : co_await calculate_natural_endpoints(tok, tm)) { if (a == ep) { insert_token_range_to_sorted_container_while_unwrapping(prev_tok, tok, ret); diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index 117d148df4..9eac93a793 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -117,6 +117,7 @@ public: replication_strategy_type get_type() const { return _my_type; } // Use the token_metadata provided by the caller instead of _token_metadata + // Note: must be called with initialized, non-empty token_metadata. future get_ranges(inet_address ep, token_metadata_ptr tmptr) const; public: @@ -175,6 +176,8 @@ public: // 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. + // + // Note: must be called after token_metadata has been initialized. dht::token_range_vector get_ranges(inet_address ep) const; // get_primary_ranges() returns the list of "primary ranges" for the given @@ -183,11 +186,15 @@ public: // returned calculate_natural_endpoints(). // This function is the analogue of Origin's // StorageService.getPrimaryRangesForEndpoint(). + // + // Note: must be called after token_metadata has been initialized. dht::token_range_vector get_primary_ranges(inet_address ep) const; // get_primary_ranges_within_dc() is similar to get_primary_ranges() // except it assigns a primary node for each range within each dc, // instead of one node globally. + // + // Note: must be called after token_metadata has been initialized. dht::token_range_vector get_primary_ranges_within_dc(inet_address ep) const; std::unordered_map