Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Cluster Size Calculation Logic into Separate Function #1636

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -5546,6 +5546,31 @@ void clusterCloseAllSlots(void) {
memset(server.cluster->importing_slots_from, 0, sizeof(server.cluster->importing_slots_from));
}

static void clusterDetermineClusterSize(int *reachable_primaries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void clusterDetermineClusterSize(int *reachable_primaries) {
static int clusterDetermineClusterSize(void) {

Then return the size at the end.

*reachable_primaries = 0;
/* Compute the cluster size, that is the number of primary nodes
* serving at least a single slot.
*
* At the same time count the number of reachable primaries having
* at least one slot. */
{
dictIterator *di;
dictEntry *de;

server.cluster->size = 0;
di = dictGetSafeIterator(server.cluster->nodes);
while ((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de);

if (clusterNodeIsVotingPrimary(node)) {
server.cluster->size++;
if ((node->flags & (CLUSTER_NODE_FAIL | CLUSTER_NODE_PFAIL)) == 0) ++*reachable_primaries;
}
}
dictReleaseIterator(di);
}
}

/* -----------------------------------------------------------------------------
* Cluster state evaluation function
* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -5609,28 +5634,7 @@ void clusterUpdateState(void) {
}
}
}

/* Compute the cluster size, that is the number of primary nodes
* serving at least a single slot.
*
* At the same time count the number of reachable primaries having
* at least one slot. */
{
dictIterator *di;
dictEntry *de;

server.cluster->size = 0;
di = dictGetSafeIterator(server.cluster->nodes);
while ((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de);

if (clusterNodeIsVotingPrimary(node)) {
server.cluster->size++;
if ((node->flags & (CLUSTER_NODE_FAIL | CLUSTER_NODE_PFAIL)) == 0) reachable_primaries++;
}
}
dictReleaseIterator(di);
}
clusterDetermineClusterSize(&reachable_primaries);

/* If we are in a minority partition, change the cluster state
* to FAIL. */
Expand Down
Loading