From 08444cbc3f6378f281a811d74c9cb152c8ad19ca Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 26 Aug 2021 10:16:42 -0500 Subject: [PATCH] Reduce max native frame size to 16MB Patch by brandonwilliams; reviewed by blerer for CASSANDRA-16886 --- CHANGES.txt | 1 + conf/cassandra.yaml | 4 ++-- src/java/org/apache/cassandra/config/Config.java | 2 +- .../apache/cassandra/config/DatabaseDescriptor.java | 10 ++++++++++ .../apache/cassandra/transport/CQLConnectionTest.java | 3 +++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f0a0dfb85d..80ee45ca2e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.1 + * Reduce native transport max frame size to 16MB (CASSANDRA-16886) * Add support for filtering using IN restrictions (CASSANDRA-14344) * Provide a nodetool command to invalidate auth caches (CASSANDRA-16404) * Catch read repair timeout exceptions and add metric (CASSANDRA-16880) diff --git a/conf/cassandra.yaml b/conf/cassandra.yaml index ff073da4c4..25f6eb1c84 100644 --- a/conf/cassandra.yaml +++ b/conf/cassandra.yaml @@ -710,9 +710,9 @@ native_transport_port: 9042 # native_transport_max_threads: 128 # # The maximum size of allowed frame. Frame (requests) larger than this will -# be rejected as invalid. The default is 256MB. If you're changing this parameter, +# be rejected as invalid. The default is 16MB. If you're changing this parameter, # you may want to adjust max_value_size_in_mb accordingly. This should be positive and less than 2048. -# native_transport_max_frame_size_in_mb: 256 +# native_transport_max_frame_size_in_mb: 16 # The maximum number of concurrent client connections. # The default is -1, which means unlimited. diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java index 731b4662c5..77607eddb9 100644 --- a/src/java/org/apache/cassandra/config/Config.java +++ b/src/java/org/apache/cassandra/config/Config.java @@ -186,7 +186,7 @@ public class Config public int native_transport_port = 9042; public Integer native_transport_port_ssl = null; public int native_transport_max_threads = 128; - public int native_transport_max_frame_size_in_mb = 256; + public int native_transport_max_frame_size_in_mb = 16; public volatile long native_transport_max_concurrent_connections = -1L; public volatile long native_transport_max_concurrent_connections_per_ip = -1L; public boolean native_transport_flush_in_batches_legacy = false; diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 7e804850f0..7a0eeb0045 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -2257,6 +2257,11 @@ public class DatabaseDescriptor return (int) ByteUnit.MEBI_BYTES.toBytes(conf.native_transport_max_frame_size_in_mb); } + public static void setNativeTransportMaxFrameSize(int bytes) + { + conf.native_transport_max_frame_size_in_mb = (int) ByteUnit.MEBI_BYTES.fromBytes(bytes); + } + public static long getNativeTransportMaxConcurrentConnections() { return conf.native_transport_max_concurrent_connections; @@ -3298,6 +3303,11 @@ public class DatabaseDescriptor { return val * multiplier; } + + public long fromBytes(int val) + { + return val / multiplier; + } } /** diff --git a/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java b/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java index 73950ae31d..adc82ea1a8 100644 --- a/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java +++ b/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java @@ -59,6 +59,7 @@ import org.apache.cassandra.utils.concurrent.SimpleCondition; import org.apache.cassandra.utils.concurrent.NonBlockingRateLimiter; import static org.apache.cassandra.config.EncryptionOptions.TlsEncryptionPolicy.UNENCRYPTED; +import static org.apache.cassandra.io.util.FileUtils.ONE_MB; import static org.apache.cassandra.net.FramingTest.randomishBytes; import static org.apache.cassandra.transport.Flusher.MAX_FRAMED_PAYLOAD_SIZE; import static org.apache.cassandra.utils.concurrent.NonBlockingRateLimiter.NO_OP_LIMITER; @@ -104,6 +105,8 @@ public class CQLConnectionTest alloc = GlobalBufferPoolAllocator.instance; // set connection-local queue size to 0 so that all capacity is allocated from reserves DatabaseDescriptor.setNativeTransportReceiveQueueCapacityInBytes(0); + // set transport to max frame size possible + DatabaseDescriptor.setNativeTransportMaxFrameSize(256 * (int) ONE_MB); } @Test