From 2028c2af14ff8b0ecb5ebbed29604184f74d7645 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sun, 16 Dec 2018 16:45:31 -0500 Subject: [PATCH] TEST: Do not assert max_seq_of_updates if promotion If a primary promotion happens in the test testAddRemoveShardOnLeader, the max_seq_no_of_updates_or_deletes on a new primary might be higher than the max_seq_no_of_updates_or_deletes on the replicas or copies of the follower. Relates #36607 --- .../action/ShardFollowTaskReplicationTests.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardFollowTaskReplicationTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardFollowTaskReplicationTests.java index cebd8479791..9dc7c6648ee 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardFollowTaskReplicationTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardFollowTaskReplicationTests.java @@ -102,7 +102,7 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest followerGroup.assertAllEqual(indexedDocIds.size() - deleteDocIds.size()); }); shardFollowTask.markAsCompleted(); - assertConsistentHistoryBetweenLeaderAndFollower(leaderGroup, followerGroup); + assertConsistentHistoryBetweenLeaderAndFollower(leaderGroup, followerGroup, true); } } @@ -122,6 +122,7 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest followerSeqNoStats.getMaxSeqNo()); int batches = between(0, 10); int docCount = 0; + boolean hasPromotion = false; for (int i = 0; i < batches; i++) { docCount += leaderGroup.indexDocs(between(1, 5)); if (leaderGroup.getReplicas().isEmpty() == false && randomInt(100) < 5) { @@ -132,6 +133,7 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest } else if (leaderGroup.getReplicas().isEmpty() == false && rarely()) { IndexShard newPrimary = randomFrom(leaderGroup.getReplicas()); leaderGroup.promoteReplicaToPrimary(newPrimary).get(); + hasPromotion = true; } else if (randomInt(100) < 5) { leaderGroup.addReplica(); leaderGroup.startReplicas(1); @@ -143,7 +145,7 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest int expectedDoc = docCount; assertBusy(() -> followerGroup.assertAllEqual(expectedDoc)); shardFollowTask.markAsCompleted(); - assertConsistentHistoryBetweenLeaderAndFollower(leaderGroup, followerGroup); + assertConsistentHistoryBetweenLeaderAndFollower(leaderGroup, followerGroup, hasPromotion == false); } } @@ -285,7 +287,7 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest try { assertBusy(() -> { assertThat(followerGroup.getPrimary().getGlobalCheckpoint(), equalTo(leadingPrimary.getGlobalCheckpoint())); - assertConsistentHistoryBetweenLeaderAndFollower(leaderGroup, followerGroup); + assertConsistentHistoryBetweenLeaderAndFollower(leaderGroup, followerGroup, true); }); } finally { shardFollowTask.markAsCompleted(); @@ -476,7 +478,8 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest }; } - private void assertConsistentHistoryBetweenLeaderAndFollower(ReplicationGroup leader, ReplicationGroup follower) throws Exception { + private void assertConsistentHistoryBetweenLeaderAndFollower(ReplicationGroup leader, ReplicationGroup follower, + boolean assertMaxSeqNoOfUpdatesOrDeletes) throws Exception { final List> docAndSeqNosOnLeader = getDocIdAndSeqNos(leader.getPrimary()).stream() .map(d -> Tuple.tuple(d.getId(), d.getSeqNo())).collect(Collectors.toList()); final Set> operationsOnLeader = new HashSet<>(); @@ -487,7 +490,9 @@ public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTest } } for (IndexShard followingShard : follower) { - assertThat(followingShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(leader.getPrimary().getMaxSeqNoOfUpdatesOrDeletes())); + if (assertMaxSeqNoOfUpdatesOrDeletes) { + assertThat(followingShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(leader.getPrimary().getMaxSeqNoOfUpdatesOrDeletes())); + } List> docAndSeqNosOnFollower = getDocIdAndSeqNos(followingShard).stream() .map(d -> Tuple.tuple(d.getId(), d.getSeqNo())).collect(Collectors.toList()); assertThat(docAndSeqNosOnFollower, equalTo(docAndSeqNosOnLeader));