tolbertam commented on code in PR #4644:
URL: https://github.com/apache/cassandra/pull/4644#discussion_r2986305653


##########
test/distributed/org/apache/cassandra/distributed/upgrade/AutoRepairUpgradeTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.upgrade;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+import com.google.common.collect.ImmutableMap;
+
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.UpgradeableCluster;
+import org.apache.cassandra.distributed.api.ConsistencyLevel;
+import org.apache.cassandra.distributed.api.Feature;
+import org.apache.cassandra.repair.autorepair.AutoRepairConfig;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Upgrade test for auto-repair verifying that it runs successfully before and 
after
+ * upgrading from 5.0 to current. The first repair round executes on 5.0 nodes
+ * (automatically during startup) and the second round after all nodes are 
upgraded.
+ *
+ * Host IDs may change across the upgrade, so the test verifies that:
+ * <ol>
+ *   <li>3 repair history entries exist before the upgrade (on 5.0)</li>
+ *   <li>3 repair history entries exist after the upgrade (on trunk)</li>
+ *   <li>All post-upgrade finish timestamps are strictly greater than
+ *       the maximum pre-upgrade finish timestamp</li>
+ * </ol>
+ *
+ * Auto-repair is started automatically during node startup via
+ * {@code StorageService.doAutoRepairSetup()} when the config is enabled.
+ * In 5.0, the JVM property {@code cassandra.autorepair.enable=true} is also 
required.
+ */
+public class AutoRepairUpgradeTest extends UpgradeTestBase
+{
+    @Test
+    public void testAutoRepairAcrossUpgrade() throws Throwable
+    {
+        // 5.0 requires this JVM property to enable auto-repair (schema 
tables, JMX, scheduler).
+        // Trunk does not use this property.
+        System.setProperty("cassandra.autorepair.enable", "true"); // 
checkstyle: suppress nearby 'blockSystemPropertyUsage'
+
+        AtomicLong maxPreUpgradeTimestamp = new AtomicLong(0);
+
+        new TestCase()
+        .nodes(3)
+        .singleUpgradeToCurrentFrom(v50)
+        .withConfig(cfg -> cfg.with(Feature.NETWORK, Feature.GOSSIP)
+                              .set("auto_repair",
+                                   ImmutableMap.of(
+                                   "repair_type_overrides",
+                                   
ImmutableMap.of(AutoRepairConfig.RepairType.FULL.getConfigName(),
+                                                   ImmutableMap.of(
+                                                   "initial_scheduler_delay", 
"5s",
+                                                   "enabled", "true",
+                                                   "parallel_repair_count", 
"3",
+                                                   
"allow_parallel_replica_repair", "true",
+                                                   "min_repair_interval", 
"5s"))))
+                              .set("auto_repair.enabled", "true")
+                              
.set("auto_repair.global_settings.repair_by_keyspace", "true")
+                              
.set("auto_repair.global_settings.repair_retry_backoff", "5s")
+                              .set("auto_repair.repair_task_min_duration", 
"0s")
+                              .set("auto_repair.repair_check_interval", "5s"))
+        .setup(cluster -> {
+            cluster.schemaChange("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE +
+                                 " WITH replication = {'class': 
'SimpleStrategy', 'replication_factor': 3};");
+            cluster.schemaChange("CREATE TABLE IF NOT EXISTS " + KEYSPACE +
+                                 ".tbl (pk int, ck text, v1 int, v2 int, 
PRIMARY KEY (pk, ck))");
+
+            // Wait for auto-repair to complete on all 5.0 nodes.
+            waitForNEntries(cluster, 3);
+
+            Map<String, Long> preUpgradeTimestamps = 
captureFinishTimestamps(cluster);
+            assertEquals("Expected repair history for all 3 nodes on 5.0",
+                         3, preUpgradeTimestamps.size());
+
+            maxPreUpgradeTimestamp.set(max(preUpgradeTimestamps.values()));
+        })
+        .runAfterClusterUpgrade(cluster -> {
+            long threshold = maxPreUpgradeTimestamp.get();
+
+            // Wait for 3 entries whose finish timestamps all exceed the 
pre-upgrade max.
+            waitForNewRepairRound(cluster, 3, threshold);
+
+            Map<String, Long> postUpgradeTimestamps = 
captureFinishTimestamps(cluster);
+            assertEquals("Expected repair history for all 3 nodes after 
upgrade",

Review Comment:
   I'm seeing 5 repair_history entries when i run this:
   
   ```
   Caused by: java.lang.AssertionError: Expected repair history for all 3 nodes 
after upgrade expected:<3> but was:<5>
        at org.junit.Assert.fail(Assert.java:88)
   ```
   
   I see you note in comments that host-ids may change as part of upgrade which 
I think explains this.
   
   It's odd to me that host id is changing on upgrade though, is it just a 
quirk of the dtest framework exclusively?



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