Return the node, among 'nodes' with the greatest number of keys * in the specified slot. */
| 4078 | /* Return the node, among 'nodes' with the greatest number of keys |
| 4079 | * in the specified slot. */ |
| 4080 | clusterManagerNode * clusterManagerGetNodeWithMostKeysInSlot(list *nodes, |
| 4081 | int slot, |
| 4082 | char **err) |
| 4083 | { |
| 4084 | clusterManagerNode *node = NULL; |
| 4085 | int numkeys = 0; |
| 4086 | listIter li; |
| 4087 | listNode *ln; |
| 4088 | listRewind(nodes, &li); |
| 4089 | if (err) *err = NULL; |
| 4090 | while ((ln = listNext(&li)) != NULL) { |
| 4091 | clusterManagerNode *n = ln->value; |
| 4092 | if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE || n->replicate) |
| 4093 | continue; |
| 4094 | redisReply *r = |
| 4095 | CLUSTER_MANAGER_COMMAND(n, "CLUSTER COUNTKEYSINSLOT %d", slot); |
| 4096 | int success = clusterManagerCheckRedisReply(n, r, err); |
| 4097 | if (success) { |
| 4098 | if (r->integer > numkeys || node == NULL) { |
| 4099 | numkeys = r->integer; |
| 4100 | node = n; |
| 4101 | } |
| 4102 | } |
| 4103 | if (r != NULL) freeReplyObject(r); |
| 4104 | /* If the reply contains errors */ |
| 4105 | if (!success) { |
| 4106 | if (err != NULL && *err != NULL) |
| 4107 | CLUSTER_MANAGER_PRINT_REPLY_ERROR(n, err); |
| 4108 | node = NULL; |
| 4109 | break; |
| 4110 | } |
| 4111 | } |
| 4112 | return node; |
| 4113 | } |
| 4114 | |
| 4115 | /* This function returns the master that has the least number of replicas |
| 4116 | * in the cluster. If there are multiple masters with the same smaller |
no test coverage detected