This is an automated email from the ASF dual-hosted git repository.

samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git

commit 0a1f72bf68c1284cfb467c8156d5cc4480f03c5a
Author: Marcus Eriksson <[email protected]>
AuthorDate: Mon Mar 13 13:44:20 2023 +0100

    [CEP-21] Secondary indexes should not be rebuilt on restart
    
    patch by Marcus Eriksson; reviewed by Alex Petrov and Sam Tunnicliffe
    for CASSANDRA-18412
---
 .../cassandra/index/SecondaryIndexManager.java     |  2 +-
 .../test/log/BounceIndexRebuildTest.java           | 52 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/java/org/apache/cassandra/index/SecondaryIndexManager.java 
b/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
index c871c9b721..dded13f681 100644
--- a/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
@@ -190,7 +190,7 @@ public class SecondaryIndexManager implements 
IndexRegistry, INotificationConsum
         // we call add for every index definition in the collection as
         // some may not have been created here yet, only added to schema
         for (IndexMetadata tableIndex : tableIndexes)
-            addIndex(tableIndex, false);
+            addIndex(tableIndex, 
SystemKeyspace.isIndexBuilt(baseTable.keyspace, tableIndex.name));
     }
 
     private Future<?> reloadIndex(IndexMetadata indexDef)
diff --git 
a/test/distributed/org/apache/cassandra/distributed/test/log/BounceIndexRebuildTest.java
 
b/test/distributed/org/apache/cassandra/distributed/test/log/BounceIndexRebuildTest.java
new file mode 100644
index 0000000000..3fb2178e12
--- /dev/null
+++ 
b/test/distributed/org/apache/cassandra/distributed/test/log/BounceIndexRebuildTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.log;
+
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.test.TestBaseImpl;
+
+import static org.junit.Assert.assertEquals;
+
+public class BounceIndexRebuildTest extends TestBaseImpl
+{
+    @Test
+    public void bounceTest() throws Exception
+    {
+        try (Cluster cluster = init(builder().withNodes(1)
+                                             .start()))
+        {
+            cluster.schemaChange(withKeyspace("create table %s.tbl (id int 
primary key, x int)"));
+            for (int i = 0; i < 10; i++)
+                cluster.coordinator(1).execute(withKeyspace("insert into 
%s.tbl (id, x) values (?, ?)"), ConsistencyLevel.ALL, i, i);
+
+            cluster.schemaChange(withKeyspace("create index idx on %s.tbl 
(x)"));
+            Object[][] res = 
cluster.coordinator(1).execute(withKeyspace("select * from %s.tbl where x=5"), 
ConsistencyLevel.ALL);
+            assert res.length > 0;
+
+            cluster.get(1).shutdown().get();
+            cluster.get(1).startup();
+            assertEquals(1, cluster.get(1).logs().grep("Index build of idx 
complete").getResult().size());
+            res = cluster.coordinator(1).execute(withKeyspace("select * from 
%s.tbl where x=5"), ConsistencyLevel.ALL);
+            assert res.length > 0;
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to