aratno commented on code in PR #3987:
URL: https://github.com/apache/cassandra/pull/3987#discussion_r2001249658


##########
src/java/org/apache/cassandra/utils/ByteBufferUtil.java:
##########
@@ -544,6 +548,17 @@ else if (obj instanceof byte[])
             return ByteBuffer.wrap((byte[]) obj);
         else if (obj instanceof ByteBuffer)
             return (ByteBuffer) obj;
+        else if (obj instanceof Set)
+        {
+            Set<?> set = (Set<?>) obj;
+            // convert subtypes to BB
+            Set<ByteBuffer> bbs = new LinkedHashSet<>();

Review Comment:
   Can set initial capacity here to match obj?



##########
test/distributed/org/apache/cassandra/distributed/test/CollectionsTest.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.distributed.test;
+
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+
+import static org.apache.cassandra.distributed.shared.AssertUtils.assertRows;
+import static org.apache.cassandra.distributed.shared.AssertUtils.row;
+
+public class CollectionsTest extends TestBaseImpl
+{
+    private static Cluster CLUSTER;
+
+    @BeforeClass
+    public static void setUpCluster() throws IOException
+    {
+        CLUSTER = init(Cluster.build(2).start());
+    }
+
+    @Test
+    public void testMultipleSetsComplexDeletion()
+    {
+        CLUSTER.schemaChange(withKeyspace("CREATE TABLE %s.multi_collection (k 
int, c int, s1 set<int>, s2 set<int>, s3 set<int>, PRIMARY KEY (k, c)) WITH 
read_repair = 'NONE'"));
+        CLUSTER.coordinator(1).execute(withKeyspace("INSERT INTO 
%s.multi_collection (k, c, s1, s2, s3) VALUES (?, ?, ?, ?, ?)"), 
ConsistencyLevel.ALL, 0, 0, set(1), set(1), set(1));
+        CLUSTER.coordinator(1).execute(withKeyspace("UPDATE 
%s.multi_collection SET s2 = ?, s1 = s1 + ?, s3 = s3 + ? WHERE k = ? AND c = 
?"), ConsistencyLevel.ALL, set(2), set(2), set(2), 0, 0);
+
+        String select = withKeyspace("SELECT k, c, s1, s2, s3 FROM 
%s.multi_collection");
+        assertRows(CLUSTER.get(1).executeInternal(select), row(0, 0, set(1, 
2), set(2), set(1, 2)));
+        
+        // If the complex deletion is not properly serialized, node 2 will 
think the update on s2 was an append... 
+        assertRows(CLUSTER.get(2).executeInternal(select), row(0, 0, set(1, 
2), set(2), set(1, 2)));
+    }

Review Comment:
   Confirmed test fails without the changes, passes with 👍 



##########
test/distributed/org/apache/cassandra/distributed/test/CollectionsTest.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.distributed.test;
+
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+
+import static org.apache.cassandra.distributed.shared.AssertUtils.assertRows;
+import static org.apache.cassandra.distributed.shared.AssertUtils.row;
+
+public class CollectionsTest extends TestBaseImpl
+{
+    private static Cluster CLUSTER;
+
+    @BeforeClass
+    public static void setUpCluster() throws IOException
+    {
+        CLUSTER = init(Cluster.build(2).start());
+    }
+
+    @Test
+    public void testMultipleSetsComplexDeletion()
+    {
+        CLUSTER.schemaChange(withKeyspace("CREATE TABLE %s.multi_collection (k 
int, c int, s1 set<int>, s2 set<int>, s3 set<int>, PRIMARY KEY (k, c)) WITH 
read_repair = 'NONE'"));
+        CLUSTER.coordinator(1).execute(withKeyspace("INSERT INTO 
%s.multi_collection (k, c, s1, s2, s3) VALUES (?, ?, ?, ?, ?)"), 
ConsistencyLevel.ALL, 0, 0, set(1), set(1), set(1));
+        CLUSTER.coordinator(1).execute(withKeyspace("UPDATE 
%s.multi_collection SET s2 = ?, s1 = s1 + ?, s3 = s3 + ? WHERE k = ? AND c = 
?"), ConsistencyLevel.ALL, set(2), set(2), set(2), 0, 0);
+
+        String select = withKeyspace("SELECT k, c, s1, s2, s3 FROM 
%s.multi_collection");
+        assertRows(CLUSTER.get(1).executeInternal(select), row(0, 0, set(1, 
2), set(2), set(1, 2)));
+        
+        // If the complex deletion is not properly serialized, node 2 will 
think the update on s2 was an append... 
+        assertRows(CLUSTER.get(2).executeInternal(select), row(0, 0, set(1, 
2), set(2), set(1, 2)));
+    }
+}

Review Comment:
   We should be able to assert roundtrip serialization of Mutations (and add 
Mutation.equals). I was also thinking we'd be able to find this in one of 
David's tests that uses a model and runs commands like unsafe bounce (where 
commit log replay occurs on startup). But we'd have to read across all replicas 
at NODE_LOCAL to find this, since including a replica with the correct update 
in the memtable would have hidden the issue.
   
   TopologyMixupTestBase appears to do an unsafe shutdown but 
HarryTopologyMixupTest doesn't appear to generate mixed set overwrite + set 
append operations, so we wouldn't find it there as it's currently implemented.



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to