You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "vldpyatkov (via GitHub)" <gi...@apache.org> on 2023/05/17 17:55:10 UTC

[GitHub] [ignite-3] vldpyatkov commented on a diff in pull request #2078: IGNITE-19428 PlacementDriver API implemented.

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


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/PlacementDriver.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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 java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+
+/**
+ * Service that provides an ability to await and retrieve primary replicas for replication groups.
+ */
+public interface PlacementDriver {
+    /**
+     * Returns a future for the primary replica for the specified replication group whose expiration time (the right border of the
+     * corresponding lease interval) is greater than or equal to the timestamp passed as a parameter. Please pay attention that there are
+     * no restriction on the lease start time (left border), it can either be less or greater than or equal to proposed timestamp.
+     * Given method will await for an appropriate primary replica appearance if there's no already existing one. Such awaiting logic is
+     * unbounded, so it's mandatory to use explicit await termination like {@code orTimeout}.
+     *
+     * @param groupId Replication group id.
+     * @param timestamp Timestamp reference value.
+     * @return Primary replica future.
+     */
+    CompletableFuture<LeaseMeta> awaitPrimaryReplica(ReplicationGroupId groupId, HybridTimestamp timestamp);
+
+    /**
+     * Same as {@link #awaitPrimaryReplica(ReplicationGroupId, HybridTimestamp)} despite the fact that given method await logic is bounded.
+     * It will wait for a primary replica for a reasonable period of time, and complete a future with {@code TimeoutException} if a matching
+     * lease isn't found. Generally speaking reasonable here means enough for distribution across cluster nodes.
+     *
+     * @param replicationGroupId Replication group id.
+     * @param timestamp Timestamp reference value.
+     * @return Primary replica future.
+     */
+    CompletableFuture<LeaseMeta> getPrimaryReplica(ReplicationGroupId replicationGroupId, HybridTimestamp timestamp);
+}

Review Comment:
   Add empty line in the end of the file.



##########
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.
+     * @param busyLock Busy lock to protect {@link PlacementDriver} methods on corresponding manager stop.
      */
-    public LeaseTracker(VaultManager vaultManager, MetaStorageManager msManager) {
+    public LeaseTracker(
+            VaultManager vaultManager,
+            MetaStorageManager msManager,
+            long longLeaseInterval,
+            IgniteSpinBusyLock busyLock
+    ) {
         this.vaultManager = vaultManager;
         this.msManager = msManager;
+        this.longLeaseInterval = longLeaseInterval;
+        this.busyLock = busyLock;

Review Comment:
   It is forbidden to take the lock object from where it was created.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java:
##########
@@ -92,6 +121,11 @@ public void startTrack() {
                 Lease lease = fromBytes(entry.value());
 
                 leases.put(grpId, lease);
+
+                assert lease.getExpirationTime() != MAX_VALUE : "INFINITE lease expiration time isn't expected";

Review Comment:
   I do not understand which is the reason to check expiration time to MAX_VALUE. We never use the constant to define a lease.



##########
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:
   I do not have any objection. I think the both definition are clear.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java:
##########
@@ -138,10 +175,16 @@ public CompletableFuture<Void> onUpdate(WatchEvent event) {
 
                 if (msEntry.empty()) {
                     leases.remove(grpId);
+                    tryRemoveTracker(grpId);
                 } else {
                     Lease lease = fromBytes(msEntry.value());
 
+                    assert lease.getExpirationTime() != MAX_VALUE : "INFINITE lease expiration time isn't expected";

Review Comment:
   The same as above, using of MAX_VALUE is unexpected.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -74,7 +73,7 @@ public class LeaseUpdater {
 
     private final AtomicBoolean active = new AtomicBoolean();
 
-    /** Long lease interval. The interval is used between lease granting attempts. */
+    /** Long lease interval in {@code TimeUnit.MILLISECONDS}. The interval is used between lease granting attempts. */

Review Comment:
   Why do you use {@code TimeUnit.MILLISECONDS} (as a part of code)?
   Millisecond has a well known definition. I think the word "milliseconds" is enough.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org