Properly fake corrupted translog (#49918)

The fake translog corruption in the test sometimes generates invalid translog files where some
assertions do not hold (e.g. minSeqNo <= maxSeqNo or minTranslogGen <= translogGen)

Closes #49909
This commit is contained in:
Yannick Welsch 2019-12-09 08:28:23 +01:00
parent 01d36afa4b
commit 7a2e35caa0
1 changed files with 15 additions and 5 deletions

View File

@ -92,11 +92,21 @@ public class TestTranslog {
// if we crashed while rolling a generation then we might have copied `translog.ckp` to its numbered generation file but
// have not yet written a new `translog.ckp`. During recovery we must also verify that this file is intact, so it's ok to
// corrupt this file too (either by writing the wrong information, correctly formatted, or by properly corrupting it)
final Checkpoint checkpointCopy = LuceneTestCase.usually(random) ? checkpoint
: new Checkpoint(checkpoint.offset + random.nextInt(2), checkpoint.numOps + random.nextInt(2),
checkpoint.generation + random.nextInt(2), checkpoint.minSeqNo + random.nextInt(2),
checkpoint.maxSeqNo + random.nextInt(2), checkpoint.globalCheckpoint + random.nextInt(2),
checkpoint.minTranslogGeneration + random.nextInt(2), checkpoint.trimmedAboveSeqNo + random.nextInt(2));
final Checkpoint checkpointCopy;
if (LuceneTestCase.usually(random)) {
checkpointCopy = checkpoint;
} else {
long newTranslogGeneration = checkpoint.generation + random.nextInt(2);
long newMinTranslogGeneration = Math.min(newTranslogGeneration, checkpoint.minTranslogGeneration + random.nextInt(2));
long newMaxSeqNo = checkpoint.maxSeqNo + random.nextInt(2);
long newMinSeqNo = Math.min(newMaxSeqNo, checkpoint.minSeqNo + random.nextInt(2));
long newTrimmedAboveSeqNo = Math.min(newMaxSeqNo, checkpoint.trimmedAboveSeqNo + random.nextInt(2));
checkpointCopy = new Checkpoint(checkpoint.offset + random.nextInt(2), checkpoint.numOps + random.nextInt(2),
newTranslogGeneration, newMinSeqNo,
newMaxSeqNo, checkpoint.globalCheckpoint + random.nextInt(2),
newMinTranslogGeneration, newTrimmedAboveSeqNo);
}
Checkpoint.write(FileChannel::open, unnecessaryCheckpointCopyPath, checkpointCopy,
StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);