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

Function clusterInit

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

Source from the content-addressed store, hash-verified

477}
478
479void clusterInit(void) {
480 int saveconf = 0;
481
482 server.cluster = zmalloc(sizeof(clusterState));
483 server.cluster->myself = NULL;
484 server.cluster->currentEpoch = 0;
485 server.cluster->state = CLUSTER_FAIL;
486 server.cluster->size = 1;
487 server.cluster->todo_before_sleep = 0;
488 server.cluster->nodes = dictCreate(&clusterNodesDictType,NULL);
489 server.cluster->nodes_black_list =
490 dictCreate(&clusterNodesBlackListDictType,NULL);
491 server.cluster->failover_auth_time = 0;
492 server.cluster->failover_auth_count = 0;
493 server.cluster->failover_auth_rank = 0;
494 server.cluster->failover_auth_epoch = 0;
495 server.cluster->cant_failover_reason = CLUSTER_CANT_FAILOVER_NONE;
496 server.cluster->lastVoteEpoch = 0;
497 for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
498 server.cluster->stats_bus_messages_sent[i] = 0;
499 server.cluster->stats_bus_messages_received[i] = 0;
500 }
501 server.cluster->stats_pfail_nodes = 0;
502 memset(server.cluster->slots,0, sizeof(server.cluster->slots));
503 clusterCloseAllSlots();
504
505 /* Lock the cluster config file to make sure every node uses
506 * its own nodes.conf. */
507 server.cluster_config_file_lock_fd = -1;
508 if (clusterLockConfig(server.cluster_configfile) == C_ERR)
509 exit(1);
510
511 /* Load or create a new nodes configuration. */
512 if (clusterLoadConfig(server.cluster_configfile) == C_ERR) {
513 /* No configuration found. We will just use the random name provided
514 * by the createClusterNode() function. */
515 myself = server.cluster->myself =
516 createClusterNode(NULL,CLUSTER_NODE_MYSELF|CLUSTER_NODE_MASTER);
517 serverLog(LL_NOTICE,"No cluster configuration found, I'm %.40s",
518 myself->name);
519 clusterAddNode(myself);
520 saveconf = 1;
521 }
522 if (saveconf) clusterSaveConfigOrDie(1);
523
524 /* We need a listening TCP port for our cluster messaging needs. */
525 server.cfd.count = 0;
526
527 /* Port sanity check II
528 * The other handshake port check is triggered too late to stop
529 * us from trying to use a too-high cluster port number. */
530 int port = server.tls_cluster ? server.tls_port : server.port;
531 if (port > (65535-CLUSTER_PORT_INCR)) {
532 serverLog(LL_WARNING, "Redis port number too high. "
533 "Cluster communication port is 10,000 port "
534 "numbers higher than your Redis port. "
535 "Your Redis port number must be 55535 or less.");
536 exit(1);

Callers 1

initServerFunction · 0.85

Calls 15

zmallocFunction · 0.85
memsetFunction · 0.85
clusterCloseAllSlotsFunction · 0.85
clusterLockConfigFunction · 0.85
clusterLoadConfigFunction · 0.85
clusterAddNodeFunction · 0.85
clusterSaveConfigOrDieFunction · 0.85
listenToPortFunction · 0.85
raxNewFunction · 0.85
deriveAnnouncedPortsFunction · 0.85
resetManualFailoverFunction · 0.85

Tested by

no test coverage detected