public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tatsuo Ishii <[email protected]>
To: [email protected]
Subject: pgpool: Fix to send sync message to necessary backend node.
Date: Thu, 30 Apr 2026 23:30:21 +0000
Message-ID: <[email protected]> (raw)

Fix to send sync message to necessary backend node.

This is a follow-up commit for a350afd70.

The commit failed to send sync messages to necessary backend node if
previous query was generated by do_query. When do_query generates
extended queries outsiede an explicit transaction, it does not send
sync message because if it sends, unnamed portal may be closed. If
nothing happen until session ends, when queries in reset_query_list
are executed, typically including DISCARD ALL, FATAL error occurs
(remeber that PostgreSQL opens a transaction while executing extended
queries until sync message received).

backend pid: 62624 statement: "DISCARD ALL" message: "DISCARD ALL cannot run inside a transaction block"
2026-04-29 01:00:58.288: pgbench pid 62605: WARNING:  packet kind of backend 1 ['C'] does not match with main/majority nodes packet kind ['E']
2026-04-29 01:00:58.288: pgbench pid 62605: FATAL:  failed to read kind from backend
2026-04-29 01:00:58.288: pgbench pid 62605: DETAIL:  kind mismatch among backends. Possible last query was: "DISCARD ALL" kind details are:0[E: DISCARD ALL cannot run inside a transaction block] 1[C]
2026-04-29 01:00:58.288: pgbench pid 62605: HINT:  check data consistency among db nodes

This was observed in 120.memory_leak_extended_memqcache test.

Commit a350afd70 allows to send sync messages only to necessary
backend nodes. Any queries comes from clients are tracked for this
purpose. However it forgot to the case when do_query generates
internal queries. We should have tracked such that queries, so that a
sync message is issued to the server which do_query sent to, when the
client sends a sync message.

For this purpose I add a new member "bool
pending_sync_map[MAX_NUM_BACKENDS]" to session_context, which a node
id is set to when do_query sends a extended query to backend. Note
that it is set only when do_query is called outside an explicit
transaction. In add_sync_pending_message, which is called when client
sends a sync message, we check the map and set sync_map accordingly so
that subsequent call to SimpleForwardToBackend will send sync message
to the necessary backend node.

The commit also includes some tweaks to regression tests.

120.memory_leak_extended_memqcache: explicitely set backend_weight0 =
0 so that the load balance node is always 1. If load balance node is
0, the error above will not happen because when clients sends sync
message, it is surely forwarded to 0, which do_query previously sent
queries.

039.log_backend_messages: by the effect of the patch, trace of sending
to node 0 is now included in the expected.s. This is normal.

Author: Tatsuo Ishii <[email protected]>
Discussion: https://www.postgresql.org/message-id/20260430.191509.901412343921235299.ishii%40postgresql.org
Backpatch-through: master only

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=da7ec78f35d24acb8fb575216e46f8e471394...

Modified Files
--------------
src/include/context/pool_session_context.h                |  6 ++++++
src/protocol/pool_process_query.c                         |  4 ++++
src/protocol/pool_proto_modules.c                         | 15 +++++++++++++++
.../regression/tests/039.log_backend_messages/expected.s  |  1 +
.../tests/120.memory_leak_extended_memqcache/test.sh      |  2 ++
5 files changed, 28 insertions(+)



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgpool: Fix to send sync message to necessary backend node.
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox