Skip to content

Commit cf9a73b

Browse files
committed
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 25c6102 commit cf9a73b

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
@@ -296,18 +296,20 @@ public void finalizeRecovery(final long globalCheckpoint, final long trimAboveSe
296296
// Persist the global checkpoint.
297297
indexShard.sync();
298298
indexShard.persistRetentionLeases();
299-
if (hasUncommittedOperations()) {
300-
indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true));
301-
}
302299
if (trimAboveSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) {
303300
// We should erase all translog operations above trimAboveSeqNo as we have received either the same or a newer copy
304301
// from the recovery source in phase2. Rolling a new translog generation is not strictly required here for we won't
305302
// trim the current generation. It's merely to satisfy the assumption that the current generation does not have any
306303
// operation that would be trimmed (see TranslogWriter#assertNoSeqAbove). This assumption does not hold for peer
307304
// recovery because we could have received operations above startingSeqNo from the previous primary terms.
308305
indexShard.rollTranslogGeneration();
306+
// the flush or translog generation threshold can be reached after we roll a new translog
307+
indexShard.afterWriteOperation();
309308
indexShard.trimOperationOfPreviousPrimaryTerms(trimAboveSeqNo);
310309
}
310+
if (hasUncommittedOperations()) {
311+
indexShard.flush(new FlushRequest().force(true).waitIfOngoing(true));
312+
}
311313
indexShard.finalizeRecovery();
312314
return null;
313315
});

0 commit comments

Comments
 (0)