aweisberg commented on code in PR #4569:
URL: https://github.com/apache/cassandra/pull/4569#discussion_r2755951884


##########
src/java/org/apache/cassandra/repair/RepairCoordinator.java:
##########
@@ -503,7 +503,15 @@ private Future<Pair<CoordinatedRepairResult, 
Supplier<String>>> repair(String[]
         }
         else if (state.options.isIncremental())
         {

Review Comment:
   Create a static method that is used to construct repair coordinator and make 
the constructor private. In that static method determine whether mutation 
tracking should be used and if a regular repair is required for migration and 
store those values in RepairCoordinator and then pass them to 
MutationTrackingIncrementalRepairTask when it is created.
   
   Also in this method of IR is requested and we are going to do mutation 
tracking repair WITHOUT requiring also a regular repair then turn IR off if it 
is on and maybe just log that you did that at info.
   
   



##########
src/java/org/apache/cassandra/repair/MutationTrackingIncrementalRepairTask.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.repair;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.cassandra.concurrent.ExecutorPlus;
+import org.apache.cassandra.config.CassandraRelevantProperties;
+import org.apache.cassandra.dht.Range;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.replication.MutationTrackingSyncCoordinator;
+import org.apache.cassandra.schema.KeyspaceMetadata;
+import 
org.apache.cassandra.service.replication.migration.KeyspaceMigrationInfo;
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.utils.TimeUUID;
+import org.apache.cassandra.utils.concurrent.AsyncPromise;
+import org.apache.cassandra.utils.concurrent.Future;
+
+/** Incremental repair task for keyspaces using mutation tracking */
+public class MutationTrackingIncrementalRepairTask extends AbstractRepairTask
+{
+    private static final long SYNC_TIMEOUT_MINUTES = 
CassandraRelevantProperties.REPAIR_SYNC_TIMEOUT_MINUTES.getLong();
+
+    private final TimeUUID parentSession;
+    private final RepairCoordinator.NeighborsAndRanges neighborsAndRanges;
+    private final String[] cfnames;
+
+    protected MutationTrackingIncrementalRepairTask(RepairCoordinator 
coordinator,
+                                                    TimeUUID parentSession,
+                                                    
RepairCoordinator.NeighborsAndRanges neighborsAndRanges,
+                                                    String[] cfnames)
+    {
+        super(coordinator);
+        this.parentSession = parentSession;
+        this.neighborsAndRanges = neighborsAndRanges;
+        this.cfnames = cfnames;
+    }
+
+    @Override
+    public String name()
+    {
+        return "MutationTrackingIncrementalRepair";
+    }
+
+    @Override
+    public Future<CoordinatedRepairResult> performUnsafe(ExecutorPlus 
executor, Scheduler validationScheduler)
+    {
+        List<CommonRange> allRanges = 
neighborsAndRanges.filterCommonRanges(keyspace, cfnames);
+
+        if (allRanges.isEmpty())
+        {
+            logger.info("No common ranges to repair for keyspace {}", 
keyspace);
+            return new 
AsyncPromise<CoordinatedRepairResult>().setSuccess(CoordinatedRepairResult.create(List.of(),
 List.of()));
+        }
+
+        List<MutationTrackingSyncCoordinator> syncCoordinators = new 
ArrayList<>();
+        List<Collection<Range<Token>>> rangeCollections = new ArrayList<>();
+
+        for (CommonRange commonRange : allRanges)
+        {
+            for (Range<Token> range : commonRange.ranges)
+            {
+                MutationTrackingSyncCoordinator syncCoordinator = new 
MutationTrackingSyncCoordinator(keyspace, range);
+                syncCoordinator.start();
+                syncCoordinators.add(syncCoordinator);
+                rangeCollections.add(List.of(range));
+
+                logger.info("Started mutation tracking sync for range {}", 
range);
+            }
+        }
+
+        coordinator.notifyProgress("Started mutation tracking sync for " + 
syncCoordinators.size() + " ranges");
+
+        AsyncPromise<CoordinatedRepairResult> resultPromise = new 
AsyncPromise<>();
+
+        executor.execute(() -> {
+            try
+            {
+                waitForSyncCompletion(syncCoordinators, executor, 
validationScheduler, allRanges, rangeCollections, resultPromise);
+            }
+            catch (Exception e)
+            {
+                logger.error("Error during mutation tracking repair", e);
+                resultPromise.tryFailure(e);
+            }
+        });
+
+        return resultPromise;
+    }
+
+    private void waitForSyncCompletion(List<MutationTrackingSyncCoordinator> 
syncCoordinators,
+                                       ExecutorPlus executor,
+                                       Scheduler validationScheduler,
+                                       List<CommonRange> allRanges,
+                                       List<Collection<Range<Token>>> 
rangeCollections,
+                                       AsyncPromise<CoordinatedRepairResult> 
resultPromise) throws InterruptedException
+    {
+        boolean allSucceeded = true;
+        for (MutationTrackingSyncCoordinator syncCoordinator : 
syncCoordinators)
+        {
+            boolean completed = 
syncCoordinator.awaitCompletion(SYNC_TIMEOUT_MINUTES, TimeUnit.MINUTES);

Review Comment:
   Calculate the deadline before this loop and then every time you call await 
completion calculate how much of the deadline remains and await that amount so 
the timeout isn't increased by # of common ranges.



##########
src/java/org/apache/cassandra/repair/MutationTrackingIncrementalRepairTask.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.repair;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.cassandra.concurrent.ExecutorPlus;
+import org.apache.cassandra.config.CassandraRelevantProperties;
+import org.apache.cassandra.dht.Range;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.replication.MutationTrackingSyncCoordinator;
+import org.apache.cassandra.schema.KeyspaceMetadata;
+import 
org.apache.cassandra.service.replication.migration.KeyspaceMigrationInfo;
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.utils.TimeUUID;
+import org.apache.cassandra.utils.concurrent.AsyncPromise;
+import org.apache.cassandra.utils.concurrent.Future;
+
+/** Incremental repair task for keyspaces using mutation tracking */
+public class MutationTrackingIncrementalRepairTask extends AbstractRepairTask
+{
+    private static final long SYNC_TIMEOUT_MINUTES = 
CassandraRelevantProperties.REPAIR_SYNC_TIMEOUT_MINUTES.getLong();
+
+    private final TimeUUID parentSession;
+    private final RepairCoordinator.NeighborsAndRanges neighborsAndRanges;
+    private final String[] cfnames;
+
+    protected MutationTrackingIncrementalRepairTask(RepairCoordinator 
coordinator,
+                                                    TimeUUID parentSession,
+                                                    
RepairCoordinator.NeighborsAndRanges neighborsAndRanges,
+                                                    String[] cfnames)
+    {
+        super(coordinator);
+        this.parentSession = parentSession;
+        this.neighborsAndRanges = neighborsAndRanges;
+        this.cfnames = cfnames;
+    }
+
+    @Override
+    public String name()
+    {
+        return "MutationTrackingIncrementalRepair";
+    }
+
+    @Override
+    public Future<CoordinatedRepairResult> performUnsafe(ExecutorPlus 
executor, Scheduler validationScheduler)
+    {
+        List<CommonRange> allRanges = 
neighborsAndRanges.filterCommonRanges(keyspace, cfnames);
+
+        if (allRanges.isEmpty())
+        {
+            logger.info("No common ranges to repair for keyspace {}", 
keyspace);
+            return new 
AsyncPromise<CoordinatedRepairResult>().setSuccess(CoordinatedRepairResult.create(List.of(),
 List.of()));
+        }
+
+        List<MutationTrackingSyncCoordinator> syncCoordinators = new 
ArrayList<>();
+        List<Collection<Range<Token>>> rangeCollections = new ArrayList<>();
+
+        for (CommonRange commonRange : allRanges)
+        {
+            for (Range<Token> range : commonRange.ranges)
+            {
+                MutationTrackingSyncCoordinator syncCoordinator = new 
MutationTrackingSyncCoordinator(keyspace, range);
+                syncCoordinator.start();
+                syncCoordinators.add(syncCoordinator);
+                rangeCollections.add(List.of(range));
+
+                logger.info("Started mutation tracking sync for range {}", 
range);
+            }
+        }
+
+        coordinator.notifyProgress("Started mutation tracking sync for " + 
syncCoordinators.size() + " ranges");
+
+        AsyncPromise<CoordinatedRepairResult> resultPromise = new 
AsyncPromise<>();
+
+        executor.execute(() -> {
+            try
+            {
+                waitForSyncCompletion(syncCoordinators, executor, 
validationScheduler, allRanges, rangeCollections, resultPromise);
+            }
+            catch (Exception e)
+            {
+                logger.error("Error during mutation tracking repair", e);
+                resultPromise.tryFailure(e);
+            }
+        });
+
+        return resultPromise;
+    }
+
+    private void waitForSyncCompletion(List<MutationTrackingSyncCoordinator> 
syncCoordinators,
+                                       ExecutorPlus executor,
+                                       Scheduler validationScheduler,
+                                       List<CommonRange> allRanges,
+                                       List<Collection<Range<Token>>> 
rangeCollections,
+                                       AsyncPromise<CoordinatedRepairResult> 
resultPromise) throws InterruptedException
+    {
+        boolean allSucceeded = true;

Review Comment:
   Add a listener to the repair session to listen for it transitioning to 
canceled and if it does iterate the list of sync coordinators and cancel them 
all.



##########
src/java/org/apache/cassandra/repair/MutationTrackingIncrementalRepairTask.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.repair;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.cassandra.concurrent.ExecutorPlus;
+import org.apache.cassandra.config.CassandraRelevantProperties;
+import org.apache.cassandra.dht.Range;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.replication.MutationTrackingSyncCoordinator;
+import org.apache.cassandra.schema.KeyspaceMetadata;
+import 
org.apache.cassandra.service.replication.migration.KeyspaceMigrationInfo;
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.utils.TimeUUID;
+import org.apache.cassandra.utils.concurrent.AsyncPromise;
+import org.apache.cassandra.utils.concurrent.Future;
+
+/** Incremental repair task for keyspaces using mutation tracking */
+public class MutationTrackingIncrementalRepairTask extends AbstractRepairTask
+{
+    private static final long SYNC_TIMEOUT_MINUTES = 
CassandraRelevantProperties.REPAIR_SYNC_TIMEOUT_MINUTES.getLong();
+
+    private final TimeUUID parentSession;
+    private final RepairCoordinator.NeighborsAndRanges neighborsAndRanges;
+    private final String[] cfnames;
+
+    protected MutationTrackingIncrementalRepairTask(RepairCoordinator 
coordinator,
+                                                    TimeUUID parentSession,
+                                                    
RepairCoordinator.NeighborsAndRanges neighborsAndRanges,
+                                                    String[] cfnames)
+    {
+        super(coordinator);
+        this.parentSession = parentSession;
+        this.neighborsAndRanges = neighborsAndRanges;
+        this.cfnames = cfnames;
+    }
+
+    @Override
+    public String name()
+    {
+        return "MutationTrackingIncrementalRepair";
+    }
+
+    @Override
+    public Future<CoordinatedRepairResult> performUnsafe(ExecutorPlus 
executor, Scheduler validationScheduler)
+    {
+        List<CommonRange> allRanges = 
neighborsAndRanges.filterCommonRanges(keyspace, cfnames);
+
+        if (allRanges.isEmpty())
+        {
+            logger.info("No common ranges to repair for keyspace {}", 
keyspace);
+            return new 
AsyncPromise<CoordinatedRepairResult>().setSuccess(CoordinatedRepairResult.create(List.of(),
 List.of()));
+        }
+
+        List<MutationTrackingSyncCoordinator> syncCoordinators = new 
ArrayList<>();
+        List<Collection<Range<Token>>> rangeCollections = new ArrayList<>();
+
+        for (CommonRange commonRange : allRanges)
+        {
+            for (Range<Token> range : commonRange.ranges)
+            {
+                MutationTrackingSyncCoordinator syncCoordinator = new 
MutationTrackingSyncCoordinator(keyspace, range);
+                syncCoordinator.start();
+                syncCoordinators.add(syncCoordinator);
+                rangeCollections.add(List.of(range));
+
+                logger.info("Started mutation tracking sync for range {}", 
range);
+            }
+        }
+
+        coordinator.notifyProgress("Started mutation tracking sync for " + 
syncCoordinators.size() + " ranges");
+
+        AsyncPromise<CoordinatedRepairResult> resultPromise = new 
AsyncPromise<>();
+
+        executor.execute(() -> {
+            try
+            {
+                waitForSyncCompletion(syncCoordinators, executor, 
validationScheduler, allRanges, rangeCollections, resultPromise);
+            }
+            catch (Exception e)
+            {
+                logger.error("Error during mutation tracking repair", e);
+                resultPromise.tryFailure(e);
+            }
+        });
+
+        return resultPromise;
+    }
+
+    private void waitForSyncCompletion(List<MutationTrackingSyncCoordinator> 
syncCoordinators,
+                                       ExecutorPlus executor,
+                                       Scheduler validationScheduler,
+                                       List<CommonRange> allRanges,
+                                       List<Collection<Range<Token>>> 
rangeCollections,
+                                       AsyncPromise<CoordinatedRepairResult> 
resultPromise) throws InterruptedException
+    {
+        boolean allSucceeded = true;
+        for (MutationTrackingSyncCoordinator syncCoordinator : 
syncCoordinators)
+        {
+            boolean completed = 
syncCoordinator.awaitCompletion(SYNC_TIMEOUT_MINUTES, TimeUnit.MINUTES);
+            if (!completed)
+            {
+                logger.warn("Mutation tracking sync timed out for keyspace {} 
range {}",
+                            keyspace, syncCoordinator.getRange());
+                syncCoordinator.cancel();
+                allSucceeded = false;
+            }
+        }
+
+        if (!allSucceeded)
+        {
+            resultPromise.tryFailure(new RuntimeException("Mutation tracking 
sync timed out for some ranges"));
+            return;
+        }
+
+        coordinator.notifyProgress("Mutation tracking sync completed for all 
ranges");
+
+        if (requiresTraditionalRepair(keyspace))

Review Comment:
   This needs to be checked using the value determined when RepairCoordinator 
is created.



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