From c2ceed29098369b3b52f02affe5a0123bdc0758e Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 19 Jul 2024 20:43:03 +0900 Subject: [PATCH] Fix dynamic process management. Calculation of pooled_connection, which is used by the process eviction algorithm, was not correct. The number always resulted in max_pool. Also more comments are added. Discussion: [pgpool-hackers: 4490] Issue with dynamic process management https://www.pgpool.net/pipermail/pgpool-hackers/2024-July/004491.html Backpatch-through: master, 4.5, 4.4 --- src/protocol/child.c | 5 +++++ src/protocol/pool_connection_pool.c | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/protocol/child.c b/src/protocol/child.c index 0b6a2389c..c12a5a2c1 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -477,7 +477,12 @@ do_child(int *fds) /* Mark this connection pool is not connected from frontend */ pool_coninfo_unset_frontend_connected(pool_get_process_context()->proc_id, pool_pool_index()); + + /* + * Update number of established connections in the connection pool. + */ update_pooled_connection_count(); + accepted = 0; connection_count_down(); if (pool_config->log_disconnections) diff --git a/src/protocol/pool_connection_pool.c b/src/protocol/pool_connection_pool.c index ae2ac735c..c0d65c39b 100644 --- a/src/protocol/pool_connection_pool.c +++ b/src/protocol/pool_connection_pool.c @@ -1084,12 +1084,17 @@ close_all_backend_connections(void) POOL_SETMASK(&oldmask); } -void update_pooled_connection_count(void) +/* + * Return number of established connections in the connection pool. + * This is called when a client disconnects to pgpool. + */ +void +update_pooled_connection_count(void) { int i; int count = 0; POOL_CONNECTION_POOL *p = pool_connection_pool; - for (i = 0; i < pool_config->max_pool; i++) + for (i = 0; i < pool_config->max_pool; i++, p++) { if (MAIN_CONNECTION(p)) count++; -- 2.39.5