xtern commented on code in PR #4240:
URL: https://github.com/apache/ignite-3/pull/4240#discussion_r1724631436


##########
modules/catalog-compaction/src/main/java/org/apache/ignite/internal/catalog/compaction/CatalogCompactionRunner.java:
##########
@@ -401,74 +441,94 @@ private static List<String> missingNodes(Set<String> 
requiredNodes, Collection<L
         return 
requiredNodes.stream().filter(not(logicalNodeIds::contains)).collect(Collectors.toList());
     }
 
-    CompletableFuture<Void> propagateTimeToReplicas(long timestamp, 
Collection<? extends ClusterNode> topologyNodes) {
+    CompletableFuture<Boolean> propagateTimeToReplicas(long timestamp, 
Collection<? extends ClusterNode> nodes) {
+        CatalogCompactionPrepareUpdateTxBeginTimeRequest request = 
COMPACTION_MESSAGES_FACTORY
+                .catalogCompactionPrepareUpdateTxBeginTimeRequest()
+                .timestamp(timestamp)
+                .build();
+
+        List<CompletableFuture<?>> responseFutures = new 
ArrayList<>(nodes.size());
+        AtomicBoolean successFlag = new AtomicBoolean(true);
+
+        for (ClusterNode node : nodes) {
+            CompletableFuture<?> fut =
+                    messagingService.invoke(node, request, ANSWER_TIMEOUT)
+                    .thenApply(message -> {
+                        CatalogCompactionPrepareUpdateTxBeginTimeResponse 
response =
+                                
(CatalogCompactionPrepareUpdateTxBeginTimeResponse) message;
+
+                        if (response.error() != null) {
+                            throw new IllegalStateException(format(
+                                    "Remote node responded with error 
[node={}, error={}]",
+                                    node.name(), response.error()));
+                        }
+
+                        if (!response.success()) {
+                            successFlag.set(false);
+                        }
+
+                        return null;
+                    });
+
+            responseFutures.add(fut);
+        }
+
+        return CompletableFutures.allOf(responseFutures).thenApply(ignore -> 
successFlag.get());
+    }
+
+    CompletableFuture<Boolean> propagateTimeToReplicasLocal(long txBeginTime) {
         HybridTimestamp nowTs = clockService.now();
 
         return schemaSyncService.waitForMetadataCompleteness(nowTs)
                 .thenComposeAsync(ignore -> {
-                    Map<Integer, Integer> tablesWithPartitions =
-                            
catalogManagerFacade.collectTablesWithPartitionsBetween(timestamp, 
nowTs.longValue());
+                    AtomicBoolean abortFlag = new AtomicBoolean();
+                    Int2IntMap tablesWithPartitions =
+                            
catalogManagerFacade.collectTablesWithPartitionsBetween(txBeginTime, 
nowTs.longValue());
 
-                    Set<String> topologyNodeNames = topologyNodes.stream()
-                            .map(ClusterNode::name)
-                            .collect(Collectors.toSet());
+                    ObjectIterator<Entry> itr = 
tablesWithPartitions.int2IntEntrySet().iterator();
 
-                    // TODO https://issues.apache.org/jira/browse/IGNITE-22951 
Minimize the number of network requests
-                    return 
CompletableFutures.allOf(tablesWithPartitions.entrySet().stream()
-                            .map(e -> invokeOnReplicas(e.getKey(), 
e.getValue(), timestamp, nowTs, topologyNodeNames))
-                            .collect(Collectors.toList())
-                    );
+                    return invokeOnLocalReplicas(txBeginTime, itr, abortFlag)
+                            .thenApply(v -> !abortFlag.get());
                 }, executor);
     }
 
-    private CompletableFuture<Void> invokeOnReplicas(
-            int tableId,
-            int partitions,
-            long txBeginTime,
-            HybridTimestamp nowTs,
-            Set<String> logicalTopologyNodes
-    ) {
-        List<TablePartitionId> replicationGroupIds = new 
ArrayList<>(partitions);
+    private CompletableFuture<Void> invokeOnLocalReplicas(long txBeginTime, 
ObjectIterator<Entry> tabTtr, AtomicBoolean abortFlag) {
+        if (!tabTtr.hasNext() || abortFlag.get()) {
+            return CompletableFutures.nullCompletedFuture();
+        }
+
+        Entry tableWithPartitions = tabTtr.next();
+        int tableId = tableWithPartitions.getIntKey();
+        int partitions = tableWithPartitions.getIntValue();
+        List<CompletableFuture<?>> partFutures = new ArrayList<>(partitions);
 
         for (int p = 0; p < partitions; p++) {
-            replicationGroupIds.add(new TablePartitionId(tableId, p));
-        }
+            TablePartitionId tablePartitionId = new TablePartitionId(tableId, 
p);
 
-        return placementDriver.getAssignments(replicationGroupIds, nowTs)
-                .thenComposeAsync(tokenizedAssignments -> {
-                    assert tokenizedAssignments.size() == 
replicationGroupIds.size();
+            CompletableFuture<?> fut = placementDriver
+                    .getPrimaryReplica(tablePartitionId, clockService.now())

Review Comment:
   Done, thanks.



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