Skip to content

Commit 5712460

Browse files
authored
Fix relocation targets in FieldCapabilitiesIT (elastic#121606) (elastic#121623)
The test failed because we tried to move a shard to a node that already has a copy. This change prevents that from happening. Closes elastic#119280 Closes elastic#120772
1 parent de31cc6 commit 5712460

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ tests:
359359
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
360360
method: test {p0=synonyms/90_synonyms_reloading_for_synset/Reload analyzers for specific synonym set}
361361
issue: https://github.com/elastic/elasticsearch/issues/116777
362-
- class: org.elasticsearch.search.fieldcaps.FieldCapabilitiesIT
363-
method: testRelocation
364-
issue: https://github.com/elastic/elasticsearch/issues/119280
365362
- class: org.elasticsearch.xpack.esql.action.EsqlNodeFailureIT
366363
method: testFailureLoadingFields
367364
issue: https://github.com/elastic/elasticsearch/issues/118000

server/src/internalClusterTest/java/org/elasticsearch/search/fieldcaps/FieldCapabilitiesIT.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.client.Cancellable;
2929
import org.elasticsearch.client.Request;
3030
import org.elasticsearch.client.Response;
31+
import org.elasticsearch.cluster.ClusterState;
3132
import org.elasticsearch.cluster.metadata.IndexMetadata;
3233
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
3334
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
@@ -73,6 +74,7 @@
7374
import java.util.Collection;
7475
import java.util.Collections;
7576
import java.util.HashMap;
77+
import java.util.HashSet;
7678
import java.util.List;
7779
import java.util.Map;
7880
import java.util.concurrent.CancellationException;
@@ -591,21 +593,31 @@ public void testNoActiveCopy() throws Exception {
591593

592594
private void moveOrCloseShardsOnNodes(String nodeName) throws Exception {
593595
final IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
596+
final ClusterState clusterState = clusterService().state();
594597
for (IndexService indexService : indicesService) {
595598
for (IndexShard indexShard : indexService) {
596599
if (randomBoolean()) {
597600
closeShardNoCheck(indexShard, randomBoolean());
598601
} else if (randomBoolean()) {
599602
final ShardId shardId = indexShard.shardId();
600-
603+
final var assignedNodes = new HashSet<>();
604+
clusterState.routingTable().shardRoutingTable(shardId).allShards().forEach(shr -> {
605+
if (shr.currentNodeId() != null) {
606+
assignedNodes.add(shr.currentNodeId());
607+
}
608+
if (shr.relocatingNodeId() != null) {
609+
assignedNodes.add(shr.relocatingNodeId());
610+
}
611+
});
601612
final var targetNodes = new ArrayList<String>();
602613
for (final var targetIndicesService : internalCluster().getInstances(IndicesService.class)) {
603614
final var targetNode = targetIndicesService.clusterService().localNode();
604-
if (targetNode.canContainData() && targetIndicesService.getShardOrNull(shardId) == null) {
615+
if (targetNode.canContainData()
616+
&& targetIndicesService.getShardOrNull(shardId) == null
617+
&& assignedNodes.contains(targetNode.getId()) == false) {
605618
targetNodes.add(targetNode.getId());
606619
}
607620
}
608-
609621
if (targetNodes.isEmpty()) {
610622
continue;
611623
}

0 commit comments

Comments
 (0)