Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dw DataSize for validation #3642

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading