beobal commented on code in PR #4688:
URL: https://github.com/apache/cassandra/pull/4688#discussion_r3111459739


##########
src/java/org/apache/cassandra/tcm/listeners/LegacyStateListener.java:
##########
@@ -75,52 +77,96 @@ public void notifyPostCommit(ClusterMetadata prev, 
ClusterMetadata next, boolean
                 changed.add(node);
         }
 
-        for (InetAddressAndPort remove : removedAddr)
+        // next.myNodeId() can be null during replay (before we have 
registered) but if it is present and
+        // there is a relevant change to the state of the local node, process 
that synchronously.
+        if (next.myNodeId() != null && changed.contains(next.myNodeId()))
         {
-            GossipHelper.removeFromGossip(remove);
-            GossipHelper.evictFromMembership(remove);
-            PeersTable.removeFromSystemPeersTables(remove);
+            // Default is to process updates for the local node synchronously, 
overridable via config/hotprop
+            if (DatabaseDescriptor.getLegacyStateListenerSyncLocalUpdates())
+                processChangesToLocalState(prev, next, next.myNodeId());
+            else
+                ScheduledExecutors.optionalTasks.submit(() -> 
processChangesToLocalState(prev, next, next.myNodeId()));
+
+            changed.remove(next.myNodeId());
         }
 
-        for (NodeId change : changed)
+        // Schedule async processing of changes to peers and removing 
unregistered nodes (potentially including the
+        // local node).
+        ScheduledExecutors.optionalTasks.submit(() -> {
+            processRemovedNodes(removedAddr);
+            processChangesToRemotePeers(prev, next, changed);
+        });
+    }
+
+    private void processChangesToLocalState(ClusterMetadata prev, 
ClusterMetadata next, NodeId localId)
+    {
+        logger.info("Processing changes to local node state {} for epoch 
{}->{}", localId, prev.epoch.getEpoch(), next.epoch.getEpoch());
+        Collection<Token> tokensForGossip = next.tokenMap.tokens(localId);
+        NodeState state = next.directory.peerState(localId);
+        switch (state)
         {
-            // next.myNodeId() can be null during replay (before we have 
registered)
-            if (next.myNodeId() != null && next.myNodeId().equals(change))
-            {
-                switch (next.directory.peerState(change))
+            case BOOTSTRAPPING:
+            case BOOT_REPLACING:

Review Comment:
   It is intentional, extracting the tokens from the in-flight sequence for the 
local node when in a `BOOT_REPLACING` state & then updating gossip state was 
done later on in this method, in the part outside the 
   
   ```if (next.myNodeId() != null && next.myNodeId().equals(change))```
   
   section, so this is an artefact of refactoring into distinct methods for 
applying changes to local/remote node states.



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