Search in sources :

Example 1 with LogEntryWriter

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

the class RecoveryTest method shouldSeeThatACleanDatabaseShouldNotRequireRecovery.

@Test
public void shouldSeeThatACleanDatabaseShouldNotRequireRecovery() throws Exception {
    final PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), "log", fileSystemRule.get());
    File file = logFiles.getLogFileForVersion(logVersion);
    writeSomeData(file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException>() {

        @Override
        public boolean visit(Pair<LogEntryWriter, Consumer<LogPositionMarker>> pair) throws IOException {
            LogEntryWriter writer = pair.first();
            Consumer<LogPositionMarker> consumer = pair.other();
            LogPositionMarker marker = new LogPositionMarker();
            // last committed tx
            consumer.accept(marker);
            writer.writeStartEntry(0, 1, 2L, 3L, new byte[0]);
            writer.writeCommitEntry(4L, 5L);
            // check point
            consumer.accept(marker);
            writer.writeCheckPointEntry(marker.newPosition());
            return true;
        }
    });
    LifeSupport life = new LifeSupport();
    Recovery.Monitor monitor = mock(Recovery.Monitor.class);
    try {
        StorageEngine storageEngine = mock(StorageEngine.class);
        final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
        LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fileSystemRule.get(), reader);
        TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
        LogHeaderCache logHeaderCache = new LogHeaderCache(10);
        LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 50, () -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository, mock(PhysicalLogFile.Monitor.class), logHeaderCache));
        LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, metadataCache, reader);
        life.add(new Recovery(new DefaultRecoverySPI(storageEngine, logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore, NO_MONITOR) {

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
                fail("Recovery should not be required");
                // <-- to satisfy the compiler
                return null;
            }
        }, monitor));
        life.start();
        verifyZeroInteractions(monitor);
    } finally {
        life.shutdown();
    }
}
Also used : DefaultRecoverySPI(org.neo4j.kernel.recovery.DefaultRecoverySPI) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Recovery(org.neo4j.kernel.recovery.Recovery) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Consumer(java.util.function.Consumer) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) Pair(org.neo4j.helpers.collection.Pair) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) IOException(java.io.IOException) IOException(java.io.IOException) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Test(org.junit.Test)

Example 2 with LogEntryWriter

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

the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInACommitToTheFile.

@Test
public void shouldWriteAllTheEntryInACommitToTheFile() throws IOException {
    // given
    final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
    final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
    final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
    final LogEntryStart start = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    final LogEntryCommand command = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
    final LogEntryCommit commit = new OnePhaseCommit(42L, 43L);
    // when
    final IOCursor<LogEntry> cursor = mockCursor(start, command, commit);
    writer.writeAllLogEntries(channel, cursor);
    // then
    verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
    final TransactionRepresentation expected = new PhysicalTransactionRepresentation(Arrays.asList(command.getXaCommand()));
    verify(logEntryWriter, times(1)).serialize(eq(expected));
    verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 3 with LogEntryWriter

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

the class ReplicatedTokenRequestSerializer method commandBytes.

public static byte[] commandBytes(Collection<StorageCommand> commands) {
    ByteBuf commandBuffer = Unpooled.buffer();
    NetworkFlushableChannelNetty4 channel = new NetworkFlushableChannelNetty4(commandBuffer);
    try {
        new LogEntryWriter(channel).serialize(commands);
    } catch (IOException e) {
        // TODO: Handle or throw.
        e.printStackTrace();
    }
    byte[] commandsBytes = commandBuffer.array().clone();
    commandBuffer.release();
    return commandsBytes;
}
Also used : NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with LogEntryWriter

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

the class TransactionLogRecoveryIT method writePartialTx.

private void writePartialTx(File storeDir) throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache.getPageCache(fs), storeDir);
    ReadOnlyTransactionIdStore txIdStore = new ReadOnlyTransactionIdStore(pageCache.getPageCache(fs), storeDir);
    PhysicalLogFile logFile = new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
    txIdStore::getLastCommittedTransactionId, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), new LogHeaderCache(10));
    try (Lifespan ignored = new Lifespan(logFile)) {
        LogEntryWriter writer = new LogEntryWriter(logFile.getWriter());
        writer.writeStartEntry(0, 0, 0x123456789ABCDEFL, txIdStore.getLastCommittedTransactionId() + 1, new byte[] { 0 });
    }
}
Also used : ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) Monitors(org.neo4j.kernel.monitoring.Monitors) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) ReadOnlyLogVersionRepository(org.neo4j.kernel.impl.transaction.log.ReadOnlyLogVersionRepository) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 5 with LogEntryWriter

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

the class StoreMigratorCheckPointer method checkPoint.

/**
     * Write a check point in the log file with the given version
     * <p>
     * It will create the file with header containing the log version and lastCommittedTx given as arguments
     *
     * @param logVersion the log version to open
     * @param lastCommittedTx the last committed tx id
     */
public void checkPoint(long logVersion, long lastCommittedTx) throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fileSystem);
    File logFileForVersion = logFiles.getLogFileForVersion(logVersion);
    if (!fileSystem.fileExists(logFileForVersion)) {
        try (StoreChannel channel = fileSystem.create(logFileForVersion)) {
            writeLogHeader(channel, logVersion, lastCommittedTx);
        }
    }
    try (LogVersionedStoreChannel storeChannel = PhysicalLogFile.openForVersion(logFiles, fileSystem, logVersion, true)) {
        long offset = storeChannel.size();
        storeChannel.position(offset);
        try (PositionAwarePhysicalFlushableChannel channel = new PositionAwarePhysicalFlushableChannel(storeChannel)) {
            TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
            writer.checkPoint(new LogPosition(logVersion, offset));
        }
    }
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PositionAwarePhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Aggregations

LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)28 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)16 IOException (java.io.IOException)11 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)11 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)11 File (java.io.File)10 Path (java.nio.file.Path)10 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)10 Test (org.junit.Test)9 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)9 Consumer (java.util.function.Consumer)7 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)7 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)7 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)7 Pair (org.neo4j.helpers.collection.Pair)6 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)6 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)6 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)6