use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class AbstractLogTailScannerTest method bigFileLatestCheckpointFindsStartAfter.
@ParameterizedTest
@MethodSource("params")
void bigFileLatestCheckpointFindsStartAfter(int startLogVersion, int endLogVersion) throws IOException {
long firstTxAfterCheckpoint = Integer.MAX_VALUE + 4L;
InlinedLogTailScanner tailScanner = new FirstTxIdConfigurableTailScanner(firstTxAfterCheckpoint, logFiles, reader, monitors);
LogEntryStart startEntry = new LogEntryStart(3L, 4L, 0, new byte[] { 5, 6 }, new LogPosition(endLogVersion, Integer.MAX_VALUE + 17L));
CheckpointInfo checkPoint = new CheckpointInfo(new LogPosition(endLogVersion, 16L), StoreId.UNKNOWN, LogPosition.UNSPECIFIED);
LogTailInformation logTailInformation = tailScanner.checkpointTailInformation(endLogVersion, startEntry, endLogVersion, (byte) -1, checkPoint, false, StoreId.UNKNOWN);
assertLatestCheckPoint(true, true, firstTxAfterCheckpoint, false, logTailInformation);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CheckpointInfoTest method checkpointInfoOfLegacyCheckpointEntry.
@Test
void checkpointInfoOfLegacyCheckpointEntry() {
var logPosition = new LogPosition(0, 1);
StoreId storeId = new StoreId(1, 2, 3, 4, 5);
LogPosition position = new LogPosition(1, 2);
var checkpointInfo = new CheckpointInfo(new LogEntryInlinedCheckPoint(logPosition), storeId, position);
assertSame(logPosition, checkpointInfo.getTransactionLogPosition());
assertSame(storeId, checkpointInfo.storeId());
assertSame(position, checkpointInfo.getCheckpointEntryPosition());
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CompositeCheckpointLogFileTest method shouldFindReachableCheckpointsForBothLegacyAndDetachedCheckpoints.
@Test
void shouldFindReachableCheckpointsForBothLegacyAndDetachedCheckpoints() throws IOException {
assertThat(checkpointFile.reachableCheckpoints()).isEmpty();
assertThat(checkpointFile.getReachableDetachedCheckpoints()).isEmpty();
// Add legacy checkpoints
LogPosition logPosition = new LogPosition(0, 1);
LogPosition logPosition2 = new LogPosition(0, 2);
writeLegacyCheckpoint(logPosition);
writeLegacyCheckpoint(logPosition2);
logFiles.getLogFile().forceAfterAppend(LogAppendEvent.NULL);
// Add detached checkpoints
LogPosition logPosition3 = new LogPosition(0, 3);
LogPosition logPosition4 = new LogPosition(0, 4);
checkpointFile.getCheckpointAppender().checkPoint(NULL, logPosition3, Instant.now(), "detached");
checkpointFile.getCheckpointAppender().checkPoint(NULL, logPosition4, Instant.now(), "detached");
List<CheckpointInfo> reachableCheckpoints = checkpointFile.reachableCheckpoints();
assertThat(reachableCheckpoints.size()).isEqualTo(4);
assertThat(reachableCheckpoints.get(0).getTransactionLogPosition()).isEqualTo(logPosition);
assertThat(reachableCheckpoints.get(1).getTransactionLogPosition()).isEqualTo(logPosition2);
assertThat(reachableCheckpoints.get(2).getTransactionLogPosition()).isEqualTo(logPosition3);
assertThat(reachableCheckpoints.get(3).getTransactionLogPosition()).isEqualTo(logPosition4);
List<CheckpointInfo> detachedCheckpoints = checkpointFile.getReachableDetachedCheckpoints();
assertThat(detachedCheckpoints.size()).isEqualTo(2);
assertThat(detachedCheckpoints.get(0).getTransactionLogPosition()).isEqualTo(logPosition3);
assertThat(detachedCheckpoints.get(1).getTransactionLogPosition()).isEqualTo(logPosition4);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CompositeCheckpointLogFileTest method findLatestCheckpointShouldWorkForBothLegacyAndDetachedCheckpoints.
@Test
void findLatestCheckpointShouldWorkForBothLegacyAndDetachedCheckpoints() throws IOException {
LogPosition logPosition = new LogPosition(0, 1);
writeLegacyCheckpoint(logPosition);
logFiles.getLogFile().forceAfterAppend(LogAppendEvent.NULL);
assertThat(checkpointFile.findLatestCheckpoint().orElseThrow().getTransactionLogPosition()).isEqualTo(logPosition);
// Should find the detached checkpoint first
LogPosition logPosition2 = new LogPosition(logVersionRepository.getCurrentLogVersion(), CURRENT_FORMAT_LOG_HEADER_SIZE);
checkpointFile.getCheckpointAppender().checkPoint(NULL, logPosition2, Instant.now(), "detached");
assertThat(checkpointFile.findLatestCheckpoint().orElseThrow().getTransactionLogPosition()).isEqualTo(logPosition2);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CorruptedLogsTruncatorTest method pruneAndArchiveMultipleLogs.
@Test
void pruneAndArchiveMultipleLogs() throws IOException {
life.start();
generateTransactionLogFiles(logFiles);
long highestCorrectLogFileIndex = 5;
var logFile = logFiles.getLogFile();
Path highestCorrectLogFile = logFile.getLogFileForVersion(highestCorrectLogFileIndex);
long fileSizeBeforePrune = Files.size(highestCorrectLogFile);
long highestLogFileLength = Files.size(logFile.getHighestLogFile());
int bytesToPrune = 7;
long byteOffset = fileSizeBeforePrune - bytesToPrune;
LogPosition prunePosition = new LogPosition(highestCorrectLogFileIndex, byteOffset);
CheckpointFile checkpointFile = logFiles.getCheckpointFile();
checkpointFile.getCheckpointAppender().checkPoint(LogCheckPointEvent.NULL, new LogPosition(highestCorrectLogFileIndex, byteOffset - 1), Instant.now(), "within okay transactions");
/* Write checkpoints that should be truncated. Write enough to get them get them in two files. */
for (int i = 0; i < 5; i++) {
checkpointFile.getCheckpointAppender().checkPoint(LogCheckPointEvent.NULL, new LogPosition(highestCorrectLogFileIndex, byteOffset + 1), Instant.now(), "in the part being truncated");
}
life.shutdown();
logPruner.truncate(prunePosition);
life.start();
// 6 transaction log files and a checkpoint file
logVersionRepository.setCheckpointLogVersion(0, NULL);
assertEquals(7, logFiles.logFiles().length);
assertEquals(byteOffset, Files.size(highestCorrectLogFile));
assertThat(checkpointFile.getDetachedCheckpointFiles()).hasSize(1);
assertEquals(CURRENT_FORMAT_LOG_HEADER_SIZE + 192, /* one checkpoint */
Files.size(checkpointFile.getDetachedCheckpointFiles()[0]));
Path corruptedLogsDirectory = databaseDirectory.resolve(CORRUPTED_TX_LOGS_BASE_NAME);
assertTrue(Files.exists(corruptedLogsDirectory));
File[] files = corruptedLogsDirectory.toFile().listFiles();
assertNotNull(files);
assertEquals(1, files.length);
File corruptedLogsArchive = files[0];
checkArchiveName(highestCorrectLogFileIndex, byteOffset, corruptedLogsArchive);
try (ZipFile zipFile = new ZipFile(corruptedLogsArchive)) {
assertEquals(9, zipFile.size());
checkEntryNameAndSize(zipFile, highestCorrectLogFile.getFileName().toString(), bytesToPrune);
long nextLogFileIndex = highestCorrectLogFileIndex + 1;
int lastFileIndex = TOTAL_NUMBER_OF_TRANSACTION_LOG_FILES - 1;
for (long index = nextLogFileIndex; index < lastFileIndex; index++) {
checkEntryNameAndSize(zipFile, TransactionLogFilesHelper.DEFAULT_NAME + "." + index, SINGLE_LOG_FILE_SIZE);
}
checkEntryNameAndSize(zipFile, TransactionLogFilesHelper.DEFAULT_NAME + "." + lastFileIndex, highestLogFileLength);
checkEntryNameAndSize(zipFile, TransactionLogFilesHelper.CHECKPOINT_FILE_PREFIX + ".0", 192 * 4);
checkEntryNameAndSize(zipFile, TransactionLogFilesHelper.CHECKPOINT_FILE_PREFIX + ".1", CURRENT_FORMAT_LOG_HEADER_SIZE + 192);
}
}
Aggregations