adelapena commented on code in PR #1684:
URL: https://github.com/apache/cassandra/pull/1684#discussion_r942586794


##########
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 think that regular columns over the threshold can be deleted because the 
required tombstone doesn't contain the value. The exception to this is deleting 
not-frozen set or map elements when that element is over the threshold. 
   
   Sets and maps store their items in cell names. So deleting and set/map item 
would generate a tombstone containing the value of the item to be deleted. Such 
tombstone will be rejected by the guardrail, 
[here](https://github.com/apache/cassandra/blob/68c37ede1e1ade868ec6e6a9081b48e73db3f124/src/java/org/apache/cassandra/cql3/UpdateParameters.java#L147-L148).
 The only way to remove it would be either modifying the guardrail or deleting 
the entire collection. Deleting the entire row of the partition would also be 
possible.
   
   If we wouldn't have that check for tombstone names it would be possible to 
insert large tombstones (over the threshold) into sets and maps, even if the 
element has never been written before.



-- 
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]

Reply via email to