From d7fe135d90f74cf00eab61525c77ae80b74a4029 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 12 Feb 2020 11:08:48 -0500 Subject: [PATCH] Fix testPrepareIndexForPeerRecovery (#52245) Since #51905, we skip translog recovery if the local checkpoint of the safe commit equals to the global checkpoint. This change adjusts the test not to create a new snapshot in that case. Closes #52221 Relates #51905 --- .../recovery/PeerRecoveryTargetServiceTests.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java index 0db222c14ea..18bf8c8e225 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java @@ -177,11 +177,13 @@ public class PeerRecoveryTargetServiceTests extends IndexShardTestCase { Optional safeCommit = shard.store().findSafeIndexCommit(globalCheckpoint); assertTrue(safeCommit.isPresent()); int expectedTotalLocal = 0; - try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot(safeCommit.get().localCheckpoint + 1, globalCheckpoint)) { - Translog.Operation op; - while ((op = snapshot.next()) != null) { - if (op.seqNo() <= globalCheckpoint) { - expectedTotalLocal++; + if (safeCommit.get().localCheckpoint < globalCheckpoint) { + try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot(safeCommit.get().localCheckpoint + 1, globalCheckpoint)) { + Translog.Operation op; + while ((op = snapshot.next()) != null) { + if (op.seqNo() <= globalCheckpoint) { + expectedTotalLocal++; + } } } }