Fix errors/hung up when load_balance_mode is off.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 2 Apr 2024 10:30:27 +0000 (19:30 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 2 Apr 2024 10:30:27 +0000 (19:30 +0900)
commitda2b555e75444b50a949f181dbfeeabb3bc0a076
treea3048cc5f38d7c9cd3d2a36e796201251924f78d
parentc28e448d300a87ae36d02c8dc4cb4779db605856
Fix errors/hung up when load_balance_mode is off.

Commit: 3f3c1656 Fix statement_level_load_balance with BEGIN etc.

brought errors/hung up when load_balance_mode is off, primary node id
is not 0 and queries are BEGIN etc.

pool_setall_node_to_be_sent() checked if the node is primary. If not,
just returned with empty where_to_send map which makes
set_vrtual_main_node() not to set
query_context->virtual_main_node_id. As a result, MAIN_NODE macro
(it's actually pool_virtual_main_db_node_id()) returns
REAL_MAIN_NODE_ID, which is 0 if node 0 is alive (this should have
been primary node id).

Following simple test reveals the bug.

(1) create a two-node cluster using pgpool_setup

(2) shutdown node 0 and recover node 1 (pcp_recovery_node 0). This
makes node 0 to be standby, node 1 to be primary.

(3) add followings to pgpool.conf and restart whole cluster.

load_balance_mode = off
backend_weight1 = 0

(4) type "begin" from psql. It gets stuck.

Bug found and analyzed by Emond Papegaaij.
Discussion: https://www.pgpool.net/pipermail/pgpool-general/2024-March/009113.html
Backpatch-through: v4.1
src/context/pool_query_context.c