pgpool2.git
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.

7 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.

7 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.

7 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.

7 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.

7 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.

7 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.

7 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.

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

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

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

7 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.

7 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".

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

7 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.

7 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.

7 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.

7 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.

7 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.

7 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.

7 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

7 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".

7 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

7 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.

8 years agoFix failing "make dist".
Tatsuo Ishii [Tue, 15 Aug 2017 23:13:58 +0000 (08:13 +0900)]
Fix failing "make dist".

doc.ja/src/Makefile seemed to be broken.

8 years agoFix ancient bug of pool_unread.
Tatsuo Ishii [Tue, 15 Aug 2017 01:25:35 +0000 (10:25 +0900)]
Fix ancient bug of pool_unread.

When realloc() is called in pool_unread(), it did not update the
buffer size.  This could cause variety of memory corruption and
unexpected data reading from backend. The reason why we did not found
that is, probably recently Pgpool-II starts extensively to use
pool_unread().

8 years agoFix handling of empty queries.
Tatsuo Ishii [Sun, 13 Aug 2017 07:16:02 +0000 (16:16 +0900)]
Fix handling of empty queries.

When empty query (empty string or all comment query) is sent, command
complete message was returned to frontend.  This is not correct. An
empty query response should be returned to frontend.

Per bug328.

8 years agoFix query cache bug with streaming replication mode and extended query case.
Tatsuo Ishii [Wed, 9 Aug 2017 07:23:57 +0000 (16:23 +0900)]
Fix query cache bug with streaming replication mode and extended query case.

- Commit cache upon receiving a command complete message, rather than
  upon receiving a "ready for query" message, except in an explicit
  transaction. Doing it upon the receiving ready for query message had
  serious problem with streaming replication mode and extended query
  case, because it is possible that multiple selects get executed
  before the ready for query message arrives. The older way cannot
  handle it because it only looked at the last command before the
  ready for query message.

- When query cache hits, do not forward cached messages to frontend in
  Execute(). Instead "inject" cached messages into the backend
  buffer. This is better than older way since it respects the pending
  messages and necessary treatment while receiving messages including
  parse complete and bind complete. Note that now the cached messages
  are returned only after a flush or a sync message sent. Before they
  are returned immediately while executing execute message. The newer
  behavior more resembles to the ordinary messages (no cached message).

  To avoid adding cache by the injected messages twice,
  "skip_cache_commit" flags is introduced in query context. The flag
  is set to true in Execute() if the injection
  happens. handle_query_cache() checks the flag and skips registering
  query results to the query cache if the flag is true. The flags is
  set to false if cache is not hit.

- Introduce new function pool_at_command_success() which were the code
  fragments in ReadyForQuery() to take care misc treatments including
  unsettling writing transaction flags in CommandComplete() as
  well. Also ReadyForQuery() now calls it.

- Fix memory leak. If a close request is not issued (this is typically
  the case when unnamed statements/portals used), temp cache buffer
  remains until the session end (at the session end, the memory for
  the buffer will be freed because they are in the session context
  memory. Thus only long running sessions hit the bug). Before we
  prepared new buffer when query cache committed. Now do not create
  new buffer there. Rather create a buffer when memqcache_register
  gets called if the temp buffer is not allocated yet.

8 years agoFix memory leak with streaming replication mode/extended query case.
Tatsuo Ishii [Thu, 3 Aug 2017 08:03:12 +0000 (17:03 +0900)]
Fix memory leak with streaming replication mode/extended query case.

When Close Complete message arrives, Pgpool-II did not remove sent
message because at this point the pending message, which includes info
to remove the sent message, has been already removed by
read_kind_from_backend(). To fix the problem read_kind_from_backend()
does not remove the pending message for Close Complete and let
CloseComplete() to extract and remove the pending message to remove
the sent message data.

Per bug#324.

8 years agoFix Java program in 005.regression test.
Tatsuo Ishii [Thu, 3 Aug 2017 03:41:40 +0000 (12:41 +0900)]
Fix Java program in 005.regression test.

The program forgot issue commit and always ended up with ABORT.  This
does not affect the test result itself, it would be better to finish
the test with commit, rather than ABORT.

8 years agoFix bug #303.
Tatsuo Ishii [Thu, 3 Aug 2017 02:52:24 +0000 (11:52 +0900)]
Fix bug #303.

When failover is triggered by worker process, it is possible that
wrong DB node could failover. This is due to the db_node_id member in
the POLL_CONNECTION structure is not initialized in the process (in
child process the member is properly initialized). To solve the
problem, add new function pool_set_db_node_id() to set the structure
member variable and call it inside
make_persistent_db_connection(). For this purpose also the new
parameter "db_node_id" is added to make_persistent_db_connection and
friends.

8 years agoFix starting unnecessary transaction when SET command is issued.
Tatsuo Ishii [Mon, 31 Jul 2017 08:29:27 +0000 (17:29 +0900)]
Fix starting unnecessary transaction when SET command is issued.

In streaming replication mode, there's no point to start internal
transaction when SET command is issued. The existing behavior is
harmless but waste of CPU cycle.

8 years agoFix bug with memory leak tests and add new memory leak test.
Tatsuo Ishii [Fri, 28 Jul 2017 08:24:13 +0000 (17:24 +0900)]
Fix bug with memory leak tests and add new memory leak test.

They did not correctly detect the memory leak.

Also add new memory leak test for extended query/query cache.

8 years agoFix Pgpool-II hung up bug or other errors in error case in extended query in replicat...
Tatsuo Ishii [Wed, 26 Jul 2017 23:00:32 +0000 (08:00 +0900)]
Fix Pgpool-II hung up bug or other errors in error case in extended query in replication mode.

In extended query in streaming replication mode, responses supposed to
be returned from backend is managed by the pending messages. However,
if an error response returned from backend, the sequence of returned
message from backend is not what we expect. The mismatch was partially
solved in the code but it turned out they were not sufficient.

The cause of hung is basically when an error response is received from
backend before frontend sends 'S' (sync) message. If backend detects
errors while doing extended query, it does not return any response
until it receives sync message. Of course at this point frontend is
expected to send sync message to Pgpool-II, but it may not reach to
the socket of Pgpool-II. So it is possible that Pgpool-II does not
notice the sync message is coming, and does not forward the sync
message to backend. As a result, nothing goes on and Pgpool-II is
stuck. To fix the problem following modifications are made in this
commit:

- When error response is received from backend, after forwarding the
  error response to frontend, remove all pending messages and backend
  message buffer data except POOL_SYNC pending message and ready for
  query (before we removed all messages including ready for query,
  which is apparently wrong).  If sync message is not received yet,
  call ProcessFrontendResponse() to read data from frontend. This
  ensures eliminating the expectation of receiving messages from backend
  in normal cases, and receiving the sync message from frontend.

- When 'S' (sync) message is received from frontend, forward it to
  backends and wait till "ready for query" message is received from
  the backends. This ensures Pgpool-II to receive the read for query
  message and goes into the proper sync point.

- It is still possible after receiving the ready for query message,
  different messages arrived from each backend. If the numbers of
  messages are same, "kind mismatch" error will occur. If the number
  of messages are different, it is possible that Pgpool-II is stuck,
  because read_kind_from_backend() will wait till a message coming
  from backend. To fix this if either load balance node or primary
  node returns 'Z' (ready for query), try to skip messages on the
  other node. This is done in read_kind_from_backend(). See comments
  around in line 3391 of pool_process_query.c for more details.

Other fixes in this commit.

- Do not send intended error query to backend in streaming replication
  mode in ErrorResponse3(). This is not necessary in streaming
  replication mode.

- Fix pool_virtual_master_db_node_id() to return the
  virtual_master_node_id only when query is in progress and query
  context exists. Before in progress state was not checked and may
  return bogus node id.

8 years agoFix document typo.
pengbo [Wed, 26 Jul 2017 00:31:30 +0000 (09:31 +0900)]
Fix document typo.

8 years agoAdd Pgpool-II + Watchdog configuration example.
pengbo [Tue, 25 Jul 2017 07:51:49 +0000 (16:51 +0900)]
Add Pgpool-II + Watchdog configuration example.

8 years agoFix Pgpool-II document typo.
pengbo [Tue, 25 Jul 2017 07:38:31 +0000 (16:38 +0900)]
Fix Pgpool-II document typo.

8 years agoAllow make dist to include pgpool.service
Yugo Nagata [Thu, 20 Jul 2017 05:55:31 +0000 (14:55 +0900)]
Allow make dist to include pgpool.service

8 years agoAdd log after health check retrying succeeds.
Tatsuo Ishii [Thu, 13 Jul 2017 06:44:41 +0000 (15:44 +0900)]
Add log after health check retrying succeeds.

Previously only health check retry logs were produced. So it was not
clear if the retry succeeded or not in the end.

8 years agoAdd more settings to Aurora example.
Tatsuo Ishii [Thu, 13 Jul 2017 05:26:18 +0000 (14:26 +0900)]
Add more settings to Aurora example.

8 years agoAdd neccessary setting for health check retry in the Aurora example.
Tatsuo Ishii [Thu, 13 Jul 2017 04:53:41 +0000 (13:53 +0900)]
Add neccessary setting for health check retry in the Aurora example.

8 years agoAdd Aurora setting documentation in Japanese.
Tatsuo Ishii [Wed, 12 Jul 2017 08:35:18 +0000 (17:35 +0900)]
Add Aurora setting documentation in Japanese.

8 years agoAdd Aurora setting example.
Tatsuo Ishii [Wed, 12 Jul 2017 08:01:17 +0000 (17:01 +0900)]
Add Aurora setting example.

8 years agoAdd description about "ALWAYS_MASTER" flag.
Tatsuo Ishii [Wed, 12 Jul 2017 07:20:30 +0000 (16:20 +0900)]
Add description about "ALWAYS_MASTER" flag.

8 years agoFix indentation.
Tatsuo Ishii [Wed, 12 Jul 2017 07:12:16 +0000 (16:12 +0900)]
Fix indentation.

8 years agoSupport AWS Aurora.
Tatsuo Ishii [Wed, 12 Jul 2017 06:36:59 +0000 (15:36 +0900)]
Support AWS Aurora.

Add new backend flag "ALWAYS_MASTER" to control the primary node
detecting logic. Since we cannot use pg_is_in_recovery() in Aurora, we
assign the new flag to a backend which is specified as "writer" in
Aurora. Since Aurora always use the same hostname for the master (it's
called "writer"), find_primary_node() just returns the node id which
has ALWAYS_MASTER flag on.

Other than that, user can use the streaming replication mode with
Aurora. Notice that replication delay cannot be performed in Aurora,
sr_check_period should be always 0.

8 years agoAdd 3.6.5 - 3.2.21 release-notes.
pengbo [Mon, 10 Jul 2017 07:19:07 +0000 (16:19 +0900)]
Add 3.6.5 - 3.2.21 release-notes.

8 years agoFix for [pgpool-hackers: 2400] Garbage output
Muhammad Usama [Thu, 6 Jul 2017 19:21:19 +0000 (00:21 +0500)]
Fix for [pgpool-hackers: 2400] Garbage output

Mostly the log messages fixes and few code cleanups.

8 years agoImporting the latest changes in the MemoryManager API from PostgreSQL code.
Muhammad Usama [Thu, 29 Jun 2017 15:30:59 +0000 (20:30 +0500)]
Importing the latest changes in the MemoryManager API from PostgreSQL code.

Pgpool-II has borrowed the MemoryManager from PostgreSQL source and recently
there have been some performance updates made to the PostgreSQL's
memory manager, from which Pgpool-II can also benefit from.
This need was identified by the reporter of issue: "315: High CPU usage when
commiting large transactions and using in (shared) memory cache"

8 years agoFixing 0000306: Pgpool steals back MASTER status
Muhammad Usama [Sat, 24 Jun 2017 18:04:52 +0000 (23:04 +0500)]
Fixing 0000306: Pgpool steals back MASTER status

This is next in the series of the patches, and hopefully the last one to fix
bug where the unworthy master node gets its way while the watchdog cluster
recovers from the split - brain syndrome. It's a relatively small patch that
makes a little tweak in the area which handles the split-brain when the
split-brain is detected by one of the standby node.

8 years agoFixing: [pgpool-hackers: 2390] Problems with the relative paths in daemon mode
Muhammad Usama [Wed, 21 Jun 2017 12:54:04 +0000 (17:54 +0500)]
Fixing: [pgpool-hackers: 2390] Problems with the relative paths in daemon mode

Pgpool-II does all the path related calculations based on CWD
(current working directory) which only works as expected and intended
until the CWD does not change.
But in daemon mode the first thing Pgpool-II do after becoming the daemon
process is, it changes it's CWD to system root ("/") and after that all the
relative paths becomes invalid.
This means in daemon mode if the pgpool.conf file is specified as an argument
using the relative path, Pgpool-II will not be able to find the pool_passwd
or other required file whose location depends on the location of pgpool.conf
file, and will eventually fail to start, or even worst may read/write
some wrong file.

The solution to this is to convert the relative path of the pgpool.conf and
all file paths provided in the argument list to the Pgpool-II to the absolute
paths at the startup and later use those absolute paths for all path related
calculations.

Apart from using the absolute paths for pgpool.conf, pcp.conf and pool_hba.conf
files, The commit also modifies the behaviour of pid_file_name configuration
parameter, when the relative path is used for this config in pgpool.conf,
that relative path is considered with relative to the pgpool.conf path,
instead of the current working directory.

8 years agoAdjust function name change in PostgreSQL 10 dev head.
Tatsuo Ishii [Mon, 19 Jun 2017 07:40:06 +0000 (16:40 +0900)]
Adjust function name change in PostgreSQL 10 dev head.

pg_current_wal_location -> pg_current_wal_lsn
pg_last_wal_replay_location -> pg_last_wal_replay_lsn

8 years agoFix a posible hang with streaming replication and extended protocol
Yugo Nagata [Fri, 9 Jun 2017 01:47:44 +0000 (10:47 +0900)]
Fix a posible hang with streaming replication and extended protocol

This hang occured under a certain condition. The following is an example.

- pgpool.conf is configured so that all read queries are sent to the standby.
- First, issue a writing query in a transaction block
- After commiting the transaction, issue a select query.
- When processing the query, send Describe (statement) message just after Parse.

Without using JDBC, we can reproduce the problem by pgproto with the followeing messages.
--------------------------------------------

'Q' "DROP TABLE IF EXISTS test_tbl"
'Y'
'Q' "CREATE TABLE test_tbl(i int)"
'Y'
'Q' "INSERT INTO test_tbl VALUES(1)"
'Y'

'P' "" "BEGIN" 0
'B' "" "" 0 0 0
'E' "" 0
'S'
'Y'

'P' "" "INSERT INTO test_tbl VALUES(1)" 0
'B' "" "" 0 0 0
'E' "" 0
'S'
'Y'

'P' "" "COMMIT" 0
'B' "" "" 0 0 0
'E' "" 0
'S'
'Y'

'P' "S_1" "SELECT * FROM test_tbl" 0
'D' 'S' "S_1"
'B' "C_1" "S_1" 0 0 0
'E' "C_1" 0
'S'
'Y'

'X'
---------------------------------------------

In practice, such Describe message can be sent by JDBC when executing PreparedStatement
with a parameter of timestamp type more than prepare_threshold times. In addition,
queries can be issued outside of a transaction block when autocommit is enabled.

When a writing query is issued in a transaction block, writing_transaction flag
is set, but after commiting the transaction this flag is not unset. The problem
is that parse_before_bind() is always called when writing_transaction is set.

Alhough Parse of the select and Describe following are sent to standby
due to load balancing, another Parse and Bind, Execute are to be sent to
primary due to parse_before_bind.

In this situation, Pgpool-II waits for the responces of Describe from
standby forever because any messages after Describe is not sent to the
standby and any responce is not returned.

To fix it, parse_before_bind() should be called only if we are in a transaction
block so that we can send Bind and Execute to the right backend.

8 years agoRemove unnecessary log messages.
Muhammad Usama [Wed, 7 Jun 2017 10:00:47 +0000 (15:00 +0500)]
Remove unnecessary log messages.

See [pgpool-hackers: 2378] Debug log

8 years agoFix Pgpool-II hang when used by erlang applications.
Tatsuo Ishii [Wed, 7 Jun 2017 08:27:54 +0000 (17:27 +0900)]
Fix Pgpool-II hang when used by erlang applications.

Erlang client sends "Describe" message followed by "Flush".  So the
backend returns "Row description." However Pgpool-II forgets to reset
the query in progress flag upon receiving "Row description" message,
then Pgpool-II keeps on waiting for response from backend. This is the
cause of erlang client hanging.

Fix is, just reset the query in progress flag upon receiving "Row
description" message. Same thing can be said to "no data" message.

Discussion: [pgpool-general: 5555]
http://www.pgpool.net/pipermail/pgpool-general/2017-June/005613.html

8 years agoFix bug with sending bind message to wrong target node.
Tatsuo Ishii [Wed, 7 Jun 2017 04:53:13 +0000 (13:53 +0900)]
Fix bug with sending bind message to wrong target node.

When a close portal message received, Pgpool-II forwards it to both
primary and load balance node in streaming replication mode. Later on
a close complete message returned from backend, and
read_kind_from_backend gets called, then it calls
pool_pending_message_query_context_dest_set, which rewrites
where_to_send map in the current query context accordingly. If a bind
message using the same query is received, it will be forwarded to both
primary and load balance node because the where_to_send map was
rewritten so. Unfortunately, the prepared statement might not exist on
primary node, if the query was parsed only on the load balance
node. So we get an error.

Fix is, restoring the where_to_send map after processing the close
complete message. For this sake, where_to_send map back up area is
added to session context. Also new flag need_to_restore_where_to_send
is added. Those new data is handled inside
pool_pending_message_query_context_dest_set. The where_to_send map is
restored in pool_unset_query_in_progress. There were several places
which do not call pool_unset_query_in_progress. They are also fixed to
call it.

Per bug #314.
https://www.pgpool.net/mantisbt/view.php?id=314

To reproduce the problem, following pgproto data can be used. Also you
need to set the weight parameter on primary to 0 and standby to 1 to reliably
reproduce the problem.

'P' "S_1" "SELECT 1" 0
'B' "C_1" "S_1" 0 0    0
'E' "C_1" 0
'S'
'Y'

'C' 'P' "C_1"

'B' "C_2" "S_1" 0 0 0
'E' "C_2" 0
'S'
'Y'

'X'

8 years agoAllow to fork new health check process when it exits.
Tatsuo Ishii [Wed, 31 May 2017 07:14:46 +0000 (16:14 +0900)]
Allow to fork new health check process when it exits.

8 years agoAdd new group "health_check" to PGPOOL SHOW command doc.
Tatsuo Ishii [Wed, 31 May 2017 06:50:54 +0000 (15:50 +0900)]
Add new group "health_check" to PGPOOL SHOW command doc.

8 years agoAdd description about per node health check parameters.
Tatsuo Ishii [Wed, 31 May 2017 06:40:07 +0000 (15:40 +0900)]
Add description about per node health check parameters.

8 years agoFix descriptions of white/black_memcache_table_list.
Tatsuo Ishii [Wed, 31 May 2017 05:58:51 +0000 (14:58 +0900)]
Fix descriptions of white/black_memcache_table_list.

They are far from actual implementations.
See [pgpool-general: 5479] for more details.