pgpool2.git / summary / log / commit / refs
commit 64f5bffdac2cf71c764b32f408a35ff50938dcdf
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Sun Feb 05 05:24:42 2012 +0000
Fix failover/failback in RAW mode.
problem #1: Simply does not failover if target node is not master.
problem #2: Fail to select master node if the node is in CON_UP.
For this purpose new macro VALID_BACKEND_RAW is added, which is usefull
where health node status checking is required in raw mode.
Existing VALID_BACKEND macro does not regard standby nodes as healthy
in RAW mode.
main.c | 11 +++++------
pool.h | 7 +++++++
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/main.c b/main.c
index c1f04b83e..3c379c642 100644
--- a/main.c
+++ b/main.c
@@ -716,6 +716,7 @@ int main(int argc, char **argv)
Req_info->node_id[0] = sts;
failover();
/* need to distribute this info to children */
+ retrying = false;
}
}
else
@@ -1508,12 +1509,10 @@ static int get_next_master_node(void)
* Do not use VALID_BACKEND macro in raw mode.
* VALID_BACKEND return true only if the argument is master
* node id. In other words, standby nodes are false. So need
- * to check backend status without VALID_BACKEND.
+ * to check backend status with VALID_BACKEND_RAW.
*/
- if (RAW_MODE)
+ if (RAW_MODE && VALID_BACKEND_RAW(i))
{
- /* 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))
@@ -1654,13 +1653,13 @@ static void failover(void)
for (i = 0; i < MAX_NUM_BACKENDS; i++)
{
if (Req_info->node_id[i] != -1 &&
- VALID_BACKEND(Req_info->node_id[i]))
+ ((RAW_MODE && VALID_BACKEND_RAW(Req_info->node_id[i])) ||
+ VALID_BACKEND(Req_info->node_id[i])))
{
pool_log("starting degeneration. shutdown host %s(%d)",
BACKEND_INFO(Req_info->node_id[i]).backend_hostname,
BACKEND_INFO(Req_info->node_id[i]).backend_port);
-
BACKEND_INFO(Req_info->node_id[i]).backend_status = CON_DOWN; /* set down status */
/* save down node */
nodes[Req_info->node_id[i]] = 1;
diff --git a/pool.h b/pool.h
index 7932ec4ca..449b0901a 100644
--- a/pool.h
+++ b/pool.h
@@ -275,6 +275,13 @@ extern BACKEND_STATUS* my_backend_status[];
((*(my_backend_status[(backend_id)]) == CON_UP) || \
(*(my_backend_status[(backend_id)]) == CON_CONNECT_WAIT))))
+/*
+ * For raw mode failover control
+ */
+#define VALID_BACKEND_RAW(backend_id) \
+ ((*(my_backend_status[(backend_id)]) == CON_UP) || \
+ (*(my_backend_status[(backend_id)]) == CON_CONNECT_WAIT))
+
#define CONNECTION_SLOT(p, slot) ((p)->slots[(slot)])
#define CONNECTION(p, slot) (CONNECTION_SLOT(p, slot)->con)
[parent: c7bc1b2a4b80]