Search in sources :

Example 6 with PhysicalTransactionRepresentation

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

the class CheckTxLogsTest method writeTxContent.

private void writeTxContent(File log, long txId, Command... commands) throws IOException {
    PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(Arrays.asList(commands));
    tx.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
    writeContent(log, (txWriter) -> txWriter.append(tx, txId));
}
Also used : PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 7 with PhysicalTransactionRepresentation

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation 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 8 with PhysicalTransactionRepresentation

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

the class SlaveTransactionCommitProcessTest method setUp.

@Before
public void setUp() {
    lastSeenEventIdentifier = new AtomicInteger(-1);
    master = mock(Master.class);
    requestContext = new RequestContext(10, 11, 12, 13, 14);
    reqFactory = new ConstantRequestContextFactory(requestContext) {

        @Override
        public RequestContext newRequestContext(int eventIdentifier) {
            lastSeenEventIdentifier.set(eventIdentifier);
            return super.newRequestContext(eventIdentifier);
        }
    };
    response = new LongResponse(42L);
    tx = new PhysicalTransactionRepresentation(Collections.<StorageCommand>emptyList());
    tx.setHeader(new byte[] {}, 1, 1, 1, 1, 1, 1337);
    commitProcess = new SlaveTransactionCommitProcess(master, reqFactory);
}
Also used : Master(org.neo4j.kernel.ha.com.master.Master) LongResponse(org.neo4j.test.LongResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ConstantRequestContextFactory(org.neo4j.test.ConstantRequestContextFactory) RequestContext(org.neo4j.com.RequestContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Before(org.junit.Before)

Example 9 with PhysicalTransactionRepresentation

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

the class RaftContentByteBufferMarshalTest method shouldSerializeTransactionRepresentation.

@Test
public void shouldSerializeTransactionRepresentation() throws Exception {
    // given
    CoreReplicatedContentMarshal serializer = new CoreReplicatedContentMarshal();
    Collection<StorageCommand> commands = new ArrayList<>();
    IndexCommand.AddNodeCommand addNodeCommand = new IndexCommand.AddNodeCommand();
    addNodeCommand.init(0, 0, 0, 0);
    commands.add(addNodeCommand);
    byte[] extraHeader = new byte[0];
    PhysicalTransactionRepresentation txIn = new PhysicalTransactionRepresentation(commands);
    txIn.setHeader(extraHeader, -1, -1, 0, 0, 0, 0);
    ReplicatedTransaction in = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(txIn);
    // when
    ByteBuf buf = Unpooled.buffer();
    serializer.marshal(in, new NetworkFlushableByteBuf(buf));
    ReplicatedTransaction out = (ReplicatedTransaction) serializer.unmarshal(new NetworkReadableClosableChannelNetty4(buf));
    TransactionRepresentation txOut = ReplicatedTransactionFactory.extractTransactionRepresentation(out, extraHeader);
    // then
    assertEquals(in, out);
    assertEquals(txIn, txOut);
}
Also used : NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) StorageCommand(org.neo4j.storageengine.api.StorageCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) CoreReplicatedContentMarshal(org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 10 with PhysicalTransactionRepresentation

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

the class TransactionWriter method representation.

public TransactionRepresentation representation(byte[] additionalHeader, int masterId, int authorId, long startTime, long lastCommittedTx, long committedTime) {
    prepareForCommit();
    PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(allCommands());
    representation.setHeader(additionalHeader, masterId, authorId, startTime, lastCommittedTx, committedTime, -1);
    return representation;
}
Also used : PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Aggregations

PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)35 Test (org.junit.Test)15 StorageCommand (org.neo4j.storageengine.api.StorageCommand)9 ArrayList (java.util.ArrayList)7 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)6 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)5 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)5 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)4 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)4 ByteBuf (io.netty.buffer.ByteBuf)3 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 Command (org.neo4j.kernel.impl.transaction.command.Command)3 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)3 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)3 ReplicatedTransaction (org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)2