Relax ShardFollowTasksExecutor validation (#60054)

If a primary shard of a follower index is being relocated, then we
will fail to create a follow-task. This validation is too restricted.
We should ensure that all primaries of the follower index are active
instead.

Closes #59625
This commit is contained in:
Nhat Nguyen 2020-07-27 09:26:51 -04:00
parent 6ece629ec3
commit 416e51980c
1 changed files with 5 additions and 3 deletions

View File

@ -33,6 +33,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata; import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexRoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.CheckedConsumer;
import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.IndexScopedSettings;
@ -112,9 +113,10 @@ public class ShardFollowTasksExecutor extends PersistentTasksExecutor<ShardFollo
@Override @Override
public void validate(ShardFollowTask params, ClusterState clusterState) { public void validate(ShardFollowTask params, ClusterState clusterState) {
IndexRoutingTable routingTable = clusterState.getRoutingTable().index(params.getFollowShardId().getIndex()); final IndexRoutingTable routingTable = clusterState.getRoutingTable().index(params.getFollowShardId().getIndex());
if (routingTable.shard(params.getFollowShardId().id()).primaryShard().started() == false) { final ShardRouting primaryShard = routingTable.shard(params.getFollowShardId().id()).primaryShard();
throw new IllegalArgumentException("Not all copies of follow shard are started"); if (primaryShard.active() == false) {
throw new IllegalArgumentException("The primary shard of a follower index " + primaryShard + " is not active");
} }
} }