Speed up failover when all of backends are down.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 3 May 2019 00:02:29 +0000 (09:02 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 3 May 2019 00:16:34 +0000 (09:16 +0900)
Pgpool-II tries to find primary node till search_primary_node_timeout
expires even if all of the backend are in down status. This is not
only a waste of time but makes Pgpool-II looked like hanged because
while searching primary node failover process is suspended and all of
the Pgpool-II child process are in defunct state, thus there's no
process which accepts connection requests from clients. Since the
default value of searching primary is 300 seconds, typically this
keeps on for 300 seconds. This is not comfortable for users.

So immediately give up finding primary node regardless
search_primary_node_timeout and promptly finish the failover process
if all of the backend are in down status.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2019-May/003321.html

src/main/pgpool_main.c

index a3f2a98b7aa005fe30943a93a7367359b407a25f..f546ed5ad5e589d472f8e68854d2f385f7c2a158 100644 (file)
@@ -2707,6 +2707,7 @@ static int find_primary_node_repeatedly(void)
 {
        int sec;
        int node_id = -1;
+       int                     i;
 
        /* Streaming replication mode? */
        if (pool_config->master_slave_mode == 0 ||
@@ -2720,6 +2721,22 @@ static int find_primary_node_repeatedly(void)
                return -1;
        }
 
+       /*
+        * If all of the backends are down, there's no point to keep on searching
+        * primary node.
+        */
+       for (i = 0; i < NUM_BACKENDS; i++)
+       {
+               if (VALID_BACKEND(i))
+                       break;
+       }
+       if (i == NUM_BACKENDS)
+       {
+               ereport(LOG,
+                               (errmsg("find_primary_node_repeatedly: all of the backends are down. Giving up finding primary node")));
+               return -1;
+       }
+
        /*
         * Try to find the new primary node and keep trying for
         * search_primary_node_timeout seconds.