You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "smiklosovic (via GitHub)" <gi...@apache.org> on 2023/04/20 09:13:25 UTC

[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2286: CASSANDRA-18105 3.0

smiklosovic commented on code in PR #2286:
URL: https://github.com/apache/cassandra/pull/2286#discussion_r1172308436


##########
test/distributed/org/apache/cassandra/distributed/test/IndexAndMVDroppingTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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 org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+
+import static org.apache.cassandra.distributed.Cluster.build;
+import static org.apache.cassandra.distributed.api.ConsistencyLevel.ONE;
+import static org.apache.cassandra.distributed.api.Feature.NETWORK;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests CASSANDRA-18105.
+ * <p>
+ * Trucation will insert an entry to system.local into truncated_at map for given table. Because id of an index
+ * is same as id of the base table, when dropping an index, it in fact drops a table with same id as the base table
+ * which will remove an entry for trucated_at column. Hence, after restart of the node, querying the base table
+ * will resurrect the data because commitlog was fully replayed, not taking into consideration (now removed) entry
+ * in truncated_at column.
+ * <p>
+ * The fix consists of not removing an entry in trucated_at column in system.local
+ * if the table being removed is an index.
+ */
+public class IndexAndMVDroppingTest extends TestBaseImpl
+{
+    @Test
+    public void testIndexDropping() throws Throwable
+    {
+        try (Cluster c = build(1).withConfig(conf -> conf.with(NETWORK)).start())
+        {
+            c.schemaChange("CREATE KEYSPACE " + KEYSPACE + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
+            c.schemaChange("CREATE TABLE " + KEYSPACE + ".tb (c3 TEXT, c4 TEXT, c2 INT, c1 TEXT, PRIMARY KEY (c1, c2, c3 ))");
+            c.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tb (c3, c1, c2) VALUES ('val1','val2',1)", ONE);
+            c.schemaChange("CREATE INDEX tb ON " + KEYSPACE + ".tb (c3)");
+            c.schemaChange("TRUNCATE TABLE " + KEYSPACE + " .tb");
+            c.schemaChange("DROP INDEX " + KEYSPACE + ".tb");
+
+            assertEquals(0, c.coordinator(1).execute("SELECT c2 FROM " + KEYSPACE + " .tb", ONE).length);
+
+            c.get(1).shutdown(true).get();
+            c.get(1).startup();
+
+            assertEquals(0, c.coordinator(1).execute("SELECT c2 FROM " + KEYSPACE + " .tb", ONE).length);
+        }
+    }
+
+    @Test
+    public void testMaterializedViewDropping() throws Throwable

Review Comment:
   I added MV case as well, just to be sure.



-- 
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-unsubscribe@cassandra.apache.org

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


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