MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterInit

Function clusterInit

src/cluster.cpp:494–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

492}
493
494void clusterInit(void) {
495 int saveconf = 0;
496 if (g_pserver->enable_multimaster)
497 {
498 serverLog(LL_WARNING, "Clusters are not compatible with multi-master");
499 exit(EXIT_FAILURE);
500 }
501
502 g_pserver->cluster = (clusterState*)zmalloc(sizeof(clusterState), MALLOC_LOCAL);
503 g_pserver->cluster->myself = NULL;
504 g_pserver->cluster->currentEpoch = 0;
505 g_pserver->cluster->state = CLUSTER_FAIL;
506 g_pserver->cluster->size = 1;
507 g_pserver->cluster->todo_before_sleep = 0;
508 g_pserver->cluster->nodes = dictCreate(&clusterNodesDictType,NULL);
509 g_pserver->cluster->nodes_black_list =
510 dictCreate(&clusterNodesBlackListDictType,NULL);
511 g_pserver->cluster->failover_auth_time = 0;
512 g_pserver->cluster->failover_auth_count = 0;
513 g_pserver->cluster->failover_auth_rank = 0;
514 g_pserver->cluster->failover_auth_epoch = 0;
515 g_pserver->cluster->cant_failover_reason = CLUSTER_CANT_FAILOVER_NONE;
516 g_pserver->cluster->lastVoteEpoch = 0;
517 for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
518 g_pserver->cluster->stats_bus_messages_sent[i] = 0;
519 g_pserver->cluster->stats_bus_messages_received[i] = 0;
520 }
521 g_pserver->cluster->stats_pfail_nodes = 0;
522 memset(g_pserver->cluster->slots,0, sizeof(g_pserver->cluster->slots));
523 clusterCloseAllSlots();
524
525 /* Lock the cluster config file to make sure every node uses
526 * its own nodes.conf. */
527 g_pserver->cluster_config_file_lock_fd = -1;
528 if (clusterLockConfig(g_pserver->cluster_configfile) == C_ERR)
529 exit(1);
530
531 /* Load or create a new nodes configuration. */
532 if (clusterLoadConfig(g_pserver->cluster_configfile) == C_ERR) {
533 /* No configuration found. We will just use the random name provided
534 * by the createClusterNode() function. */
535 myself = g_pserver->cluster->myself =
536 createClusterNode(NULL,CLUSTER_NODE_MYSELF|CLUSTER_NODE_MASTER);
537 serverLog(LL_NOTICE,"No cluster configuration found, I'm %.40s",
538 myself->name);
539 clusterAddNode(myself);
540 saveconf = 1;
541 }
542 if (saveconf) clusterSaveConfigOrDie(1);
543
544 /* We need a listening TCP port for our cluster messaging needs. */
545 g_pserver->cfd.count = 0;
546
547 /* Port sanity check II
548 * The other handshake port check is triggered too late to stop
549 * us from trying to use a too-high cluster port number. */
550 int port = g_pserver->tls_cluster ? g_pserver->tls_port : g_pserver->port;
551 if (port > (65535-CLUSTER_PORT_INCR)) {

Callers 1

initServerFunction · 0.85

Calls 15

serverLogFunction · 0.85
zmallocFunction · 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