Add new field "load_balance_node" to "SHOW pool_pools" and pcp_proc_info.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 23 Jul 2023 21:04:27 +0000 (06:04 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 23 Jul 2023 21:07:57 +0000 (06:07 +0900)
The new field is "1" if pgpool process is connected by a client and
the session uses the backend id as a load balance node. Users can
execute the commands to find out if there's any session that uses the
backend as the load balance node. If so, shutting down the backend may
cause session disconnection.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-July/004353.html

Note: I accidentally pushed only doc part of the commit in 4658f84870e8edfd39920f273bab1a12d71d8986.
This is a follow-up commit for actual codes.

src/include/pcp/libpcp_ext.h
src/tools/pcp/pcp_frontend_client.c
src/utils/pool_health_check_stats.c
src/utils/pool_process_reporting.c

index 2d86dd304719dd92aa78055a33aebe56356e5b0e..7d2ab70db9f32133a1ac95d9d1251ab9a7492c04 100644 (file)
@@ -262,6 +262,7 @@ typedef struct
        char            pool_backendpid[POOLCONFIG_MAXCOUNTLEN + 1];
        char            pool_connected[POOLCONFIG_MAXCOUNTLEN + 1];
        char            status[POOLCONFIG_MAXPROCESSSTATUSLEN + 1];
+       char            load_balance_node[POOLCONFIG_MAXPROCESSSTATUSLEN + 1];
 }                      POOL_REPORT_POOLS;
 
 /* version struct */
index 8799b9889b024060b6e5bea1e92601d6bceddf05..576bd8ce13aae180a2bba94d90dee62d9420de1e 100644 (file)
@@ -721,13 +721,14 @@ output_procinfo_result(PCPResultInfo * pcpResInfo, bool all, bool verbose)
                "Database", "Username", "Start time", "Client connection count",
                "Major", "Minor", "Backend connection time", "Client connection time",
                "Client idle duration", "Client disconnection time", "Pool Counter", "Backend PID",
-               "Connected", "PID", "Backend ID", "Status"
+               "Connected", "PID", "Backend ID", "Status", "Load balance node"
        };
        const char *types[] = {
                "s", "s", "s", "s",
                "s", "s", "s", "s",
                "s", "s", "s", "s",
-               "s", "s", "s", "s"
+               "s", "s", "s", "s",
+               "s"
        };
 
 
@@ -735,7 +736,7 @@ output_procinfo_result(PCPResultInfo * pcpResInfo, bool all, bool verbose)
                format = format_titles(titles, types, sizeof(titles)/sizeof(char *));
        else
        {
-               format = "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n";
+               format = "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n";
        }
 
        for (i = 0; i < array_size; i++)
@@ -764,7 +765,8 @@ output_procinfo_result(PCPResultInfo * pcpResInfo, bool all, bool verbose)
                           pools->pool_connected,
                           pools->pool_pid,
                           pools->backend_id,
-                          pools->status);
+                          pools->status,
+                          pools->load_balance_node);
        }
        if (printed == false)
                printf("No process information available\n\n");
index b062ed25dfb77ad07ca01e21c676aaea527e6e43..f717b1a3e6d2a569e98f0f4f2634ded2b9fc0370 100644 (file)
@@ -84,7 +84,8 @@ int * pool_report_pools_offsets(int *n)
                offsetof(POOL_REPORT_POOLS, pool_counter),
                offsetof(POOL_REPORT_POOLS, pool_backendpid),
                offsetof(POOL_REPORT_POOLS, pool_connected),
-               offsetof(POOL_REPORT_POOLS, status)
+               offsetof(POOL_REPORT_POOLS, status),
+               offsetof(POOL_REPORT_POOLS, load_balance_node)
        };
 
        *n = sizeof(offsettbl)/sizeof(int);
index 5b22ab20a1cbe3496432ab7b056d2dd20db21d00..c7c4b0245cd383ed7a7c0d5ad8f56c5e8b3061ff 100644 (file)
@@ -1552,6 +1552,7 @@ get_pools(int *nrows)
                for (pool = 0; pool < pool_config->max_pool; pool++)
                {
                        int idle_duration = pi->connection_info[pool * MAX_NUM_BACKENDS].client_idle_duration;
+                       int load_balancing_node_id = pi->connection_info[pool * MAX_NUM_BACKENDS].load_balancing_node;
                        int cliet_idle_time = pool_config->client_idle_limit;
 
                        if (pool_config->client_idle_limit > 0)
@@ -1675,6 +1676,10 @@ get_pools(int *nrows)
                                                *(pools[lines].status) = '\0';
                                }
 
+                               if (pi->connection_info[poolBE].connected && backend_id == load_balancing_node_id)
+                                       StrNCpy(pools[lines].load_balance_node, "1", POOLCONFIG_MAXPROCESSSTATUSLEN);
+                               else
+                                       StrNCpy(pools[lines].load_balance_node, "0", POOLCONFIG_MAXPROCESSSTATUSLEN);
                                lines++;
                        }
                }
@@ -1694,7 +1699,8 @@ pools_reporting(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
        static char *field_names[] = {"pool_pid", "start_time", "client_connection_count", "pool_id",
                                                                  "backend_id", "database", "username", "backend_connection_time",
                                                                  "client_connection_time", "client_disconnection_time", "client_idle_duration",
-                                                                 "majorversion", "minorversion", "pool_counter", "pool_backendpid", "pool_connected", "status"};
+                                                                 "majorversion", "minorversion", "pool_counter", "pool_backendpid", "pool_connected",
+                                                                 "status", "load_balance_node"};
        int             n;
        int             *offsettbl;
        int             nrows;