Fix per node health check parameters ignored.
authorTatsuo Ishii <ishii@postgresql.org>
Tue, 19 Dec 2017 01:09:46 +0000 (10:09 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Tue, 19 Dec 2017 01:12:02 +0000 (10:12 +0900)
Per bug 371. Back patch to the 3.7 stable tree where the feature was
introduced.

Also pgpool_setup is modified to add appropriate per node health check
parameters to pgpool.conf.  This is necessary because
pgpool.conf.sample sets health_check_user0 to 'nobody', which
immediately causes health check failure on DB node 0.

src/main/health_check.c
src/test/pgpool_setup

index fcdb59b726400c3832cffae724621aa7b0f63521..de3eda8e8218eee19fac1cd9126f378f97b94352 100644 (file)
@@ -165,7 +165,7 @@ void do_health_check_child(int *node_id)
 
                CHECK_REQUEST;
 
-               if (pool_config->health_check_period <= 0)
+               if (pool_config->health_check_params[*node_id].health_check_period <= 0)
                {
                        sleep(30);
                }
@@ -174,7 +174,7 @@ void do_health_check_child(int *node_id)
                 * If health checking is enabled and the node is not in down status,
                 * do health check.
                 */
-               else if (pool_config->health_check_period > 0)
+               else if (pool_config->health_check_params[*node_id].health_check_period > 0)
                {
                        bool result;
 
@@ -207,7 +207,7 @@ void do_health_check_child(int *node_id)
 
                        /* Discard persistent connections */
                        discard_persistent_connection(*node_id);
-                       sleep(pool_config->health_check_period);
+                       sleep(pool_config->health_check_params[*node_id].health_check_period);
                }
        }
        exit(0);
@@ -235,15 +235,15 @@ static bool establish_persistent_connection(int node)
        /*
         * If database is not specified, "postgres" database is assumed.
         */
-       if (*pool_config->health_check_database == '\0')
-               pool_config->health_check_database = "postgres";
+       if (*pool_config->health_check_params[node].health_check_database == '\0')
+               pool_config->health_check_params[node].health_check_database = "postgres";
 
        /*
         * Try to connect to the database.
         */
        if (slot == NULL)
        {
-               retry_cnt = pool_config->health_check_max_retries;
+               retry_cnt = pool_config->health_check_params[node].health_check_max_retries;
 
                do
                {
@@ -252,22 +252,22 @@ static bool establish_persistent_connection(int node)
                         * communication path failure much earlier before
                         * TCP/IP stack detects it.
                         */
-                       if (pool_config->health_check_timeout > 0)
+                       if (pool_config->health_check_params[node].health_check_timeout > 0)
                        {
                                CLEAR_ALARM;
                                pool_signal(SIGALRM, health_check_timer_handler);
-                               alarm(pool_config->health_check_timeout);
+                               alarm(pool_config->health_check_params[node].health_check_timeout);
                                errno = 0;
                                health_check_timer_expired = 0;
                        }
 
                        slot = make_persistent_db_connection_noerror(node, bkinfo->backend_hostname,
                                                                                                                 bkinfo->backend_port,
-                                                                                                                pool_config->health_check_database,
-                                                                                                                pool_config->health_check_user,
-                                                                                                                pool_config->health_check_password, false);
+                                                                                                                pool_config->health_check_params[node].health_check_database,
+                                                                                                                pool_config->health_check_params[node].health_check_user,
+                                                                                                                pool_config->health_check_params[node].health_check_password, false);
 
-                       if (pool_config->health_check_timeout > 0)
+                       if (pool_config->health_check_params[node].health_check_timeout > 0)
                        {
                                /* cancel health check timer */
                                pool_signal(SIGALRM, SIG_IGN);
@@ -276,7 +276,7 @@ static bool establish_persistent_connection(int node)
 
                        if (slot)
                        {
-                               if (retry_cnt != pool_config->health_check_max_retries)
+                               if (retry_cnt != pool_config->health_check_params[node].health_check_max_retries)
                                {
                                        ereport(LOG,
                                                        (errmsg("health check retrying on DB node: %d succeeded",
@@ -292,9 +292,9 @@ static bool establish_persistent_connection(int node)
                                ereport(LOG,
                                                (errmsg("health check retrying on DB node: %d (round:%d)",
                                                                node,
-                                                               pool_config->health_check_max_retries - retry_cnt)));
+                                                               pool_config->health_check_params[node].health_check_max_retries - retry_cnt)));
 
-                               sleep(pool_config->health_check_retry_delay);
+                               sleep(pool_config->health_check_params[node].health_check_retry_delay);
                        }
                } while (retry_cnt >= 0);
        }
index 6ce80632f055ca19bc75586a06d9e5d5c40776bd..d4e06e4c7ae9fab2263a01b0112961b7b194717d 100755 (executable)
@@ -505,8 +505,18 @@ function set_pgpool_conf {
                echo "recovery_2nd_stage_command = 'pgpool_recovery_pitr'" >> $CONF
        fi
 
-       echo "health_check_period = 10" >> $CONF
-       echo "health_check_user = '$WHOAMI'" >> $CONF
+       n=0
+       while [ $n -lt $NUMCLUSTERS ]
+       do
+           echo "health_check_period$n = 10" >> $CONF
+           echo "health_check_user$n = '$WHOAMI'" >> $CONF
+           echo "health_check_password$n = ''" >> $CONF
+           echo "health_check_database$n = 'postgres'" >> $CONF
+           echo "health_check_max_retries$n = '3'" >> $CONF
+           echo "health_check_retry_delay$n = '1'" >> $CONF
+           echo "connect_timeout$n = '1000'" >> $CONF
+           n=`expr $n + 1`
+       done
        OIDDIR=$BASEDIR/log/pgpool/oiddir
        mkdir -p $OIDDIR
        echo "memqcache_oiddir = '$OIDDIR'" >> $CONF