Account trimAboveSeqNo in committed translog generation (#50205)
Today we do not consider trimAboveSeqNo when calculating the translog generation of an index commit. If there is no new indexing after the primary promotion, then we won't be able to clean up the translog.
This commit is contained in:
parent
be78d5cc74
commit
731bfa6614
|
@ -120,6 +120,17 @@ final class Checkpoint {
|
||||||
out.writeLong(trimmedAboveSeqNo);
|
out.writeLong(trimmedAboveSeqNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the maximum sequence number of operations in this checkpoint after applying {@link #trimmedAboveSeqNo}.
|
||||||
|
*/
|
||||||
|
long maxEffectiveSeqNo() {
|
||||||
|
if (trimmedAboveSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO) {
|
||||||
|
return maxSeqNo;
|
||||||
|
} else {
|
||||||
|
return Math.min(trimmedAboveSeqNo, maxSeqNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Checkpoint emptyTranslogCheckpoint(final long offset, final long generation, final long globalCheckpoint,
|
static Checkpoint emptyTranslogCheckpoint(final long offset, final long generation, final long globalCheckpoint,
|
||||||
long minTranslogGeneration) {
|
long minTranslogGeneration) {
|
||||||
final long minSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
|
final long minSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
|
||||||
|
|
|
@ -702,11 +702,7 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
||||||
assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread() :
|
assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread() :
|
||||||
"callers of readersAboveMinSeqNo must hold a lock: readLock ["
|
"callers of readersAboveMinSeqNo must hold a lock: readLock ["
|
||||||
+ readLock.isHeldByCurrentThread() + "], writeLock [" + readLock.isHeldByCurrentThread() + "]";
|
+ readLock.isHeldByCurrentThread() + "], writeLock [" + readLock.isHeldByCurrentThread() + "]";
|
||||||
return Stream.concat(readers.stream(), Stream.of(current))
|
return Stream.concat(readers.stream(), Stream.of(current)).filter(reader -> minSeqNo <= reader.getCheckpoint().maxEffectiveSeqNo());
|
||||||
.filter(reader -> {
|
|
||||||
final long maxSeqNo = reader.getCheckpoint().maxSeqNo;
|
|
||||||
return maxSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || maxSeqNo >= minSeqNo;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1638,7 +1634,7 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
||||||
*/
|
*/
|
||||||
long minTranslogFileGeneration = this.currentFileGeneration();
|
long minTranslogFileGeneration = this.currentFileGeneration();
|
||||||
for (final TranslogReader reader : readers) {
|
for (final TranslogReader reader : readers) {
|
||||||
if (seqNo <= reader.getCheckpoint().maxSeqNo) {
|
if (seqNo <= reader.getCheckpoint().maxEffectiveSeqNo()) {
|
||||||
minTranslogFileGeneration = Math.min(minTranslogFileGeneration, reader.getGeneration());
|
minTranslogFileGeneration = Math.min(minTranslogFileGeneration, reader.getGeneration());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -803,6 +803,11 @@ public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestC
|
||||||
shards.assertAllEqual(initDocs + inFlightOpsOnNewPrimary + moreDocsAfterRollback);
|
shards.assertAllEqual(initDocs + inFlightOpsOnNewPrimary + moreDocsAfterRollback);
|
||||||
done.set(true);
|
done.set(true);
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|
||||||
|
for (IndexShard shard : shards) {
|
||||||
|
shard.flush(new FlushRequest().force(true).waitIfOngoing(true));
|
||||||
|
assertThat(shard.translogStats().getUncommittedOperations(), equalTo(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue