Fix MAIN_NODE macro (actually pool_virtual_main_db_node_id()).
authorTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 21 Jun 2024 05:21:15 +0000 (14:21 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 21 Jun 2024 05:21:15 +0000 (14:21 +0900)
commitd699b8f129c70f434c525208b58bcc09da36f3a3
treef78d8bfb37c28b8759a55d3b24c16bd5d0620de7
parentd6f5b11516887088cbfe3ca6aa712f529b01b6c9
Fix MAIN_NODE macro (actually pool_virtual_main_db_node_id()).

The macro used to REAL_MAIN_NODE_ID if there's no session context.
This is wrong since REAL_MAIN_NODE_ID can be changed any time when
failover/failback happens.  Suppose REAL_MAIN_NODE_ID ==
my_main_node_id == 1. Then due to failback, REAL_MAIN_NODE_ID is
changed to 0. Then MAIN_CONNECTION(cp) will return NULL and any
reference to it will cause segmentation fault. To prevent the issue we
should return my_main_node_id instead.

Discussion: https://www.pgpool.net/pipermail/pgpool-general/2024-June/009205.html
Backpatch-through: V4.1
src/context/pool_query_context.c