ekaterinadimitrova2 commented on code in PR #1684: URL: https://github.com/apache/cassandra/pull/1684#discussion_r940695796
########## conf/cassandra.yaml: ########## @@ -1752,6 +1752,17 @@ drop_compact_storage_enabled: false # write_consistency_levels_warned: [] # write_consistency_levels_disallowed: [] # +# Guardrail to warn or fail when writing column values larger than threshold. +# This guardrail is only applied to the values of regular columns because both the serialized partitions keys and the +# values of the components of the clustering key already have a fixed, relatively small size limit of 65535 bytes, which +# is probably lesser than the thresholds defined here. +# This guardrail is different to max_value_size. max_value_size is checked when deserializing any value to detect +# sstable corruption, whereas this guardrail is checked on the CQL layer at write time to reject regular user queries +# inserting too large columns. +# Default -1 to disable. Review Comment: `# Default null to disable.` ########## test/unit/org/apache/cassandra/db/guardrails/GuardrailColumnValueSizeTest.java: ########## @@ -0,0 +1,650 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.guardrails; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import org.junit.Test; + +import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.ListType; +import org.apache.cassandra.db.marshal.MapType; +import org.apache.cassandra.db.marshal.SetType; + +import static java.lang.String.format; +import static java.nio.ByteBuffer.allocate; + +/** + * Tests the guardrail for the size of column values, {@link Guardrails#columnValueSize}. + */ +public class GuardrailColumnValueSizeTest extends ThresholdTester +{ + private static final int WARN_THRESHOLD = 1024; // bytes + private static final int FAIL_THRESHOLD = WARN_THRESHOLD * 4; // bytes + + public GuardrailColumnValueSizeTest() + { + super(WARN_THRESHOLD + "B", + FAIL_THRESHOLD + "B", + Guardrails.columnValueSize, + Guardrails::setColumnValueSizeThreshold, + Guardrails::getColumnValueSizeWarnThreshold, + Guardrails::getColumnValueSizeFailThreshold); + } + + @Test + public void testSimplePartitionKey() throws Throwable + { + createTable("CREATE TABLE %s (k text PRIMARY KEY, v int)"); + + // the size of primary key columns is not guarded because they already have a fixed limit of 65535B + + testNoThreshold("INSERT INTO %s (k, v) VALUES (?, 0)"); + testNoThreshold("UPDATE %s SET v = 1 WHERE k = ?"); + testNoThreshold("DELETE v FROM %s WHERE k = ?"); + testNoThreshold("DELETE FROM %s WHERE k = ?"); + } + + @Test + public void testComplexPartitionKey() throws Throwable Review Comment: I think this was meant to be `testCompositePartitionKey`? No? ########## conf/cassandra.yaml: ########## @@ -1752,6 +1752,17 @@ drop_compact_storage_enabled: false # write_consistency_levels_warned: [] # write_consistency_levels_disallowed: [] # +# Guardrail to warn or fail when writing column values larger than threshold. +# This guardrail is only applied to the values of regular columns because both the serialized partitions keys and the +# values of the components of the clustering key already have a fixed, relatively small size limit of 65535 bytes, which Review Comment: So I was not sure immediately where that value came from - 65535 bytes. So I found this in the QueryProcessor - ``` // check that key can be handled by FBUtilities.writeShortByteArray if (key.remaining() > FBUtilities.MAX_UNSIGNED_SHORT) ``` The comment seems outdated as there is no `FBUtilities.writeShortByteArray` now. Shall we use the opportunity to clear this a bit? WDYT? ########## test/unit/org/apache/cassandra/db/guardrails/GuardrailColumnValueSizeTest.java: ########## @@ -0,0 +1,650 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.guardrails; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import org.junit.Test; + +import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.ListType; +import org.apache.cassandra.db.marshal.MapType; +import org.apache.cassandra.db.marshal.SetType; + +import static java.lang.String.format; +import static java.nio.ByteBuffer.allocate; + +/** + * Tests the guardrail for the size of column values, {@link Guardrails#columnValueSize}. + */ +public class GuardrailColumnValueSizeTest extends ThresholdTester +{ + private static final int WARN_THRESHOLD = 1024; // bytes + private static final int FAIL_THRESHOLD = WARN_THRESHOLD * 4; // bytes + + public GuardrailColumnValueSizeTest() + { + super(WARN_THRESHOLD + "B", + FAIL_THRESHOLD + "B", + Guardrails.columnValueSize, + Guardrails::setColumnValueSizeThreshold, + Guardrails::getColumnValueSizeWarnThreshold, + Guardrails::getColumnValueSizeFailThreshold); + } + + @Test + public void testSimplePartitionKey() throws Throwable + { + createTable("CREATE TABLE %s (k text PRIMARY KEY, v int)"); + + // the size of primary key columns is not guarded because they already have a fixed limit of 65535B + + testNoThreshold("INSERT INTO %s (k, v) VALUES (?, 0)"); + testNoThreshold("UPDATE %s SET v = 1 WHERE k = ?"); + testNoThreshold("DELETE v FROM %s WHERE k = ?"); + testNoThreshold("DELETE FROM %s WHERE k = ?"); Review Comment: I was wondering about the following case - someone added some column when the guardrail was disabled... Then operator enables it with certain threshold and someone wants to delete now the column created before which seems to be over the threshold, then we can't delete it anymore, the only way would be if we raise the threshold or disable? Did I get it right? ########## conf/cassandra.yaml: ########## @@ -1752,6 +1752,17 @@ drop_compact_storage_enabled: false # write_consistency_levels_warned: [] # write_consistency_levels_disallowed: [] # +# Guardrail to warn or fail when writing column values larger than threshold. +# This guardrail is only applied to the values of regular columns because both the serialized partitions keys and the +# values of the components of the clustering key already have a fixed, relatively small size limit of 65535 bytes, which +# is probably lesser than the thresholds defined here. +# This guardrail is different to max_value_size. max_value_size is checked when deserializing any value to detect +# sstable corruption, whereas this guardrail is checked on the CQL layer at write time to reject regular user queries +# inserting too large columns. +# Default -1 to disable. Review Comment: I have review in progress, just haven’t submitted it yet. This is just wording, he uses null internally :-) needs to be corrected only in the text -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

