Fix dynamic process management.
authorTatsuo Ishii <ishii@postgresql.org>
Fri, 19 Jul 2024 11:43:03 +0000 (20:43 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Fri, 19 Jul 2024 11:43:03 +0000 (20:43 +0900)
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
src/protocol/pool_connection_pool.c

index 0b6a2389c05f5af6ada579706ce20213d874961a..c12a5a2c1b2deef8b99e6e980e3879678f6d84c4 100644 (file)
@@ -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)
index ae2ac735c0c128606ea5122e76fd1e8600f554fc..c0d65c39bfbd262f5f0217d5f06d84da11cda331 100644 (file)
@@ -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++;