pgpool2.git / summary / log / commit / refs
commit a3aa5156925ed4bc7417aefa3c50689f195b5f5e
Author: Tatsuo Ishii <ishii at sraoss.co.jp>
Date: Sun May 16 08:38:16 2010 +0000
Subject: Re: [Pgpool-general] pg_terminate_backend triggers failover on pgpool when used as standalone pool
From: Tatsuo Ishii
Date: Wed, 12 May 2010 22:08:31 +0900 (JST)
It seems the problem occurs when there's only one DB node.
1) it tries to failover to non existing node
2) it makes the node into down status which might not what you want.
#1 is purely a bug. I fix this and for #2 I'm leaning to change
existing behavior.
- In row mode and if there's only one DB node, if a problem occurs
with the DB node, it will be brought to down status. However if the
DB node goes into good condition again, you can use the DB node
without restarting pgpool.
- In other mode the behavior is not changed.
main.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/main.c b/main.c
index 3ce8867bd..288e2efb9 100644
--- a/main.c
+++ b/main.c
@@ -1225,11 +1225,13 @@ static RETSIGTYPE exit_handler(int sig)
}
/*
- * calculate next master node id
+ * Calculate next valid master node id.
+ * If no valid node found, returns -1.
*/
static int get_next_master_node(void)
{
int i;
+
for (i=0;i<pool_config->backend_desc->num_backends;i++)
{
/*
@@ -1240,12 +1242,17 @@ static int get_next_master_node(void)
*/
if (RAW_MODE)
{
+ /* if in raw mode, we can switch to a standby node */
if (BACKEND_INFO(i).backend_status == CON_CONNECT_WAIT)
break;
}
else if (VALID_BACKEND(i))
break;
}
+
+ if (i == pool_config->backend_desc->num_backends)
+ i = -1;
+
return i;
}
@@ -1379,7 +1386,7 @@ static void failover(void)
new_master = get_next_master_node();
- if (new_master == pool_config->backend_desc->num_backends)
+ if (new_master < 0)
{
pool_error("failover_handler: no valid DB node found");
}
@@ -1449,8 +1456,11 @@ static void failover(void)
trigger_failover_command(i, pool_config->failover_command);
}
- pool_log("failover_handler: set new master node: %d", new_master);
- Req_info->master_node_id = new_master;
+ if (new_master >= 0)
+ {
+ pool_log("failover_handler: set new master node: %d", new_master);
+ Req_info->master_node_id = new_master;
+ }
/* no need to wait since it will be done in reap_handler */
#ifdef NOT_USED
[parent: b0e5fd05759b]