Search in sources :

Example 11 with LogFile

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

the class CorruptedLogsTruncator method isRecoveredLogCorrupted.

private boolean isRecoveredLogCorrupted(long recoveredTransactionLogVersion, long recoveredTransactionOffset) throws IOException {
    try {
        LogFile logFile = logFiles.getLogFile();
        if (Files.size(logFile.getLogFileForVersion(recoveredTransactionLogVersion)) > recoveredTransactionOffset) {
            try (PhysicalLogVersionedStoreChannel channel = logFile.openForVersion(recoveredTransactionLogVersion);
                var scopedBuffer = new NativeScopedBuffer(safeCastLongToInt(kibiBytes(64)), memoryTracker)) {
                channel.position(recoveredTransactionOffset);
                ByteBuffer byteBuffer = scopedBuffer.getBuffer();
                while (channel.read(byteBuffer) >= 0) {
                    byteBuffer.flip();
                    while (byteBuffer.hasRemaining()) {
                        if (byteBuffer.get() != 0) {
                            return true;
                        }
                    }
                    byteBuffer.clear();
                }
            }
        }
        return false;
    } catch (NoSuchFileException ignored) {
        return false;
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) NoSuchFileException(java.nio.file.NoSuchFileException) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 12 with LogFile

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

the class RecoveryCorruptedTransactionLogIT method writeRandomBytesAfterLastCommandInLastLogFile.

private void writeRandomBytesAfterLastCommandInLastLogFile(Supplier<ByteBuffer> source) throws IOException {
    int someRandomPaddingAfterEndOfDataInLogFile = random.nextInt(1, 10);
    try (Lifespan lifespan = new Lifespan()) {
        LogFile transactionLogFile = logFiles.getLogFile();
        lifespan.add(logFiles);
        LogPosition position = getLastReadablePosition(transactionLogFile);
        try (StoreFileChannel writeChannel = fileSystem.write(logFiles.getLogFile().getHighestLogFile())) {
            writeChannel.position(position.getByteOffset() + someRandomPaddingAfterEndOfDataInLogFile);
            for (int i = 0; i < 10; i++) {
                writeChannel.writeAll(source.get());
            }
        }
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 13 with LogFile

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

the class RecoveryCorruptedTransactionLogIT method addRandomBytesToLastLogFile.

private void addRandomBytesToLastLogFile(Supplier<Byte> byteSource) throws IOException {
    try (Lifespan lifespan = new Lifespan()) {
        LogFile transactionLogFile = logFiles.getLogFile();
        lifespan.add(logFiles);
        var channel = transactionLogFile.getTransactionLogWriter().getChannel();
        for (int i = 0; i < 10; i++) {
            channel.put(byteSource.get());
        }
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 14 with LogFile

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

the class TestLogPruning method noPruning.

@Test
void noPruning() throws Exception {
    newDb("true", 2);
    for (int i = 0; i < 100; i++) {
        doTransaction();
    }
    LogFile logFile = files.getLogFile();
    long currentVersion = logFile.getHighestLogVersion();
    for (long version = 0; version < currentVersion; version++) {
        assertTrue(fs.fileExists(logFile.getLogFileForVersion(version)), "Version " + version + " has been unexpectedly pruned");
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Test(org.junit.jupiter.api.Test)

Example 15 with LogFile

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

the class TestLogPruning method aggregateLogData.

private int aggregateLogData(Extractor extractor) throws IOException {
    int total = 0;
    LogFile logFile = files.getLogFile();
    for (long i = logFile.getHighestLogVersion(); i >= 0; i--) {
        if (logFile.versionExists(i)) {
            total += extractor.extract(i);
        } else {
            break;
        }
    }
    return total;
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile)

Aggregations

LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)42 Test (org.junit.jupiter.api.Test)25 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)21 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)15 Path (java.nio.file.Path)12 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)9 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)7 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)7 File (java.io.File)5 ZipFile (java.util.zip.ZipFile)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)5 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)5 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)5 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 FlushablePositionAwareChecksumChannel (org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel)4 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)3 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)3