Search in sources :

Example 1 with MessageTooBigException

use of org.neo4j.causalclustering.messaging.MessageTooBigException in project neo4j by neo4j.

the class ReplicatedTransactionFactory method createImmutableReplicatedTransaction.

public static ReplicatedTransaction createImmutableReplicatedTransaction(TransactionRepresentation tx) {
    ByteBuf transactionBuffer = Unpooled.buffer();
    NetworkFlushableChannelNetty4 channel = new NetworkFlushableChannelNetty4(transactionBuffer, MAX_SERIALIZED_TX_SIZE);
    try {
        TransactionSerializer.write(tx, channel);
    } catch (MessageTooBigException e) {
        throw new IllegalStateException("Transaction size was too large to replicate across the cluster.", e);
    } catch (IOException e) {
        // Easier said than done though, we use the LogEntry handling routines which throw IOException
        throw new RuntimeException(e);
    }
    /*
         * This trims down the array to send up to the actual index it was written. While sending additional zeroes
         * is safe, since LogEntryReader stops reading once it sees a zero entry, it is wasteful.
         */
    byte[] txBytes = Arrays.copyOf(transactionBuffer.array(), transactionBuffer.writerIndex());
    transactionBuffer.release();
    return new ReplicatedTransaction(txBytes);
}
Also used : MessageTooBigException(org.neo4j.causalclustering.messaging.MessageTooBigException) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 MessageTooBigException (org.neo4j.causalclustering.messaging.MessageTooBigException)1 NetworkFlushableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4)1