Skip to content

Commit

Permalink
Merge pull request #3642 from ingef/fix/review-mina-stack
Browse files Browse the repository at this point in the history
Use dw DataSize for validation
  • Loading branch information
thoniTUB authored Feb 3, 2025
2 parents 4e8c834 + 9834008 commit b0db47d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

Expand All @@ -16,7 +15,11 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.core.Configuration;
import io.dropwizard.util.DataSize;
import io.dropwizard.util.DataSizeUnit;
import io.dropwizard.util.Duration;
import io.dropwizard.validation.MaxDataSize;
import io.dropwizard.validation.MinDataSize;
import io.dropwizard.validation.PortRange;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -49,18 +52,18 @@ public class ClusterConfig extends Configuration {
* <p/>
* May only touch this for testing purposes.
*/
@Max(Integer.MAX_VALUE - 4)
@Min(64) // not practical
private int maxIoBufferSizeBytes = Integer.MAX_VALUE - 4;
@MaxDataSize(value = Integer.MAX_VALUE - 4, unit = DataSizeUnit.BYTES)
@MinDataSize(value = 64, unit = DataSizeUnit.BYTES)
private DataSize maxIoBufferSize = DataSize.bytes(Integer.MAX_VALUE - 4);

/**
* Defines the starting buffer allocation size. Larger can reduce reallocations, but can cause a greater memory demand.
* <p/>
* May only touch this for testing purposes.
*/
@Max(Integer.MAX_VALUE - 4)
@Min(64) // Mina's default
private int initialIoBufferSizeBytes = 8192; // 8kb
@MaxDataSize(value = Integer.MAX_VALUE - 4, unit = DataSizeUnit.BYTES)
@MinDataSize(value = 64, unit = DataSizeUnit.BYTES)
private DataSize initialIoBufferSize = DataSize.bytes(8192); // 8kb

/**
* @see com.bakdata.conquery.models.messages.namespaces.specific.CollectColumnValuesJob
Expand Down Expand Up @@ -90,8 +93,8 @@ public NioSocketConnector getClusterConnector(ObjectMapper om, IoHandler ioHandl
final NioSocketConnector connector = new NioSocketConnector();

JacksonProtocolEncoder encoder = new JacksonProtocolEncoder(om.writerFor(NetworkMessage.class));
encoder.setMaxObjectSize(maxIoBufferSizeBytes);
encoder.setInitialBufferCapacityBytes(initialIoBufferSizeBytes);
encoder.setMaxObjectSize(Math.toIntExact(maxIoBufferSize.toBytes()));
encoder.setInitialBufferCapacityBytes(Math.toIntExact(initialIoBufferSize.toBytes()));

ProtocolCodecFilter codecFilter = new ProtocolCodecFilter(
encoder,
Expand All @@ -115,8 +118,8 @@ public NioSocketAcceptor getClusterAcceptor(ObjectMapper om, IoHandler ioHandler


JacksonProtocolEncoder encoder = new JacksonProtocolEncoder(om.writerFor(NetworkMessage.class));
encoder.setMaxObjectSize(maxIoBufferSizeBytes);
encoder.setInitialBufferCapacityBytes(initialIoBufferSizeBytes);
encoder.setMaxObjectSize(Math.toIntExact(maxIoBufferSize.toBytes()));
encoder.setInitialBufferCapacityBytes(Math.toIntExact(initialIoBufferSize.toBytes()));

ProtocolCodecFilter codecFilter = new ProtocolCodecFilter(
encoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class MinaStackTest {
public static void beforeAll() throws IOException {

CLUSTER_CONFIG.setPort(0);
CLUSTER_CONFIG.setMaxIoBufferSizeBytes(toIntExact(DataSize.mebibytes(10).toBytes()));
CLUSTER_CONFIG.setMaxIoBufferSize(DataSize.mebibytes(10));

// This enables the Chunking filter, which triggers for messages > 1 MebiByte
CLUSTER_CONFIG.getMina().setSendBufferSize(toIntExact(DataSize.mebibytes(1).toBytes()));
Expand Down

0 comments on commit b0db47d

Please sign in to comment.