Skip to content

Commit

Permalink
Set default chunk size to play well with default RecvByteBufAllocator
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW authored and martinfurmanski committed Sep 10, 2018
1 parent ed46113 commit 7e9dd4e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 141 deletions.
Expand Up @@ -34,17 +34,14 @@
import org.neo4j.causalclustering.messaging.BoundedNetworkChannel; import org.neo4j.causalclustering.messaging.BoundedNetworkChannel;
import org.neo4j.causalclustering.messaging.marshalling.ChunkedEncoder; import org.neo4j.causalclustering.messaging.marshalling.ChunkedEncoder;
import org.neo4j.function.ThrowingConsumer; import org.neo4j.function.ThrowingConsumer;
import org.neo4j.io.ByteUnit;
import org.neo4j.kernel.impl.transaction.TransactionRepresentation; import org.neo4j.kernel.impl.transaction.TransactionRepresentation;
import org.neo4j.kernel.impl.transaction.log.entry.StorageCommandSerializer; import org.neo4j.kernel.impl.transaction.log.entry.StorageCommandSerializer;
import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.StorageCommand;
import org.neo4j.storageengine.api.WritableChannel; import org.neo4j.storageengine.api.WritableChannel;


import static org.neo4j.causalclustering.helper.NettyHelpers.calculateChunkSize;

public class TransactionRepresentationReplicatedTransaction implements ReplicatedTransaction 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; private final TransactionRepresentation tx;


TransactionRepresentationReplicatedTransaction( TransactionRepresentation tx ) TransactionRepresentationReplicatedTransaction( TransactionRepresentation tx )
Expand Down Expand Up @@ -84,8 +81,7 @@ public ByteBuf encodeChunk( ByteBufAllocator allocator ) throws IOException
if ( channel == null ) if ( channel == null )
{ {
// Ensure that the written buffers does not overflow the allocators chunk size. // 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, CHUNK_SIZE, output );
channel = new BoundedNetworkChannel( allocator, maxChunkSize, output );
// Unknown length // Unknown length
channel.putInt( -1 ); channel.putInt( -1 );
} }
Expand Down

This file was deleted.

Expand Up @@ -28,14 +28,11 @@
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;


import org.neo4j.io.ByteUnit;
import org.neo4j.storageengine.api.WritableChannel; import org.neo4j.storageengine.api.WritableChannel;


import static org.neo4j.causalclustering.helper.NettyHelpers.calculateChunkSize;

public class ByteArrayChunkedEncoder implements ChunkedEncoder 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 final byte[] content;
private int chunkSize; private int chunkSize;
private int pos; private int pos;
Expand All @@ -58,21 +55,12 @@ public class ByteArrayChunkedEncoder implements ChunkedEncoder


public ByteArrayChunkedEncoder( byte[] content ) public ByteArrayChunkedEncoder( byte[] content )
{ {
Objects.requireNonNull( content, "content cannot be null" ); this( content, DEFAULT_CHUNK_SIZE );
if ( content.length == 0 )
{
throw new IllegalArgumentException( "Content cannot be an empty array" );
}
this.content = content;
} }


@Override @Override
public ByteBuf encodeChunk( ByteBufAllocator allocator ) public ByteBuf encodeChunk( ByteBufAllocator allocator )
{ {
if ( chunkSize == 0 )
{
chunkSize = calculateChunkSize( allocator, 0.8f, DEFAULT_CHUNK_SIZE );
}
if ( isEndOfInput() ) if ( isEndOfInput() )
{ {
return null; return null;
Expand Down

This file was deleted.

0 comments on commit 7e9dd4e

Please sign in to comment.