denis-chudov commented on code in PR #2078:
URL: https://github.com/apache/ignite-3/pull/2078#discussion_r1196473114


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/Lease.java:
##########
@@ -23,17 +23,19 @@
 
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
+import java.util.Objects;
 import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.placementdriver.LeaseMeta;
 
 /**
  * A lease representation in memory.
  * The real lease is stored in Meta storage.
  */
-public class Lease {
+public class Lease implements LeaseMeta {
     /** The object is used when nothing holds the lease. Empty lease is always 
expired. */
     public static Lease EMPTY_LEASE = new Lease(null, MIN_VALUE, MIN_VALUE);
 
-    /** A node that holds a lease until {@code stopLeas}. */
+    /** A node that holds a lease until {@code stopLeas}LeaseMeta. */

Review Comment:
   I can't get this. Could you rephrase?



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java:
##########
@@ -65,12 +84,22 @@ public class LeaseTracker {
      *
      * @param vaultManager Vault manager.
      * @param msManager Meta storage manager.
+     * @param longLeaseInterval Long lease interval in {@code 
TimeUnit.MILLISECONDS}.  The interval is used between lease granting attempts.

Review Comment:
   It's not obvious from this description that this is the interval for newly 
granted lease that is not accepted yet, and is never used for actual leases.



##########
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:
   why `longLeaseInterval` is used here?



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/Lease.java:
##########
@@ -234,4 +224,22 @@ public String toString() {
                 + ", prolongable=" + prolongable
                 + '}';
     }
+
+    @Override
+    public boolean equals(Object o) {

Review Comment:
   Could you please replace `LeaseSerializationTest#assertLeasesEqual` with 
this `equals` method?



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseMeta.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.placementdriver;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+
+/**
+ * Replica lease meta.
+ */
+public interface LeaseMeta {

Review Comment:
   Shouldn't this interface be in `placement-driver-api`?



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