Skip to content

Commit c26f850

Browse files
authored
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
1 parent ae7c071 commit c26f850

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

server/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,20 @@ public void finalizeRecovery(final long globalCheckpoint, final long trimAboveSe
295295
// Persist the global checkpoint.
296296
indexShard.sync();
297297
indexShard.persistRetentionLeases();
298-
if (hasUncommittedOperations()) {
299-
indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true));
300-
}
301298
if (trimAboveSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) {
302299
// We should erase all translog operations above trimAboveSeqNo as we have received either the same or a newer copy
303300
// from the recovery source in phase2. Rolling a new translog generation is not strictly required here for we won't
304301
// trim the current generation. It's merely to satisfy the assumption that the current generation does not have any
305302
// operation that would be trimmed (see TranslogWriter#assertNoSeqAbove). This assumption does not hold for peer
306303
// recovery because we could have received operations above startingSeqNo from the previous primary terms.
307304
indexShard.rollTranslogGeneration();
305+
// the flush or translog generation threshold can be reached after we roll a new translog
306+
indexShard.afterWriteOperation();
308307
indexShard.trimOperationOfPreviousPrimaryTerms(trimAboveSeqNo);
309308
}
309+
if (hasUncommittedOperations()) {
310+
indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true));
311+
}
310312
indexShard.finalizeRecovery();
311313
return null;
312314
});

0 commit comments

Comments
 (0)