Search in sources :

Example 21 with PhysicalTransactionRepresentation

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

the class MadeUpServerImplementation method transaction.

private TransactionRepresentation transaction(long txId) {
    Collection<StorageCommand> commands = new ArrayList<>();
    NodeRecord node = new NodeRecord(txId);
    node.setInUse(true);
    commands.add(new NodeCommand(new NodeRecord(txId), node));
    PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
    transaction.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
    return transaction;
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 22 with PhysicalTransactionRepresentation

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

the class ReplicatedTokenStateMachine method applyToStore.

private int applyToStore(Collection<StorageCommand> commands, long logIndex) throws NoSuchEntryException {
    int tokenId = extractTokenId(commands);
    PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(commands);
    representation.setHeader(encodeLogIndexAsTxHeader(logIndex), 0, 0, 0, 0L, 0L, 0);
    try (LockGroup ignored = new LockGroup()) {
        commitProcess.commit(new TransactionToApply(representation), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL);
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    }
    return tokenId;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 23 with PhysicalTransactionRepresentation

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

the class RaftContentByteBufferMarshalTest method txSerializationShouldNotResultInExcessZeroes.

@Test
public void txSerializationShouldNotResultInExcessZeroes() throws Exception {
    /*
         * This test ensures that the buffer used to serialize a transaction and then extract the byte array for
         * sending over the wire is trimmed properly. Not doing so will result in sending too many trailing garbage
         * (zeroes) that will be ignored from the other side, as zeros are interpreted as null entries from the
         * LogEntryReader and stop the deserialization process.
         * The test creates a single transaction which has just a header, no commands. That should amount to 40 bytes
         * as ReplicatedTransactionFactory.TransactionSerializer.write() makes it out at the time of this writing. If
         * that code changes, this test will break.
         */
    byte[] extraHeader = new byte[0];
    PhysicalTransactionRepresentation txIn = new PhysicalTransactionRepresentation(new ArrayList<>());
    txIn.setHeader(extraHeader, -1, -1, 0, 0, 0, 0);
    // when
    ReplicatedTransaction in = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(txIn);
    // then
    assertEquals(40, in.getTxBytes().length);
}
Also used : ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 24 with PhysicalTransactionRepresentation

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

the class LegacyLogEntryWriter method writeAllLogEntries.

public void writeAllLogEntries(LogVersionedStoreChannel channel, IOCursor<LogEntry> cursor) throws IOException {
    try (PositionAwarePhysicalFlushableChannel writable = new PositionAwarePhysicalFlushableChannel(channel)) {
        final LogEntryWriter writer = factory.apply(writable);
        List<StorageCommand> commands = new ArrayList<>();
        while (cursor.next()) {
            LogEntry entry = cursor.get();
            if (entry instanceof LogEntryStart) {
                final LogEntryStart startEntry = entry.as();
                writer.writeStartEntry(startEntry.getMasterId(), startEntry.getLocalId(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), startEntry.getAdditionalHeader());
            } else if (entry instanceof LogEntryCommit) {
                if (!commands.isEmpty()) {
                    writer.serialize(new PhysicalTransactionRepresentation(commands));
                    commands = new ArrayList<>();
                }
                final LogEntryCommit commitEntry = (LogEntryCommit) entry;
                writer.writeCommitEntry(commitEntry.getTxId(), commitEntry.getTimeWritten());
            } else if (entry instanceof LogEntryCommand) {
                commands.add(((LogEntryCommand) entry).getXaCommand());
            } else {
                throw new IllegalStateException("Unknown entry: " + entry);
            }
        }
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) PositionAwarePhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) ArrayList(java.util.ArrayList) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 25 with PhysicalTransactionRepresentation

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

the class CoreReplicatedContentMarshalTest method shouldMarshalTransactionReferenceWithMissingHeader.

@Test
public void shouldMarshalTransactionReferenceWithMissingHeader() throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(Collections.emptyList());
    ReplicatedContent replicatedTx = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(representation);
    assertMarshalingEquality(buffer, replicatedTx);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

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