From: Tatsuo Ishii Date: Tue, 3 Jul 2018 00:44:56 +0000 (+0900) Subject: Sync pcp_node_info with pgpool show command. X-Git-Tag: V4_0_0_ALPHA1~51 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=a8a666a27b07b608ea1118c99dfece9fab4dd3be;p=pgpool2.git Sync pcp_node_info with pgpool show command. Add "Replication Delay" and "Last Status Change" to pcp_node_info. --- diff --git a/doc.ja/src/sgml/ref/pcp_node_info.sgml b/doc.ja/src/sgml/ref/pcp_node_info.sgml index b860c561e..03a3ddd9b 100644 --- a/doc.ja/src/sgml/ref/pcp_node_info.sgml +++ b/doc.ja/src/sgml/ref/pcp_node_info.sgml @@ -95,8 +95,8 @@ Pgpool-II documentation --> ここでは例を示します。 -$ pcp_node_info -h localhost -U postgres 0 -host1 5432 1 0.500000 waiting primary +$ pcp_node_info -h localhost -U postgres 1 +/tmp 11003 2 0.500000 up standby 208 2018-07-03 08:26:39 @@ -112,6 +112,8 @@ host1 5432 1 0.500000 waiting primary 4. load balance weight 5. status name 6. backend role +7. replication delay +8. last status change time --> 1. ノードのホスト名 2. ノードのポート番号 @@ -119,6 +121,8 @@ host1 5432 1 0.500000 waiting primary 4. ロードバランスウェイト 5. バックエンド状態名 6. バックエンドの役割 +7. レプリケーションの遅延 +8. 最終ステータス変更時刻 @@ -152,13 +156,15 @@ host1 5432 1 0.500000 waiting primary オプションは出力内容を理解するのに役に立ちます。例: -$ pcp_node_info --verbose -h localhost -U postgres 0 -Hostname : host1 -Port : 5432 -Status : 1 -Weight : 0.500000 -Status Name: waiting -Role : primary +$ pcp_node_info --verbose -h localhost -U postgres 1 +Hostname : /tmp +Port : 11003 +Status : 2 +Weight : 0.500000 +Status Name : up +Role : standby +Replication Delay : 208 +Last Status Change: 2018-07-03 08:26:39 diff --git a/doc/src/sgml/ref/pcp_node_info.sgml b/doc/src/sgml/ref/pcp_node_info.sgml index d60485ce8..06cae4a3e 100644 --- a/doc/src/sgml/ref/pcp_node_info.sgml +++ b/doc/src/sgml/ref/pcp_node_info.sgml @@ -68,8 +68,8 @@ Pgpool-II documentation Here is an example output: -$ pcp_node_info -h localhost -U postgres 0 -host1 5432 1 0.500000 waiting primary +$ pcp_node_info -h localhost -U postgres 1 +/tmp 11003 2 0.500000 up standby 208 2018-07-03 08:26:39 @@ -81,6 +81,8 @@ host1 5432 1 0.500000 waiting primary 4. load balance weight 5. status name 6. backend role +7. replication delay +8. last status change time @@ -99,13 +101,15 @@ host1 5432 1 0.500000 waiting primary The option can help understand the output. For example: -$ pcp_node_info --verbose -h localhost -U postgres 0 -Hostname : host1 -Port : 5432 -Status : 1 -Weight : 0.500000 -Status Name: waiting -Role : primary +$ pcp_node_info --verbose -h localhost -U postgres 1 +Hostname : /tmp +Port : 11003 +Status : 2 +Weight : 0.500000 +Status Name : up +Role : standby +Replication Delay : 208 +Last Status Change: 2018-07-03 08:26:39 diff --git a/src/libs/pcp/pcp.c b/src/libs/pcp/pcp.c index eb78bbb0a..7db312fef 100644 --- a/src/libs/pcp/pcp.c +++ b/src/libs/pcp/pcp.c @@ -707,6 +707,24 @@ process_node_info_response(PCPConnInfo* pcpConn, char* buf, int len) index++; backend_info->role = atoi(index); + index = (char *) memchr(index, '\0', len); + if(index == NULL) + goto INVALID_RESPONSE; + + index++; + backend_info->standby_delay = atol(index); + + index = (char *) memchr(index, '\0', len); + if(index == NULL) + goto INVALID_RESPONSE; + + index++; + backend_info->status_changed_time = atol(index); + + index = (char *) memchr(index, '\0', len); + if(index == NULL) + goto INVALID_RESPONSE; + if (setNextResultBinaryData(pcpConn->pcpResInfo, (void *)backend_info, sizeof(BackendInfo) , NULL) < 0) goto INVALID_RESPONSE; diff --git a/src/pcp_con/pcp_worker.c b/src/pcp_con/pcp_worker.c index aa1a503c0..10ac9cb3b 100644 --- a/src/pcp_con/pcp_worker.c +++ b/src/pcp_con/pcp_worker.c @@ -811,6 +811,8 @@ inform_node_info(PCP_CONNECTION *frontend,char *buf) char status[2]; char weight_str[20]; char role_str[10]; + char standby_delay_str[20]; + char status_changed_time_str[20]; char code[] = "CommandComplete"; BackendInfo *bi = NULL; SERVER_ROLE role; @@ -847,6 +849,10 @@ inform_node_info(PCP_CONNECTION *frontend,char *buf) role = ROLE_SLAVE; } snprintf(role_str, sizeof(role_str), "%d", role); + + snprintf(standby_delay_str, sizeof(standby_delay_str), UINT64_FORMAT, bi->standby_delay); + + snprintf(status_changed_time_str, sizeof(status_changed_time_str), UINT64_FORMAT, bi->status_changed_time); pcp_write(frontend, "i", 1); wsize = htonl(sizeof(code) + @@ -855,6 +861,8 @@ inform_node_info(PCP_CONNECTION *frontend,char *buf) strlen(status)+1 + strlen(weight_str)+1 + strlen(role_str)+1 + + strlen(standby_delay_str)+1 + + strlen(status_changed_time_str)+1 + sizeof(int)); pcp_write(frontend, &wsize, sizeof(int)); pcp_write(frontend, code, sizeof(code)); @@ -862,8 +870,10 @@ inform_node_info(PCP_CONNECTION *frontend,char *buf) pcp_write(frontend, port_str, strlen(port_str)+1); pcp_write(frontend, status, strlen(status)+1); pcp_write(frontend, weight_str, strlen(weight_str)+1); - pcp_write(frontend, role_str, strlen(role_str)+1); + pcp_write(frontend, standby_delay_str, strlen(standby_delay_str)+1); + pcp_write(frontend, status_changed_time_str, strlen(status_changed_time_str)+1); + do_pcp_flush(frontend); } diff --git a/src/tools/pcp/pcp_frontend_client.c b/src/tools/pcp/pcp_frontend_client.c index 2fbe85e8d..9fbc16d73 100644 --- a/src/tools/pcp/pcp_frontend_client.c +++ b/src/tools/pcp/pcp_frontend_client.c @@ -4,7 +4,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2016 PgPool Global Development Group + * Copyright (c) 2003-2018 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -463,24 +463,35 @@ static void output_nodeinfo_result(PCPResultInfo* pcpResInfo, bool verbose) { BackendInfo *backend_info = (BackendInfo *) pcp_get_binary_data(pcpResInfo,0); + char last_status_change[20]; + struct tm tm; + + localtime_r(&backend_info->status_changed_time, &tm); + strftime(last_status_change, sizeof(last_status_change), "%F %T", &tm); if (verbose) { - printf("Hostname : %s\nPort : %d\nStatus : %d\nWeight : %f\nStatus Name: %s\nRole : %s\n", + printf("Hostname : %s\nPort : %d\nStatus : %d\nWeight : %f\nStatus Name : %s\nRole : %s\nReplication Delay : %lu\nLast Status Change: %s\n", backend_info->backend_hostname, backend_info->backend_port, backend_info->backend_status, backend_info->backend_weight/RAND_MAX, backend_status_to_string(backend_info), - role_to_str(backend_info->role)); - } else { - printf("%s %d %d %f %s %s\n", + role_to_str(backend_info->role), + backend_info->standby_delay, + last_status_change); + } + else + { + printf("%s %d %d %f %s %s %lu %s\n", backend_info->backend_hostname, backend_info->backend_port, backend_info->backend_status, backend_info->backend_weight/RAND_MAX, backend_status_to_string(backend_info), - role_to_str(backend_info->role)); + role_to_str(backend_info->role), + backend_info->standby_delay, + last_status_change); } }