Flush the dirty node configuration by calling replicate for slaves or * adding the slots defined in the masters. */
| 3594 | /* Flush the dirty node configuration by calling replicate for slaves or |
| 3595 | * adding the slots defined in the masters. */ |
| 3596 | static int clusterManagerFlushNodeConfig(clusterManagerNode *node, char **err) { |
| 3597 | if (!node->dirty) return 0; |
| 3598 | redisReply *reply = NULL; |
| 3599 | int is_err = 0, success = 1; |
| 3600 | if (err != NULL) *err = NULL; |
| 3601 | if (node->replicate != NULL) { |
| 3602 | reply = CLUSTER_MANAGER_COMMAND(node, "CLUSTER REPLICATE %s", |
| 3603 | node->replicate); |
| 3604 | if (reply == NULL || (is_err = (reply->type == REDIS_REPLY_ERROR))) { |
| 3605 | if (is_err && err != NULL) { |
| 3606 | *err = zmalloc((reply->len + 1) * sizeof(char), MALLOC_LOCAL); |
| 3607 | strcpy(*err, reply->str); |
| 3608 | } |
| 3609 | success = 0; |
| 3610 | /* If the cluster did not already joined it is possible that |
| 3611 | * the slave does not know the master node yet. So on errors |
| 3612 | * we return ASAP leaving the dirty flag set, to flush the |
| 3613 | * config later. */ |
| 3614 | goto cleanup; |
| 3615 | } |
| 3616 | } else { |
| 3617 | int added = clusterManagerAddSlots(node, err); |
| 3618 | if (!added || *err != NULL) success = 0; |
| 3619 | } |
| 3620 | node->dirty = 0; |
| 3621 | cleanup: |
| 3622 | if (reply != NULL) freeReplyObject(reply); |
| 3623 | return success; |
| 3624 | } |
| 3625 | |
| 3626 | /* Load node's cluster configuration by calling "CLUSTER NODES" command. |
| 3627 | * Node's configuration (name, replicate, slots, ...) is then updated. |
no test coverage detected