Search in sources :

Example 1 with FlushablePositionAwareChecksumChannel

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

the class ReversedSingleFileTransactionCursorTest method writeTransactions.

private void writeTransactions(int transactionCount, int minTransactionSize, int maxTransactionSize) throws IOException {
    FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
    TransactionLogWriter writer = logFile.getTransactionLogWriter();
    int previousChecksum = BASE_TX_CHECKSUM;
    for (int i = 0; i < transactionCount; i++) {
        previousChecksum = writer.append(tx(random.intBetween(minTransactionSize, maxTransactionSize)), ++txId, previousChecksum);
    }
    channel.prepareForFlush().flush();
// Don't close the channel, LogFile owns it
}
Also used : FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)

Example 2 with FlushablePositionAwareChecksumChannel

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

the class CorruptedLogsTruncatorTest method truncateLogWithCorruptionThatLooksLikePreAllocatedZeros.

@Test
void truncateLogWithCorruptionThatLooksLikePreAllocatedZeros() throws IOException {
    life.start();
    generateTransactionLogFiles(logFiles);
    var logFile = logFiles.getLogFile();
    long highestLogVersion = logFile.getHighestLogVersion();
    long fileSizeBeforeAppend = Files.size(logFile.getHighestLogFile());
    LogPosition endOfLogsPosition = new LogPosition(highestLogVersion, fileSizeBeforeAppend);
    FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
    for (int i = 0; i < RandomUtils.nextInt(100, 10240); i++) {
        channel.putLong(0);
    }
    // corruption byte
    channel.put((byte) 7);
    for (int i = 0; i < RandomUtils.nextInt(10, 1024); i++) {
        channel.putLong(0);
    }
    channel.prepareForFlush().flush();
    long fileAfterZeroAppend = Files.size(logFile.getHighestLogFile());
    assertNotEquals(fileSizeBeforeAppend, fileAfterZeroAppend);
    logPruner.truncate(endOfLogsPosition);
    assertEquals(TOTAL_NUMBER_OF_LOG_FILES, logFiles.logFiles().length);
    assertEquals(fileSizeBeforeAppend, Files.size(logFile.getHighestLogFile()));
    Path corruptedLogsDirectory = databaseDirectory.resolve(CORRUPTED_TX_LOGS_BASE_NAME);
    assertTrue(Files.exists(corruptedLogsDirectory));
    File[] files = corruptedLogsDirectory.toFile().listFiles();
    assertNotNull(files);
    assertEquals(1, files.length);
}
Also used : Path(java.nio.file.Path) FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel) 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) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 3 with FlushablePositionAwareChecksumChannel

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

the class CorruptedLogsTruncatorTest method generateTransactionLogFiles.

private static void generateTransactionLogFiles(LogFiles logFiles) throws IOException {
    LogFile logFile = logFiles.getLogFile();
    FlushablePositionAwareChecksumChannel writer = logFile.getTransactionLogWriter().getChannel();
    for (byte i = 0; i < 107; i++) {
        writer.put(i);
        writer.prepareForFlush();
        if (logFile.rotationNeeded()) {
            logFile.rotate();
        }
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel)

Example 4 with FlushablePositionAwareChecksumChannel

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

the class RecoveryCorruptedTransactionLogIT method addCorruptedCommandsToLastLogFile.

private void addCorruptedCommandsToLastLogFile(LogEntryWriterWrapper logEntryWriterWrapper) throws IOException {
    PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository(logFiles);
    LogFiles internalLogFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(versionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).build();
    try (Lifespan lifespan = new Lifespan(internalLogFiles)) {
        LogFile transactionLogFile = internalLogFiles.getLogFile();
        LogEntryWriter<FlushablePositionAwareChecksumChannel> realLogEntryWriter = transactionLogFile.getTransactionLogWriter().getWriter();
        LogEntryWriter<FlushablePositionAwareChecksumChannel> wrappedLogEntryWriter = logEntryWriterWrapper.wrap(realLogEntryWriter);
        StaticLogEntryWriterFactory<FlushablePositionAwareChecksumChannel> factory = new StaticLogEntryWriterFactory<>(wrappedLogEntryWriter);
        TransactionLogWriter writer = new TransactionLogWriter(realLogEntryWriter.getChannel(), factory);
        List<StorageCommand> commands = new ArrayList<>();
        commands.add(new Command.PropertyCommand(new PropertyRecord(1), new PropertyRecord(2)));
        commands.add(new Command.NodeCommand(new NodeRecord(2), new NodeRecord(3)));
        PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
        transaction.setHeader(new byte[0], 0, 0, 0, 0, ANONYMOUS);
        writer.append(transaction, 1000, BASE_TX_CHECKSUM);
    }
}
Also used : SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) ArrayList(java.util.ArrayList) FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Command(org.neo4j.internal.recordstorage.Command) StorageCommand(org.neo4j.storageengine.api.StorageCommand) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 5 with FlushablePositionAwareChecksumChannel

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

the class CorruptedLogsTruncatorTest method doNotTruncateLogWithPreAllocatedZeros.

@Test
void doNotTruncateLogWithPreAllocatedZeros() throws IOException {
    life.start();
    generateTransactionLogFiles(logFiles);
    var logFile = logFiles.getLogFile();
    long highestLogVersion = logFile.getHighestLogVersion();
    long fileSizeBeforeAppend = Files.size(logFile.getHighestLogFile());
    LogPosition endOfLogsPosition = new LogPosition(highestLogVersion, fileSizeBeforeAppend);
    FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
    for (int i = 0; i < RandomUtils.nextInt(100, 10240); i++) {
        channel.putLong(0);
    }
    channel.prepareForFlush().flush();
    long fileAfterZeroAppend = Files.size(logFile.getHighestLogFile());
    assertNotEquals(fileSizeBeforeAppend, fileAfterZeroAppend);
    logPruner.truncate(endOfLogsPosition);
    assertEquals(TOTAL_NUMBER_OF_LOG_FILES, logFiles.logFiles().length);
    assertEquals(fileAfterZeroAppend, Files.size(logFile.getHighestLogFile()));
    assertNotEquals(fileSizeBeforeAppend, Files.size(logFile.getHighestLogFile()));
    assertTrue(ArrayUtils.isEmpty(databaseDirectory.toFile().listFiles(File::isDirectory)));
}
Also used : FlushablePositionAwareChecksumChannel(org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel) 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) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Aggregations

FlushablePositionAwareChecksumChannel (org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel)5 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)4 File (java.io.File)2 ZipFile (java.util.zip.ZipFile)2 Test (org.junit.jupiter.api.Test)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)2 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Command (org.neo4j.internal.recordstorage.Command)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)1 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)1 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)1 StorageCommand (org.neo4j.storageengine.api.StorageCommand)1