Enhance find_primary_node() not to fail if pgpool_walrecrunning()
authorTatsuo Ishii <ishii at sraoss.co.jp>
Sat, 19 Feb 2011 12:44:35 +0000 (12:44 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Sat, 19 Feb 2011 12:44:35 +0000 (12:44 +0000)
is not installed. In this case it returns -1, which means
pgpool-II assumes the youngest node to be the primary.

main.c

diff --git a/main.c b/main.c
index f2f0e3477f96d98fa0a24fdd68ffbd9ebe10dfcb..31dc6d946702ef8278d6dbb6a07adc54def3fee8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2303,8 +2303,9 @@ static int find_primary_node(void)
        {
                if (!VALID_BACKEND(i))
                        continue;
+
                /*
-                * Check to see if this is a standby node or not
+                * Check to see if this is a standby node or not.
                 */
                is_standby = false;
 
@@ -2321,6 +2322,28 @@ static int find_primary_node(void)
                }
                con = s->con;
 
+               status = do_query(con, "SELECT count(*) FROM pg_catalog.pg_proc AS p WHERE p.proname = 'pgpool_walrecrunning'",
+                                                 &res, PROTO_MAJOR_V3);
+               if (res->numrows <= 0)
+               {
+                       pool_log("find_primary_node: do_query returns no rows");
+               }
+               if (res->data[0] == NULL)
+               {
+                       pool_log("find_primary_node: do_query returns no data");
+               }
+               if (res->nullflags[0] == -1)
+               {
+                       pool_log("find_primary_node: do_query returns NULL");
+               }
+               if (res->data[0] && !strcmp(res->data[0], "0"))
+               {
+                       pool_log("find_primary_node: pgpool_walrecrunning does not exist");
+                       free_select_result(res);
+                       discard_persistent_db_connection(s);
+                       return -1;
+               }
+
                status = do_query(con, "SELECT pg_is_in_recovery() AND pgpool_walrecrunning()",
                                                  &res, PROTO_MAJOR_V3);
                if (res->numrows <= 0)