pgpool2.git / summary / log / commit / refs

commit    b69e695758dcb2fea0dacfeaf1e40299352ccdaf
Author:   Masaya Kawamoto <kawamoto@sraoss.co.jp>
Date:     Mon Jun 21 04:34:03 2021 +0000

    New feature "prefer_lower_delay_standby"
    
    Currently on streaming replication mode, when the node selected as the load
    balancing node has streaming delay over delay_threshold, pgpool sends the
    query to the primary regardless of other standbys.
    
    When this parameter is set to on, if the delayed load balancing node is the
    standby, pgpool selects the new load balancing node from the lowest delay standbys.
    
    If all standbys are delayed or the primary is chosen as the load balancing node,
    pgpool sends the query to the primary.


.../tests/033.prefer_lower_standby_delay/test.sh | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/src/test/regression/tests/033.prefer_lower_standby_delay/test.sh b/src/test/regression/tests/033.prefer_lower_standby_delay/test.sh new file mode 100644 index 000000000..5b436d7eb --- /dev/null +++ b/src/test/regression/tests/033.prefer_lower_standby_delay/test.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------- +# test script for load balancing. +# +source $TESTLIBS +TESTDIR=testdir +PG_CTL=$PGBIN/pg_ctl +PSQL="$PGBIN/psql -X " + +version=`$PSQL --version|awk '{print $3}'` +major_version=${version%.*} + +result=`echo "$major_version >= 10"|bc` +if [ $result == 1 ];then + REPLAY_PAUSE="SELECT pg_wal_replay_pause();" + REPLAY_RESUME="SELECT pg_wal_replay_resume();" +else + REPLAY_PAUSE="SELECT pg_xlog_replay_pause();" + REPLAY_RESUME="SELECT pg_xlog_replay_resume();" +fi + +for mode in s +do + rm -fr $TESTDIR + mkdir $TESTDIR + cd $TESTDIR + + # create test environment + echo -n "creating test environment..." + $PGPOOL_SETUP -m $mode -n 3 || exit 1 + echo "done." + + source ./bashrc.ports + echo "app_name_redirect_preference_list = 'psql:1'" >> etc/pgpool.conf + echo "delay_threshold = 10" >> etc/pgpool.conf + echo "prefer_lower_delay_standby = on" >> etc/pgpool.conf + echo "sr_check_period = 3" >> etc/pgpool.conf + + ./startall + + export PGPORT=$PGPOOL_PORT + + wait_for_pgpool_startup + + $PSQL test <<EOF +CREATE TABLE t1(i INTEGER); +CREATE TABLE t2(i INTEGER); +EOF + + echo start: prefer_lower_delay_standby is on. + + $PSQL -p 11003 test -c "$REPLAY_PAUSE" + + $PSQL test <<EOF +PGPOOL SET log_min_messages TO DEBUG1; +INSERT INTO t1 VALUES (1), (2), (3); +SELECT pg_sleep(4); +SELECT * FROM t1; +EOF + + fgrep "SELECT * FROM t1;" log/pgpool.log |grep "DB node id: 2">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: query is sent to primary node. + ./shutdownall + exit 1 + fi + + echo ok: query is sent to another standby node. + + $PSQL -p 11003 test -c "$REPLAY_RESUME" + + echo start: prefer_lower_delay_standby is off. + + echo "prefer_lower_delay_standby = off" >> etc/pgpool.conf + + $PGPOOL_INSTALL_DIR/bin/pcp_reload_config -w -h localhost -p $PCP_PORT + + wait_for_pgpool_startup + + $PSQL -p 11003 test -c "$REPLAY_PAUSE" + + $PSQL test <<EOF +PGPOOL SET log_min_messages TO DEBUG1; +INSERT INTO t2 VALUES (1), (2), (3); +SELECT pg_sleep(4); +SELECT * FROM t2; +EOF + + fgrep "SELECT * FROM t2;" log/pgpool.log |grep "DB node id: 0">/dev/null 2>&1 + if [ $? != 0 ];then + # expected result not found + echo fail: query is sent to standby node. + ./shutdownall + exit 1 + fi + + echo ok: prefer lower delay standby works. + + ./shutdownall + +done +exit 0 [parent: 7de9987ff977]