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

Function clusterManagerGetConfigSignature

app/redis-6.2.6/src/redis-cli.c:4354–4445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4352}
4353
4354static sds clusterManagerGetConfigSignature(clusterManagerNode *node) {
4355 sds signature = NULL;
4356 int node_count = 0, i = 0, name_len = 0;
4357 char **node_configs = NULL;
4358 redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "CLUSTER NODES");
4359 if (reply == NULL || reply->type == REDIS_REPLY_ERROR)
4360 goto cleanup;
4361 char *lines = reply->str, *p, *line;
4362 while ((p = strstr(lines, "\n")) != NULL) {
4363 i = 0;
4364 *p = '\0';
4365 line = lines;
4366 lines = p + 1;
4367 char *nodename = NULL;
4368 int tot_size = 0;
4369 while ((p = strchr(line, ' ')) != NULL) {
4370 *p = '\0';
4371 char *token = line;
4372 line = p + 1;
4373 if (i == 0) {
4374 nodename = token;
4375 tot_size = (p - token);
4376 name_len = tot_size++; // Make room for ':' in tot_size
4377 }
4378 if (++i == 8) break;
4379 }
4380 if (i != 8) continue;
4381 if (nodename == NULL) continue;
4382 int remaining = strlen(line);
4383 if (remaining == 0) continue;
4384 char **slots = NULL;
4385 int c = 0;
4386 while (remaining > 0) {
4387 p = strchr(line, ' ');
4388 if (p == NULL) p = line + remaining;
4389 int size = (p - line);
4390 remaining -= size;
4391 tot_size += size;
4392 char *slotsdef = line;
4393 *p = '\0';
4394 if (remaining) {
4395 line = p + 1;
4396 remaining--;
4397 } else line = p;
4398 if (slotsdef[0] != '[') {
4399 c++;
4400 slots = zrealloc(slots, (c * sizeof(char *)));
4401 slots[c - 1] = slotsdef;
4402 }
4403 }
4404 if (c > 0) {
4405 if (c > 1)
4406 qsort(slots, c, sizeof(char *), clusterManagerSlotCompare);
4407 node_count++;
4408 node_configs =
4409 zrealloc(node_configs, (node_count * sizeof(char *)));
4410 /* Make room for '|' separators. */
4411 tot_size += (sizeof(char) * (c - 1));

Callers 1

Calls 11

strstrFunction · 0.85
strchrFunction · 0.85
zreallocFunction · 0.85
qsortFunction · 0.85
zmallocFunction · 0.85
sdsemptyFunction · 0.85
sdscatprintfFunction · 0.85
sdscatfmtFunction · 0.85
freeReplyObjectFunction · 0.85
zfreeFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected