From e827d2ed928b501b89a4bd83f7d1db37b9127905 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 2 Jul 2020 10:03:03 -0400 Subject: [PATCH] Fix testRestoreLocalHistoryFromTranslogOnPromotion (#58745) If the global checkpoint equals max_seq_no, then we won't reset an engine (as all operations are safe), and max_seqno_of_updates_or_deletes won't advance to max_seq_no. Closes #58163 --- .../index/shard/IndexShardTests.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 70d6cb05a3d..3b13b6e9cbc 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -1187,13 +1187,13 @@ public class IndexShardTests extends IndexShardTestCase { indexShard.updateGlobalCheckpointOnReplica(globalCheckpointOnReplica, "test"); final long globalCheckpoint = randomLongBetween(UNASSIGNED_SEQ_NO, indexShard.getLocalCheckpoint()); - final long maxSeqNoOfUpdatesOrDeletes = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, maxSeqNo); + final long maxSeqNoOfUpdatesOrDeletesBeforeRollback = indexShard.getMaxSeqNoOfUpdatesOrDeletes(); final Set docsBeforeRollback = getShardDocUIDs(indexShard); final CountDownLatch latch = new CountDownLatch(1); randomReplicaOperationPermitAcquisition(indexShard, indexShard.getPendingPrimaryTerm() + 1, globalCheckpoint, - maxSeqNoOfUpdatesOrDeletes, + randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, maxSeqNo), new ActionListener() { @Override public void onResponse(Releasable releasable) { @@ -1208,7 +1208,11 @@ public class IndexShardTests extends IndexShardTestCase { }, ""); latch.await(); - assertThat(indexShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(maxSeqNo)); + if (globalCheckpoint < maxSeqNo) { + assertThat(indexShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(maxSeqNo)); + } else { + assertThat(indexShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(maxSeqNoOfUpdatesOrDeletesBeforeRollback)); + } final ShardRouting newRouting = indexShard.routingEntry().moveActiveReplicaToPrimary(); final CountDownLatch resyncLatch = new CountDownLatch(1); indexShard.updateShardState( @@ -1222,7 +1226,11 @@ public class IndexShardTests extends IndexShardTestCase { assertThat(indexShard.getLocalCheckpoint(), equalTo(maxSeqNo)); assertThat(indexShard.seqNoStats().getMaxSeqNo(), equalTo(maxSeqNo)); assertThat(getShardDocUIDs(indexShard), equalTo(docsBeforeRollback)); - assertThat(indexShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(maxSeqNo)); + if (globalCheckpoint < maxSeqNo) { + assertThat(indexShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(maxSeqNo)); + } else { + assertThat(indexShard.getMaxSeqNoOfUpdatesOrDeletes(), equalTo(maxSeqNoOfUpdatesOrDeletesBeforeRollback)); + } closeShard(indexShard, false); }