Search in sources :

Example 1 with LogEntryCommand

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand 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 2 with LogEntryCommand

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

the class LegacyLogsTest method createNode.

private static LogEntry createNode(int id) {
    NodeRecord before = new NodeRecord(id).initialize(false, NO_NEXT_REL, false, NO_NEXT_REL, NO_LABELS);
    NodeRecord after = new NodeRecord(id).initialize(true, NO_NEXT_REL, false, NO_NEXT_REL, NO_LABELS);
    Command.NodeCommand command = new Command.NodeCommand(before, after);
    return new LogEntryCommand(command);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)

Example 3 with LogEntryCommand

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

the class LogEntrySortingCursorTest method command.

private LogEntry command() {
    NodeRecord before = new NodeRecord(random.nextInt());
    NodeRecord after = new NodeRecord(random.nextInt());
    return new LogEntryCommand(new Command.NodeCommand(before, after));
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)

Example 4 with LogEntryCommand

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

the class ReplicatedTransactionFactory method read.

public static TransactionRepresentation read(NetworkReadableClosableChannelNetty4 channel, byte[] extraHeader) throws IOException {
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    int authorId = channel.getInt();
    int masterId = channel.getInt();
    long latestCommittedTxWhenStarted = channel.getLong();
    long timeStarted = channel.getLong();
    long timeCommitted = channel.getLong();
    int lockSessionId = channel.getInt();
    int headerLength = channel.getInt();
    byte[] header;
    if (headerLength == 0) {
        header = extraHeader;
    } else {
        header = new byte[headerLength];
    }
    channel.get(header, headerLength);
    LogEntryCommand entryRead;
    List<StorageCommand> commands = new LinkedList<>();
    while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
        commands.add(entryRead.getXaCommand());
    }
    PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
    tx.setHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId);
    return tx;
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LinkedList(java.util.LinkedList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 5 with LogEntryCommand

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

the class ReplicatedTokenRequestSerializer method extractCommands.

static Collection<StorageCommand> extractCommands(byte[] commandBytes) {
    ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes);
    NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer);
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    LogEntryCommand entryRead;
    List<StorageCommand> commands = new LinkedList<>();
    try {
        while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
            commands.add(entryRead.getXaCommand());
        }
    } catch (IOException e) {
        // TODO: Handle or throw.
        e.printStackTrace();
    }
    return commands;
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) LinkedList(java.util.LinkedList) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Aggregations

LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)14 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)9 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)8 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)7 StorageCommand (org.neo4j.storageengine.api.StorageCommand)7 Command (org.neo4j.kernel.impl.transaction.command.Command)6 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)4 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 RecordStorageCommandReaderFactory (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory)2 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)2