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


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -210,39 +237,88 @@ public void run() {
         }
 
         /**
-         * Writes a lease in Meta storage.
+         * Writes a new lease in Meta storage.
          *
          * @param grpId Replication group id.
          * @param lease Old lease to apply CAS in Meta storage.
          * @param candidate Lease candidate.
          */
-        private void updateLeaseInMetaStorage(ReplicationGroupId grpId, Lease 
lease, ClusterNode candidate) {
+        private void writeNewLeasInMetaStorage(ReplicationGroupId grpId, Lease 
lease, ClusterNode candidate) {
             var leaseKey = ByteArray.fromString(PLACEMENTDRIVER_PREFIX + 
grpId);
-            var newTs = new HybridTimestamp(clock.now().getPhysical() + 
LEASE_PERIOD, 0);
+
+            HybridTimestamp startTs = clock.now();
+
+            var expirationTs = new HybridTimestamp(startTs.getPhysical() + 
longLeasePeriod, 0);
 
             byte[] leaseRaw = ByteUtils.toBytes(lease);
 
-            Lease renewedLease = new Lease(candidate, newTs);
+            Lease renewedLease = new Lease(candidate, startTs, expirationTs);
 
             msManager.invoke(
                     or(notExists(leaseKey), value(leaseKey).eq(leaseRaw)),
                     put(leaseKey, ByteUtils.toBytes(renewedLease)),
                     noop()
+            ).thenAccept(isCreated -> {
+                if (isCreated) {
+                    boolean force = candidate.equals(lease.getLeaseholder());
+
+                    leaseConciliator.conciliate(grpId, renewedLease, force);
+                }
+            });
+        }
+
+        /**
+         * Writes a prolong lease in Meta storage.
+         *
+         * @param grpId Replication group id.
+         * @param lease Lease to prolong.
+         */
+        private void prolongLeaseInMetaStorage(ReplicationGroupId grpId, Lease 
lease) {
+            var leaseKey = ByteArray.fromString(PLACEMENTDRIVER_PREFIX + 
grpId);
+            var newTs = new HybridTimestamp(clock.now().getPhysical() + 
LEASE_PERIOD, 0);
+
+            byte[] leaseRaw = ByteUtils.toBytes(lease);
+
+            Lease renewedLease = lease.prolongLease(newTs);
+
+            msManager.invoke(
+                    value(leaseKey).eq(leaseRaw),
+                    put(leaseKey, ByteUtils.toBytes(renewedLease)),
+                    noop()
+            );
+        }
+
+        /**
+         * Writes an accepted lease in Meta storage.
+         *
+         * @param grpId Replication group id.
+         * @param lease Lease to accept.
+         */
+        private void acceptLeaseInMetaStorage(ReplicationGroupId grpId, Lease 
lease) {
+            var leaseKey = ByteArray.fromString(PLACEMENTDRIVER_PREFIX + 
grpId);
+            var newTs = new HybridTimestamp(clock.now().getPhysical() + 
LEASE_PERIOD, 0);
+
+            byte[] leaseRaw = ByteUtils.toBytes(lease);
+
+            Lease renewedLease = lease.acceptLease(newTs);
+
+            msManager.invoke(
+                    value(leaseKey).eq(leaseRaw),
+                    put(leaseKey, ByteUtils.toBytes(renewedLease)),
+                    noop()
             );
         }
 
         /**
-         * Checks that a leaseholder candidate can take a lease on the 
replication group.
+         * Checks that the lease is outdated.
          *
          * @param lease Lease.
-         * @param candidate The node is a leaseholder candidate.
          * @return True when the candidate can be a leaseholder, otherwise 
false.
          */
-        private boolean isReplicationGroupUpdateLeaseholder(Lease lease, 
ClusterNode candidate) {
+        private boolean isLeaseIsOutdated(Lease lease) {

Review Comment:
   Actually, this returns true not only if the lease is outdated, but when 
there is no lease at all (due to EMPTY_LEASE). Please rename this to 
`isLeaseOutdatedOrNonExistent` and explain in javadoc why the logic for both 
cases should be the same: we can't prolong the expired lease because we already 
have an interval of time when the lease was not active, so we must start ne 
negotiation round from the beginning; the same we do for the groups that don't 
have leaseholders at all.



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