pgpool2.git
7 years agoFix writing transaction flag is accidentally set at commit or rollback.
Tatsuo Ishii [Fri, 9 Feb 2018 04:18:50 +0000 (13:18 +0900)]
Fix writing transaction flag is accidentally set at commit or rollback.

We set writing transaction flag if it's a write query while processing
an execute message. However, the flag is set even it's a commit or
rollback. This is an oversight. The flag is reset while starting next
transaction anyway, so it's actually harmless but a bug is a bug.

7 years agoThrow a warning message when failover consensus settings on watchdog nodes differs.
Muhammad Usama [Thu, 1 Feb 2018 14:55:16 +0000 (19:55 +0500)]
Throw a warning message when failover consensus settings on watchdog nodes differs.

7 years agoFix document typo.
Bo Peng [Wed, 31 Jan 2018 02:39:37 +0000 (11:39 +0900)]
Fix document typo.

7 years agoFix bug with socket writing.
Tatsuo Ishii [Mon, 29 Jan 2018 10:13:21 +0000 (19:13 +0900)]
Fix bug with socket writing.

pool_write_flush() is responsible for writing to sockets when pgpool's
write buffer is full (this function was introduced in 3.6.6 etc). When
network write buffer in kernel is full, it does retrying but it forgot
to update the internal buffer pointer. As a result, broken data is
written to the socket. This results in variety of problems including
too large message length.

7 years agoSet TCP_NODELAY and non blocking to frontend socket.
Tatsuo Ishii [Mon, 29 Jan 2018 04:53:18 +0000 (13:53 +0900)]
Set TCP_NODELAY and non blocking to frontend socket.

TCP_NODELAY is employed by PostgreSQL, so do we it.

Listen fd is set to non blocking. To make sure accept fd is set to non
blocking.

7 years agoFix pgpool child process segfault when ALWAYS_MASTER is on.
Tatsuo Ishii [Mon, 29 Jan 2018 04:04:58 +0000 (13:04 +0900)]
Fix pgpool child process segfault when ALWAYS_MASTER is on.

If following conditions are all met pgpool child segfaults:

1) Streaming replication mode.

2) fail_over_on_backend_error is off.

3) ALWAYS_MASTER flags is set to the master (writer) node.

4) pgpool_status file indicates that the node mentioned in #3 is in
   down status.

What happens here is,

1) find_primary_node() returns node id 0 without checking the status
   of node 0 since ALWAYS_MASTER is set. It's remembered as the
   primary node id. The node id is stored in Req_info->primary_node_id.

2) The connection to backend 0 is not created since pgpool_status says
   it's in down status.

3) upon starting of session, select_load_balancing_node () is called
   and it tries to determine the database name from client's start up
   packet.

4) Since MASTER_CONNECTION macro points to the PRIMARY_NODE,
   MASTER_CONNECTION(ses->backend) is NULL and it results in a segfault.

The fix I propose is, to change PRIMARY_NODE_ID macro so that it
returns REAL_MASTER_NODE_ID (that is the youngest node id which is
alive) if the node id in Req_info->primary_node_id is in down status.
So we have the "true" primary node id in Req_info->primary_node_id,
and "fake" primary node id returned by PRIMARY_NODE_ID macro.

See [pgpool-hackers: 2687] and [pgpool-general: 5881] Pgpool-3.7.1
segmentation fault for more details.

Since ALWAYS_MASTER flag was introduced in 3.7, back pached to 3.7
only.

Per bug report from Philip Champon.

7 years agoFix segfault when %a is in log_line_prefix and debug message is on.
Tatsuo Ishii [Tue, 23 Jan 2018 23:01:22 +0000 (08:01 +0900)]
Fix segfault when %a is in log_line_prefix and debug message is on.

log_line_prefix() gets called to create a log line prefix string. If
"%a" is specified in "log_line_prefix" parameter, log_line_prefix()
calls MASTER_CONNECTION macro, which calls
pool_virtual_master_db_node_id(), which calls ereport(), which calls
log_line_prefix() if debug message is on. This leads to an infinite
recursion and a segfault. Fix is, calling MASTER_NODE_ID macro instead
of MASTER_CONNECTION macro.

Per bug 376.

7 years agoFix per node health check parameters.
Tatsuo Ishii [Tue, 23 Jan 2018 04:24:40 +0000 (13:24 +0900)]
Fix per node health check parameters.

Some them were string types, that should have been integer types.

7 years agoChange systemd service file to use STOP_OPTS=" -m fast".
Bo Peng [Fri, 19 Jan 2018 05:00:27 +0000 (14:00 +0900)]
Change systemd service file to use STOP_OPTS=" -m fast".

7 years agoChange pgpool_setup to add restore_command in recovery.conf.
Bo Peng [Fri, 19 Jan 2018 04:58:44 +0000 (13:58 +0900)]
Change pgpool_setup to add restore_command in recovery.conf.

7 years agoFix queries hanging in parse_before_bind with extended protocol and replication ...
Tatsuo Ishii [Thu, 18 Jan 2018 13:14:38 +0000 (22:14 +0900)]
Fix queries hanging in parse_before_bind with extended protocol and replication + load-balancing.

In case the client sends a BIND message for a query
that has not yet been parsed by the executing node,
the PARSE will be executed before attempting to BIND
the parameters.

However, during the execution of the PARSE, the session
context is not set to in_progress, which leads to wrong
backend validity tests in read_kind_from_backend which
in turn makes the process wait on a backend which is not
going to send anything.

Fixes bug #377.

Problem analysis and fix by Ancoron Luciferis and me.

7 years agoFix comment typo.
Tatsuo Ishii [Wed, 10 Jan 2018 08:29:58 +0000 (17:29 +0900)]
Fix comment typo.

7 years agoAdd 3.7.1 - 3.3.19 release-notes.
Bo Peng [Mon, 8 Jan 2018 06:46:34 +0000 (15:46 +0900)]
Add 3.7.1 - 3.3.19 release-notes.

7 years agoImprove Makefiles.
Bo Peng [Mon, 8 Jan 2018 06:13:11 +0000 (15:13 +0900)]
Improve Makefiles.

Patch provided by Tomoaki Sato.

7 years agoFix document typo.
Bo Peng [Sat, 6 Jan 2018 07:16:17 +0000 (16:16 +0900)]
Fix document typo.

7 years agoReplace /bin/ed with /bin/sed.
Tatsuo Ishii [Fri, 22 Dec 2017 06:20:13 +0000 (15:20 +0900)]
Replace /bin/ed with /bin/sed.

This change requires less packages in order to install pgpool_setup,
because /bin/sed is included in most distribution's base packages,
while //bin/ed is not.

7 years agoChange the pgpool.service and sysconfig files to output Pgpool-II log.
Bo Peng [Thu, 21 Dec 2017 05:42:39 +0000 (14:42 +0900)]
Change the pgpool.service and sysconfig files to output Pgpool-II log.

Removeing "Type=forking" and add OPTS=" -n" to
run Pgpool-II with non-daemon mode, because we need to redirect logs.
Using "journalctl" command to see Pgpool-II systemd log.

7 years agoFix some document errors.
Bo Peng [Thu, 21 Dec 2017 03:34:05 +0000 (12:34 +0900)]
Fix some document errors.

7 years agoAdd documentation for SGML document build.
Tatsuo Ishii [Tue, 19 Dec 2017 08:33:31 +0000 (17:33 +0900)]
Add documentation for SGML document build.

7 years agoFix per node health check parameters ignored.
Tatsuo Ishii [Tue, 19 Dec 2017 01:09:46 +0000 (10:09 +0900)]
Fix per node health check parameters ignored.

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.

7 years agoFix health checking process death and forking forever.
Tatsuo Ishii [Mon, 18 Dec 2017 22:25:35 +0000 (07:25 +0900)]
Fix health checking process death and forking forever.

When failed to read from backend socket (this could happen when wrong
health_check_user is specified), the health check process raises a
FATAL error in pool_read(), which causes death of health check
process. And Pgpool-II main forks off a new health check process. This
repeats forever.

Fix is, check the process type and it raises if the type is HEALTH
CHECK in addition to MAIN.

Back patch to 3.7 stable tree as well.

7 years agoFix some test script error of 002.native_replication.
Bo Peng [Mon, 18 Dec 2017 02:31:59 +0000 (11:31 +0900)]
Fix some test script error of 002.native_replication.

7 years agoFix timestamp data inconsistency by replication mode.
Bo Peng [Sun, 17 Dec 2017 14:30:15 +0000 (23:30 +0900)]
Fix timestamp data inconsistency by replication mode.

From PostgreSQL10 the column default value such as 'CURRENT_DATE' changes,
Pgpool-II should also rewrite timestamp by the added default values in stead of
"'now'::text::date".

7 years agoFix watchdog_setup up doc.
Tatsuo Ishii [Thu, 14 Dec 2017 04:21:20 +0000 (13:21 +0900)]
Fix watchdog_setup up doc.

It lacked to mention that it supports logical replication mode.

7 years agoDowngrade a log message to debug message.
Tatsuo Ishii [Thu, 14 Dec 2017 04:06:35 +0000 (13:06 +0900)]
Downgrade a log message to debug message.

That was mistaken left while last development cycle.

7 years agoAdd test data for bug370.
Tatsuo Ishii [Wed, 13 Dec 2017 05:13:06 +0000 (14:13 +0900)]
Add test data for bug370.

7 years agoFix for re-sync logic in reading packet from backend.
Tatsuo Ishii [Tue, 12 Dec 2017 06:18:56 +0000 (15:18 +0900)]
Fix for re-sync logic in reading packet from backend.

read_kind_from_backend(), which reads message kind from backend,
re-syncs backend nodes when a ready for query message is
received. Unfortunately it forgot to call
pool_pending_message_pull_out() to delete sync pending message. This
leads to random stuck while reading packets from backend. Fix this to
call pool_pending_message_pull_out().

7 years agoFix bug reported in bug370.
Tatsuo Ishii [Mon, 11 Dec 2017 23:13:16 +0000 (08:13 +0900)]
Fix bug reported in bug370.

If an erroneous query is sent to primary and the next query requires a
catalog cache look up, Pgpool-II hangs in do_query().  do_query()
calls pool_push_pending_data() which expects response from backend
because it internally send CLOSE message and flush message. In normal
cases this guarantees some response from backend at least. However
since the backend is in error state, any command including CLOSE sent
by pool_push_pending_data() is ignored.

This only happens if the erroneous query is sent to primary and
without a sync message next query is sent *and* the query requires
catalog cache look up.

Fix is, let pool_push_pending_data() detect an error message and set
ignore_till_sync flag. This will let do_query() just pops the data
pushed in pool_push_pending_data(). pool_search_relcache(), caller of
do_query(), in turn checks the flag. If the flag is set, do not cache
the result. The caller of pool_search_relcache(), pool_select_walker()
may get wrong result, which may let where_to_send() (caller of
pool_select_walker) choose wrong db node, but this is harmless because
ignore_till_sync flag is set.

7 years agoFix returning transaction state when "ready for query" message received.
Tatsuo Ishii [Sun, 10 Dec 2017 12:04:15 +0000 (21:04 +0900)]
Fix returning transaction state when "ready for query" message received.

We return primary or master node state of ready for query message to
frontend. In most cases this is good. However if other than primary
node or master node returns an error state (this could happen if load
balance node is other than primary or master node and the query is an
errornous SELECT), this should be returned to frontend, because the
frontend already received an error.

How much this affects to applications is not clear. However this
behavior has been there for long time, probably applications do not
care the state returned by ready for query message.

7 years agoFix but with extended-query-test test driver.
Tatsuo Ishii [Sun, 10 Dec 2017 08:54:06 +0000 (17:54 +0900)]
Fix but with extended-query-test test driver.

The driver checked directory "result" instead of "results".

7 years agoEnhance documents.
Tatsuo Ishii [Thu, 23 Nov 2017 09:10:59 +0000 (18:10 +0900)]
Enhance documents.

restrictions.sgml: use "xreflabel" in the sect1 title so that xref can
render proper label.

runtime.sgml: enhance "Running mode of Pgpool-II" section.

7 years agoEnhance documents.
Tatsuo Ishii [Thu, 23 Nov 2017 08:40:24 +0000 (17:40 +0900)]
Enhance documents.

restrictions.sgml: use "xreflabel" in the sect1 title so that xref can
render proper label.

runtime.sgml: enhance "Running mode of Pgpool-II" section.

7 years agoChange the test script directory name to fix some make dist error. V3_7_0 V3_7_0_RPM
Bo Peng [Tue, 21 Nov 2017 07:43:20 +0000 (16:43 +0900)]
Change the test script directory name to fix some make dist error.

7 years agoPrepare 3.7.0.
Bo Peng [Tue, 21 Nov 2017 07:05:56 +0000 (16:05 +0900)]
Prepare 3.7.0.

7 years agoEnhancing few comments in pgpool.conf sample files
Muhammad Usama [Fri, 17 Nov 2017 13:55:47 +0000 (18:55 +0500)]
Enhancing few comments in pgpool.conf sample files

7 years agoFix pgpool start message printed multiple times.
Tatsuo Ishii [Wed, 15 Nov 2017 23:12:13 +0000 (08:12 +0900)]
Fix pgpool start message printed multiple times.

When an exception occurs in the main loop, longjmp() gets called and
the variable "first" restored to the initial value. This make the
pgpool start message printed multiple times. This is harmless but
confusing. To fix that, add "volatile" qualifier so that the variable
is on the stack, rather than on a register.

Fix suggested by Muhammad Usama.

7 years agoAdd an execute permission bit to the start/stop script.
Tatsuo Ishii [Tue, 14 Nov 2017 23:18:13 +0000 (08:18 +0900)]
Add an execute permission bit to the start/stop script.

7 years agoPrepare 3.7RC1. V3_7_0_RC1 V3_7_0_RC1_RPM
pengbo [Sun, 12 Nov 2017 07:15:10 +0000 (16:15 +0900)]
Prepare 3.7RC1.

7 years agoAdd 3.7RC1 release-notes.
pengbo [Sun, 12 Nov 2017 07:09:48 +0000 (16:09 +0900)]
Add 3.7RC1 release-notes.

7 years agoAdd some watchdog test cases
Muhammad Usama [Thu, 9 Nov 2017 13:46:52 +0000 (18:46 +0500)]
Add some watchdog test cases

7 years agoChange the "failover_when_quorum_exists", "failover_require_consensus"
pengbo [Thu, 9 Nov 2017 02:22:44 +0000 (11:22 +0900)]
Change the "failover_when_quorum_exists", "failover_require_consensus"
and "enable_multiple_failover_requests_from_node" default value to "on/off".

7 years agoFix for a possible issue in watchdog failover handling.
Muhammad Usama [Thu, 2 Nov 2017 13:48:43 +0000 (18:48 +0500)]
Fix for a possible issue in watchdog failover handling.

Watchdog process should make sure that it's Master/coordinator status is
synchronised across the watchdog cluster before accepting the failover requests.
This will make sure that no other node is processing the same failover request.

8 years agoAdd pgpool_rhel7.sysconfig and pgpool_rhel6.sysconfig files to distribution.
pengbo [Wed, 1 Nov 2017 00:54:26 +0000 (09:54 +0900)]
Add pgpool_rhel7.sysconfig and pgpool_rhel6.sysconfig files to distribution.

8 years agoAdd 3.3.18 - 3.6.7 release notes.
pengbo [Tue, 31 Oct 2017 23:49:57 +0000 (08:49 +0900)]
Add 3.3.18 - 3.6.7 release notes.

8 years agoAdd different pgpool.sysconfig file for RHEL6 and RHEL7.
pengbo [Tue, 31 Oct 2017 03:26:15 +0000 (12:26 +0900)]
Add different pgpool.sysconfig file for RHEL6 and RHEL7.

In RHEL6, the "-n" option is needed to redirect log.

Reported in bug 343.

8 years agoFixing an issue in the handling of pg_terminate_backend()
Muhammad Usama [Wed, 25 Oct 2017 15:22:38 +0000 (20:22 +0500)]
Fixing an issue in the handling of pg_terminate_backend()

In some cases pg_terminate_backend() can cause failover even when
the call is properly issued through Pgpool-II.

This problem is, we do not set of the swallow_termination flag when the
pg_terminate_backend refers to the backend connection of the child
process on which the pg_terminate_backend() was issued.
This was due to the wrong assumption, that we always get the proper
socket close indication when backend to terminate is the same on which
pg_terminate_backend() is issued, Apparently this is not the case,
and PostgreSQL backend can still get abruptly killed even when it is
asked to terminate itself, And this abrupt termination of the connection
makes the Pgpool-II to consider it as a backend failure.

The solution to this is to always set the swallow_termination, even when the
pg_terminate_backend is referring to the local backend connection.

8 years agoFix centos6 compiler error. V3_7_0_BETA1 V3_7_0_BETA1_RPM
pengbo [Mon, 16 Oct 2017 12:18:51 +0000 (21:18 +0900)]
Fix centos6 compiler error.

8 years agoAllow make dist to include pgpool.conf.sample-logical file.
pengbo [Mon, 16 Oct 2017 06:02:36 +0000 (15:02 +0900)]
Allow make dist to include pgpool.conf.sample-logical file.

8 years agoUpdate documentation version to 3.7beta1.
pengbo [Mon, 16 Oct 2017 01:53:29 +0000 (10:53 +0900)]
Update documentation version to 3.7beta1.

8 years agoDisable AM_MAINTAINER_MODE.
pengbo [Mon, 16 Oct 2017 01:04:23 +0000 (10:04 +0900)]
Disable AM_MAINTAINER_MODE.

8 years agoPrepare 3.7beta1.
pengbo [Mon, 16 Oct 2017 01:01:48 +0000 (10:01 +0900)]
Prepare 3.7beta1.

8 years agoEnglish/Japanese documentation updates.
pengbo [Sun, 15 Oct 2017 22:53:30 +0000 (07:53 +0900)]
English/Japanese documentation updates.

8 years agoUpdate Japanese document for pool_hba enhancements.
pengbo [Sun, 15 Oct 2017 22:47:32 +0000 (07:47 +0900)]
Update Japanese document for pool_hba enhancements.

8 years agoAdd Japanese document "5.14.6 Controlling the Failover behavior".
pengbo [Sun, 15 Oct 2017 22:45:17 +0000 (07:45 +0900)]
Add Japanese document "5.14.6 Controlling the Failover behavior".

8 years agoUpdate sql-error expected data.
Tatsuo Ishii [Tue, 10 Oct 2017 07:17:52 +0000 (16:17 +0900)]
Update sql-error expected data.

8 years agoFix bug with handling of 'H' (flush) message in streaming replication mode.
Tatsuo Ishii [Tue, 10 Oct 2017 07:06:22 +0000 (16:06 +0900)]
Fix bug with handling of 'H' (flush) message in streaming replication mode.

If user expects to read response right after 'H', Pgpool-II hangs. The
cause was, when 'H' received, extended query mode was reset and
pending message was not used.

Reported in bug 345.

8 years agoAdd an expected data to extneded-query-test.
Tatsuo Ishii [Tue, 10 Oct 2017 07:05:05 +0000 (16:05 +0900)]
Add an expected data to extneded-query-test.

8 years agoAdd new test case "node_js.data" to extended-query-test.
Tatsuo Ishii [Tue, 10 Oct 2017 06:45:18 +0000 (15:45 +0900)]
Add new test case "node_js.data" to extended-query-test.

- Allow test.sh to specify subset of tests.

- Let ignore source code line numbers in pgproto output data so that
  tests won't fail if source code line has been changed.

- Fix bug with timeout.

- Change timeout from 300 seconds to 60 seconds.

- Change expected/sql-error.data so that it won't be affected previous
  test results.

8 years agoAdd debug aid to disable postmaster shutdown detection.
Tatsuo Ishii [Tue, 10 Oct 2017 02:17:37 +0000 (11:17 +0900)]
Add debug aid to disable postmaster shutdown detection.

By turning on DISABLE_POSTMASTER_DOWN in
detect_postmaster_down_error(), Pgpool-II will not detect postmaster
shutdown event.

8 years agoAdd Pgpool-II 3.7 release notes.
Tatsuo Ishii [Fri, 6 Oct 2017 00:53:18 +0000 (09:53 +0900)]
Add Pgpool-II 3.7 release notes.

Created by Peng Bo.

8 years agoFix to create results directory beforehand.
Tatsuo Ishii [Thu, 5 Oct 2017 05:59:42 +0000 (14:59 +0900)]
Fix to create results directory beforehand.

8 years agoDocumentation updates for pool_hba enhancements
Muhammad Usama [Wed, 4 Oct 2017 11:19:44 +0000 (16:19 +0500)]
Documentation updates for pool_hba enhancements

8 years agoAdd "role" field to pcp_node_info command.
Tatsuo Ishii [Wed, 4 Oct 2017 08:51:58 +0000 (17:51 +0900)]
Add "role" field to pcp_node_info command.

Role is the server role: one of "primary", "standby", "master" and
"slave".

8 years agoDocumentation update for quorum aware failover feature
Muhammad Usama [Tue, 3 Oct 2017 16:03:09 +0000 (21:03 +0500)]
Documentation update for quorum aware failover feature

The commit also renames the configuration parameter
enable_multiple_failover_requests_from_node to
allow_multiple_failover_requests_from_node

8 years agoImport PostgreSQL 10 parser.
pengbo [Tue, 3 Oct 2017 10:27:49 +0000 (19:27 +0900)]
Import PostgreSQL 10 parser.

8 years agoRevert "Import PostgreSQL 10.0 SQL parser."
pengbo [Sun, 24 Sep 2017 06:25:40 +0000 (15:25 +0900)]
Revert "Import PostgreSQL 10.0 SQL parser."

This reverts commit d9b35160a66b1e9c4c32cd0363e2099c93c968b6.

8 years agoImport PostgreSQL 10.0 SQL parser.
pengbo [Fri, 22 Sep 2017 08:02:04 +0000 (17:02 +0900)]
Import PostgreSQL 10.0 SQL parser.

8 years agoFix bug mistakenly overriding global backend status right after failover.
Tatsuo Ishii [Fri, 22 Sep 2017 02:50:28 +0000 (11:50 +0900)]
Fix bug mistakenly overriding global backend status right after failover.

In [pgpool-general: 5728] it is reported that even if failover
disconnects a backend, the status is changed from "down" to "up" in
certain timing. After debugging I found that the backend status in
pgpool_status was changed to down, then changed again by the first
connection from a client after the failover. This happened in
new_connection(), which in charge of creating a new connection to
backend. It checks the local cached status of the backend and if it's
up, then it tries to connect to the backend. In the particular case,
the failover is triggered by failover_if_affected_tuples_mismatch, so
actually the backend is alive and new_connection() succeeds in
establishing connection to the disconnected backend. Then it override
the global status and pgpool_status file.

Fix is, check if the local backend status is obsoleted. If the global
status does not agree the local status, skip the effort to establish
the connection.

In this report the user uses native replication mode, but I think
similar situation can happen in other mode.

8 years agoFix exit signal handlers to not call ereport.
Tatsuo Ishii [Fri, 22 Sep 2017 01:51:45 +0000 (10:51 +0900)]
Fix exit signal handlers to not call ereport.

There could be a race condition in the exit signal handlers. While
ereport is called in the handler, other interruption could call
ereport again. If ereport calls tz_convert which tries to acquire a
lock, it goes into a deadlock situation. In other word, tz_convert is
not reentrant and should not be used in signal handlers. So I removed
all ereport calls from exit signal handlers.

BTW pcp main calls ereport before the exception handler is
established. This could cause problem of course. So I fixed this
together. See [pgpool-hackers: 2545] for more details.

8 years ago[New feature] Allow specifying the hostnames in pool_hba
Muhammad Usama [Wed, 20 Sep 2017 09:34:49 +0000 (14:34 +0500)]
[New feature] Allow specifying the hostnames in pool_hba

The commit adds the support of hostnames to be used in the address field of
pool_hba records, previously only CIDR address was supported.

Along with allowing the hostnames in address field of the HBA record the commit
also made the following enhancements in the area.

-- pool_hba records are now completely parsed at the loading time and we now
   keep the structured data of records instead of raw record lines,  This
   saves the parsing at every new connection time and however little it may
   be but its a performance enhancement.

-- Enhanced parsing now gives the better descriptive error/log messages.

-- Better handling of auth-options field

8 years agoFixing some paths in 011.watchdoc_quorum_failover test script
Muhammad Usama [Tue, 19 Sep 2017 11:03:22 +0000 (16:03 +0500)]
Fixing some paths in 011.watchdoc_quorum_failover test script

8 years agoFixing coverity scan reported issues in watchdog
Muhammad Usama [Tue, 19 Sep 2017 10:13:35 +0000 (15:13 +0500)]
Fixing coverity scan reported issues in watchdog

CID:1381301 Missing break in switch
CID:1381300 Dereference after null check
CID:1379622 Missing break in switch

8 years agoFix typo in previous commit.
Tatsuo Ishii [Tue, 19 Sep 2017 05:48:16 +0000 (14:48 +0900)]
Fix typo in previous commit.

8 years agoAdd new test 011.watchdoc_quorum_failover.
Tatsuo Ishii [Tue, 19 Sep 2017 01:43:33 +0000 (10:43 +0900)]
Add new test 011.watchdoc_quorum_failover.

Also modify Makefiles and health_check.c so that only when made with
"HEALTHCHECK_DEBUG=1" option to enable the health_check's "fake
failover" functionality which is necessary for the new test.  Always
enabling the functionality is dangerous for a production environment.

8 years agoNew Feature: Quorum and Consensus for backend failover
Muhammad Usama [Mon, 18 Sep 2017 16:11:07 +0000 (21:11 +0500)]
New Feature: Quorum and Consensus for backend failover

Add ability in the Pgpool-II to considers the existence of quorum and seek the
majority node (Pgpool-II nodes part of the watchdog cluster) consensus to
validate the backend node failover request.

The addition of this feature also made some modification in the execution
behaviour of the failover (failover, failback, promote-node) command.

Now Only the Pgpool-II of master watchdog node executes the failover
=====================================================================
The mechanism of synchronised failover across the cluster has given the way to
the failover on master. Now, only the Pgpool-II of master watchdog node performs
the failover, and rest of the Pgpool-II nodes (standby nodes in the watchdog
cluster) re-sync the backend statuses with master after it is finished with
the execution of failover.

No More Failover locks
======================
Since with this new failover mechanism we do not require any synchronisation and
guards against the execution of failover_commands by multiple Pgpool-II nodes,
So the commit removes all the distributed locks from failover function,
This makes the failover simpler and faster.

NODE_QUARANTINE_REQUEST operation
==================================
The commit adds the new kind of backend node operation NODE_QUARANTINE which is
effectively same as the NODE_DOWN, but with node_quarantine the configured
failover_command is not triggered,
Also the NODE_DOWN_REQUEST is automatically converted to the
NODE_QUARANTINE_REQUEST when the failover is requested on the backend node but
is rejected by the watchdog cluster because of missing quorum or consensus.
This means in the absence of quorum or consensus the failed backend nodes are
quarantined and when the quorum and consensus becomes available again the
Pgpool-II performs the failback operation on all the quarantine nodes.
And again when the failback is performed on the quarantine backend node the
failover function does not trigger the failback_command.

Controlling the Failover behaviour.
===================================
The commit adds three new configuration parameters to configure the failover
behaviour from user side.

failover_when_quorum_exists
===========================
When enabled the failover command will only be executed when the watchdog cluster
holds the quorum. And when the quorum is absent and failover_when_quorum_exists
is enabled, the failed backend nodes will get quarantine until the quorum becomes
available again. disabling it will enable the old behaviour of failover commands.

failover_require_consensus
==========================
This new configuration parameter can be used to make sure we get the majority
vote before performing the failover on the node. When failover_require_consensus
is enabled then the failover is only performed after receiving the failover
request from the majority (From at least 50% nodes) of Pgpool-II nodes.
For example: In three nodes cluster the failover will not be performed until at
least two nodes ask to perform the failover on the particular backend node.

It is worthwhile to mention here that failover_require_consensus only works
when failover_when_quorum_exists is enables.

enable_multiple_failover_requests_from_node
===========================================
This parameter works in connection with failover_require_consensus config. When
enabled a single Pgpool-II node can vote for failover multiple times.
For example: In the three nodes cluster if one Pgpool-II node sends the failover
request of particular node twice that would be counted as two votes in favour of
failover and the failover will be performed even if we do not get a vote from
other two nodes.

And when enable_multiple_failover_requests_from_node is disabled, Only the first
vote from each Pgpool-II will be accepted and all other subsequent votes will
be marked duplicate and rejected.
So in that case Pgpool-II will require a majority votes from distinct nodes to
execute the failover.
Again this enable_multiple_failover_requests_from_node only becomes effective
when both failover_when_quorum_exists and failover_require_consensus are enabled.

Controlling the failover: The Coding perspective.
=================================================
Although the failover functions are made quorum and consensus aware but there is
still a way to bypass the quorum conditions, and requirement of consensus.

For this the commit adds new request_details flags to control the
failover behaviour.
Below are the newly added flags values.

REQ_DETAIL_WATCHDOG:
====================
Setting this flag while issuing the failover command will not send the failover
request to the watchdog. But this flag may not be useful in any other place
other than where it is already used.
Mostly this flag can be used to avoid the failover command from going to
watchdog that is already originated from watchdog. Otherwise we may end up in
the infinite loop.

REQ_DETAIL_CONFIRMED:
=====================
Setting this flag will bypass the failover_require_consensus configuration and
immediately perform the failover if quorum is present. This flag can be used to
issue the failover request originated from PCP command.

REQ_DETAIL_UPDATE:
==================
This flag is used for the command where we are failing back the quarantine nodes.
Setting this flag will not trigger the failback_command.

8 years agoAdd timeout functionality to extended-query-test.
Tatsuo Ishii [Sun, 17 Sep 2017 23:04:13 +0000 (08:04 +0900)]
Add timeout functionality to extended-query-test.

Also change the report format of extended-query-test to match with
existing regression test.

8 years agoAdd new test suits.
Tatsuo Ishii [Sun, 17 Sep 2017 10:00:57 +0000 (19:00 +0900)]
Add new test suits.

The new test suit "extended-query-test" is intended to test extended
queries using pgproto command.

8 years agoDeal with OpenSSL 1.1.
Tatsuo Ishii [Mon, 11 Sep 2017 06:11:28 +0000 (15:11 +0900)]
Deal with OpenSSL 1.1.

Patch by me and Usama.

8 years agoAdd debugging aid to check pending message and backend response.
Tatsuo Ishii [Sun, 10 Sep 2017 09:06:47 +0000 (18:06 +0900)]
Add debugging aid to check pending message and backend response.

New function pool_check_pending_message_and_reply() added.  If pending
message kind and backend reply message kind is not inconsistent, it
prints a debug message. Currently the only client of the function is
read_kind_from_backend().

8 years agoAdd debugging/testing aid for health check.
Tatsuo Ishii [Fri, 8 Sep 2017 06:38:08 +0000 (15:38 +0900)]
Add debugging/testing aid for health check.

By creating logidr/backend_down_request file, an artificial backend
error can be raised in heal check. The file should contain:

    node_id[TAB]down

Example:
1 down

If the health check process finds such a line in the file, failover is
triggered.
After this, the line is rewritten to:
1     already_down

to prevent infinite failover requests.

This feature can only be enabled by defining the C compiler definition
in the source src/main/health_check.c around line 75.

8 years agoFix wrong comment.
Tatsuo Ishii [Fri, 8 Sep 2017 04:22:50 +0000 (13:22 +0900)]
Fix wrong comment.

The comment for pool_discard_except_sync_and_ready_for_query() did not
match with what the actual code does.

8 years agoFix table about replicate_select behavior
Yugo Nagata [Tue, 5 Sep 2017 05:52:17 +0000 (14:52 +0900)]
Fix table about replicate_select behavior

8 years agoAdd release-notes of 3.6.6 - 3.2.2.
pengbo [Mon, 4 Sep 2017 07:29:53 +0000 (16:29 +0900)]
Add release-notes of 3.6.6 - 3.2.2.

8 years agoRemove pending message when Close Complete received.
Tatsuo Ishii [Sun, 3 Sep 2017 06:21:34 +0000 (15:21 +0900)]
Remove pending message when Close Complete received.

When parse_before_bind() is called and a close message is sent, a
pending message is created but it is not removed later on. For usual
close message read_kind_from_backend() does not remove the pending
message because CloseComplete() does it later on. But in the code path
for parse_before_bind() gets called, CloseComplete() did not remove
the pending message. This brings loosing sync of pending messages and
messages from backend, which could cause a hang in
read_kind_from_backend().

8 years agoFix Pgpool-II hanging when error occurs in streaming replication mode and extended...
Tatsuo Ishii [Fri, 1 Sep 2017 23:53:19 +0000 (08:53 +0900)]
Fix Pgpool-II hanging when error occurs in streaming replication mode and extended query.

If backend returns ERROR, Pgpool-II reads message from frontend until
a sync message is sent. Previous code assumed next message is sync.
However it is possible that more message coming before the sync
message, it's a low probability though. Fix it to continue reading
messages until the sync message is read.

8 years agoFix wd_authkey bug in that a request to add new node to the clusetr is rejected by...
Yugo Nagata [Fri, 1 Sep 2017 07:27:46 +0000 (16:27 +0900)]
Fix wd_authkey bug in that a request to add new node to the clusetr is rejected by master

This is a bug is due to the following commit.

commit 39de4a11d48b0ca50a4e8a9538265441994298b8
Author: Muhammad Usama <m.usama@gmail.com>
Date:   Thu Mar 30 02:00:49 2017 +0500

    Enhancing the handling of split-brain scenario by the watchdog.

This changed the definition of tv_sec that is used to check wd_authkey so
that this was affected by the clock of OS. So, if there is a lag between
two nodes' clocks, the wd_authkey check fails.

8 years agoFix load balance test driver.
Tatsuo Ishii [Fri, 1 Sep 2017 04:54:33 +0000 (13:54 +0900)]
Fix load balance test driver.

Some tests only for native replication mode was executed in streaming
replication mode as well.

8 years agoAdd "slony mode" to pgpool_setup.
Tatsuo Ishii [Fri, 1 Sep 2017 04:19:27 +0000 (13:19 +0900)]
Add "slony mode" to pgpool_setup.

8 years agoChange master_slave_sub_mode default to 'stream'.
Tatsuo Ishii [Fri, 1 Sep 2017 02:20:14 +0000 (11:20 +0900)]
Change master_slave_sub_mode default to 'stream'.

This is necessary since the default value for the
pool_config_variable.c is STREAM_MODE.

8 years agoFix not working slony mode in extended query.
Tatsuo Ishii [Thu, 31 Aug 2017 12:32:33 +0000 (21:32 +0900)]
Fix not working slony mode in extended query.

When response returned from backend, in progress flag was not reset in
slony mode, which cause waiting for next message from backend in vain.

8 years agoFix ancient bug of stream write modules.
Tatsuo Ishii [Tue, 29 Aug 2017 06:28:35 +0000 (15:28 +0900)]
Fix ancient bug of stream write modules.

- Fix bug with pool_write_noerror() when requested length exceeds
  remaining write buffer size. This could lead to a buffer overrun
  problem, which has not been reported in the field as far as I know
  though.

- When write buffer is full, pool_flush_it() is called, which could
  write data to socket in the middle of message. I found this by using
  following pgproto data. To fix the problem directly write requested
  data if the write buffer is going to be full.

  'P' "" "SELECT * FROM pgbench_accounts LIMIT 100" 0
  'B' "" "" 0 0 0
  'E' "" 0
  'S'
  'Y'
  'X'

- Enhance performance of pool_unread(). When retrieving large number
  of rows in streaming replication and extended query, pool_unread is
  very slow because it needs to memmove large number of bytes in the
  read buffer. This happens in read_kind_from_backend() since it uses
  pool_unread() to check 'A' packet. To optimize the situation, modify
  pool_unread(). If there's enough room in front of cp->po, copies the
  data there to avoid memmove.

8 years agoSome miscellanies small fixes in regression test scripts
Muhammad Usama [Thu, 24 Aug 2017 18:21:46 +0000 (23:21 +0500)]
Some miscellanies small fixes in regression test scripts

8 years agoFix documentation about load-balancing
Yugo Nagata [Thu, 24 Aug 2017 09:31:44 +0000 (18:31 +0900)]
Fix documentation about load-balancing

8 years agoChange Makefile to copy figure files to tarball.
pengbo [Mon, 21 Aug 2017 03:52:07 +0000 (12:52 +0900)]
Change Makefile to copy figure files to tarball.

8 years agoAdd figures for document.
pengbo [Mon, 21 Aug 2017 01:37:39 +0000 (10:37 +0900)]
Add figures for document.

8 years agoAdd new document of "Pgpoo-II + Watchdog Setup Example".
pengbo [Mon, 21 Aug 2017 01:35:29 +0000 (10:35 +0900)]
Add new document of "Pgpoo-II + Watchdog Setup Example".

8 years agoUpdate pgpool_setup manual.
Tatsuo Ishii [Thu, 17 Aug 2017 08:26:20 +0000 (17:26 +0900)]
Update pgpool_setup manual.

Logical replication mode is supported.

8 years agoFist cut patch to deal with logical replication.
Tatsuo Ishii [Thu, 17 Aug 2017 07:10:24 +0000 (16:10 +0900)]
Fist cut patch to deal with logical replication.

8 years agoFix infinite loop while resetting connection.
Tatsuo Ishii [Wed, 16 Aug 2017 05:54:44 +0000 (14:54 +0900)]
Fix infinite loop while resetting connection.

If there was an error, bogus sent_message is registered and it causes
an infinite loop because removing the bogus list does not work in the
current implementation. Solution is, not to register bogus sent
message in the error case.

8 years agoFix core dump and mishandling of temp tables.
Tatsuo Ishii [Wed, 16 Aug 2017 04:40:46 +0000 (13:40 +0900)]
Fix core dump and mishandling of temp tables.

Fix two issues:

1) Protect pool_remove_sent_message() and pool_get_sent_message()
   against null parameters.

2) Fix bug while determining if the created table is temporary or not.