pgpool2.git / summary / log / commit / refs

commit    ab125ec6a4bbbe23a3444c01beca9a2b09638147
Author:   Yugo Nagata <nagata@sraoss.co.jp>
Date:     Tue Jan 28 07:46:06 2014 +0000

    Fix to output error message when if_up_cmd fails.
    
    This is suggested by Sergey Arlashin in [pgpool-general: 2457].
    (including commit: 6d6afb6ebffa45d32f05288dd0ab2235a495c0ed)


src/watchdog/wd_if.c | 43 ++++++++++++++++++++++++++++++++++++++----- src/watchdog/wd_packet.c | 23 ++++++++++++++++++----- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/watchdog/wd_if.c b/src/watchdog/wd_if.c index 55082ef52..2836052d2 100644 --- a/src/watchdog/wd_if.c +++ b/src/watchdog/wd_if.c @@ -39,12 +39,14 @@ static int exec_ifconfig(char * path,char * command); +#define WD_TRY_PING_AT_IPUP 3 int wd_IP_up(void) { int rtn = WD_OK; char path[WD_MAX_PATH_LEN]; char cmd[128]; + int i; if (strlen(pool_config->delegate_IP) == 0) return WD_NG; @@ -57,13 +59,41 @@ wd_IP_up(void) snprintf(path,sizeof(path),"%s/%s",pool_config->ifconfig_path,cmd); rtn = exec_ifconfig(path,pool_config->if_up_cmd); - wd_get_cmd(cmd,pool_config->arping_cmd); - snprintf(path,sizeof(path),"%s/%s",pool_config->arping_path,cmd); - rtn = exec_ifconfig(path,pool_config->arping_cmd); + if (rtn == WD_OK) + { + wd_get_cmd(cmd,pool_config->arping_cmd); + snprintf(path,sizeof(path),"%s/%s",pool_config->arping_path,cmd); + rtn = exec_ifconfig(path,pool_config->arping_cmd); + } + if (rtn == WD_OK) + { + for (i = 0; i < WD_TRY_PING_AT_IPUP; i++) + { + if (!wd_is_unused_ip(pool_config->delegate_IP)) + break; + } + + if (i >= WD_TRY_PING_AT_IPUP) + rtn = WD_NG; + } + + if (rtn == WD_OK) + pool_log("wd_IP_up: ifconfig up succeeded"); + else + { + WD_List->delegate_ip_flag = 0; + pool_error("wd_IP_up: ifconfig up failed"); + } } + else + { + pool_debug("wd_IP_up: already delegate IP holder"); + } + return rtn; } +#define WD_TRY_PING_AT_IPDOWN 3 int wd_IP_down(void) { @@ -84,20 +114,23 @@ wd_IP_down(void) if (rtn == WD_OK) { - for (i = 0; i < 3; i++) + for (i = 0; i < WD_TRY_PING_AT_IPDOWN; i++) { if (wd_is_unused_ip(pool_config->delegate_IP)) break; } - if (i >= 3) + if (i >= WD_TRY_PING_AT_IPDOWN) rtn = WD_NG; } if (rtn == WD_OK) pool_log("wd_IP_down: ifconfig down succeeded"); else + { + WD_List->delegate_ip_flag = 1; pool_error("wd_IP_down: ifconfig down failed"); + } } else { diff --git a/src/watchdog/wd_packet.c b/src/watchdog/wd_packet.c index cc675dd8b..314760eae 100644 --- a/src/watchdog/wd_packet.c +++ b/src/watchdog/wd_packet.c @@ -631,7 +631,7 @@ send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type) while (p->status != WD_END) { /* don't send packet to pgpool in down */ - if (p->status == WD_DOWN || + if (p->status == WD_DOWN || (packet->packet_no != WD_ADD_REQ && p->status == WD_INIT)) { p->is_contactable = false; @@ -916,7 +916,8 @@ ntoh_wd_lock_packet(WdPacket * to, WdPacket * from) int wd_escalation(void) { - int rtn; + int rtn, r; + bool has_error = false; pool_log("wd_escalation: escalating to master pgpool"); @@ -931,22 +932,31 @@ wd_escalation(void) /* execute escalation command */ if (strlen(pool_config->wd_escalation_command)) { - int r; r = system(pool_config->wd_escalation_command); if (WIFEXITED(r)) { if (WEXITSTATUS(r) == EXIT_SUCCESS) pool_log("wd_escalation: escalation command succeeded"); else + { pool_error("wd_escalation: escalation command failed. exit status: %d", WEXITSTATUS(r)); + has_error = true; + } } else + { pool_error("wd_escalation: escalation command exit abnormally"); + has_error = true; + } } /* interface up as delegate IP */ if (strlen(pool_config->delegate_IP) != 0) - wd_IP_up(); + { + r = wd_IP_up(); + if (r == WD_NG) + has_error = true; + } /* set master status to the wd list */ wd_set_wd_list(pool_config->wd_hostname, pool_config->port, @@ -957,7 +967,10 @@ wd_escalation(void) rtn = wd_declare(); if (rtn == WD_OK) { - pool_log("wd_escalation: escalated to master pgpool successfully"); + if (has_error) + pool_log("wd_escalation: escalated to master pgpool with some errors"); + else + pool_log("wd_escalation: escalated to master pgpool successfully"); } return rtn; [parent: c95415805860]