rpuch commented on code in PR #7156: URL: https://github.com/apache/ignite-3/pull/7156#discussion_r2642350782
########## 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: Imagine that 'node left' handling and normal future finish handling are processed concurrently. 1. This method copies the set of operation IDs 2. Then an operation is completed and removed from the map concurrently 3. Then this method executes the loop. It will get `null` for the removed operation -- 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]
