Search in sources :

Example 11 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method batchOf.

private TransactionToApply batchOf(TransactionRepresentation... transactions) {
    TransactionToApply first = null, last = null;
    for (TransactionRepresentation transaction : transactions) {
        TransactionToApply tx = new TransactionToApply(transaction);
        if (first == null) {
            first = last = tx;
        } else {
            last.next(tx);
            last = tx;
        }
    }
    return first;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)

Example 12 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class ApplyRecoveredTransactionsTest method applyExternalTransaction.

private void applyExternalTransaction(long transactionId, Command... commands) throws Exception {
    LockService lockService = mock(LockService.class);
    when(lockService.acquireNodeLock(anyLong(), any(LockService.LockType.class))).thenReturn(LockService.NO_LOCK);
    when(lockService.acquireRelationshipLock(anyLong(), any(LockService.LockType.class))).thenReturn(LockService.NO_LOCK);
    NeoStoreBatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), lockService);
    TransactionRepresentation tx = new PhysicalTransactionRepresentation(Arrays.asList(commands));
    CommandHandlerContract.apply(applier, txApplier -> {
        tx.accept(txApplier);
        return false;
    }, new TransactionToApply(tx, transactionId));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LockService(org.neo4j.kernel.impl.locking.LockService) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 13 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class MasterClient214 method commit.

@Override
public Response<Long> commit(RequestContext context, TransactionRepresentation tx) {
    Serializer serializer = new Protocol.TransactionSerializer(tx);
    Deserializer<Long> deserializer = (buffer, temporaryBuffer) -> buffer.readLong();
    return sendRequest(requestTypes.type(HaRequestTypes.Type.COMMIT), context, serializer, deserializer);
}
Also used : VOID_DESERIALIZER(org.neo4j.com.Protocol.VOID_DESERIALIZER) StoreId(org.neo4j.kernel.impl.store.StoreId) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) RequestType(org.neo4j.com.RequestType) LockResult(org.neo4j.kernel.ha.lock.LockResult) ObjectSerializer(org.neo4j.com.ObjectSerializer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ResourceType(org.neo4j.storageengine.api.lock.ResourceType) Exceptions(org.neo4j.helpers.Exceptions) StoreWriter(org.neo4j.com.storecopy.StoreWriter) LogProvider(org.neo4j.logging.LogProvider) Serializer(org.neo4j.com.Serializer) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) IdRange(org.neo4j.kernel.impl.store.id.IdRange) RequestContext(org.neo4j.com.RequestContext) RequestMonitor(org.neo4j.com.monitor.RequestMonitor) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) INTERNAL_PROTOCOL_VERSION(org.neo4j.com.ProtocolVersion.INTERNAL_PROTOCOL_VERSION) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) Client(org.neo4j.com.Client) EMPTY_SERIALIZER(org.neo4j.com.Protocol.EMPTY_SERIALIZER) Response(org.neo4j.com.Response) Protocol(org.neo4j.com.Protocol) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) IOException(java.io.IOException) Protocol214(org.neo4j.com.Protocol214) MasterServer(org.neo4j.kernel.ha.com.master.MasterServer) LockStatus(org.neo4j.kernel.ha.lock.LockStatus) String.format(java.lang.String.format) IdType(org.neo4j.kernel.impl.store.id.IdType) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) Protocol.writeString(org.neo4j.com.Protocol.writeString) ProtocolVersion(org.neo4j.com.ProtocolVersion) Protocol.readString(org.neo4j.com.Protocol.readString) Deserializer(org.neo4j.com.Deserializer) Master(org.neo4j.kernel.ha.com.master.Master) ObjectSerializer(org.neo4j.com.ObjectSerializer) Serializer(org.neo4j.com.Serializer)

Example 14 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class SlaveTransactionCommitProcess method commit.

@Override
public long commit(TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode) throws TransactionFailureException {
    if (batch.next() != null) {
        throw new IllegalArgumentException("Only supports single-commit on slave --> master");
    }
    try {
        TransactionRepresentation representation = batch.transactionRepresentation();
        RequestContext context = requestContextFactory.newRequestContext(representation.getLockSessionId());
        try (Response<Long> response = master.commit(context, representation)) {
            return response.response();
        }
    } catch (IOException e) {
        throw new TransactionFailureException(Status.Transaction.TransactionCommitFailed, e, "Could not commit transaction on the master");
    } catch (ComException e) {
        throw new TransientTransactionFailureException("Cannot commit this transaction on the master. " + "The master is either down, or we have network connectivity problems.", e);
    }
}
Also used : ComException(org.neo4j.com.ComException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) RequestContext(org.neo4j.com.RequestContext) IOException(java.io.IOException)

Example 15 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class ProtocolTest method shouldSerializeAndDeserializeTransactionRepresentation.

@Test
public void shouldSerializeAndDeserializeTransactionRepresentation() throws Exception {
    // GIVEN
    PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(justOneNode());
    byte[] additionalHeader = "extra".getBytes();
    int masterId = 1, authorId = 2;
    long timeStarted = 12345, lastTxWhenStarted = 12, timeCommitted = timeStarted + 10;
    transaction.setHeader(additionalHeader, masterId, authorId, timeStarted, lastTxWhenStarted, timeCommitted, -1);
    Protocol.TransactionSerializer serializer = new Protocol.TransactionSerializer(transaction);
    ChannelBuffer buffer = new ChannelBufferWrapper(new InMemoryClosableChannel());
    // WHEN serializing the transaction
    serializer.write(buffer);
    // THEN deserializing the same transaction should yield the same data.
    // ... remember that this deserializer doesn't read the data source name string. Read it manually here
    assertEquals(NeoStoreDataSource.DEFAULT_DATA_SOURCE_NAME, Protocol.readString(buffer));
    VersionAwareLogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
    TransactionRepresentation readTransaction = new Protocol.TransactionRepresentationDeserializer(reader).read(buffer, ByteBuffer.allocate(1000));
    assertArrayEquals(additionalHeader, readTransaction.additionalHeader());
    assertEquals(masterId, readTransaction.getMasterId());
    assertEquals(authorId, readTransaction.getAuthorId());
    assertEquals(timeStarted, readTransaction.getTimeStarted());
    assertEquals(lastTxWhenStarted, readTransaction.getLatestCommittedTxWhenStarted());
    assertEquals(timeCommitted, readTransaction.getTimeCommitted());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Aggregations

TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)26 Test (org.junit.Test)13 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)12 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)9 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)3 RequestContext (org.neo4j.com.RequestContext)3 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)3 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)2 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ByteBuf (io.netty.buffer.ByteBuf)1