From: Yunkai Zhang <qiushu.zyk at taobao.com> Show inner information of delay recovery to user: $ collie delay_recovery info Status: Start ---------------------------- Id Recovery Nodes Type 0 127.0.0.1:7006 Join 1 127.0.0.1:7008 Join 2 127.0.0.1:7007 Join 3 127.0.0.1:7009 Join 4 127.0.0.1:7015 Left Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com> --- collie/delay_recovery.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ include/internal_proto.h | 1 + sheep/ops.c | 15 ++++++++++++ 3 files changed, 79 insertions(+) diff --git a/collie/delay_recovery.c b/collie/delay_recovery.c index 2cd4841..1a8feef 100644 --- a/collie/delay_recovery.c +++ b/collie/delay_recovery.c @@ -50,7 +50,70 @@ static int delay_recovery_stop(int argc, char **argv) return EXIT_SUCCESS; } +static int delay_recovery_info(int argc, char **argv) +{ + int fd, ret = EXIT_SYSFAIL; + struct sd_req hdr; + struct sd_rsp *rsp = (struct sd_rsp *)&hdr; + unsigned rlen, wlen; + void *buf; + int i, nr_nodes; + const char *status[] = {"Stop", "Start"}; + + wlen = 0; + rlen = SD_MAX_NODES * sizeof(struct recovery_node); + + buf = malloc(rlen); + if (!buf) + return EXIT_SYSFAIL; + + fd = connect_to(sdhost, sdport); + if (fd < 0) + goto out; + + sd_init_req(&hdr, SD_OP_INFO_DELAY_RECOVERY); + hdr.data_length = rlen; + + ret = exec_req(fd, &hdr, buf, &wlen, &rlen); + close(fd); + + if (ret) { + fprintf(stderr, "Failed to connect\n"); + goto out; + } + + if (rsp->result != SD_RES_SUCCESS) { + fprintf(stderr, "failed to get delay_recovery info: %s\n", + sd_strerror(rsp->result)); + ret = EXIT_FAILURE; + goto out; + } + nr_nodes = rsp->data_length/sizeof(struct recovery_node); + + printf("Status: %s\n", status[rsp->__pad[0]]); + printf("----------------------------\n"); + printf("Id Recovery Nodes Type\n"); + + for (i = 0; i < nr_nodes; i++) { + char ipaddr[128]; + const char *type[] = {"Join", "Left"}; + struct recovery_node *rnodes; + + rnodes = (struct recovery_node *)buf; + addr_to_str(ipaddr, sizeof(ipaddr), rnodes[i].node.nid.addr, + rnodes[i].node.nid.port); + printf("%2d %s %s\n", i, ipaddr, type[rnodes[i].type]); + } + + +out: + free(buf); + return EXIT_SUCCESS; +} + static struct subcommand delay_recovery_cmd[] = { + {"info", NULL, "aph", "show delay recovery information", + 0, delay_recovery_info}, {"start", NULL, "aph", "start delay recovery", 0, delay_recovery_start}, {"stop", NULL, "aph", "stop delay recovery", diff --git a/include/internal_proto.h b/include/internal_proto.h index e38d843..1d160bb 100644 --- a/include/internal_proto.h +++ b/include/internal_proto.h @@ -62,6 +62,7 @@ #define SD_OP_REMOVE_PEER 0xA6 #define SD_OP_STOP_DELAY_RECOVERY 0xA7 #define SD_OP_START_DELAY_RECOVERY 0xA8 +#define SD_OP_INFO_DELAY_RECOVERY 0xA9 /* internal flags for hdr.flags, must be above 0x80 */ #define SD_FLAG_CMD_RECOVERY 0x0080 diff --git a/sheep/ops.c b/sheep/ops.c index 45279ff..5fadbc1 100644 --- a/sheep/ops.c +++ b/sheep/ops.c @@ -431,6 +431,16 @@ static int local_get_epoch(struct request *req) return SD_RES_SUCCESS; } +static int local_info_delay_recovery(const struct sd_req *req, + struct sd_rsp *rsp, void *data) +{ + rsp->__pad[0] = sys->delay_recovery; + rsp->data_length = nr_dr_nodes * sizeof(struct recovery_node); + memcpy(data, dr_nodes, rsp->data_length); + + return SD_RES_SUCCESS; +} + static int cluster_manual_recover(const struct sd_req *req, struct sd_rsp *rsp, void *data) { @@ -1042,6 +1052,11 @@ static struct sd_op_template sd_ops[] = { .type = SD_OP_TYPE_CLUSTER, .process_main = cluster_stop_delay_recovery, }, + [SD_OP_INFO_DELAY_RECOVERY] = { + .name = "INFO_DELAY_RECOVERY", + .type = SD_OP_TYPE_LOCAL, + .process_main = local_info_delay_recovery, + }, }; struct sd_op_template *get_sd_op(uint8_t opcode) -- 1.7.11.2 |