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

Function clusterManagerGetSlotOwner

src/redis-cli.c:3056–3099  ·  view source on GitHub ↗

Get the node the slot is assigned to from the point of view of node *n. * If the slot is unassigned or if the reply is an error, return NULL. * Use the **err argument in order to check wether the slot is unassigned * or the reply resulted in an error. */

Source from the content-addressed store, hash-verified

3054 * Use the **err argument in order to check wether the slot is unassigned
3055 * or the reply resulted in an error. */
3056static clusterManagerNode *clusterManagerGetSlotOwner(clusterManagerNode *n,
3057 int slot, char **err)
3058{
3059 assert(slot >= 0 && slot < CLUSTER_MANAGER_SLOTS);
3060 clusterManagerNode *owner = NULL;
3061 redisReply *reply = CLUSTER_MANAGER_COMMAND(n, "CLUSTER SLOTS");
3062 if (clusterManagerCheckRedisReply(n, reply, err)) {
3063 assert(reply->type == REDIS_REPLY_ARRAY);
3064 size_t i;
3065 for (i = 0; i < reply->elements; i++) {
3066 redisReply *r = reply->element[i];
3067 assert(r->type == REDIS_REPLY_ARRAY && r->elements >= 3);
3068 int from, to;
3069 from = r->element[0]->integer;
3070 to = r->element[1]->integer;
3071 if (slot < from || slot > to) continue;
3072 redisReply *nr = r->element[2];
3073 assert(nr->type == REDIS_REPLY_ARRAY && nr->elements >= 2);
3074 char *name = NULL;
3075 if (nr->elements >= 3)
3076 name = nr->element[2]->str;
3077 if (name != NULL)
3078 owner = clusterManagerNodeByName(name);
3079 else {
3080 char *ip = nr->element[0]->str;
3081 assert(ip != NULL);
3082 int port = (int) nr->element[1]->integer;
3083 listIter li;
3084 listNode *ln;
3085 listRewind(cluster_manager.nodes, &li);
3086 while ((ln = listNext(&li)) != NULL) {
3087 clusterManagerNode *nd = ln->value;
3088 if (strcmp(nd->ip, ip) == 0 && port == nd->port) {
3089 owner = nd;
3090 break;
3091 }
3092 }
3093 }
3094 if (owner) break;
3095 }
3096 }
3097 if (reply) freeReplyObject(reply);
3098 return owner;
3099}
3100
3101/* Set slot status to "importing" or "migrating" */
3102int clusterManagerSetSlot(clusterManagerNode *node1,

Callers 2

clusterManagerDelSlotFunction · 0.85

Calls 5

clusterManagerNodeByNameFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected