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

Function clusterReset

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

Reset a node performing a soft or hard reset: * * 1) All other nodes are forgotten. * 2) All the assigned / open slots are released. * 3) If the node is a slave, it turns into a master. * 4) Only for hard reset: a new Node ID is generated. * 5) Only for hard reset: currentEpoch and configEpoch are set to 0. * 6) The new configuration is saved and the cluster state updated. * 7) If the node

Source from the content-addressed store, hash-verified

566 * 6) The new configuration is saved and the cluster state updated.
567 * 7) If the node was a slave, the whole data set is flushed away. */
568void clusterReset(int hard) {
569 dictIterator *di;
570 dictEntry *de;
571 int j;
572
573 /* Turn into master. */
574 if (nodeIsSlave(myself)) {
575 clusterSetNodeAsMaster(myself);
576 replicationUnsetMaster();
577 emptyDb(-1,EMPTYDB_NO_FLAGS,NULL);
578 }
579
580 /* Close slots, reset manual failover state. */
581 clusterCloseAllSlots();
582 resetManualFailover();
583
584 /* Unassign all the slots. */
585 for (j = 0; j < CLUSTER_SLOTS; j++) clusterDelSlot(j);
586
587 /* Forget all the nodes, but myself. */
588 di = dictGetSafeIterator(server.cluster->nodes);
589 while((de = dictNext(di)) != NULL) {
590 clusterNode *node = dictGetVal(de);
591
592 if (node == myself) continue;
593 clusterDelNode(node);
594 }
595 dictReleaseIterator(di);
596
597 /* Hard reset only: set epochs to 0, change node ID. */
598 if (hard) {
599 sds oldname;
600
601 server.cluster->currentEpoch = 0;
602 server.cluster->lastVoteEpoch = 0;
603 myself->configEpoch = 0;
604 serverLog(LL_WARNING, "configEpoch set to 0 via CLUSTER RESET HARD");
605
606 /* To change the Node ID we need to remove the old name from the
607 * nodes table, change the ID, and re-add back with new name. */
608 oldname = sdsnewlen(myself->name, CLUSTER_NAMELEN);
609 dictDelete(server.cluster->nodes,oldname);
610 sdsfree(oldname);
611 getRandomHexChars(myself->name, CLUSTER_NAMELEN);
612 clusterAddNode(myself);
613 serverLog(LL_NOTICE,"Node hard reset, now I'm %.40s", myself->name);
614 }
615
616 /* Make sure to persist the new config and update the state. */
617 clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG|
618 CLUSTER_TODO_UPDATE_STATE|
619 CLUSTER_TODO_FSYNC_CONFIG);
620}
621
622/* -----------------------------------------------------------------------------
623 * CLUSTER communication link

Callers 1

clusterCommandFunction · 0.85

Calls 15

clusterSetNodeAsMasterFunction · 0.85
replicationUnsetMasterFunction · 0.85
emptyDbFunction · 0.85
clusterCloseAllSlotsFunction · 0.85
resetManualFailoverFunction · 0.85
clusterDelSlotFunction · 0.85
dictGetSafeIteratorFunction · 0.85
clusterDelNodeFunction · 0.85
sdsnewlenFunction · 0.85
sdsfreeFunction · 0.85
getRandomHexCharsFunction · 0.85
clusterAddNodeFunction · 0.85

Tested by

no test coverage detected