dcapwell commented on code in PR #65:
URL: https://github.com/apache/cassandra-accord/pull/65#discussion_r1309219019


##########
accord-core/src/test/java/accord/impl/list/ListStore.java:
##########
@@ -96,4 +328,222 @@ private static boolean isStrictPrefix(int[] a, int[] b)
         }
         return true;
     }
+
+    public synchronized void onTopologyUpdate(Node node, Topology topology)
+    {
+        long epoch = topology.epoch();
+        Ranges updatedRanges = topology.rangesForNode(node.id());
+        if (previousTopology == null)
+        {
+            previousTopology = topology;
+            allowed = updatedRanges;
+            addedAts.add(new ChangeAt(epoch, updatedRanges));
+            return;
+        }
+
+        Ranges previousRanges = previousTopology.rangesForNode(node.id());
+
+        Ranges added = updatedRanges.subtract(previousRanges);
+        Ranges removed = previousRanges.subtract(updatedRanges);
+        if (!added.isEmpty())
+        {
+            addedAts.add(new ChangeAt(epoch, added));
+            for (Range range : added)
+            {
+                if (!previousTopology.ranges().intersects(range))
+                {
+                    // A range was added that globally didn't exist before; 
there is nothing to bootstrap here!
+                    // TODO (now): document this history change
+                    allowed = allowed.with(Ranges.of(range));
+                }
+            }
+        }
+        if (!removed.isEmpty())
+        {
+            pendingRemoves.add(epoch);
+            removedAts.add(new ChangeAt(epoch, removed));
+            // There are 2 different types of remove
+            // 1) node no longer covers, but the range exists in the cluster
+            // 2) the range no longer exists in the cluster
+            // Given this, we need 2 different solutions for the purge logic 
as sync points are not safe when running in older epoch.
+            Ranges localRemove = Ranges.EMPTY;
+            Ranges globalRemove = Ranges.EMPTY;
+            for (Range range : removed)
+            {
+                if (topology.ranges().intersects(range)) localRemove = 
localRemove.with(Ranges.of(range));
+                else                                     globalRemove = 
globalRemove.with(Ranges.of(range));
+            }
+            if (!localRemove.isEmpty())
+            {
+                Ranges finalLocalRemove = localRemove;
+                runWhenReady(node, epoch, () -> removeLocalWhenReady(node, 
epoch, finalLocalRemove));
+            }
+            // TODO (correctness, coverage): add cleanup logic for global 
ranges removed. This must be solved in CASSANDRA-18675
+        }
+        previousTopology = topology;
+    }
+
+    private void runWhenReady(Node node, long epoch, Runnable whenKnown)
+    {
+        if (node.topology().epoch() >= epoch) whenKnown.run();

Review Comment:
   was finding issues as this logic happens *before* accord sees the epoch (to 
better mimic TCM) and the wait logic didn't expect gaps... so implemented my 
own wait logic...



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to