rpuch commented on code in PR #7156:
URL: https://github.com/apache/ignite-3/pull/7156#discussion_r2639519925
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/restart/RestartPartitionsCall.java:
##########
@@ -34,13 +34,16 @@
public class RestartPartitionsCall implements Call<RestartPartitionsCallInput,
String> {
private final ApiClientFactory clientFactory;
+ /** Timeout used for disaster recovery operations. */
+ private static final int TIMEOUT_MILLIS = 30_000;
Review Comment:
Could we just introduce a common constant in a shared module and use it both
in CLI and server part?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java:
##########
@@ -1446,6 +1556,16 @@ private void handleLocalPartitionStatesRequest(
}, threadPool);
}
+ private void handleOperationCompletedMessage(
+ OperationCompletedMessage message,
+ InternalClusterNode sender
+ ) {
+ MultiNodeOperations multiNodeOperations =
operationsByNodeName.get(sender.name());
Review Comment:
Is there a race here?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/MultiNodeOperations.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.table.distributed.disaster;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import
org.apache.ignite.internal.table.distributed.disaster.exceptions.RemoteOperationException;
+import org.jetbrains.annotations.Nullable;
+
+/** Contains operations that should be processed by remote node. */
+class MultiNodeOperations {
+ private final Map<UUID, CompletableFuture<Void>> operationsById = new
ConcurrentHashMap<>();
+
+ /** Adds new operation to track. */
+ void add(UUID operationId, CompletableFuture<Void> operationFuture) {
+ operationsById.put(operationId, operationFuture);
+ }
+
+ /**
+ * Removes operation tracking.
+ *
+ * @return Removed operation future.
+ */
+ CompletableFuture<Void> remove(UUID operationId) {
+ return operationsById.remove(operationId);
+ }
+
+ /** Completes all tracked operations with a given exception. */
+ void completeAllExceptionally(String nodeName, Throwable e) {
+ Set<UUID> operationIds = Set.copyOf(operationsById.keySet());
+
+ for (UUID operationId : operationIds) {
+ operationsById.remove(operationId).completeExceptionally(new
RemoteOperationException(e.getMessage(), nodeName));
Review Comment:
Can `operationsById.remove(operationId)` return null if the operation was
already removed concurrently?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/exceptions/RemoteOperationException.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.table.distributed.disaster.exceptions;
+
+import org.apache.ignite.lang.ErrorGroups.DisasterRecovery;
+
+/** Exception is thrown when remote node encounters an error while executing a
disaster recovery operation. */
Review Comment:
```suggestion
/** Exception thrown when remote node encounters an error while executing a
disaster recovery operation. */
```
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/ManualGroupRestartRequestSerializer.java:
##########
@@ -48,6 +49,7 @@ protected void writeExternalData(ManualGroupRestartRequest
request, IgniteDataOu
writeStringSet(request.nodeNames(), out);
hybridTimestamp(request.assignmentsTimestamp()).writeTo(out);
out.writeBoolean(request.cleanUp()); // Write the new 'cleanUp' field
introduced in protocol version 2.
+ out.writeUTF(request.coordinator()); // Write the new 'coordinator'
field introduced in protocol version 3.
Review Comment:
`writeUTF()` does not tolerate nulls, but `request.coordinator()` could be
null. Is everything ok here? If yes, please add a validation in the beginning
of the method
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java:
##########
@@ -1151,7 +1185,66 @@ private CompletableFuture<Void>
processNewRequest(DisasterRecoveryRequest reques
metaStorageManager.put(RECOVERY_TRIGGER_KEY, serializedRequest);
}
- return operationFuture;
+ return operationFuture.thenCompose(v -> remoteProcessingFuture);
+ }
+
+ private CompletableFuture<Void>
remoteProcessingFuture(DisasterRecoveryRequest request) {
+ if (request.type() != DisasterRecoveryRequestType.MULTI_NODE) {
+ return nullCompletedFuture();
+ }
+
+ UUID operationId = request.operationId();
+
+ MultiNodeDisasterRecoveryRequest multiNodeRequest =
(MultiNodeDisasterRecoveryRequest) request;
+
+ Collection<String> actualNodeNames =
getActualNodeNames(multiNodeRequest.nodeNames());
+
+ CompletableFuture<?>[] remoteProcessingFutures = actualNodeNames
+ .stream()
+ .map(nodeName -> addMultiNodeOperation(nodeName, operationId))
+ .toArray(CompletableFuture[]::new);
+
+ return allOf(remoteProcessingFutures)
+ .whenComplete((ignored, e) -> {
+ for (String nodeName : actualNodeNames) {
+ operationsByNodeName.compute(nodeName, (node,
operations) -> {
+ if (operations != null) {
+ operations.remove(operationId);
+
+ return operations.isEmpty() ? null :
operations;
+ }
+
+ return null;
+ });
+ }
+ });
+ }
+
+ /** If request node names is empty, returns all nodes in the logical
topology. */
+ private Collection<String> getActualNodeNames(Set<String>
requestNodeNames) {
+ if (requestNodeNames.isEmpty()) {
+ return dzManager.logicalTopology().stream()
+ .map(NodeWithAttributes::nodeName)
+ .collect(toSet());
+ } else {
+ return requestNodeNames;
+ }
+ }
+
+ private CompletableFuture<Void> addMultiNodeOperation(String nodeName,
UUID operationId) {
+ CompletableFuture<Void> result = new
CompletableFuture<Void>().orTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+
+ operationsByNodeName.compute(nodeName, (node, operations) -> {
Review Comment:
What if a node leaves before we add its operations to the map? In such case
the object will remain there forever.
You could use `.compute()` in the 'node left' handler, plus here you could
check whether the node is in the LT currently, to remove a stale object from
the map
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java:
##########
@@ -260,6 +274,16 @@ public DisasterRecoveryManager(
// There is no need to block a watch thread any longer.
return nullCompletedFuture();
});
+
+ nodeLeftListener = new LogicalTopologyEventListener() {
+ @Override
+ public void onNodeLeft(LogicalNode leftNode,
LogicalTopologySnapshot newTopology) {
+ MultiNodeOperations operations =
operationsByNodeName.get(leftNode.name());
+ if (operations != null) {
+ operations.completeAllExceptionally(leftNode.name(), new
NodeStoppingException());
+ }
Review Comment:
1. There seems to be a race between adding to this map and handling 'node
left' on it. How do we protect from a situation when 'node left' is handled
before addition to the map?
2. You identify nodes by names and not by IDs. What happens if a node is
restarted and returns with the same name, but different ID?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/MultiNodeOperations.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.table.distributed.disaster;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import
org.apache.ignite.internal.table.distributed.disaster.exceptions.RemoteOperationException;
+import org.jetbrains.annotations.Nullable;
+
+/** Contains operations that should be processed by remote node. */
+class MultiNodeOperations {
+ private final Map<UUID, CompletableFuture<Void>> operationsById = new
ConcurrentHashMap<>();
+
+ /** Adds new operation to track. */
+ void add(UUID operationId, CompletableFuture<Void> operationFuture) {
+ operationsById.put(operationId, operationFuture);
+ }
+
+ /**
+ * Removes operation tracking.
+ *
+ * @return Removed operation future.
+ */
+ CompletableFuture<Void> remove(UUID operationId) {
+ return operationsById.remove(operationId);
+ }
+
+ /** Completes all tracked operations with a given exception. */
+ void completeAllExceptionally(String nodeName, Throwable e) {
+ Set<UUID> operationIds = Set.copyOf(operationsById.keySet());
+
+ for (UUID operationId : operationIds) {
+ operationsById.remove(operationId).completeExceptionally(new
RemoteOperationException(e.getMessage(), nodeName));
Review Comment:
Also, if an exception happens on our node, we'll not send the stack trace to
the remote node. Will we log it here?
--
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]