Cyrill commented on code in PR #5046:
URL: https://github.com/apache/ignite-3/pull/5046#discussion_r1922803506


##########
modules/partition-distribution/src/main/java/org/apache/ignite/internal/partitiondistribution/AssignmentsChain.java:
##########
@@ -64,31 +71,70 @@ public AssignmentsChain replaceLast(Assignments newLast) {
      * @param newLast New last link.
      * @return new AssignmentsChain.
      */
-    public AssignmentsChain addLast(Assignments newLast) {
+    public AssignmentsChain addLast(Assignments newLast, long 
configurationTerm, long configurationIndex) {
         assert !chain.isEmpty() : "Assignments chain is empty.";
 
-        List<Assignments> newChain = new ArrayList<>(chain);
+        List<AssignmentsLink> newChain = new ArrayList<>(chain);
 
-        newChain.add(newLast);
+        newChain.add(new AssignmentsLink(newLast, configurationTerm, 
configurationIndex));
 
         return new AssignmentsChain(newChain);
     }
 
+
+    /**
+     * Gets the next link in the chain after the given link.
+     *
+     * @param link The link to get the next one from.
+     * @return The next link in the chain, or {@code null} if the given link 
is the last one in the chain.
+     */
+    public @Nullable AssignmentsLink nextLink(AssignmentsLink link) {
+        int i = chain.indexOf(link);
+
+        return i < 0 || i == chain().size() - 1 ? null : chain.get(i + 1);
+    }
+
+    /**
+     * Returns the last {@link AssignmentsLink} in the chain that contains the 
specified node.
+     *
+     * @param nodeConsistentId The consistent identifier of the node to search 
for.
+     * @return The last {@link AssignmentsLink} that contains the node, or 
{@code null} if no such link exists.
+     */
+    public @Nullable AssignmentsLink lastLink(String nodeConsistentId) {
+        for (int i = chain.size() - 1; i >= 0; i--) {
+            AssignmentsLink link = chain.get(i);
+            if (link.hasNode(nodeConsistentId)) {
+                return link;
+            }
+        }
+
+        return null;
+    }

Review Comment:
   added



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to