sanpwc commented on code in PR #6641:
URL: https://github.com/apache/ignite-3/pull/6641#discussion_r2388227903


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -156,6 +184,124 @@ public CompletableFuture<List<TokenizedAssignments>> 
getAssignments(
                 }));
     }
 
+    @Override
+    public CompletableFuture<List<TokenizedAssignments>> 
awaitNonEmptyAssignments(
+            List<? extends ReplicationGroupId> replicationGroupIds,
+            HybridTimestamp clusterTimeToAwait,
+            long timeoutMillis
+    ) {
+        return msManager
+                .clusterTime()
+                .waitFor(clusterTimeToAwait)
+                .thenCompose(ignored -> inBusyLock(busyLock, () -> {
+                    long now = coarseCurrentTimeMillis();
+                    return 
awaitNonEmptyAssignmentsWithCheckMostRecent(replicationGroupIds, now, 
timeoutMillis);
+                }))
+                .thenApply(identity());
+    }
+
+    private CompletableFuture<List<TokenizedAssignments>> 
awaitNonEmptyAssignmentsWithCheckMostRecent(
+            List<? extends ReplicationGroupId> replicationGroupIds,
+            long startTime,
+            long timeoutMillis
+    ) {
+        Map<ReplicationGroupId, TokenizedAssignments> assignmentsMap = 
stableAssignments();
+
+        Map<Integer, CompletableFuture<TokenizedAssignments>> futures = new 
HashMap<>();
+        List<TokenizedAssignments> result = new 
ArrayList<>(replicationGroupIds.size());
+
+        for (int i = 0; i < replicationGroupIds.size(); i++) {
+            ReplicationGroupId groupId = replicationGroupIds.get(i);
+
+            TokenizedAssignments a = assignmentsMap.get(groupId);
+            result.add(a);
+
+            if (a.nodes().isEmpty()) {
+                if (timeoutMillis > 0) {
+                    futures.put(i, nonEmptyAssignmentFuture(groupId, 
timeoutMillis));
+                } else {
+                    // If timeout is zero or less, then this group is failed, 
the correct exception will be thrown
+                    // in #checkEmptyAssignmentsReasons().
+                    futures.put(i, failedFuture(new TimeoutException()));
+                }
+            }
+        }
+
+        if (futures.isEmpty()) {
+            return completedFuture(result);
+        } else {
+            return allOf(futures.values())
+                    .handle((unused, ex) -> {
+                        if (ex == null) {
+                            // Get the most recent assignments after the 
waiting.
+                            long now = System.currentTimeMillis();
+                            long newTimeoutMillis = timeoutMillis - (now - 
startTime);
+                            return 
awaitNonEmptyAssignmentsWithCheckMostRecent(replicationGroupIds, startTime, 
newTimeoutMillis);

Review Comment:
   From my point of view, after completing both futures in 
groupStableAssignments there will be [D,E] for group 0 so reading from there is 
safe.



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