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


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java:
##########
@@ -152,4 +195,46 @@ public CompletableFuture<Void> onUpdate(WatchEvent event) {
         public void onError(Throwable e) {
         }
     }
+
+    @Override
+    public CompletableFuture<LeaseMeta> awaitPrimaryReplica(ReplicationGroupId 
groupId, HybridTimestamp timestamp) {
+        if (!busyLock.enterBusy()) {
+            return failedFuture(new NodeStoppingException("Component is 
stopping."));
+        }
+        try {
+            return primaryReplicaWaiters.computeIfAbsent(groupId, id -> new 
PendingIndependentComparableValuesTracker<>(MIN_VALUE))
+                    .waitFor(timestamp);
+        } finally {
+            busyLock.leaveBusy();
+        }
+    }
+
+    @Override
+    public CompletableFuture<LeaseMeta> getPrimaryReplica(ReplicationGroupId 
replicationGroupId, HybridTimestamp timestamp) {
+        if (!busyLock.enterBusy()) {
+            return failedFuture(new NodeStoppingException("Component is 
stopping."));
+        }
+        try {
+            // There's no sense in awaiting previously detected primary 
replica more than lease interval.
+            return awaitPrimaryReplica(replicationGroupId, 
timestamp).orTimeout(longLeaseInterval, TimeUnit.MILLISECONDS);

Review Comment:
   Because it's maximum reasonable time to await for lease appearance based on 
lease propagation.
   First of all, from the one hand leaseInterval should be gt the 
MAX_CLOCK_SKEW by design thus we've safe with clock drift here, on the other 
hand if distribution duration will be more than leaseInterval we may see an 
inappropriate gap.
   Another approach with awaiting ms safe time, seems to be to invasive, code 
will become ugly, so I've finished with await bounding with given lease 
interval.



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