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

Function clusterManagerGetConfigSignature

src/redis-cli.c:3909–4000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3907}
3908
3909static sds clusterManagerGetConfigSignature(clusterManagerNode *node) {
3910 sds signature = NULL;
3911 int node_count = 0, i = 0, name_len = 0;
3912 char **node_configs = NULL;
3913 redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "CLUSTER NODES");
3914 if (reply == NULL || reply->type == REDIS_REPLY_ERROR)
3915 goto cleanup;
3916 char *lines = reply->str, *p, *line;
3917 while ((p = strstr(lines, "\n")) != NULL) {
3918 i = 0;
3919 *p = '\0';
3920 line = lines;
3921 lines = p + 1;
3922 char *nodename = NULL;
3923 int tot_size = 0;
3924 while ((p = strchr(line, ' ')) != NULL) {
3925 *p = '\0';
3926 char *token = line;
3927 line = p + 1;
3928 if (i == 0) {
3929 nodename = token;
3930 tot_size = (p - token);
3931 name_len = tot_size++; // Make room for ':' in tot_size
3932 }
3933 if (++i == 8) break;
3934 }
3935 if (i != 8) continue;
3936 if (nodename == NULL) continue;
3937 int remaining = strlen(line);
3938 if (remaining == 0) continue;
3939 char **slots = NULL;
3940 int c = 0;
3941 while (remaining > 0) {
3942 p = strchr(line, ' ');
3943 if (p == NULL) p = line + remaining;
3944 int size = (p - line);
3945 remaining -= size;
3946 tot_size += size;
3947 char *slotsdef = line;
3948 *p = '\0';
3949 if (remaining) {
3950 line = p + 1;
3951 remaining--;
3952 } else line = p;
3953 if (slotsdef[0] != '[') {
3954 c++;
3955 slots = zrealloc(slots, (c * sizeof(char *)), MALLOC_LOCAL);
3956 slots[c - 1] = slotsdef;
3957 }
3958 }
3959 if (c > 0) {
3960 if (c > 1)
3961 qsort(slots, c, sizeof(char *), clusterManagerSlotCompare);
3962 node_count++;
3963 node_configs =
3964 zrealloc(node_configs, (node_count * sizeof(char *)), MALLOC_LOCAL);
3965 /* Make room for '|' separators. */
3966 tot_size += (sizeof(char) * (c - 1));

Callers 1

Calls 7

zreallocFunction · 0.85
zmallocFunction · 0.85
zfreeFunction · 0.85
sdsemptyFunction · 0.85
sdscatprintfFunction · 0.85
sdscatfmtFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected