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
This commit is contained in:
Nhat Nguyen 2018-12-16 16:45:31 -05:00
parent 97107e99e8
commit 2028c2af14
1 changed files with 10 additions and 5 deletions

View File

@ -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<Tuple<String, Long>> docAndSeqNosOnLeader = getDocIdAndSeqNos(leader.getPrimary()).stream()
.map(d -> Tuple.tuple(d.getId(), d.getSeqNo())).collect(Collectors.toList());
final Set<Tuple<Long, Translog.Operation.Type>> 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<Tuple<String, Long>> docAndSeqNosOnFollower = getDocIdAndSeqNos(followingShard).stream()
.map(d -> Tuple.tuple(d.getId(), d.getSeqNo())).collect(Collectors.toList());
assertThat(docAndSeqNosOnFollower, equalTo(docAndSeqNosOnLeader));