Return the node, among 'nodes' with the greatest number of keys * in the specified slot. */
| 4600 | /* Return the node, among 'nodes' with the greatest number of keys |
| 4601 | * in the specified slot. */ |
| 4602 | static clusterManagerNode * clusterManagerGetNodeWithMostKeysInSlot(list *nodes, |
| 4603 | int slot, |
| 4604 | char **err) |
| 4605 | { |
| 4606 | clusterManagerNode *node = NULL; |
| 4607 | int numkeys = 0; |
| 4608 | listIter li; |
| 4609 | listNode *ln; |
| 4610 | listRewind(nodes, &li); |
| 4611 | if (err) *err = NULL; |
| 4612 | while ((ln = listNext(&li)) != NULL) { |
| 4613 | clusterManagerNode *n = ln->value; |
| 4614 | if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE || n->replicate) |
| 4615 | continue; |
| 4616 | redisReply *r = |
| 4617 | CLUSTER_MANAGER_COMMAND(n, "CLUSTER COUNTKEYSINSLOT %d", slot); |
| 4618 | int success = clusterManagerCheckRedisReply(n, r, err); |
| 4619 | if (success) { |
| 4620 | if (r->integer > numkeys || node == NULL) { |
| 4621 | numkeys = r->integer; |
| 4622 | node = n; |
| 4623 | } |
| 4624 | } |
| 4625 | if (r != NULL) freeReplyObject(r); |
| 4626 | /* If the reply contains errors */ |
| 4627 | if (!success) { |
| 4628 | if (err != NULL && *err != NULL) |
| 4629 | CLUSTER_MANAGER_PRINT_REPLY_ERROR(n, err); |
| 4630 | node = NULL; |
| 4631 | break; |
| 4632 | } |
| 4633 | } |
| 4634 | return node; |
| 4635 | } |
| 4636 | |
| 4637 | /* This function returns the master that has the least number of replicas |
| 4638 | * in the cluster. If there are multiple masters with the same smaller |
no test coverage detected