From c26f850c4434621fd385b55e90d57270df30e54b Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Mon, 5 Aug 2019 13:55:43 -0400 Subject: [PATCH] Call afterWriteOperation after trim translog in peer recovery (#45182) testShouldFlushAfterPeerRecovery was added #28350 to make sure the flushing loop triggered by afterWriteOperation eventually terminates. This test relies on the fact that we call afterWriteOperation after making changes in translog. In #44756, we roll a new generation in RecoveryTarget#finalizeRecovery but do not call afterWriteOperation. Relates #28350 Relates #45073 --- .../elasticsearch/indices/recovery/RecoveryTarget.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java index 166c2c5b99614..7e0e5f7cf17c8 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java @@ -295,9 +295,6 @@ public void finalizeRecovery(final long globalCheckpoint, final long trimAboveSe // Persist the global checkpoint. indexShard.sync(); indexShard.persistRetentionLeases(); - if (hasUncommittedOperations()) { - indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true)); - } if (trimAboveSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { // We should erase all translog operations above trimAboveSeqNo as we have received either the same or a newer copy // from the recovery source in phase2. Rolling a new translog generation is not strictly required here for we won't @@ -305,8 +302,13 @@ public void finalizeRecovery(final long globalCheckpoint, final long trimAboveSe // operation that would be trimmed (see TranslogWriter#assertNoSeqAbove). This assumption does not hold for peer // recovery because we could have received operations above startingSeqNo from the previous primary terms. indexShard.rollTranslogGeneration(); + // the flush or translog generation threshold can be reached after we roll a new translog + indexShard.afterWriteOperation(); indexShard.trimOperationOfPreviousPrimaryTerms(trimAboveSeqNo); } + if (hasUncommittedOperations()) { + indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true)); + } indexShard.finalizeRecovery(); return null; });