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

Function clusterManagerComputeReshardTable

src/redis-cli.c:4537–4570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4535}
4536
4537static list *clusterManagerComputeReshardTable(list *sources, int numslots) {
4538 list *moved = listCreate();
4539 int src_count = listLength(sources), i = 0, tot_slots = 0, j;
4540 clusterManagerNode **sorted = zmalloc(src_count * sizeof(*sorted), MALLOC_LOCAL);
4541 listIter li;
4542 listNode *ln;
4543 listRewind(sources, &li);
4544 while ((ln = listNext(&li)) != NULL) {
4545 clusterManagerNode *node = ln->value;
4546 tot_slots += node->slots_count;
4547 sorted[i++] = node;
4548 }
4549 qsort(sorted, src_count, sizeof(clusterManagerNode *),
4550 clusterManagerSlotCountCompareDesc);
4551 for (i = 0; i < src_count; i++) {
4552 clusterManagerNode *node = sorted[i];
4553 float n = ((float) numslots / tot_slots * node->slots_count);
4554 if (i == 0) n = ceil(n);
4555 else n = floor(n);
4556 int max = (int) n, count = 0;
4557 for (j = 0; j < CLUSTER_MANAGER_SLOTS; j++) {
4558 int slot = node->slots[j];
4559 if (!slot) continue;
4560 if (count >= max || (int)listLength(moved) >= numslots) break;
4561 clusterManagerReshardTableItem *item = zmalloc(sizeof(*item), MALLOC_LOCAL);
4562 item->source = node;
4563 item->slot = j;
4564 listAddNodeTail(moved, item);
4565 count++;
4566 }
4567 }
4568 zfree(sorted);
4569 return moved;
4570}
4571
4572static void clusterManagerShowReshardTable(list *table) {
4573 listIter li;

Callers 2

Calls 6

listCreateFunction · 0.85
zmallocFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
listAddNodeTailFunction · 0.85
zfreeFunction · 0.85

Tested by

no test coverage detected