erm: has_pending_ranges: switch to host_id

In the next patches we are going to change erm data structures
(replication_map and ring_mapping) from IP to host_id. Having
locator::host_id instead of IP in has_pending_ranges arguments
makes this transition easier.
This commit is contained in:
Petr Gusev
2023-12-18 12:49:16 +04:00
parent f0d6330204
commit 1928dc73a8
4 changed files with 14 additions and 14 deletions

View File

@@ -140,10 +140,14 @@ std::optional<tablet_routing_info> vnode_effective_replication_map::check_locali
return {};
}
bool vnode_effective_replication_map::has_pending_ranges(inet_address endpoint) const {
bool vnode_effective_replication_map::has_pending_ranges(locator::host_id endpoint) const {
const auto ep = _tmptr->get_endpoint_for_host_id_if_known(endpoint);
if (!ep) {
return false;
}
for (const auto& item : _pending_endpoints) {
const auto& nodes = item.second;
if (nodes.contains(endpoint)) {
if (nodes.contains(*ep)) {
return true;
}
}

View File

@@ -230,7 +230,7 @@ public:
/// Returns true if there are any pending ranges for this endpoint.
/// This operation is expensive, for vnode_erm it iterates
/// over all pending ranges which is O(number of tokens).
virtual bool has_pending_ranges(inet_address endpoint) const = 0;
virtual bool has_pending_ranges(locator::host_id endpoint) const = 0;
/// Returns a token_range_splitter which is line with the replica assignment of this replication map.
/// The splitter can live longer than this instance.
@@ -303,7 +303,7 @@ public: // effective_replication_map
inet_address_vector_topology_change get_pending_endpoints(const token& search_token) const override;
inet_address_vector_replica_set get_endpoints_for_reading(const token& search_token) const override;
std::optional<tablet_routing_info> check_locality(const token& token) const override;
bool has_pending_ranges(inet_address endpoint) const override;
bool has_pending_ranges(locator::host_id endpoint) const override;
std::unique_ptr<token_range_splitter> make_splitter() const override;
const dht::sharder& get_sharder(const schema& s) const override;
public:

View File

@@ -465,13 +465,9 @@ public:
return make_tablet_routing_info();
}
virtual bool has_pending_ranges(inet_address endpoint) const override {
const auto host_id = _tmptr->get_host_id_if_known(endpoint);
if (!host_id.has_value()) {
return false;
}
virtual bool has_pending_ranges(locator::host_id host_id) const override {
for (const auto& [id, transition_info]: get_tablet_map().transitions()) {
if (transition_info.pending_replica.host == *host_id) {
if (transition_info.pending_replica.host == host_id) {
return true;
}
}

View File

@@ -4958,7 +4958,7 @@ future<> storage_service::decommission() {
auto non_system_keyspaces = db.get_non_local_vnode_based_strategy_keyspaces();
for (const auto& keyspace_name : non_system_keyspaces) {
if (ss._db.local().find_keyspace(keyspace_name).get_effective_replication_map()->has_pending_ranges(ss.get_broadcast_address())) {
if (ss._db.local().find_keyspace(keyspace_name).get_effective_replication_map()->has_pending_ranges(ss.get_token_metadata_ptr()->get_my_id())) {
throw std::runtime_error("data is currently moving to this node; unable to leave the ring");
}
}
@@ -7664,9 +7664,9 @@ future<> storage_service::wait_for_normal_state_handled_on_boot() {
future<bool> storage_service::is_cleanup_allowed(sstring keyspace) {
return container().invoke_on(0, [keyspace = std::move(keyspace)] (storage_service& ss) {
auto my_address = ss.get_broadcast_address();
auto pending_ranges = ss._db.local().find_keyspace(keyspace).get_effective_replication_map()->has_pending_ranges(my_address);
bool is_bootstrap_mode = ss._operation_mode == mode::BOOTSTRAP;
const auto my_id = ss.get_token_metadata().get_my_id();
const auto pending_ranges = ss._db.local().find_keyspace(keyspace).get_effective_replication_map()->has_pending_ranges(my_id);
const bool is_bootstrap_mode = ss._operation_mode == mode::BOOTSTRAP;
slogger.debug("is_cleanup_allowed: keyspace={}, is_bootstrap_mode={}, pending_ranges={}",
keyspace, is_bootstrap_mode, pending_ranges);
return !is_bootstrap_mode && !pending_ranges;