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


##########
modules/partition-distribution/src/main/java/org/apache/ignite/internal/partitiondistribution/AssignmentsChain.java:
##########
@@ -29,66 +32,117 @@
 /**
  * Contains the chain of changed assignments.
  */
-public class AssignmentsChain {
+public class AssignmentsChain implements Iterable<AssignmentsLink> {
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24177 Either remove 
default values or add proper javadoc.
+    private static final long DEFAULT_CONF_TERM = -1;
+    private static final long DEFAULT_CONF_IDX = -1;
+
     /** Chain of assignments. */
     @IgniteToStringInclude
-    private final List<Assignments> chain;
+    private final List<AssignmentsLink> chain;
+
+    private AssignmentsChain(List<AssignmentsLink> chain) {
+        assert !chain.isEmpty() : "Chain should not be empty";
 
-    private AssignmentsChain(List<Assignments> chain) {
         this.chain = chain;
     }
 
-    public List<Assignments> chain() {
-        return chain;
+    /**
+     * Returns the number of links in this chain.
+     *
+     * @return the number of links in this chain.
+     */
+    public int size() {
+        return chain.size();
     }
 
     /**
-     * Create a new {@link AssignmentsChain} with the last link in the chain 
replaced with the provided one.
+     * Replace the last link in the chain with the provided one.
      *
      * @param newLast New last link.
-     * @return new AssignmentsChain.
+     * @return the created {@link AssignmentsLink}
      */
-    public AssignmentsChain replaceLast(Assignments newLast) {
+    public AssignmentsLink replaceLast(Assignments newLast, long 
configurationTerm, long configurationIndex) {
         assert !chain.isEmpty() : "Assignments chain is empty.";
 
-        List<Assignments> newChain = new ArrayList<>(chain);
+        AssignmentsLink link = new AssignmentsLink(newLast, configurationTerm, 
configurationIndex);
 
-        newChain.set(newChain.size() - 1, newLast);
+        chain.set(chain.size() - 1, link);
 
-        return new AssignmentsChain(newChain);
+        if (chain.size() > 1) {
+            chain.get(chain.size() - 2).next(link);
+        }
+
+        return link;
     }
 
     /**
-     * Create a new {@link AssignmentsChain} with a new link added to the 
chain.
+     * Add a new link to the end of the chain.
      *
      * @param newLast New last link.
-     * @return new AssignmentsChain.
+     * @return the created {@link AssignmentsLink}
      */
-    public AssignmentsChain addLast(Assignments newLast) {
+    public AssignmentsLink addLast(Assignments newLast, long 
configurationTerm, long configurationIndex) {
         assert !chain.isEmpty() : "Assignments chain is empty.";

Review Comment:
   I guess it should be possible to addLast element to an empty chain.



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