pgpool2.git / summary / log / commit / refs
commit 1917df77ca1ca7110d54760af47e12bac40aca5d
Author: at.mitani <at.mitani@gmail.com>
Date: Wed Jul 11 01:59:10 2012 +0000
merged master with the watchdog branch.
pool_config.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
pool_config.l | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
recovery.c | 13 +++++++++----
watchdog/watchdog.c | 3 +++
watchdog/wd_child.c | 7 ++++++-
watchdog/wd_ext.h | 1 +
watchdog/wd_if.c | 4 ++--
watchdog/wd_init.c | 1 +
watchdog/wd_lifecheck.c | 15 +++++++++++++++
watchdog/wd_packet.c | 30 +++++++++++++++++++++++-------
10 files changed, 156 insertions(+), 14 deletions(-)
diff --git a/pool_config.c b/pool_config.c
index f1f0dff9c..45c4ec896 100644
--- a/pool_config.c
+++ b/pool_config.c
@@ -3714,6 +3714,18 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->delegate_IP = str;
}
+ else if (!strcmp(key, "wd_port") && CHECK_CONTEXT(INIT_CONFIG, context))
+ {
+ int v = atoi(yytext);
+
+ if (token != POOL_INTEGER || v <= 0)
+ {
+ pool_error("pool_config: %s must be higher than 1 numeric value", key);
+ fclose(fd);
+ return(-1);
+ }
+ pool_config->wd_port = v;
+ }
else if (!strcmp(key, "wd_interval") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -3798,6 +3810,42 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->if_down_cmd = str;
}
+ else if (!strcmp(key, "arping_path") && CHECK_CONTEXT(INIT_CONFIG, context))
+ {
+ char *str;
+
+ if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
+ {
+ PARSE_ERROR();
+ fclose(fd);
+ return(-1);
+ }
+ str = extract_string(yytext, token);
+ if (str == NULL)
+ {
+ fclose(fd);
+ return(-1);
+ }
+ pool_config->arping_path = str;
+ }
+ else if (!strcmp(key, "arping_cmd") && CHECK_CONTEXT(INIT_CONFIG, context))
+ {
+ char *str;
+
+ if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
+ {
+ PARSE_ERROR();
+ fclose(fd);
+ return(-1);
+ }
+ str = extract_string(yytext, token);
+ if (str == NULL)
+ {
+ fclose(fd);
+ return(-1);
+ }
+ pool_config->arping_cmd = str;
+ }
else if (!strcmp(key, "wd_life_point") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
diff --git a/pool_config.l b/pool_config.l
index 9d68a8ad3..abb75bdc0 100644
--- a/pool_config.l
+++ b/pool_config.l
@@ -1989,6 +1989,18 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->delegate_IP = str;
}
+ else if (!strcmp(key, "wd_port") && CHECK_CONTEXT(INIT_CONFIG, context))
+ {
+ int v = atoi(yytext);
+
+ if (token != POOL_INTEGER || v <= 0)
+ {
+ pool_error("pool_config: %s must be higher than 1 numeric value", key);
+ fclose(fd);
+ return(-1);
+ }
+ pool_config->wd_port = v;
+ }
else if (!strcmp(key, "wd_interval") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
@@ -2073,6 +2085,42 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->if_down_cmd = str;
}
+ else if (!strcmp(key, "arping_path") && CHECK_CONTEXT(INIT_CONFIG, context))
+ {
+ char *str;
+
+ if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
+ {
+ PARSE_ERROR();
+ fclose(fd);
+ return(-1);
+ }
+ str = extract_string(yytext, token);
+ if (str == NULL)
+ {
+ fclose(fd);
+ return(-1);
+ }
+ pool_config->arping_path = str;
+ }
+ else if (!strcmp(key, "arping_cmd") && CHECK_CONTEXT(INIT_CONFIG, context))
+ {
+ char *str;
+
+ if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
+ {
+ PARSE_ERROR();
+ fclose(fd);
+ return(-1);
+ }
+ str = extract_string(yytext, token);
+ if (str == NULL)
+ {
+ fclose(fd);
+ return(-1);
+ }
+ pool_config->arping_cmd = str;
+ }
else if (!strcmp(key, "wd_life_point") && CHECK_CONTEXT(INIT_CONFIG, context))
{
int v = atoi(yytext);
diff --git a/recovery.c b/recovery.c
index 483325390..9820e9711 100644
--- a/recovery.c
+++ b/recovery.c
@@ -102,14 +102,19 @@ int start_recovery(int recovery_node)
{
pool_log("starting 2nd stage");
+ /* 2nd stage */
+ *InRecovery = RECOVERY_ONLINE;
if (pool_config->use_watchdog)
{
/* announce start recovery */
- wd_start_recovery();
+ if (WD_OK != wd_start_recovery())
+ {
+ PQfinish(conn);
+ pool_error("start_recovery: timeover for waiting connection closed in the other pgpools");
+ return 1;
+ }
}
- /* 2nd stage */
- *InRecovery = RECOVERY_ONLINE;
if (wait_connection_closed() != 0)
{
PQfinish(conn);
@@ -182,7 +187,7 @@ int start_recovery(int recovery_node)
void finish_recovery(void)
{
/* announce end recovery */
- if (pool_config->use_watchdog && *InRecovery == RECOVERY_ONLINE)
+ if (pool_config->use_watchdog && *InRecovery != RECOVERY_INIT)
{
wd_end_recovery();
}
diff --git a/watchdog/watchdog.c b/watchdog/watchdog.c
index 2d3c4d143..765eaa734 100644
--- a/watchdog/watchdog.c
+++ b/watchdog/watchdog.c
@@ -39,6 +39,7 @@
WdInfo * WD_List = NULL; /* watchdog server list */
unsigned char * WD_Node_List = NULL; /* node list */
+pid_t wd_ppid = 0;
static pid_t child_pid;
pid_t wd_main(int fork_wait_time);
@@ -120,6 +121,8 @@ wd_main(int fork_wait_time)
return 0;
}
+ wd_ppid = getpid();
+
/* launch child process */
child_pid = wd_child(1);
if (child_pid < 0 )
diff --git a/watchdog/wd_child.c b/watchdog/wd_child.c
index fb8aa164c..044fc080c 100644
--- a/watchdog/wd_child.c
+++ b/watchdog/wd_child.c
@@ -205,15 +205,20 @@ send_response(int sock, WdPacket * recv_pack)
{
send_packet.packet_no = WD_NODE_READY;
*InRecovery = RECOVERY_ONLINE;
+ if (wait_connection_closed() != 0)
+ {
+ send_packet.packet_no = WD_NODE_FAILED;
+ }
}
break;
case WD_END_RECOVERY:
send_packet.packet_no = WD_NODE_READY;
*InRecovery = RECOVERY_INIT;
+ kill(wd_ppid, SIGUSR2);
break;
case WD_FAILBACK_REQUEST:
node = &(recv_pack->wd_body.wd_node_info);
- wd_set_node_mask(WD_FAILBACK_REQUEST,node->node_id_set, node->node_num);
+ wd_set_node_mask(WD_FAILBACK_REQUEST,node->node_id_set,node->node_num);
send_failback_request(node->node_id_set[0]);
send_packet.packet_no = WD_NODE_READY;
break;
diff --git a/watchdog/wd_ext.h b/watchdog/wd_ext.h
index 87801db40..593fae503 100644
--- a/watchdog/wd_ext.h
+++ b/watchdog/wd_ext.h
@@ -27,6 +27,7 @@
#define WD_EXT_H
/* watchdog.c */
+extern pid_t wd_ppid;
extern pid_t wd_main(int fork_wait_time);
/* wd_child.c */
diff --git a/watchdog/wd_if.c b/watchdog/wd_if.c
index bbb3a5a98..33d059619 100644
--- a/watchdog/wd_if.c
+++ b/watchdog/wd_if.c
@@ -42,7 +42,7 @@ static int exec_ifconfig(char * path,char * command);
int
wd_IP_up(void)
{
- int rtn;
+ int rtn = WD_OK;
char path[128];
if (WD_List->delegate_ip == 0)
{
@@ -57,7 +57,7 @@ wd_IP_up(void)
int
wd_IP_down(void)
{
- int rtn;
+ int rtn = WD_OK;
char path[128];
if (WD_List->delegate_ip == 1)
{
diff --git a/watchdog/wd_init.c b/watchdog/wd_init.c
index 50ed1f9ff..185f27419 100644
--- a/watchdog/wd_init.c
+++ b/watchdog/wd_init.c
@@ -71,6 +71,7 @@ wd_init(void)
/* check upper connection */
if ((pool_config->trusted_servers != NULL) &&
+ (strlen(pool_config->trusted_servers) > 0) &&
(wd_is_upper_ok(pool_config->trusted_servers) != WD_OK))
{
pool_error("failed to connect trusted server");
diff --git a/watchdog/wd_lifecheck.c b/watchdog/wd_lifecheck.c
index 66984f5fa..5224f245d 100644
--- a/watchdog/wd_lifecheck.c
+++ b/watchdog/wd_lifecheck.c
@@ -91,11 +91,13 @@ wd_lifecheck(void)
pthread_t thread[MAX_WATCHDOG_NUM];
WdPgpoolThreadArg thread_arg[MAX_WATCHDOG_NUM];
+
/* set startup time */
gettimeofday(&tv, NULL);
/* check upper connection */
if ((pool_config->trusted_servers != NULL) &&
+ (strlen(pool_config->trusted_servers ) > 0) &&
(wd_is_upper_ok(pool_config->trusted_servers) != WD_OK))
{
pool_error("failed to connect trusted server");
@@ -109,6 +111,12 @@ wd_lifecheck(void)
return WD_NG;
}
+ /* skip lifecheck during recovery execution */
+ if (*InRecovery != RECOVERY_INIT)
+ {
+ return WD_OK;
+ }
+
/* thread init */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
@@ -131,6 +139,9 @@ wd_lifecheck(void)
for (i = 0; i < cnt; )
{
int result;
+
+ pool_debug("wd_lifecheck: checking pgpool %d (%s:%d)", i, p->hostname, p->pgpool_port);
+
rc = pthread_join(thread[i], (void **)&result);
if ((rc != 0) && (errno == EINTR))
{
@@ -139,6 +150,8 @@ wd_lifecheck(void)
}
if (result == WD_OK)
{
+ pool_debug("wd_lifecheck: OK, status: %d", p->status);
+
p->life = pool_config->wd_life_point;
if ((i == 0) &&
(WD_List->status == WD_DOWN))
@@ -155,6 +168,8 @@ wd_lifecheck(void)
}
else
{
+ pool_debug("wd_lifecheck: NG, status: %d life:%d", p->status, p->life);
+
if (p->life > 0)
{
p->life --;
diff --git a/watchdog/wd_packet.c b/watchdog/wd_packet.c
index 440004b07..1b5b88dc8 100644
--- a/watchdog/wd_packet.c
+++ b/watchdog/wd_packet.c
@@ -62,6 +62,11 @@ int wd_recv_packet(int sock, WdPacket * buf);
int wd_escalation(void);
int wd_start_recovery(void);
int wd_end_recovery(void);
+int wd_send_failback_request(int node_id);
+int wd_degenerate_backend_set(int *node_id_set, int count);
+int wd_promote_backend(int node_id);
+int wd_set_node_mask (WD_PACKET_NO packet_no, int *node_id_set, int count);
+
static int wd_send_packet_no(WD_PACKET_NO packet_no );
static void * wd_negotiation(void * arg);
static int send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type);
@@ -614,7 +619,15 @@ send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type)
{
return WD_OK;
}
- rtn = (packet->packet_no == WD_STAND_FOR_MASTER)?WD_OK:WD_NG;
+ if ((packet->packet_no == WD_STAND_FOR_MASTER) ||
+ (packet->packet_no == WD_START_RECOVERY))
+ {
+ rtn = WD_OK;
+ }
+ else
+ {
+ rtn = WD_NG;
+ }
for (i=0; i<cnt; )
{
int result;
@@ -624,7 +637,8 @@ send_packet_4_nodes(WdPacket *packet, WD_SEND_TYPE type)
usleep(100);
continue;
}
- if (packet->packet_no == WD_STAND_FOR_MASTER)
+ if ((packet->packet_no == WD_STAND_FOR_MASTER) ||
+ (packet->packet_no == WD_START_RECOVERY))
{
if (result == WD_NG)
{
@@ -700,7 +714,7 @@ hton_wd_node_packet(WdPacket * to, WdPacket * from)
to_info = &(to->wd_body.wd_node_info);
from_info = &(from->wd_body.wd_node_info);
to->packet_no = htonl(from->packet_no);
- for (i = 0 ; i < to_info->node_num ; i ++)
+ for (i = 0 ; i < from_info->node_num ; i ++)
{
to_info->node_id_set[i] = htonl(from_info->node_id_set[i]);
}
@@ -735,6 +749,8 @@ wd_escalation(void)
{
int rtn;
+ pool_log("wd_escalation: eslcalated to master pgpool");
+
/* interface up as delegate IP */
wd_IP_up();
/* set master status to the wd list */
@@ -774,7 +790,7 @@ wd_send_failback_request(int node_id)
if (wd_chk_node_mask(WD_FAILBACK_REQUEST,&n,1))
{
- return rtn;
+ return WD_OK;
}
/* send failback packet */
@@ -789,7 +805,7 @@ wd_degenerate_backend_set(int *node_id_set, int count)
if (wd_chk_node_mask(WD_DEGENERATE_BACKEND,node_id_set,count))
{
- return rtn;
+ return WD_OK;
}
/* send degenerate packet */
rtn = wd_send_node_packet(WD_DEGENERATE_BACKEND, node_id_set, count);
@@ -804,7 +820,7 @@ wd_promote_backend(int node_id)
if (wd_chk_node_mask(WD_PROMOTE_BACKEND,&n,1))
{
- return rtn;
+ return WD_OK;
}
/* send promote packet */
rtn = wd_send_node_packet(WD_PROMOTE_BACKEND, &n, 1);
@@ -832,6 +848,7 @@ wd_send_node_packet(WD_PACKET_NO packet_no, int *node_id_set, int count)
return rtn;
}
+
static int
wd_chk_node_mask (WD_PACKET_NO packet_no, int *node_id_set, int count)
{
@@ -867,4 +884,3 @@ wd_set_node_mask (WD_PACKET_NO packet_no, int *node_id_set, int count)
}
return rtn;
}
-
[parent: a36819d8a23b]