Skip to content

Commit 435fe25

Browse files
committed
Rewrite min generation
1 parent 32e14d0 commit 435fe25

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

core/src/main/java/org/elasticsearch/index/translog/Translog.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,15 +1356,18 @@ public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Transl
13561356
*/
13571357
public TranslogGeneration getMinGenerationForSeqNo(final long seqNo) {
13581358
try (ReleasableLock ignored = writeLock.acquire()) {
1359-
final long minTranslogFileGeneration = readers
1360-
.stream()
1361-
.filter(r -> {
1362-
final Checkpoint checkpoint = r.getCheckpoint();
1363-
return seqNo <= checkpoint.maxSeqNo;
1364-
})
1365-
.mapToLong(TranslogReader::getGeneration)
1366-
.min()
1367-
.orElseGet(this::currentFileGeneration);
1359+
/*
1360+
* When flushing, the engine will ask the translog for the minimum generation that could contain any sequence number after the
1361+
* local checkpoint. Immediately after flushing, there will be no such generation, so this minimum generation in this case will
1362+
* be the current translog generation as we do not need any prior generations to have a complete history up to the current local
1363+
* checkpoint.
1364+
*/
1365+
long minTranslogFileGeneration = this.currentFileGeneration();
1366+
for (final TranslogReader reader : readers) {
1367+
if (seqNo <= reader.getCheckpoint().maxSeqNo) {
1368+
minTranslogFileGeneration = Math.min(minTranslogFileGeneration, reader.getGeneration());
1369+
}
1370+
}
13681371
return new TranslogGeneration(translogUUID, minTranslogFileGeneration);
13691372
}
13701373
}

0 commit comments

Comments
 (0)