| 6455 | } |
| 6456 | |
| 6457 | static int clusterManagerCommandSetTimeout(int argc, char **argv) { |
| 6458 | UNUSED(argc); |
| 6459 | int port = 0; |
| 6460 | char *ip = NULL; |
| 6461 | if (!getClusterHostFromCmdArgs(1, argv, &ip, &port)) goto invalid_args; |
| 6462 | int timeout = atoi(argv[1]); |
| 6463 | if (timeout < 100) { |
| 6464 | fprintf(stderr, "Setting a node timeout of less than 100 " |
| 6465 | "milliseconds is a bad idea.\n"); |
| 6466 | return 0; |
| 6467 | } |
| 6468 | // Load cluster information |
| 6469 | clusterManagerNode *node = clusterManagerNewNode(ip, port); |
| 6470 | if (!clusterManagerLoadInfoFromNode(node, 0)) return 0; |
| 6471 | int ok_count = 0, err_count = 0; |
| 6472 | |
| 6473 | clusterManagerLogInfo(">>> Reconfiguring node timeout in every " |
| 6474 | "cluster node...\n"); |
| 6475 | listIter li; |
| 6476 | listNode *ln; |
| 6477 | listRewind(cluster_manager.nodes, &li); |
| 6478 | while ((ln = listNext(&li)) != NULL) { |
| 6479 | clusterManagerNode *n = ln->value; |
| 6480 | char *err = NULL; |
| 6481 | redisReply *reply = CLUSTER_MANAGER_COMMAND(n, "CONFIG %s %s %d", |
| 6482 | "SET", |
| 6483 | "cluster-node-timeout", |
| 6484 | timeout); |
| 6485 | if (reply == NULL) goto reply_err; |
| 6486 | int ok = clusterManagerCheckRedisReply(n, reply, &err); |
| 6487 | freeReplyObject(reply); |
| 6488 | if (!ok) goto reply_err; |
| 6489 | reply = CLUSTER_MANAGER_COMMAND(n, "CONFIG %s", "REWRITE"); |
| 6490 | if (reply == NULL) goto reply_err; |
| 6491 | ok = clusterManagerCheckRedisReply(n, reply, &err); |
| 6492 | freeReplyObject(reply); |
| 6493 | if (!ok) goto reply_err; |
| 6494 | clusterManagerLogWarn("*** New timeout set for %s:%d\n", n->ip, |
| 6495 | n->port); |
| 6496 | ok_count++; |
| 6497 | continue; |
| 6498 | reply_err:; |
| 6499 | int need_free = 0; |
| 6500 | if (err == NULL) err = ""; |
| 6501 | else need_free = 1; |
| 6502 | clusterManagerLogErr("ERR setting node-timeot for %s:%d: %s\n", n->ip, |
| 6503 | n->port, err); |
| 6504 | if (need_free) zfree(err); |
| 6505 | err_count++; |
| 6506 | } |
| 6507 | clusterManagerLogInfo(">>> New node timeout set. %d OK, %d ERR.\n", |
| 6508 | ok_count, err_count); |
| 6509 | return 1; |
| 6510 | invalid_args: |
| 6511 | fprintf(stderr, CLUSTER_MANAGER_INVALID_HOST_ARG); |
| 6512 | return 0; |
| 6513 | } |
| 6514 |
nothing calls this directly
no test coverage detected