Search in sources :

Example 76 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class LogPositionMarkerTest method shouldReturnTheMarkedPosition.

@Test
void shouldReturnTheMarkedPosition() {
    // given
    final LogPositionMarker marker = new LogPositionMarker();
    // when
    marker.mark(1, 2);
    final LogPosition logPosition = marker.newPosition();
    // given
    assertEquals(new LogPosition(1, 2), logPosition);
}
Also used : LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 77 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method getLastReadablePosition.

private LogPosition getLastReadablePosition(Path logFile) throws IOException {
    VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
    LogFile txLogFile = logFiles.getLogFile();
    long logVersion = txLogFile.getLogVersion(logFile);
    LogPosition startPosition = txLogFile.extractHeader(logVersion).getStartPosition();
    try (ReadableLogChannel reader = openTransactionFileChannel(logVersion, startPosition)) {
        while (entryReader.readLogEntry(reader) != null) {
        // scroll to the end of readable entries
        }
    } catch (IncompleteLogHeaderException e) {
        return new LogPosition(logVersion, 0);
    }
    return entryReader.lastPosition();
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IncompleteLogHeaderException(org.neo4j.kernel.impl.transaction.log.entry.IncompleteLogHeaderException) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 78 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled.

@Test
void startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    long originalLogDataLength;
    Path firstLogFile;
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        LogFile logFile = logFiles.getLogFile();
        LogPosition readablePosition = getLastReadablePosition(logFile);
        firstLogFile = logFiles.getLogFile().getHighestLogFile();
        originalLogDataLength = readablePosition.getByteOffset();
        logFile.rotate();
        // append zeros in the end of previous file causing illegal suffix
        try (StoreFileChannel writeChannel = fileSystem.write(firstLogFile)) {
            writeChannel.position(writeChannel.size());
            for (int i = 0; i < 10; i++) {
                writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
            }
        }
    }
    startStopDbRecoveryOfCorruptedLogs();
    assertEquals(originalLogDataLength, fileSystem.getFileSize(firstLogFile));
    assertThat(logProvider).containsMessages("Recovery required from position LogPosition{logVersion=0, byteOffset=" + (996 + txOffsetAfterStart) + "}").assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessage("Transaction log files with version 0 has 50 unreadable bytes. Was able to read upto " + (996 + txOffsetAfterStart) + " but " + (1046 + txOffsetAfterStart) + " is available.");
}
Also used : Path(java.nio.file.Path) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 79 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method getLastReadablePosition.

private LogPosition getLastReadablePosition(LogFile logFile) throws IOException {
    VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
    LogPosition startPosition = logFile.extractHeader(logFiles.getLogFile().getHighestLogVersion()).getStartPosition();
    try (ReadableLogChannel reader = logFile.getReader(startPosition)) {
        while (entryReader.readLogEntry(reader) != null) {
        // scroll to the end of readable entries
        }
    }
    return entryReader.lastPosition();
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 80 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class CheckpointLogFileRotationIT method rotateCheckpointLogFiles.

@Test
void rotateCheckpointLogFiles() throws IOException {
    var checkpointFile = logFiles.getCheckpointFile();
    var checkpointAppender = checkpointFile.getCheckpointAppender();
    LogPosition logPosition = new LogPosition(1000, 12345);
    var reason = "checkpoint for rotation test";
    for (int i = 0; i < 105; i++) {
        checkpointAppender.checkPoint(NULL, logPosition, Instant.now(), reason);
    }
    var matchedFiles = checkpointFile.getDetachedCheckpointFiles();
    assertThat(matchedFiles).hasSize(22);
    for (var fileWithCheckpoints : matchedFiles) {
        assertThat(fileWithCheckpoints).satisfies(new Condition<>() {

            @Override
            public boolean matches(Path file) {
                long length = file.toFile().length();
                return length == kibiBytes(1) || length == CURRENT_FORMAT_LOG_HEADER_SIZE;
            }
        });
    }
}
Also used : Path(java.nio.file.Path) 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