This is executed 10 times every second */
| 3497 | |
| 3498 | /* This is executed 10 times every second */ |
| 3499 | void clusterCron(void) { |
| 3500 | dictIterator *di; |
| 3501 | dictEntry *de; |
| 3502 | int update_state = 0; |
| 3503 | int orphaned_masters; /* How many masters there are without ok slaves. */ |
| 3504 | int max_slaves; /* Max number of ok slaves for a single master. */ |
| 3505 | int this_slaves; /* Number of ok slaves for our master (if we are slave). */ |
| 3506 | mstime_t min_pong = 0, now = mstime(); |
| 3507 | clusterNode *min_pong_node = NULL; |
| 3508 | static unsigned long long iteration = 0; |
| 3509 | mstime_t handshake_timeout; |
| 3510 | |
| 3511 | iteration++; /* Number of times this function was called so far. */ |
| 3512 | |
| 3513 | /* We want to take myself->ip in sync with the cluster-announce-ip option. |
| 3514 | * The option can be set at runtime via CONFIG SET, so we periodically check |
| 3515 | * if the option changed to reflect this into myself->ip. */ |
| 3516 | { |
| 3517 | static char *prev_ip = NULL; |
| 3518 | char *curr_ip = server.cluster_announce_ip; |
| 3519 | int changed = 0; |
| 3520 | |
| 3521 | if (prev_ip == NULL && curr_ip != NULL) changed = 1; |
| 3522 | else if (prev_ip != NULL && curr_ip == NULL) changed = 1; |
| 3523 | else if (prev_ip && curr_ip && strcmp(prev_ip,curr_ip)) changed = 1; |
| 3524 | |
| 3525 | if (changed) { |
| 3526 | if (prev_ip) zfree(prev_ip); |
| 3527 | prev_ip = curr_ip; |
| 3528 | |
| 3529 | if (curr_ip) { |
| 3530 | /* We always take a copy of the previous IP address, by |
| 3531 | * duplicating the string. This way later we can check if |
| 3532 | * the address really changed. */ |
| 3533 | prev_ip = zstrdup(prev_ip); |
| 3534 | strncpy(myself->ip,server.cluster_announce_ip,NET_IP_STR_LEN); |
| 3535 | myself->ip[NET_IP_STR_LEN-1] = '\0'; |
| 3536 | } else { |
| 3537 | myself->ip[0] = '\0'; /* Force autodetection. */ |
| 3538 | } |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | /* The handshake timeout is the time after which a handshake node that was |
| 3543 | * not turned into a normal node is removed from the nodes. Usually it is |
| 3544 | * just the NODE_TIMEOUT value, but when NODE_TIMEOUT is too small we use |
| 3545 | * the value of 1 second. */ |
| 3546 | handshake_timeout = server.cluster_node_timeout; |
| 3547 | if (handshake_timeout < 1000) handshake_timeout = 1000; |
| 3548 | |
| 3549 | /* Update myself flags. */ |
| 3550 | clusterUpdateMyselfFlags(); |
| 3551 | |
| 3552 | /* Check if we have disconnected nodes and re-establish the connection. |
| 3553 | * Also update a few stats while we are here, that can be used to make |
| 3554 | * better decisions in other part of the code. */ |
| 3555 | di = dictGetSafeIterator(server.cluster->nodes); |
| 3556 | server.cluster->stats_pfail_nodes = 0; |
no test coverage detected