From 2d6791bb1157af52e20ffd1fb4ca025c283153d3 Mon Sep 17 00:00:00 2001 From: Binbin Date: Thu, 4 Jul 2024 02:42:25 +0800 Subject: [PATCH] Use clusterNodeIsVotingPrimary function to check the right (#735) Minor cleanups. --------- Signed-off-by: Binbin --- src/cluster_legacy.c | 16 ++++++++-------- src/cluster_legacy.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index dd95cc6bb7..f2f980d58c 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -1902,10 +1902,10 @@ void clearNodeFailureIfNeeded(clusterNode *node) { serverAssert(nodeFailed(node)); - /* For replicas we always clear the FAIL flag if we can contact the - * node again. */ - if (nodeIsReplica(node) || node->numslots == 0) { - serverLog(LL_NOTICE, "Clear FAIL state for node %.40s (%s):%s is reachable again.", node->name, + /* For replicas or primaries without slots, that is, nodes without voting + * right, we always clear the FAIL flag if we can contact the node again. */ + if (!clusterNodeIsVotingPrimary(node)) { + serverLog(LL_NOTICE, "Clear FAIL state for node %.40s (%s): %s is reachable again.", node->name, node->human_nodename, nodeIsReplica(node) ? "replica" : "primary without slots"); node->flags &= ~CLUSTER_NODE_FAIL; clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG); @@ -4006,9 +4006,9 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { /* IF we are not a primary serving at least 1 slot, we don't have the * right to vote, as the cluster size is the number - * of primariies serving at least one slot, and quorum is the cluster + * of primaries serving at least one slot, and quorum is the cluster * size + 1 */ - if (nodeIsReplica(myself) || myself->numslots == 0) return; + if (!clusterNodeIsVotingPrimary(myself)) return; /* Request epoch must be >= our currentEpoch. * Note that it is impossible for it to actually be greater since @@ -4086,7 +4086,7 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { } /* This function returns the "rank" of this instance, a replica, in the context - * of its primar-replicas ring. The rank of the replica is given by the number of + * of its primary-replicas ring. The rank of the replica is given by the number of * other replicas for the same primary that have a better replication offset * compared to the local one (better means, greater, so they claim more data). * @@ -6022,7 +6022,7 @@ void clusterCommandSetSlot(client *c) { * 3. Upon replication completion, primary B executes `SETSLOT n NODE B` and * returns success to client C. * 4. The following steps can happen in parallel: - * a. Client C issues `SETSLOT n NODE B` against parimary A. + * a. Client C issues `SETSLOT n NODE B` against primary A. * b. Primary B gossips its new slot ownership to the cluster (including A, A', etc.). * * This ensures that all replicas have the latest topology information, enabling diff --git a/src/cluster_legacy.h b/src/cluster_legacy.h index fb80f45eec..d054d86017 100644 --- a/src/cluster_legacy.h +++ b/src/cluster_legacy.h @@ -287,18 +287,18 @@ struct _clusterNode { uint16_t *slot_info_pairs; /* Slots info represented as (start/end) pair (consecutive index). */ int slot_info_pairs_count; /* Used number of slots in slot_info_pairs */ int numslots; /* Number of slots handled by this node */ - int num_replicas; /* Number of replica nodes, if this is a primar */ + int num_replicas; /* Number of replica nodes, if this is a primary */ clusterNode **replicas; /* pointers to replica nodes */ clusterNode *replicaof; /* pointer to the primary node. Note that it may be NULL even if the node is a replica - if we don't have the parimary node in our + if we don't have the primary node in our tables. */ unsigned long long last_in_ping_gossip; /* The number of the last carried in the ping gossip section */ mstime_t ping_sent; /* Unix time we sent latest ping */ mstime_t pong_received; /* Unix time we received the pong */ mstime_t data_received; /* Unix time we received any data */ mstime_t fail_time; /* Unix time when FAIL flag was set */ - mstime_t voted_time; /* Last time we voted for a replica of this parimary */ + mstime_t voted_time; /* Last time we voted for a replica of this primary */ mstime_t repl_offset_time; /* Unix time we received offset for this node */ mstime_t orphaned_time; /* Starting time of orphaned primary condition */ long long repl_offset; /* Last known repl offset for this node. */