diff --git a/locator/abstract_replication_strategy.hh b/locator/abstract_replication_strategy.hh index 8db7a8b9c7..ada66e53a6 100644 --- a/locator/abstract_replication_strategy.hh +++ b/locator/abstract_replication_strategy.hh @@ -345,6 +345,8 @@ public: virtual dht::shard_replica_set shards_ready_for_reads(const schema& s, const token& token) const { return {shard_for_reads(s, token)}; } + + virtual bool is_leaving(locator::host_id host, const dht::token& token) const = 0; }; using effective_replication_map_ptr = seastar::shared_ptr; @@ -440,6 +442,10 @@ public: void unregister() noexcept { _factory = nullptr; } + + virtual bool is_leaving(locator::host_id host, const token&) const override { + return get_token_metadata().is_leaving(host); + } }; // Apply the replication strategy over the current configuration and the given token_metadata. diff --git a/locator/tablets.cc b/locator/tablets.cc index bb71494cec..aa86a4816d 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -1445,6 +1445,22 @@ public: virtual dht::shard_replica_set shards_ready_for_reads(const schema& s, const token& token) const override { return _sharder.shards_ready_for_reads(token); } + + virtual bool is_leaving(locator::host_id host, const dht::token& token) const override { + // Check if the token belongs to the tablet which is currently being migrated away from host + auto& tmap = get_tablet_map(); + auto tid = tmap.get_tablet_id(token); + auto transition = tmap.get_tablet_transition_info(tid); + if (transition) { + auto& info = tmap.get_tablet_info(tid); + auto leaving_opt = locator::get_leaving_replica(info, *transition); + if (leaving_opt && leaving_opt->host == host) { + return true; + } + } + + return false; + } }; void tablet_aware_replication_strategy::validate_tablet_options(const abstract_replication_strategy& ars,