diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/state/machines/tx/TransactionRepresentationReplicatedTransaction.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/state/machines/tx/TransactionRepresentationReplicatedTransaction.java index d9fb93187dc31..67a4b271c5fbd 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/state/machines/tx/TransactionRepresentationReplicatedTransaction.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/state/machines/tx/TransactionRepresentationReplicatedTransaction.java @@ -34,17 +34,14 @@ import org.neo4j.causalclustering.messaging.BoundedNetworkChannel; import org.neo4j.causalclustering.messaging.marshalling.ChunkedEncoder; import org.neo4j.function.ThrowingConsumer; -import org.neo4j.io.ByteUnit; import org.neo4j.kernel.impl.transaction.TransactionRepresentation; import org.neo4j.kernel.impl.transaction.log.entry.StorageCommandSerializer; import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.WritableChannel; -import static org.neo4j.causalclustering.helper.NettyHelpers.calculateChunkSize; - public class TransactionRepresentationReplicatedTransaction implements ReplicatedTransaction { - private static final int DEFAULT_CHUNK_SIZE = (int) ByteUnit.mebiBytes( 1 ); + private static final int CHUNK_SIZE = 32 * 1024; private final TransactionRepresentation tx; TransactionRepresentationReplicatedTransaction( TransactionRepresentation tx ) @@ -84,8 +81,7 @@ public ByteBuf encodeChunk( ByteBufAllocator allocator ) throws IOException if ( channel == null ) { // Ensure that the written buffers does not overflow the allocators chunk size. - int maxChunkSize = calculateChunkSize( allocator, 0.8f, DEFAULT_CHUNK_SIZE ); - channel = new BoundedNetworkChannel( allocator, maxChunkSize, output ); + channel = new BoundedNetworkChannel( allocator, CHUNK_SIZE, output ); // Unknown length channel.putInt( -1 ); } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/helper/NettyHelpers.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/helper/NettyHelpers.java deleted file mode 100644 index b5845a089bd4c..0000000000000 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/helper/NettyHelpers.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j Enterprise Edition. The included source - * code can be redistributed and/or modified under the terms of the - * GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - * (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the - * Commons Clause, as found in the associated LICENSE.txt file. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * Neo4j object code can be licensed independently from the source - * under separate terms from the AGPL. Inquiries can be directed to: - * licensing@neo4j.com - * - * More information is also available at: - * https://neo4j.com/licensing/ - */ -package org.neo4j.causalclustering.helper; - -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.PooledByteBufAllocator; - -import java.util.Objects; - -public class NettyHelpers -{ - public static int calculateChunkSize( ByteBufAllocator allocator, float saftyMargin, int defaultValue ) - { - Objects.requireNonNull( allocator, "allocator cannot be null" ); - if ( 0 >= saftyMargin || 1 < saftyMargin ) - { - throw new IllegalArgumentException( "safty magin must be > 0 and less than or equal to 1. Got" + saftyMargin ); - } - if ( defaultValue <= 0 ) - { - throw new IllegalArgumentException( "default value must be > 0. Got" + defaultValue ); - } - if ( allocator instanceof PooledByteBufAllocator ) - { - return (int) ((((PooledByteBufAllocator) allocator).metric().chunkSize()) * saftyMargin); - } - return defaultValue; - } -} diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ByteArrayChunkedEncoder.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ByteArrayChunkedEncoder.java index 99692e2dc51d8..5e13f5cbd541c 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ByteArrayChunkedEncoder.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ByteArrayChunkedEncoder.java @@ -28,14 +28,11 @@ import java.io.IOException; import java.util.Objects; -import org.neo4j.io.ByteUnit; import org.neo4j.storageengine.api.WritableChannel; -import static org.neo4j.causalclustering.helper.NettyHelpers.calculateChunkSize; - public class ByteArrayChunkedEncoder implements ChunkedEncoder { - private static final int DEFAULT_CHUNK_SIZE = (int) ByteUnit.mebiBytes( 1 ); + private static final int DEFAULT_CHUNK_SIZE = 32 * 1024; private final byte[] content; private int chunkSize; private int pos; @@ -58,21 +55,12 @@ public class ByteArrayChunkedEncoder implements ChunkedEncoder public ByteArrayChunkedEncoder( byte[] content ) { - Objects.requireNonNull( content, "content cannot be null" ); - if ( content.length == 0 ) - { - throw new IllegalArgumentException( "Content cannot be an empty array" ); - } - this.content = content; + this( content, DEFAULT_CHUNK_SIZE ); } @Override public ByteBuf encodeChunk( ByteBufAllocator allocator ) { - if ( chunkSize == 0 ) - { - chunkSize = calculateChunkSize( allocator, 0.8f, DEFAULT_CHUNK_SIZE ); - } if ( isEndOfInput() ) { return null; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/helper/NettyHelpersTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/helper/NettyHelpersTest.java deleted file mode 100644 index 10623ba36c20b..0000000000000 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/helper/NettyHelpersTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j Enterprise Edition. The included source - * code can be redistributed and/or modified under the terms of the - * GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - * (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the - * Commons Clause, as found in the associated LICENSE.txt file. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * Neo4j object code can be licensed independently from the source - * under separate terms from the AGPL. Inquiries can be directed to: - * licensing@neo4j.com - * - * More information is also available at: - * https://neo4j.com/licensing/ - */ -package org.neo4j.causalclustering.helper; - -import io.netty.buffer.PooledByteBufAllocator; -import io.netty.buffer.UnpooledByteBufAllocator; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class NettyHelpersTest -{ - private final UnpooledByteBufAllocator unpooledByteBufAllocator = UnpooledByteBufAllocator.DEFAULT; - private final PooledByteBufAllocator pooledByteBufAllocator = PooledByteBufAllocator.DEFAULT; - - @Test( expected = IllegalArgumentException.class ) - public void shouldNotAllowZeroSaftyMargin() - { - NettyHelpers.calculateChunkSize( unpooledByteBufAllocator, 0, 1 ); - } - - @Test( expected = IllegalArgumentException.class ) - public void shouldNotAllowAbove1SaftyMargin() - { - NettyHelpers.calculateChunkSize( unpooledByteBufAllocator, 1.1f, 1 ); - } - - @Test( expected = IllegalArgumentException.class ) - public void shouldNotAllowNegativeDefaultValue() - { - NettyHelpers.calculateChunkSize( unpooledByteBufAllocator, 0.9f, -1 ); - } - - @Test( expected = NullPointerException.class ) - public void shouldNotAllowNullBuffer() - { - NettyHelpers.calculateChunkSize( null, 0.9f, 1 ); - } - - @Test - public void shouldUseDefaultValueIfNotPooled() - { - assertEquals( 1, NettyHelpers.calculateChunkSize( unpooledByteBufAllocator, 0.9f, 1 ) ); - } - - @Test - public void shouldUsePooledBuffersValue() - { - int chunkSize = pooledByteBufAllocator.metric().chunkSize(); - assertEquals( chunkSize, NettyHelpers.calculateChunkSize( pooledByteBufAllocator, 1, 1 ) ); - } -}