Search in sources :

Example 46 with LogPosition

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);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 47 with LogPosition

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());
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 48 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 49 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 50 with LogPosition

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);
    }
}
Also used : Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Aggregations

LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)115 Test (org.junit.jupiter.api.Test)50 File (java.io.File)16 Test (org.junit.Test)16 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)15 Path (java.nio.file.Path)14 IOException (java.io.IOException)11 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)10 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)10 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)10 StoreId (org.neo4j.storageengine.api.StoreId)10 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)9 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)8 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)8 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)7 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)7