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

Function createClusterNode

src/cluster.cpp:820–851  ·  view source on GitHub ↗

Create a new cluster node, with the specified flags. * If "nodename" is NULL this is considered a first handshake and a random * node name is assigned to this node (it will be fixed later when we'll * receive the first pong). * * The node is created and returned to the user, but it is not automatically * added to the nodes hash table. */

Source from the content-addressed store, hash-verified

818 * The node is created and returned to the user, but it is not automatically
819 * added to the nodes hash table. */
820clusterNode *createClusterNode(char *nodename, int flags) {
821 clusterNode *node = (clusterNode*)zmalloc(sizeof(*node), MALLOC_LOCAL);
822
823 if (nodename)
824 memcpy(node->name, nodename, CLUSTER_NAMELEN);
825 else
826 getRandomHexChars(node->name, CLUSTER_NAMELEN);
827 node->ctime = mstime();
828 node->configEpoch = 0;
829 node->flags = flags;
830 memset(node->slots,0,sizeof(node->slots));
831 node->slots_info = NULL;
832 node->numslots = 0;
833 node->numslaves = 0;
834 node->slaves = NULL;
835 node->slaveof = NULL;
836 node->ping_sent = node->pong_received = 0;
837 node->data_received = 0;
838 node->fail_time = 0;
839 node->link = NULL;
840 memset(node->ip,0,sizeof(node->ip));
841 node->port = 0;
842 node->cport = 0;
843 node->pport = 0;
844 node->fail_reports = listCreate();
845 node->voted_time = 0;
846 node->orphaned_time = 0;
847 node->repl_offset_time = 0;
848 node->repl_offset = 0;
849 listSetFreeMethod(node->fail_reports,zfree);
850 return node;
851}
852
853/* This function is called every time we get a failure report from a node.
854 * The side effect is to populate the fail_reports list (or to update

Callers 5

clusterLoadConfigFunction · 0.70
clusterInitFunction · 0.70
clusterStartHandshakeFunction · 0.70
clusterProcessPacketFunction · 0.70

Calls 4

zmallocFunction · 0.85
getRandomHexCharsFunction · 0.85
listCreateFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected