ibessonov commented on code in PR #6930:
URL: https://github.com/apache/ignite-3/pull/6930#discussion_r2513341964


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/StartedReplicationGroups.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.ignite.internal.partition.replicator;
+
+import static org.apache.ignite.internal.util.CompletableFutures.copyStateTo;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Stream;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.util.CompletableFutures;
+
+/**
+ * Class that helps tracking starting and already started replicas. The flow 
is controlled from the outside, this class only helps
+ * maintaining collections of replicas in different statuses.
+ */
+class StartedReplicationGroups {
+    /** The logger. */
+    private static final IgniteLogger LOG = 
Loggers.forClass(StartedReplicationGroups.class);
+
+    /** Groups that are starting but are not yet reported to be fully started. 
*/
+    private final Map<ZonePartitionId, CompletableFuture<Void>> 
startingReplicationGroupIds = new ConcurrentHashMap<>();
+
+    /** Groups that are reported to be started. */
+    private final Set<ZonePartitionId> startedReplicationGroupIds = 
ConcurrentHashMap.newKeySet();
+
+    /**
+     * Callback to be called before replication group begins start procedure. 
It is expected that whoever maintains the replication groups
+     * will call either {@link #startingFailed(ZonePartitionId)} or {@link 
#startingCompleted(ZonePartitionId)} some time after..
+     */
+    void beforeStartingGroup(ZonePartitionId zonePartitionId) {
+        CompletableFuture<Void> startingFuture = new CompletableFuture<>();
+
+        CompletableFuture<Void> prevFuture = 
startingReplicationGroupIds.put(zonePartitionId, startingFuture);
+
+        assert prevFuture == null : "Replication group is starting second 
time. [zonePartitionId=" + zonePartitionId + ']';
+
+        // Copy future state if assertions are disabled.
+        //noinspection ConstantValue
+        if (prevFuture != null) {
+            startingFuture.whenComplete(copyStateTo(prevFuture));

Review Comment:
   Sure, let's do it. It's a best effort code anyway.



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

Reply via email to