MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterUpdateState

Function clusterUpdateState

app/redis-6.2.6/src/cluster.c:3940–4034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3938#define CLUSTER_WRITABLE_DELAY 2000
3939
3940void clusterUpdateState(void) {
3941 int j, new_state;
3942 int reachable_masters = 0;
3943 static mstime_t among_minority_time;
3944 static mstime_t first_call_time = 0;
3945
3946 server.cluster->todo_before_sleep &= ~CLUSTER_TODO_UPDATE_STATE;
3947
3948 /* If this is a master node, wait some time before turning the state
3949 * into OK, since it is not a good idea to rejoin the cluster as a writable
3950 * master, after a reboot, without giving the cluster a chance to
3951 * reconfigure this node. Note that the delay is calculated starting from
3952 * the first call to this function and not since the server start, in order
3953 * to don't count the DB loading time. */
3954 if (first_call_time == 0) first_call_time = mstime();
3955 if (nodeIsMaster(myself) &&
3956 server.cluster->state == CLUSTER_FAIL &&
3957 mstime() - first_call_time < CLUSTER_WRITABLE_DELAY) return;
3958
3959 /* Start assuming the state is OK. We'll turn it into FAIL if there
3960 * are the right conditions. */
3961 new_state = CLUSTER_OK;
3962
3963 /* Check if all the slots are covered. */
3964 if (server.cluster_require_full_coverage) {
3965 for (j = 0; j < CLUSTER_SLOTS; j++) {
3966 if (server.cluster->slots[j] == NULL ||
3967 server.cluster->slots[j]->flags & (CLUSTER_NODE_FAIL))
3968 {
3969 new_state = CLUSTER_FAIL;
3970 break;
3971 }
3972 }
3973 }
3974
3975 /* Compute the cluster size, that is the number of master nodes
3976 * serving at least a single slot.
3977 *
3978 * At the same time count the number of reachable masters having
3979 * at least one slot. */
3980 {
3981 dictIterator *di;
3982 dictEntry *de;
3983
3984 server.cluster->size = 0;
3985 di = dictGetSafeIterator(server.cluster->nodes);
3986 while((de = dictNext(di)) != NULL) {
3987 clusterNode *node = dictGetVal(de);
3988
3989 if (nodeIsMaster(node) && node->numslots) {
3990 server.cluster->size++;
3991 if ((node->flags & (CLUSTER_NODE_FAIL|CLUSTER_NODE_PFAIL)) == 0)
3992 reachable_masters++;
3993 }
3994 }
3995 dictReleaseIterator(di);
3996 }
3997

Callers 3

clusterCronFunction · 0.85
clusterBeforeSleepFunction · 0.85

Calls 4

dictGetSafeIteratorFunction · 0.85
mstimeFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70

Tested by

no test coverage detected