Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long commit(final org.neo4j.kernel.impl.api.TransactionToApply tx, final org.neo4j.kernel.impl.transaction.tracing.CommitEvent commitEvent, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public override long Commit(TransactionToApply tx, CommitEvent commitEvent, TransactionApplicationMode mode)
        {
            TransactionRepresentationReplicatedTransaction transaction = ReplicatedTransaction.from(tx.TransactionRepresentation());
            Future <object> futureTxId;

            try
            {
                futureTxId = _replicator.replicate(transaction, true);
            }
            catch (ReplicationFailureException e)
            {
                throw new TransactionFailureException(ReplicationFailure, e);
            }

            try
            {
                return(( long )futureTxId.get());
            }
            catch (ExecutionException e)
            {
                if (e.InnerException is TransactionFailureException)
                {
                    throw ( TransactionFailureException )e.InnerException;
                }
                // TODO: Panic?
                throw new Exception(e);
            }
            catch (InterruptedException e)
            {
                // TODO Wait for the transaction to possibly finish within a user configurable time, before aborting.
                throw new TransactionFailureException("Interrupted while waiting for txId", e);
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void marshal(org.neo4j.storageengine.api.WritableChannel writableChannel, TransactionRepresentationReplicatedTransaction replicatedTransaction) throws java.io.IOException
        public static void Marshal(WritableChannel writableChannel, TransactionRepresentationReplicatedTransaction replicatedTransaction)
        {
            if (writableChannel is ByteBufBacked)
            {
                /*
                 * Marshals more efficiently if Channel is going over the network. In practice, this means maintaining support for
                 * RaftV1 without loosing performance
                 */
                ByteBuf buffer        = (( ByteBufBacked )writableChannel).byteBuf();
                int     metaDataIndex = buffer.writerIndex();
                int     txStartIndex  = metaDataIndex + Integer.BYTES;
                // leave room for length to be set later.
                buffer.writerIndex(txStartIndex);
                WriteTx(writableChannel, replicatedTransaction.Tx());
                int txLength = buffer.writerIndex() - txStartIndex;
                buffer.setInt(metaDataIndex, txLength);
            }
            else
            {
                /*
                 * Unknown length. This should only be reached in tests. When a ReplicatedTransaction is marshaled to file it has already passed over the network
                 * and is of a different type. More efficient marshalling is used in ByteArrayReplicatedTransaction.
                 */
                MemoryStream outputStream = new MemoryStream(1024);
                OutputStreamWritableChannel outputStreamWritableChannel = new OutputStreamWritableChannel(outputStream);
                WriteTx(outputStreamWritableChannel, replicatedTransaction.Tx());
                int length = outputStream.size();
                writableChannel.PutInt(length);
                writableChannel.Put(outputStream.toByteArray(), length);
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMarshalToSameByteIfByteBufBackedOrNot() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMarshalToSameByteIfByteBufBackedOrNot()
        {
            PhysicalTransactionRepresentation expectedTx = new PhysicalTransactionRepresentation(Collections.singleton(new Command.NodeCommand(new NodeRecord(1), new NodeRecord(2))));

            expectedTx.SetHeader(new sbyte[0], 1, 2, 3, 4, 5, 6);
            TransactionRepresentationReplicatedTransaction replicatedTransaction = ReplicatedTransaction.from(expectedTx);

            MemoryStream stream = new MemoryStream();
            ByteBuf      buffer = Buffers.buffer();
            OutputStreamWritableChannel outputStreamWritableChannel = new OutputStreamWritableChannel(stream);
            NetworkWritableChannel      networkWritableChannel      = new NetworkWritableChannel(buffer);

            replicatedTransaction.Marshal(outputStreamWritableChannel);
            replicatedTransaction.Marshal(networkWritableChannel);

            sbyte[] bufferArray = Arrays.copyOf(buffer.array(), buffer.writerIndex());

            Assertions.assertArrayEquals(bufferArray, stream.toByteArray());
        }
Esempio n. 4
0
 public static ChunkedInput <ByteBuf> Encode(TransactionRepresentationReplicatedTransaction representationReplicatedTransaction)
 {
     return(new ChunkedTransaction(representationReplicatedTransaction.Tx()));
 }
Esempio n. 5
0
 public override TransactionRepresentation Extract(TransactionRepresentationReplicatedTransaction replicatedTransaction)
 {
     return(replicatedTransaction.Tx());
 }