From 76a1a863e3a86fc5472bc2ef29091944bd1ff836 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 20 Sep 2018 13:44:26 -0400 Subject: [PATCH] TEST: stop assertSeqNos if shards movement (#33875) Currently, assertSeqNos assumes that the cluster is stable at the end of the test (i.e., no more shard movement). However, this assumption does not always hold. In these cases, we can stop the assertion instead of failing a test. Closes #33704 --- .../discovery/ClusterDisruptionIT.java | 1 - .../elasticsearch/test/ESIntegTestCase.java | 28 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionIT.java b/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionIT.java index 33b6ffb9a75..fab38a2b73b 100644 --- a/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionIT.java +++ b/server/src/test/java/org/elasticsearch/discovery/ClusterDisruptionIT.java @@ -288,7 +288,6 @@ public class ClusterDisruptionIT extends AbstractDisruptionTestCase { } // simulate handling of sending shard failure during an isolation - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33704") public void testSendingShardFailure() throws Exception { List nodes = startCluster(3, 2); String masterNode = internalCluster().getMasterName(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index fa9d4635a7d..d5d2168c7dd 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -197,6 +197,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.BiFunction; import java.util.function.BooleanSupplier; import java.util.function.Function; import java.util.stream.Collectors; @@ -2359,17 +2360,28 @@ public abstract class ESIntegTestCase extends ESTestCase { } protected void assertSeqNos() throws Exception { + final BiFunction getInstanceShardInstance = (clusterState, shardRouting) -> { + if (shardRouting.assignedToNode() == false) { + return null; + } + final DiscoveryNode assignedNode = clusterState.nodes().get(shardRouting.currentNodeId()); + if (assignedNode == null) { + return null; + } + return internalCluster().getInstance(IndicesService.class, assignedNode.getName()).getShardOrNull(shardRouting.shardId()); + }; assertBusy(() -> { final ClusterState state = clusterService().state(); for (ObjectObjectCursor indexRoutingTable : state.routingTable().indicesRouting()) { for (IntObjectCursor indexShardRoutingTable : indexRoutingTable.value.shards()) { ShardRouting primaryShardRouting = indexShardRoutingTable.value.primaryShard(); - if (primaryShardRouting == null || primaryShardRouting.assignedToNode() == false) { + if (primaryShardRouting == null) { continue; } - DiscoveryNode primaryNode = state.nodes().get(primaryShardRouting.currentNodeId()); - IndexShard primaryShard = internalCluster().getInstance(IndicesService.class, primaryNode.getName()) - .indexServiceSafe(primaryShardRouting.index()).getShard(primaryShardRouting.id()); + final IndexShard primaryShard = getInstanceShardInstance.apply(state, primaryShardRouting); + if (primaryShard == null) { + continue; //just ignore - shard movement + } final SeqNoStats primarySeqNoStats; final ObjectLongMap syncGlobalCheckpoints; try { @@ -2381,12 +2393,10 @@ public abstract class ESIntegTestCase extends ESTestCase { assertThat(primaryShardRouting + " should have set the global checkpoint", primarySeqNoStats.getGlobalCheckpoint(), not(equalTo(SequenceNumbers.UNASSIGNED_SEQ_NO))); for (ShardRouting replicaShardRouting : indexShardRoutingTable.value.replicaShards()) { - if (replicaShardRouting.assignedToNode() == false) { - continue; + final IndexShard replicaShard = getInstanceShardInstance.apply(state, replicaShardRouting); + if (replicaShard == null) { + continue; //just ignore - shard movement } - DiscoveryNode replicaNode = state.nodes().get(replicaShardRouting.currentNodeId()); - IndexShard replicaShard = internalCluster().getInstance(IndicesService.class, replicaNode.getName()) - .indexServiceSafe(replicaShardRouting.index()).getShard(replicaShardRouting.id()); final SeqNoStats seqNoStats; try { seqNoStats = replicaShard.seqNoStats();