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

Function clusterManagerComputeReshardTable

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

Source from the content-addressed store, hash-verified

5448}
5449
5450static list *clusterManagerComputeReshardTable(list *sources, int numslots) {
5451 list *moved = listCreate();
5452 int src_count = listLength(sources), i = 0, tot_slots = 0, j;
5453 clusterManagerNode **sorted = zmalloc(src_count * sizeof(*sorted));
5454 listIter li;
5455 listNode *ln;
5456 listRewind(sources, &li);
5457 while ((ln = listNext(&li)) != NULL) {
5458 clusterManagerNode *node = ln->value;
5459 tot_slots += node->slots_count;
5460 sorted[i++] = node;
5461 }
5462 qsort(sorted, src_count, sizeof(clusterManagerNode *),
5463 clusterManagerSlotCountCompareDesc);
5464 for (i = 0; i < src_count; i++) {
5465 clusterManagerNode *node = sorted[i];
5466 float n = ((float) numslots / tot_slots * node->slots_count);
5467 if (i == 0) n = ceil(n);
5468 else n = floor(n);
5469 int max = (int) n, count = 0;
5470 for (j = 0; j < CLUSTER_MANAGER_SLOTS; j++) {
5471 int slot = node->slots[j];
5472 if (!slot) continue;
5473 if (count >= max || (int)listLength(moved) >= numslots) break;
5474 clusterManagerReshardTableItem *item = zmalloc(sizeof(*item));
5475 item->source = node;
5476 item->slot = j;
5477 listAddNodeTail(moved, item);
5478 count++;
5479 }
5480 }
5481 zfree(sorted);
5482 return moved;
5483}
5484
5485static void clusterManagerShowReshardTable(list *table) {
5486 listIter li;

Callers 2

Calls 7

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

Tested by

no test coverage detected