pgpool2.git / summary / log / commit / refs
commit e3bbca3441c8d43cad8387b8daae91cf7f166a73
Author: Tatsuo Ishii <ishii@sraoss.co.jp>
Date: Wed Dec 22 01:13:20 2021 +0000
Allow to run regression test against existing installation without recompiling.
It is possible to run regression test using existing installation.
regression.sh -m noinstall
However some of tests fail in this case because those tests require
pgpool to be compiled with variable HEALTHCHECK_DEBUG is set. This is
only possible in following procedure.
make clean
cd src/test/regression
./regress.sh
To run the regression test against existing installation new config
variable "health_check_test" is added. The source code is always
compiled as if HEALTHCHECK_DEBUG is set. The test facility is not
activated unless health_check_test is set to on.
For now I push to only master branch. After some tests, I am going to
push to all supported branches. I know adding new parameter to stable
branches is unusual but the feature is for enhancing test and it is
not visible to ordinal users. So I think my plan is justified by them.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2021-December/004078.html
doc.ja/src/sgml/misc-config.sgml | 75 +++++++++++++++++++++++++++++++++++
doc.ja/src/sgml/ref/pgpool_setup.sgml | 28 +++++++++++++
doc/src/sgml/misc-config.sgml | 47 ++++++++++++++++++++++
doc/src/sgml/ref/pgpool_setup.sgml | 21 ++++++++++
src/Makefile.am | 1 -
src/config/pool_config_variables.c | 10 +++++
src/include/pool_config.h | 1 +
src/main/health_check.c | 52 ++++++------------------
src/test/pgpool_setup.in | 8 ++++
src/test/regression/regress.sh | 4 +-
10 files changed, 205 insertions(+), 42 deletions(-)
diff --git a/doc.ja/src/sgml/misc-config.sgml b/doc.ja/src/sgml/misc-config.sgml
index 418bd5ee7..cec9d9b8d 100644
--- a/doc.ja/src/sgml/misc-config.sgml
+++ b/doc.ja/src/sgml/misc-config.sgml
@@ -312,5 +312,80 @@
</listitem>
</varlistentry>
+ <varlistentry id="guc-health-check-test" xreflabel="health_check_test">
+ <term><varname>health_check_test</varname> (<type>boolean</type>)
+ <indexterm>
+<!--
+ <primary><varname>health_check_test</varname> configuration parameter</primary>
+-->
+ <primary><varname>health_check_test</varname>設定パラメータr</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <caution>
+ <para>
+<!--
+ Do not set this parameter to on in a production
+ environment. This feature is purely for testing purpose.
+-->
+ 実運用のシステムでこのパラメータをonにしないでください。
+ この機能はテスト目的専用です。
+ </para>
+ </caution>
+ <para>
+<!--
+ Setting to on,
+ enables the testing facility of health checking. In this case the
+ health check process looks
+ into <filename>backend_down_request</filename>
+ under <xref linkend="guc-logdir">. The file may contain multiple
+ lines, and each line corresponds to each backend. A line in the
+ file starts with backend id (must be a decimal number starting
+ with zero), then a TAB, and ends with "down". The backend is
+ assumed in down status and <productname>Pgpool-II</productname>
+ will start a failover. Once the failover completes, the "down" is
+ rewritten to "already_down" by health check process to prevent
+ repeating failovers.
+-->
+ onにすると、ヘルスチェックのテスト機能が有効になります。
+ この場合、ヘルスチェックプロセスは<xref linkend="guc-logdir">の下にある<filename>backend_down_request</filename>を参照します。
+ このファイルは、複数の行から構成され、各行は各々のバックエンドに対応します。
+ 各行はバックエンドID(ゼロから始まる十進数でなければなりません)で始まり、続いてタブ、最後に"down"で終わります。
+ そのバックエンドはダウン状態と見なされ、<productname>Pgpool-II</productname>はフェイルオーバを開始します。
+ フェイルオーバが完了すると、"down"はヘルスチェックプロセスによって"already_down"に書き換えられ、何度もフェイルオーバが起きることを防ぎます。
+ </para>
+ <para>
+<!--
+ This feature is particularly useful for
+ testing <xref linkend="guc-failover-require-consensus">. Suppose
+ we have 3 watchdog node. Each watchdog checks healthiness of
+ backend 0. By setting "0 down" in the file only under watchdog 0,
+ other watchdogs disagree with the unhealthiness of backend 0, so
+ failover will not occur. This kind of partial network failure can
+ be simulated using this feature.
+-->
+ この機能は特に<xref linkend="guc-failover-require-consensus">のテストに有用です。
+ 今3つのwatchdogノードがあるとします。
+ 各々のwatchdogはバックエンド0の健全性を検証します。
+ "0 down"とwatchdog 0の配下のファイルのみに書き込むと、他のバックエンドはバックエンド0が健全ではないことに同意しないので、フェイルオーバは起きません。
+ このような、部分的なネットワーク障害がこの機能でシミュレーションできます。
+ </para>
+ <para>
+<!--
+ Default is <literal>off</literal>.
+-->
+ デフォルトは<literal>off</literal>です。
+ </para>
+
+ <para>
+ <!--
+ This parameter can only be set at server start.
+ -->
+ このパラメータは、サーバ起動時にのみ設定できます。
+ </para>
+
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect1>
diff --git a/doc.ja/src/sgml/ref/pgpool_setup.sgml b/doc.ja/src/sgml/ref/pgpool_setup.sgml
index da3d3bd1a..55bb2e439 100644
--- a/doc.ja/src/sgml/ref/pgpool_setup.sgml
+++ b/doc.ja/src/sgml/ref/pgpool_setup.sgml
@@ -262,6 +262,22 @@ Pgpool-II documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-t</option></term>
+ <listitem>
+ <para>
+<!--
+ Set some additional parameters to pgpool.conf so that the
+ regression test can performs tests against existing
+ installation. Currently the parameter is
+ <xref linkend="guc-health-check-test">.
+-->
+ regression testが既存のインストールに対して実行できるように、pgpool.confに追加のパラメータを設定します。
+ 今の所、そのようなパラメータとしては<xref linkend="guc-health-check-test">があります。
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
</refsect1>
@@ -395,6 +411,18 @@ Pgpool-II documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>ENABLE_TEST</option></term>
+ <listitem>
+ <para>
+<!--
+ If "true", act as if "-t" option is specified.
+-->
+ "true"ならあたかも"-t"オプションが与えられたかのように振る舞います。
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
diff --git a/doc/src/sgml/misc-config.sgml b/doc/src/sgml/misc-config.sgml
index 918b32fdd..c82991de6 100644
--- a/doc/src/sgml/misc-config.sgml
+++ b/doc/src/sgml/misc-config.sgml
@@ -280,5 +280,52 @@
</listitem>
</varlistentry>
+ <varlistentry id="guc-health-check-test" xreflabel="health_check_test">
+ <term><varname>health_check_test</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>health_check_test</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <caution>
+ <para>
+ Do not set this parameter to on in a production
+ environment. This feature is purely for testing purpose.
+ </para>
+ </caution>
+ <para>
+ Setting to on,
+ enables the testing facility of health checking. In this case the
+ health check process looks
+ into <filename>backend_down_request</filename>
+ under <xref linkend="guc-logdir">. The file may contain multiple
+ lines, and each line corresponds to each backend. A line in the
+ file starts with backend id (must be a decimal number starting
+ with zero), then a TAB, and ends with "down". The backend is
+ assumed in down status and <productname>Pgpool-II</productname>
+ will start a failover. Once the failover completes, the "down" is
+ rewritten to "already_down" by health check process to prevent
+ repeating failovers.
+ </para>
+ <para>
+ This feature is particularly useful for
+ testing <xref linkend="guc-failover-require-consensus">. Suppose
+ we have 3 watchdog node. Each watchdog checks healthiness of
+ backend 0. By setting "0 down" in the file onky under watchdog 0,
+ other watchdogs disagree with the unhealthiness of backend 0, so
+ failover will not occur. This kind of partial network failure can
+ be simulated using this feature.
+ </para>
+ <para>
+ Default is <literal>off</literal>.
+ </para>
+
+ <para>
+ This parameter can only be set at server start.
+ </para>
+
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect1>
diff --git a/doc/src/sgml/ref/pgpool_setup.sgml b/doc/src/sgml/ref/pgpool_setup.sgml
index 3371035f1..db41fcbff 100644
--- a/doc/src/sgml/ref/pgpool_setup.sgml
+++ b/doc/src/sgml/ref/pgpool_setup.sgml
@@ -186,6 +186,18 @@ Pgpool-II documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-t</option></term>
+ <listitem>
+ <para>
+ Set some additional parameters to pgpool.conf so that the
+ regression test can performs tests against existing
+ installation. Currently the parameter is
+ <xref linkend="guc-health-check-test">.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
</refsect1>
@@ -279,6 +291,15 @@ Pgpool-II documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>ENABLE_TEST</option></term>
+ <listitem>
+ <para>
+ If "true", act as if "-t" option is specified.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
diff --git a/src/Makefile.am b/src/Makefile.am
index ee1ffa6ff..ba2358f59 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,7 +67,6 @@ pgpool_SOURCES = main/main.c \
DEFS = @DEFS@ \
-DDEFAULT_CONFIGDIR=\"$(sysconfdir)\" \
- -DHEALTHCHECK_OPTS=$(HEALTHCHECK_DEBUG) \
-DPGSQL_BIN_DIR=\"$(PGSQL_BIN_DIR)\"
sysconf_DATA = sample/pgpool.conf.sample \
diff --git a/src/config/pool_config_variables.c b/src/config/pool_config_variables.c
index 116f89417..6668050a2 100644
--- a/src/config/pool_config_variables.c
+++ b/src/config/pool_config_variables.c
@@ -759,6 +759,16 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},
+ {
+ {"health_check_test", CFGCXT_INIT, HEALTH_CHECK_CONFIG,
+ "If on, enable health check testing.",
+ CONFIG_VAR_TYPE_BOOL, false, 0
+ },
+ &g_pool_config.health_check_test,
+ false,
+ NULL, NULL, NULL
+ },
+
/* End-of-list marker */
EMPTY_CONFIG_BOOL
diff --git a/src/include/pool_config.h b/src/include/pool_config.h
index 8ebf283e9..3ec1b7abe 100644
--- a/src/include/pool_config.h
+++ b/src/include/pool_config.h
@@ -590,6 +590,7 @@ typedef struct
int num_hb_dest_if; /* number of interface devices */
char **wd_monitoring_interfaces_list; /* network interface name list
* to be monitored by watchdog */
+ bool health_check_test; /* if on, enable health check testing */
} POOL_CONFIG;
diff --git a/src/main/health_check.c b/src/main/health_check.c
index d7ed427df..f4d72f7b9 100644
--- a/src/main/health_check.c
+++ b/src/main/health_check.c
@@ -5,7 +5,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2020 PgPool Global Development Group
+ * Copyright (c) 2003-2021 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
@@ -82,15 +82,7 @@ static RETSIGTYPE reload_config_handler(int sig);
static void reload_config(void);
static RETSIGTYPE health_check_timer_handler(int sig);
-#ifdef HEALTHCHECK_OPTS
-#if HEALTHCHECK_OPTS > 0
-#define HEALTHCHECK_DEBUG
-#endif
-#endif
-
-#ifdef HEALTHCHECK_DEBUG
static bool check_backend_down_request(int node, bool done_requests);
-#endif
#undef CHECK_REQUEST
#define CHECK_REQUEST \
@@ -386,12 +378,18 @@ establish_persistent_connection(int node)
CLEAR_ALARM;
}
-#ifdef HEALTHCHECK_DEBUG
- if (slot && check_backend_down_request(node, false) == true)
+ /*
+ * If health check test is enabled, check if fake down request is
+ * set. If set, discard_persistent_connection will set slot to
+ * NULL. This simulates a connection failure.
+ */
+ if (pool_config->health_check_test)
{
- discard_persistent_connection(node);
+ if (slot && check_backend_down_request(node, false) == true)
+ {
+ discard_persistent_connection(node);
+ }
}
-#endif
if (slot)
{
@@ -564,8 +562,6 @@ health_check_stats_init(POOL_HEALTH_CHECK_STATISTICS *addr)
}
}
-#ifdef HEALTHCHECK_DEBUG
-
/*
* Node down request file. In the file, each line consists of "backend node
* id", tab and "down". If such a line found, check_backend_down_request()
@@ -577,7 +573,7 @@ health_check_stats_init(POOL_HEALTH_CHECK_STATISTICS *addr)
/*
* Check backend down request file with specified backend node id. If it's
* down ("down"), returns true and set the status to "already_down" to
- * prevent repeatable * failover. If it's other than "down", returns false.
+ * prevent repeating failover. If it's other than "down", returns false.
*
* When done_requests is true (second arg to function) the function returns
* true if the node has already_done status in the file.
@@ -668,29 +664,5 @@ check_backend_down_request(int node, bool done_requests)
if (!found)
return false;
-#ifdef NOT_USED
- fd = fopen(backend_down_request_file, "w");
- if (!fd)
- {
- ereport(WARNING,
- (errmsg("check_backend_down_request: failed to open file for writing %s",
- backend_down_request_file),
- errdetail("%m")));
- return false;
- }
-
- if (fwrite(writebuf, 1, strlen(writebuf), fd) != strlen(writebuf))
- {
- ereport(WARNING,
- (errmsg("check_backend_down_request: failed to write %s",
- backend_down_request_file),
- errdetail("%m")));
- fclose(fd);
- return false;
- }
- fclose(fd);
-#endif
-
return true;
}
-#endif
diff --git a/src/test/pgpool_setup.in b/src/test/pgpool_setup.in
index 79ee6106e..5d6eeb2d6 100644
--- a/src/test/pgpool_setup.in
+++ b/src/test/pgpool_setup.in
@@ -38,6 +38,7 @@
# -s: use replication slot, rather than wal archive.
# -r: use pg_rewind for base backup if possible.
# -e: do not create PostgreSQL clusters
+# -t: enable testing facility
#
# The user run this script will become the PostgreSQL super user as
# well. Current directory must be empty. Assume that appropriate
@@ -765,6 +766,10 @@ function set_pgpool_conf {
echo "socket_dir = '$PGSOCKET_DIR'" >> $CONF
echo "pcp_socket_dir = '$PGSOCKET_DIR'" >> $CONF
echo "log_line_prefix = '%m: %a pid %p: '" >> $CONF
+
+ if [ $ENABLE_TEST = "true" ];then
+ echo "health_check_test = on" >> $CONF
+ fi
}
#-------------------------------------------
@@ -1026,6 +1031,7 @@ MODE="s"
NO_STOP="false"
NO_CREATE_PGCLUSTER="false"
+ENABLE_TEST=${ENABLE_TEST:-"false"}
while [ $# -gt 0 ]
do
@@ -1061,6 +1067,8 @@ do
USE_PG_REWIND="true"
elif [ $1 = "-e" ];then
NO_CREATE_PGCLUSTER="true"
+ elif [ $1 = "-t" ];then
+ ENABLE_TEST="true"
elif [ $1 = "--help" -o $1 = "-o" ];then
usage
exit
diff --git a/src/test/regression/regress.sh b/src/test/regression/regress.sh
index 9eb87b72e..0cbcf5674 100755
--- a/src/test/regression/regress.sh
+++ b/src/test/regression/regress.sh
@@ -38,7 +38,7 @@ function install_pgpool
test -d $log || mkdir $log
- make install HEALTHCHECK_DEBUG=1 WATCHDOG_DEBUG=1 -C $dir/../../ -e prefix=${PGPOOL_PATH} >& regression.log 2>&1
+ make install WATCHDOG_DEBUG=1 -C $dir/../../ -e prefix=${PGPOOL_PATH} >& regression.log 2>&1
if [ $? != 0 ];then
echo "make install failed"
@@ -107,6 +107,8 @@ function export_env_vars
export PGBENCH_PATH=$PGBENCH_PATH
export PGSOCKET_DIR=$PGSOCKET_DIR
export PGVERSION=`$PGBIN/initdb -V|awk '{print $3}'|sed 's/\..*//'`
+
+ export ENABLE_TEST=true
}
function print_info
{
[parent: dea2fbf65fdb]