More cluster refactoring: move common logic from cluster_legacy.c#3701
More cluster refactoring: move common logic from cluster_legacy.c#3701zuiderkwast wants to merge 2 commits into
Conversation
…common files This refactoring is done as a preparation to, and in parallel to, implementing another cluster protocol, so the line between common logic and gossip-specific code is becomming clearer. Refactor replica migration code in cluster.c: New function clusterHandleLostLastSlot(target) — called when a node loses its last slot in slot migration. Triggers replica migration and does some logging. This code is now called from the protocol-specific code (cluster_legacy.c) when the CLUSTER SETSLOT NODE command has completed removing the last slot from a node. Replicated CLUSTER SETSLOT / CLUSTER FAILOVER handling (cluster.c). These commands are sometimes received from the primary over the replication stream. Added c == server.primary checks before blocking the client. Shutdown refactoring (cluster.c, cluster_bus.h, server.c): clusterAutoFailoverOnShutdown moved from cluster_legacy.c to cluster.c (common code). New clusterBus callback prepareShutdown — called early in shutdown for graceful handoff (intended to trigger Raft leader transfer if the leader is shutting down). Node reconnection logic extracted to cluster_link.c and cluster_link.h. Reconnect code called by common clusterCron. clusterConnectNodes() handles buffer limit checks, handshake timeout removal, reconnection with budget/throttling, and backoff logic. Node address parsing/serialization extracted (cluster_nodes.c) - parse and build the ip:port@cport,hostname,aux=val string. (To be reused for cluster V2). getClusterConnectionsCount() simplified. It's not protocol specific. reset cluster stats code moved to common code. Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## cluster-v2 #3701 +/- ##
==============================================
+ Coverage 76.65% 76.76% +0.10%
==============================================
Files 165 165
Lines 80892 80930 +38
==============================================
+ Hits 62005 62122 +117
+ Misses 18887 18808 -79
🚀 New features to boost your workflow:
|
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
c0210a9 to
0ff8777
Compare
This refactoring is done as a preparation for, and in parallel to, implementing another cluster protocol, so the line between common logic and gossip-specific code is becomming clearer.
Refactor replica migration code in cluster.c: New function clusterHandleLostLastSlot(target) — called when a node loses its last slot in slot migration. Triggers replica migration and does some logging. This code is now called from the protocol-specific code (cluster_legacy.c) when the CLUSTER SETSLOT NODE command has completed removing the last slot from a node.
Replicated CLUSTER SETSLOT / CLUSTER FAILOVER handling (cluster.c). These commands are sometimes received from the primary over the replication stream. Added c == server.primary checks before blocking the client.
Shutdown refactoring (cluster.c, cluster_bus.h, server.c): clusterAutoFailoverOnShutdown moved from cluster_legacy.c to cluster.c (common code). New clusterBus callback prepareShutdown — called early in shutdown for graceful handoff (intended to trigger Raft leader transfer if the leader is shutting down).
Node reconnection logic extracted to cluster_link.c and cluster_link.h. Reconnect code called by common clusterCron. clusterConnectNodes() handles buffer limit checks, handshake timeout removal, reconnection with budget/throttling, and backoff logic.
Node address parsing/serialization extracted (cluster_nodes.c) - parse and build the ip:port@cport,hostname,aux=val string. (To be reused for cluster V2).
getClusterConnectionsCount() simplified. It's not protocol specific.
reset cluster stats code moved to common code.