You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "JAkutenshi (via GitHub)" <gi...@apache.org> on 2024/11/12 15:45:32 UTC

[PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

JAkutenshi opened a new pull request, #4707:
URL: https://github.com/apache/ignite-3/pull/4707

   JIRA Ticket: [IGNITE-23587](https://issues.apache.org/jira/browse/IGNITE-23587)
   
   ## The goal
   
   ## The reason
   
   ## The solution
   
   ---
   


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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841209591


##########
modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java:
##########
@@ -117,19 +123,30 @@ public class LeaseUpdaterTest extends BaseIgniteAbstractTest {
     void setUp() {
         HybridClockImpl clock = new HybridClockImpl();
 
-        Entry entry = new EntryImpl(
+        Entry stableEntry = new EntryImpl(
                 stablePartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
                 Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
                 1,
                 clock.now()
         );
 
-        when(mcEntriesCursor.iterator()).thenReturn(List.of(entry).iterator());
+        Entry pendingEntry = new EntryImpl(
+                pendingPartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
+                Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
+                1,
+                clock.now()
+        );
+
+        when(msStableAssignmentsEntriesCursor.iterator()).thenReturn(List.of(stableEntry).iterator());

Review Comment:
   I would prefer to have it as a placement driver specific unit test. Integration test related to other modules can be changed anytime for any reason, but since we extend the possibilities of placement driver, the corresponding test should exist for regression purposes.



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1842106485


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -389,19 +389,19 @@ private void updateLeaseBatchInternal() {
             Map<ReplicationGroupId, Boolean> toBeNegotiated = new HashMap<>();
             Map<ReplicationGroupId, Lease> renewedLeases = new HashMap<>(leasesCurrent.leaseByGroupId());
 
-            Map<ReplicationGroupId, TokenizedAssignments> currentAssignments = assignmentsTracker.assignments();
-            Set<ReplicationGroupId> currentAssignmentsReplicationGroupIds = currentAssignments.keySet();
+            Map<ReplicationGroupId, TokenizedAssignments> currentStableAssignments = assignmentsTracker.stableAssignments();
+            Set<ReplicationGroupId> currentStableAssignmentsReplicationGroupIds = currentStableAssignments.keySet();
 
             // Remove all expired leases that are no longer present in assignments.
             renewedLeases.entrySet().removeIf(e -> clockService.before(e.getValue().getExpirationTime(), now)
-                    && !currentAssignmentsReplicationGroupIds.contains(e.getKey()));
+                    && !currentStableAssignmentsReplicationGroupIds.contains(e.getKey()));
 
-            int currentAssignmentsSize = currentAssignments.size();
+            int currentStableAssignmentsSize = currentStableAssignments.size();
             int activeLeasesCount = 0;
 
-            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentAssignments.entrySet()) {
+            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentStableAssignments.entrySet()) {

Review Comment:
   I guess we haven't the such case. On table creation we're posting in MS our first stables and then after rebalances we're only make stable switch => we always have stable assignment for a group



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841209591


##########
modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java:
##########
@@ -117,19 +123,30 @@ public class LeaseUpdaterTest extends BaseIgniteAbstractTest {
     void setUp() {
         HybridClockImpl clock = new HybridClockImpl();
 
-        Entry entry = new EntryImpl(
+        Entry stableEntry = new EntryImpl(
                 stablePartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
                 Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
                 1,
                 clock.now()
         );
 
-        when(mcEntriesCursor.iterator()).thenReturn(List.of(entry).iterator());
+        Entry pendingEntry = new EntryImpl(
+                pendingPartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
+                Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
+                1,
+                clock.now()
+        );
+
+        when(msStableAssignmentsEntriesCursor.iterator()).thenReturn(List.of(stableEntry).iterator());

Review Comment:
   I would prefer to have it as a placement driver specific unit test. Integration test related to other modules can be changed anytime, but since we extend the possibilities of placement driver, the corresponding test should exist for regression purposes.



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1843756772


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   In the end we sure that we couldn't get empty assignments (but tombstone). So, asserts are still removed 



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1840362315


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set

Review Comment:
   ```suggestion
                       // If there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set.
   ```



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {
+                        Map<ReplicationGroupId, TokenizedAssignments> pendingMap = assignmentsTracker.pendingAssignments();
+
+                        if (pendingMap.containsKey(grpId)) {
+                            Set<Assignment> pendingAssignments = pendingMap.get(grpId).nodes();
+                            candidate = nextLeaseHolder(pendingAssignments, grpId, proposedLeaseholder);
+                        }
+                    }
+
+                    // if we couldn't find a candidate neither stable nor pending assignments set, so update stats and skip iteration

Review Comment:
   ```suggestion
                       // If we couldn't find a candidate in neither stable nor pending assignments set, so update stats and skip iteration.
   ```



##########
modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java:
##########
@@ -117,19 +123,30 @@ public class LeaseUpdaterTest extends BaseIgniteAbstractTest {
     void setUp() {
         HybridClockImpl clock = new HybridClockImpl();
 
-        Entry entry = new EntryImpl(
+        Entry stableEntry = new EntryImpl(
                 stablePartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
                 Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
                 1,
                 clock.now()
         );
 
-        when(mcEntriesCursor.iterator()).thenReturn(List.of(entry).iterator());
+        Entry pendingEntry = new EntryImpl(
+                pendingPartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
+                Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
+                1,
+                clock.now()
+        );
+
+        when(msStableAssignmentsEntriesCursor.iterator()).thenReturn(List.of(stableEntry).iterator());

Review Comment:
   I would suggest a simple test when `msStableAssignmentsEntriesCursor` returns empty iterator and a node from pending assignments is selected as a leaseholder. Ofc another node should be written to `pendingEntry`.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -412,7 +412,7 @@ private void updateLeaseBatchInternal() {
                 if (!lease.isAccepted()) {
                     LeaseAgreement agreement = leaseNegotiator.getAndRemoveIfReady(grpId);
 
-                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), assignments);
+                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), stableAssignments);

Review Comment:
   I think, here should be a union of stable and pending assignments. Otherwise it will lead to invalidation of lease agreement created for pending assignment.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   I it really impossible? I mean, on a cluster where no tables exist
   Do we always get assignments from default zone?
   I am not sure this check is needed as strict assertion check
   Same question for stables



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {
+                        Map<ReplicationGroupId, TokenizedAssignments> pendingMap = assignmentsTracker.pendingAssignments();
+
+                        if (pendingMap.containsKey(grpId)) {
+                            Set<Assignment> pendingAssignments = pendingMap.get(grpId).nodes();
+                            candidate = nextLeaseHolder(pendingAssignments, grpId, proposedLeaseholder);
+                        }
+                    }

Review Comment:
   This is the place where prolonged and expired leases are processed, while you need to create a new one. So please move this block to `chooseCandidateAndCreateNewLease`, it's more suitable there.



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1840962257


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set

Review Comment:
   Done



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {
+                        Map<ReplicationGroupId, TokenizedAssignments> pendingMap = assignmentsTracker.pendingAssignments();
+
+                        if (pendingMap.containsKey(grpId)) {
+                            Set<Assignment> pendingAssignments = pendingMap.get(grpId).nodes();
+                            candidate = nextLeaseHolder(pendingAssignments, grpId, proposedLeaseholder);
+                        }
+                    }
+
+                    // if we couldn't find a candidate neither stable nor pending assignments set, so update stats and skip iteration

Review Comment:
   Done



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1843758825


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {
+                        Map<ReplicationGroupId, TokenizedAssignments> pendingMap = assignmentsTracker.pendingAssignments();
+
+                        if (pendingMap.containsKey(grpId)) {
+                            Set<Assignment> pendingAssignments = pendingMap.get(grpId).nodes();
+                            candidate = nextLeaseHolder(pendingAssignments, grpId, proposedLeaseholder);
+                        }
+                    }

Review Comment:
   Done



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1843949956


##########
modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java:
##########
@@ -117,19 +123,30 @@ public class LeaseUpdaterTest extends BaseIgniteAbstractTest {
     void setUp() {
         HybridClockImpl clock = new HybridClockImpl();
 
-        Entry entry = new EntryImpl(
+        Entry stableEntry = new EntryImpl(
                 stablePartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
                 Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
                 1,
                 clock.now()
         );
 
-        when(mcEntriesCursor.iterator()).thenReturn(List.of(entry).iterator());
+        Entry pendingEntry = new EntryImpl(
+                pendingPartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
+                Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
+                1,
+                clock.now()
+        );
+
+        when(msStableAssignmentsEntriesCursor.iterator()).thenReturn(List.of(stableEntry).iterator());

Review Comment:
   Small new `testLeaseAmongPendings` test is added and thanks to it -- I found several dumb bugs :'>



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1842104580


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   So, we assumes that stables are non-empty and we're saving assert for them, but for pendings we're making return in the case because it's possible



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1846397897


##########
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java:
##########
@@ -171,6 +171,33 @@ public static <T> Set<T> union(@Nullable Set<T> set, @Nullable T... ts) {
         return unmodifiableSet(res);
     }
 
+
+    /**
+     * Logical union on two probably {@code null} or empty sets.
+     *
+     * @param firstSet First operand.
+     * @param secondSet Second operand.
+     * @return Result of the union.
+     */
+    public static <T> Set<T> union(@Nullable Set<T> firstSet, @Nullable Set<T> secondSet) {
+        boolean isFirstSetEmptyOrNull = nullOrEmpty(firstSet);
+        boolean isSecondSetEmptyOrNull = nullOrEmpty(secondSet);
+
+        if (isFirstSetEmptyOrNull && isSecondSetEmptyOrNull) {
+            return new HashSet<>();
+        } else if (isFirstSetEmptyOrNull) {
+            return new HashSet<>(secondSet);

Review Comment:
   Done



##########
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java:
##########
@@ -147,28 +146,30 @@ public static boolean nullOrEmpty(@Nullable Iterator<?> iter) {
     }
 
     /**
-     * Union set and items.
+     * Logical union operation on two probably {@code null} or empty sets.
      *
-     * @param set Set.
-     * @param ts Items.
-     * @param <T> Type of the elements of set and items..
-     * @return Immutable union of set and items.
+     * @param firstSet First operand.
+     * @param secondSet Second operand.
+     * @return Result of the union on two sets that equals to all unique elements from the first and the second set or empty set if both
+     *      given sets are empty.
      */
-    @SafeVarargs
-    public static <T> Set<T> union(@Nullable Set<T> set, @Nullable T... ts) {
-        if (nullOrEmpty(set)) {
-            return ts == null || ts.length == 0 ? Set.of() : Set.of(ts);
-        }
-
-        if (ts == null || ts.length == 0) {
-            return unmodifiableSet(set);
+    public static <T> Set<T> union(@Nullable Set<T> firstSet, @Nullable Set<T> secondSet) {
+        boolean isFirstSetEmptyOrNull = nullOrEmpty(firstSet);
+        boolean isSecondSetEmptyOrNull = nullOrEmpty(secondSet);
+
+        if (isFirstSetEmptyOrNull && isSecondSetEmptyOrNull) {
+            return new HashSet<>();
+        } else if (isFirstSetEmptyOrNull) {
+            return new HashSet<>(secondSet);
+        } else if (isSecondSetEmptyOrNull) {
+            return new HashSet<>(firstSet);
+        } else {
+            var union = new HashSet<>(firstSet);
+
+            union.addAll(secondSet);
+
+            return union;

Review Comment:
   Done



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1842106485


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -389,19 +389,19 @@ private void updateLeaseBatchInternal() {
             Map<ReplicationGroupId, Boolean> toBeNegotiated = new HashMap<>();
             Map<ReplicationGroupId, Lease> renewedLeases = new HashMap<>(leasesCurrent.leaseByGroupId());
 
-            Map<ReplicationGroupId, TokenizedAssignments> currentAssignments = assignmentsTracker.assignments();
-            Set<ReplicationGroupId> currentAssignmentsReplicationGroupIds = currentAssignments.keySet();
+            Map<ReplicationGroupId, TokenizedAssignments> currentStableAssignments = assignmentsTracker.stableAssignments();
+            Set<ReplicationGroupId> currentStableAssignmentsReplicationGroupIds = currentStableAssignments.keySet();
 
             // Remove all expired leases that are no longer present in assignments.
             renewedLeases.entrySet().removeIf(e -> clockService.before(e.getValue().getExpirationTime(), now)
-                    && !currentAssignmentsReplicationGroupIds.contains(e.getKey()));
+                    && !currentStableAssignmentsReplicationGroupIds.contains(e.getKey()));
 
-            int currentAssignmentsSize = currentAssignments.size();
+            int currentStableAssignmentsSize = currentStableAssignments.size();
             int activeLeasesCount = 0;
 
-            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentAssignments.entrySet()) {
+            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentStableAssignments.entrySet()) {

Review Comment:
   I guess we haven't the such case. On table creation we're posting in MS our first stables and then after rebalances we're only make stable switch => we always have stable assignment for a group



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1843763044


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -389,19 +389,19 @@ private void updateLeaseBatchInternal() {
             Map<ReplicationGroupId, Boolean> toBeNegotiated = new HashMap<>();
             Map<ReplicationGroupId, Lease> renewedLeases = new HashMap<>(leasesCurrent.leaseByGroupId());
 
-            Map<ReplicationGroupId, TokenizedAssignments> currentAssignments = assignmentsTracker.assignments();
-            Set<ReplicationGroupId> currentAssignmentsReplicationGroupIds = currentAssignments.keySet();
+            Map<ReplicationGroupId, TokenizedAssignments> currentStableAssignments = assignmentsTracker.stableAssignments();
+            Set<ReplicationGroupId> currentStableAssignmentsReplicationGroupIds = currentStableAssignments.keySet();
 
             // Remove all expired leases that are no longer present in assignments.
             renewedLeases.entrySet().removeIf(e -> clockService.before(e.getValue().getExpirationTime(), now)
-                    && !currentAssignmentsReplicationGroupIds.contains(e.getKey()));
+                    && !currentStableAssignmentsReplicationGroupIds.contains(e.getKey()));
 
-            int currentAssignmentsSize = currentAssignments.size();
+            int currentStableAssignmentsSize = currentStableAssignments.size();
             int activeLeasesCount = 0;
 
-            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentAssignments.entrySet()) {
+            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentStableAssignments.entrySet()) {

Review Comment:
   Both should. Added unionization method that aggregate pendings and stables tokenized assignments maps onto map of assignments sets pairs by group id and use the pair in the cycle's body



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // If there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {

Review Comment:
   Done



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1840950280


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -412,7 +412,7 @@ private void updateLeaseBatchInternal() {
                 if (!lease.isAccepted()) {
                     LeaseAgreement agreement = leaseNegotiator.getAndRemoveIfReady(grpId);
 
-                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), assignments);
+                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), stableAssignments);

Review Comment:
   Hm, I'm not sure there: lease on pendings set is an exceptional situation and I guess It's a good idea to invalidate pending lease and grant it to a node from stables. What do you think?



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1840953229


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   I don't now, to be honest, just moved the assert as it was. I'm not sure that it's a possible situation too. Let's remove it then.



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841211991


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   Ok it's up to you, but I mean, if you remove assertion, please add `return` there to be sure that we dont try to process empty assignements



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1843753005


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -412,7 +412,7 @@ private void updateLeaseBatchInternal() {
                 if (!lease.isAccepted()) {
                     LeaseAgreement agreement = leaseNegotiator.getAndRemoveIfReady(grpId);
 
-                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), assignments);
+                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), stableAssignments);

Review Comment:
   Done



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1846159797


##########
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java:
##########
@@ -171,6 +171,33 @@ public static <T> Set<T> union(@Nullable Set<T> set, @Nullable T... ts) {
         return unmodifiableSet(res);
     }
 
+
+    /**
+     * Logical union on two probably {@code null} or empty sets.
+     *
+     * @param firstSet First operand.
+     * @param secondSet Second operand.
+     * @return Result of the union.
+     */
+    public static <T> Set<T> union(@Nullable Set<T> firstSet, @Nullable Set<T> secondSet) {
+        boolean isFirstSetEmptyOrNull = nullOrEmpty(firstSet);
+        boolean isSecondSetEmptyOrNull = nullOrEmpty(secondSet);
+
+        if (isFirstSetEmptyOrNull && isSecondSetEmptyOrNull) {
+            return new HashSet<>();
+        } else if (isFirstSetEmptyOrNull) {
+            return new HashSet<>(secondSet);
+        } else if (isSecondSetEmptyOrNull) {
+            return new HashSet<>(firstSet);

Review Comment:
   why not just `firstSet`?



##########
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java:
##########
@@ -171,6 +171,33 @@ public static <T> Set<T> union(@Nullable Set<T> set, @Nullable T... ts) {
         return unmodifiableSet(res);
     }
 
+
+    /**
+     * Logical union on two probably {@code null} or empty sets.
+     *
+     * @param firstSet First operand.
+     * @param secondSet Second operand.
+     * @return Result of the union.
+     */
+    public static <T> Set<T> union(@Nullable Set<T> firstSet, @Nullable Set<T> secondSet) {
+        boolean isFirstSetEmptyOrNull = nullOrEmpty(firstSet);
+        boolean isSecondSetEmptyOrNull = nullOrEmpty(secondSet);
+
+        if (isFirstSetEmptyOrNull && isSecondSetEmptyOrNull) {
+            return new HashSet<>();
+        } else if (isFirstSetEmptyOrNull) {
+            return new HashSet<>(secondSet);

Review Comment:
   I would suggest `Set.of()` here, it provides lightweight immutable collection for zero element set.



##########
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java:
##########
@@ -147,28 +146,30 @@ public static boolean nullOrEmpty(@Nullable Iterator<?> iter) {
     }
 
     /**
-     * Union set and items.
+     * Logical union operation on two probably {@code null} or empty sets.
      *
-     * @param set Set.
-     * @param ts Items.
-     * @param <T> Type of the elements of set and items..
-     * @return Immutable union of set and items.
+     * @param firstSet First operand.
+     * @param secondSet Second operand.
+     * @return Result of the union on two sets that equals to all unique elements from the first and the second set or empty set if both
+     *      given sets are empty.
      */
-    @SafeVarargs
-    public static <T> Set<T> union(@Nullable Set<T> set, @Nullable T... ts) {
-        if (nullOrEmpty(set)) {
-            return ts == null || ts.length == 0 ? Set.of() : Set.of(ts);
-        }
-
-        if (ts == null || ts.length == 0) {
-            return unmodifiableSet(set);
+    public static <T> Set<T> union(@Nullable Set<T> firstSet, @Nullable Set<T> secondSet) {
+        boolean isFirstSetEmptyOrNull = nullOrEmpty(firstSet);
+        boolean isSecondSetEmptyOrNull = nullOrEmpty(secondSet);
+
+        if (isFirstSetEmptyOrNull && isSecondSetEmptyOrNull) {
+            return new HashSet<>();
+        } else if (isFirstSetEmptyOrNull) {
+            return new HashSet<>(secondSet);
+        } else if (isSecondSetEmptyOrNull) {
+            return new HashSet<>(firstSet);
+        } else {
+            var union = new HashSet<>(firstSet);
+
+            union.addAll(secondSet);
+
+            return union;

Review Comment:
   btw, taking into account two comments above, in order to provide consistent output, maybe here also an ummutable set should be returned



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841223129


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -412,7 +412,7 @@ private void updateLeaseBatchInternal() {
                 if (!lease.isAccepted()) {
                     LeaseAgreement agreement = leaseNegotiator.getAndRemoveIfReady(grpId);
 
-                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), assignments);
+                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), stableAssignments);

Review Comment:
   I mean the folowing:
   - no stable assignments left, the candidate is chosen from pendings
   - lease agreement is created and negotiation starts
   - on the next iteration `agreement.checkValid` may see that the candidate is not in the given assignments (and the given assignments are stable here), and the candidate  never was in the stable assignments because if was chosen from pendings. However, `checkValid` knows nothing about it and invalidates the agreement, stopping the negotiation and beginning the lease granting process from the start. This may cause flakiness of tests.



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841223129


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -412,7 +412,7 @@ private void updateLeaseBatchInternal() {
                 if (!lease.isAccepted()) {
                     LeaseAgreement agreement = leaseNegotiator.getAndRemoveIfReady(grpId);
 
-                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), assignments);
+                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), stableAssignments);

Review Comment:
   I mean the folowing:
   - no stable assignments left, the candidate is chosen from pendings
   - lease agreement is created and negotiation starts
   - on the next iteration `agreement.checkValid` may see that the candidate is not in the given assignments (and the given assignments are stable here), and the candidate  never was in the stable assignments because if was chosen from pendings. However, `checkValid` knows nothing about it and invalidates the agreement, stopping the negotiation and beginning the lease granting process from the start. 



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841211991


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   Ok it's up to you, but I mean, if you remove assertion, please add `return` there to be sure that we dont try to process empty assignments



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841211991


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -147,48 +141,137 @@ public CompletableFuture<List<TokenizedAssignments>> getAssignments(
     }
 
     /**
-     * Gets assignments.
+     * Gets stable assignments.
      *
-     * @return Map replication group id to its assignment.
+     * @return Map replication group id to its stable assignments.
      */
-    public Map<ReplicationGroupId, TokenizedAssignments> assignments() {
-        return groupAssignments;
+    Map<ReplicationGroupId, TokenizedAssignments> stableAssignments() {
+        return groupStableAssignments;
     }
 
     /**
-     * Meta storage assignments watch.
+     * Gets pending assignments.
+     *
+     * @return Map replication group id to its pending assignments.
      */
-    private class AssignmentsListener implements WatchListener {
-        @Override
-        public CompletableFuture<Void> onUpdate(WatchEvent event) {
-            assert !event.entryEvents().stream().anyMatch(e -> e.newEntry().empty()) : "New assignments are empty";
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Assignment update [revision={}, keys={}]", event.revision(),
-                        event.entryEvents().stream()
-                                .map(e -> new ByteArray(e.newEntry().key()).toString())
-                                .collect(Collectors.joining(",")));
+    Map<ReplicationGroupId, TokenizedAssignments> pendingAssignments() {
+        return groupStableAssignments;
+    }
+
+    private WatchListener createStableAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stable assignments update [revision={}, keys={}]", event.revision(), collectKeysFromEventAsString(event));
+                }
+
+                handleReceivedAssignments(event, STABLE_ASSIGNMENTS_PREFIX, groupStableAssignments);
+
+                return nullCompletedFuture();
             }
 
-            for (EntryEvent evt : event.entryEvents()) {
-                Entry entry = evt.newEntry();
+            @Override
+            public void onError(Throwable e) {
+            }
+        };
+    }
 
-                var replicationGrpId = TablePartitionId.fromString(
-                        new String(entry.key(), StandardCharsets.UTF_8).replace(STABLE_ASSIGNMENTS_PREFIX, ""));
+    private WatchListener createPendingAssignmentsListener() {
+        return new WatchListener() {
+            @Override
+            public CompletableFuture<Void> onUpdate(WatchEvent event) {
+                assert areAssignmentsPresentedInEvent(event) : "New assignments are empty";

Review Comment:
   Ok it's up to you



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1840959806


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {
+                        Map<ReplicationGroupId, TokenizedAssignments> pendingMap = assignmentsTracker.pendingAssignments();
+
+                        if (pendingMap.containsKey(grpId)) {
+                            Set<Assignment> pendingAssignments = pendingMap.get(grpId).nodes();
+                            candidate = nextLeaseHolder(pendingAssignments, grpId, proposedLeaseholder);
+                        }
+                    }

Review Comment:
   I doubt there, because in the first scenario from the ticket lease on B is trying to expire (time is out), but we can't to find a proper candidate in this lines. So, the case `lease.getExpirationTime().getPhysical() < outdatedLeaseThreshold` is crucial there. But, may be I should add the pendings check in  `chooseCandidateAndCreateNewLease` too (not instead)?



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1843760103


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -389,19 +389,19 @@ private void updateLeaseBatchInternal() {
             Map<ReplicationGroupId, Boolean> toBeNegotiated = new HashMap<>();
             Map<ReplicationGroupId, Lease> renewedLeases = new HashMap<>(leasesCurrent.leaseByGroupId());
 
-            Map<ReplicationGroupId, TokenizedAssignments> currentAssignments = assignmentsTracker.assignments();
-            Set<ReplicationGroupId> currentAssignmentsReplicationGroupIds = currentAssignments.keySet();
+            Map<ReplicationGroupId, TokenizedAssignments> currentStableAssignments = assignmentsTracker.stableAssignments();
+            Set<ReplicationGroupId> currentStableAssignmentsReplicationGroupIds = currentStableAssignments.keySet();
 
             // Remove all expired leases that are no longer present in assignments.
             renewedLeases.entrySet().removeIf(e -> clockService.before(e.getValue().getExpirationTime(), now)
-                    && !currentAssignmentsReplicationGroupIds.contains(e.getKey()));
+                    && !currentStableAssignmentsReplicationGroupIds.contains(e.getKey()));

Review Comment:
   Done, now it checks pendings too



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc merged PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707


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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1840954916


##########
modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java:
##########
@@ -117,19 +123,30 @@ public class LeaseUpdaterTest extends BaseIgniteAbstractTest {
     void setUp() {
         HybridClockImpl clock = new HybridClockImpl();
 
-        Entry entry = new EntryImpl(
+        Entry stableEntry = new EntryImpl(
                 stablePartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
                 Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
                 1,
                 clock.now()
         );
 
-        when(mcEntriesCursor.iterator()).thenReturn(List.of(entry).iterator());
+        Entry pendingEntry = new EntryImpl(
+                pendingPartAssignmentsKey(new TablePartitionId(1, 0)).bytes(),
+                Assignments.of(HybridTimestamp.MIN_VALUE.longValue(), Assignment.forPeer(node.name())).toBytes(),
+                1,
+                clock.now()
+        );
+
+        when(msStableAssignmentsEntriesCursor.iterator()).thenReturn(List.of(stableEntry).iterator());

Review Comment:
   As a unit test? Because after https://github.com/apache/ignite-3/pull/4446 I bet we have an integration test that models such situation (that's why we're fixing it). 



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841223129


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -412,7 +412,7 @@ private void updateLeaseBatchInternal() {
                 if (!lease.isAccepted()) {
                     LeaseAgreement agreement = leaseNegotiator.getAndRemoveIfReady(grpId);
 
-                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), assignments);
+                    agreement.checkValid(grpId, topologyTracker.currentTopologySnapshot(), stableAssignments);

Review Comment:
   I mean the folowing:
   - no stable assignments left, the candidate is chosen from pendings
   - lease agreement is created and negotiation starts
   - on the next iteration `agreement.checkValid` may see that the candidate is not in the given assignments anymore (and the given assignments are stable here), and the candidate  never was in the stable assignments because if was chosen from pendings. However, `checkValid` knows nothing about it and invalidates the agreement, stopping the negotiation and beginning the lease granting process from the start. This may cause flakiness of tests.



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "vldpyatkov (via GitHub)" <gi...@apache.org>.
vldpyatkov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841696820


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // If there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {

Review Comment:
   This part has to be packed to the nextLeaseHolder method.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -389,19 +389,19 @@ private void updateLeaseBatchInternal() {
             Map<ReplicationGroupId, Boolean> toBeNegotiated = new HashMap<>();
             Map<ReplicationGroupId, Lease> renewedLeases = new HashMap<>(leasesCurrent.leaseByGroupId());
 
-            Map<ReplicationGroupId, TokenizedAssignments> currentAssignments = assignmentsTracker.assignments();
-            Set<ReplicationGroupId> currentAssignmentsReplicationGroupIds = currentAssignments.keySet();
+            Map<ReplicationGroupId, TokenizedAssignments> currentStableAssignments = assignmentsTracker.stableAssignments();
+            Set<ReplicationGroupId> currentStableAssignmentsReplicationGroupIds = currentStableAssignments.keySet();
 
             // Remove all expired leases that are no longer present in assignments.
             renewedLeases.entrySet().removeIf(e -> clockService.before(e.getValue().getExpirationTime(), now)
-                    && !currentAssignmentsReplicationGroupIds.contains(e.getKey()));
+                    && !currentStableAssignmentsReplicationGroupIds.contains(e.getKey()));
 
-            int currentAssignmentsSize = currentAssignments.size();
+            int currentStableAssignmentsSize = currentStableAssignments.size();
             int activeLeasesCount = 0;
 
-            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentAssignments.entrySet()) {
+            for (Map.Entry<ReplicationGroupId, TokenizedAssignments> entry : currentStableAssignments.entrySet()) {

Review Comment:
   Why do you think all entries are in stable assignment?
   As I understand it, we are using pending assessment because it might be that the stable assignment does not exist for a specific group.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -389,19 +389,19 @@ private void updateLeaseBatchInternal() {
             Map<ReplicationGroupId, Boolean> toBeNegotiated = new HashMap<>();
             Map<ReplicationGroupId, Lease> renewedLeases = new HashMap<>(leasesCurrent.leaseByGroupId());
 
-            Map<ReplicationGroupId, TokenizedAssignments> currentAssignments = assignmentsTracker.assignments();
-            Set<ReplicationGroupId> currentAssignmentsReplicationGroupIds = currentAssignments.keySet();
+            Map<ReplicationGroupId, TokenizedAssignments> currentStableAssignments = assignmentsTracker.stableAssignments();
+            Set<ReplicationGroupId> currentStableAssignmentsReplicationGroupIds = currentStableAssignments.keySet();
 
             // Remove all expired leases that are no longer present in assignments.
             renewedLeases.entrySet().removeIf(e -> clockService.before(e.getValue().getExpirationTime(), now)
-                    && !currentAssignmentsReplicationGroupIds.contains(e.getKey()));
+                    && !currentStableAssignmentsReplicationGroupIds.contains(e.getKey()));

Review Comment:
   Is it enough to check only stable assignment here?



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1841231234


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -443,8 +443,19 @@ private void updateLeaseBatchInternal() {
                             ? lease.getLeaseholder()
                             : lease.proposedCandidate();
 
-                    ClusterNode candidate = nextLeaseHolder(assignments, grpId, proposedLeaseholder);
+                    ClusterNode candidate = nextLeaseHolder(stableAssignments, grpId, proposedLeaseholder);
 
+                    // if there wasn't a candidate among stable assignments set then make attempt to select a candidate among pending set
+                    if (candidate == null) {
+                        Map<ReplicationGroupId, TokenizedAssignments> pendingMap = assignmentsTracker.pendingAssignments();
+
+                        if (pendingMap.containsKey(grpId)) {
+                            Set<Assignment> pendingAssignments = pendingMap.get(grpId).nodes();
+                            candidate = nextLeaseHolder(pendingAssignments, grpId, proposedLeaseholder);
+                        }
+                    }

Review Comment:
   And what about the case of creating the new lease?
   Probably, the both cases where `writeNewLease` is used should be covered. Maybe you should combine this logic with `nextLeaseHolder` method?



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


Re: [PR] IGNITE-23587 Make PlacementDriver able to choose lease candidate from pendings [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #4707:
URL: https://github.com/apache/ignite-3/pull/4707#discussion_r1846380551


##########
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java:
##########
@@ -171,6 +171,33 @@ public static <T> Set<T> union(@Nullable Set<T> set, @Nullable T... ts) {
         return unmodifiableSet(res);
     }
 
+
+    /**
+     * Logical union on two probably {@code null} or empty sets.
+     *
+     * @param firstSet First operand.
+     * @param secondSet Second operand.
+     * @return Result of the union.
+     */
+    public static <T> Set<T> union(@Nullable Set<T> firstSet, @Nullable Set<T> secondSet) {
+        boolean isFirstSetEmptyOrNull = nullOrEmpty(firstSet);
+        boolean isSecondSetEmptyOrNull = nullOrEmpty(secondSet);
+
+        if (isFirstSetEmptyOrNull && isSecondSetEmptyOrNull) {
+            return new HashSet<>();
+        } else if (isFirstSetEmptyOrNull) {
+            return new HashSet<>(secondSet);
+        } else if (isSecondSetEmptyOrNull) {
+            return new HashSet<>(firstSet);

Review Comment:
   Because the original set may be used outside separately from the union's result



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