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. */
| 3443 | * Use the **err argument in order to check wether the slot is unassigned |
| 3444 | * or the reply resulted in an error. */ |
| 3445 | static clusterManagerNode *clusterManagerGetSlotOwner(clusterManagerNode *n, |
| 3446 | int slot, char **err) |
| 3447 | { |
| 3448 | assert(slot >= 0 && slot < CLUSTER_MANAGER_SLOTS); |
| 3449 | clusterManagerNode *owner = NULL; |
| 3450 | redisReply *reply = CLUSTER_MANAGER_COMMAND(n, "CLUSTER SLOTS"); |
| 3451 | if (clusterManagerCheckRedisReply(n, reply, err)) { |
| 3452 | assert(reply->type == REDIS_REPLY_ARRAY); |
| 3453 | size_t i; |
| 3454 | for (i = 0; i < reply->elements; i++) { |
| 3455 | redisReply *r = reply->element[i]; |
| 3456 | assert(r->type == REDIS_REPLY_ARRAY && r->elements >= 3); |
| 3457 | int from, to; |
| 3458 | from = r->element[0]->integer; |
| 3459 | to = r->element[1]->integer; |
| 3460 | if (slot < from || slot > to) continue; |
| 3461 | redisReply *nr = r->element[2]; |
| 3462 | assert(nr->type == REDIS_REPLY_ARRAY && nr->elements >= 2); |
| 3463 | char *name = NULL; |
| 3464 | if (nr->elements >= 3) |
| 3465 | name = nr->element[2]->str; |
| 3466 | if (name != NULL) |
| 3467 | owner = clusterManagerNodeByName(name); |
| 3468 | else { |
| 3469 | char *ip = nr->element[0]->str; |
| 3470 | assert(ip != NULL); |
| 3471 | int port = (int) nr->element[1]->integer; |
| 3472 | listIter li; |
| 3473 | listNode *ln; |
| 3474 | listRewind(cluster_manager.nodes, &li); |
| 3475 | while ((ln = listNext(&li)) != NULL) { |
| 3476 | clusterManagerNode *nd = ln->value; |
| 3477 | if (strcmp(nd->ip, ip) == 0 && port == nd->port) { |
| 3478 | owner = nd; |
| 3479 | break; |
| 3480 | } |
| 3481 | } |
| 3482 | } |
| 3483 | if (owner) break; |
| 3484 | } |
| 3485 | } |
| 3486 | if (reply) freeReplyObject(reply); |
| 3487 | return owner; |
| 3488 | } |
| 3489 | |
| 3490 | /* Set slot status to "importing" or "migrating" */ |
| 3491 | static int clusterManagerSetSlot(clusterManagerNode *node1, |
no test coverage detected