Suppress message length log for in_hot_standby.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 6 Jan 2022 07:53:42 +0000 (16:53 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 6 Jan 2022 07:55:17 +0000 (16:55 +0900)
PostgreSQL 14 introduced new config parameter: in_hot_standby
https://www.postgresql.org/docs/14/runtime-config-preset.html
The value is either "on" for standby servers or "off" for primary
servers. As a result pgpool log is fladded by the messages:

2021-12-16 10:40:34.855: psql pid 366965: LOG:  reading message length
2021-12-16 10:40:34.855: psql pid 366965: DETAIL:  message length (22) in slot 1 does not match with slot 0(23)

To avoid this, only complain if the parameter name is not in_hot_standby.
Also the message is enhanced to show the parameter name.

2022-01-05 13:05:15.993: psql pid 642877: LOG:  ParameterStatus "TimeZone": node 1 message length 30 is different from main node message length 24

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2021-December/004077.html

src/auth/pool_auth.c
src/include/pool.h
src/protocol/pool_process_query.c

index 51439eeb79e289e4f030e3c3b48eb1a1703f9046..a5425a9a8107d3558b6cb34663ee2e64d6941805 100644 (file)
@@ -3,7 +3,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2020     PgPool Global Development Group
+ * Copyright (c) 2003-2022     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -2060,14 +2060,14 @@ pool_read_message_length2(POOL_CONNECTION_POOL * cp)
        int                     i;
        static int      length_array[MAX_CONNECTION_SLOTS];
 
-       /* read message from master node */
+       /* read message from main node */
        pool_read(CONNECTION(cp, MASTER_NODE_ID), &length0, sizeof(length0));
 
        length0 = ntohl(length0);
        length_array[MASTER_NODE_ID] = length0;
        ereport(DEBUG5,
                        (errmsg("reading message length"),
-                        errdetail("master slot: %d length: %d", MASTER_NODE_ID, length0)));
+                        errdetail("main slot: %d length: %d", MASTER_NODE_ID, length0)));
 
        for (i = 0; i < NUM_BACKENDS; i++)
        {
@@ -2078,11 +2078,11 @@ pool_read_message_length2(POOL_CONNECTION_POOL * cp)
                        length = ntohl(length);
                        ereport(DEBUG5,
                                        (errmsg("reading message length"),
-                                        errdetail("master slot: %d length: %d", i, length)));
+                                        errdetail("main slot: %d length: %d", i, length)));
 
                        if (length != length0)
                        {
-                               ereport(LOG,
+                               ereport(DEBUG1,
                                                (errmsg("reading message length"),
                                                 errdetail("message length (%d) in slot %d does not match with slot 0(%d)", length, i, length0)));
                        }
@@ -2101,6 +2101,41 @@ pool_read_message_length2(POOL_CONNECTION_POOL * cp)
        return &length_array[0];
 }
 
+/*
+ * By given message length array, emit log message to complain the difference.
+ * If no difference, no log is emitted.
+ * If "name" is not NULL, it is added to the log message.
+ */
+void
+pool_emit_log_for_message_length_diff(int *length_array, char *name)
+{
+       int                     length0,        /* message length of main node id */
+                               length;
+       int                     i;
+
+       length0 = length_array[MASTER_NODE_ID];
+
+       for (i = 0; i < NUM_BACKENDS; i++)
+       {
+               if (VALID_BACKEND(i))
+               {
+                       length = length_array[i];
+
+                       if (length != length0)
+                       {
+                               if (name != NULL)
+                                       ereport(LOG,
+                                                       (errmsg("ParameterStatus \"%s\": node %d message length %d is different from main node message length %d",
+                                                                       name, i, length_array[i], length0)));
+                               else
+                                       ereport(LOG,
+                                                       (errmsg("node %d message length %d is different from main node message length %d",
+                                                                       i, length_array[i], length0)));
+                       }
+               }
+       }
+}
+
 signed char
 pool_read_kind(POOL_CONNECTION_POOL * cp)
 {
index 1dca4e65bfac475a3c93d8358cc03adc6a97f933..a2bcb378114039e521c7d5299c169340bc0374e2 100644 (file)
@@ -4,7 +4,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2019     PgPool Global Development Group
+ * Copyright (c) 2003-2022 PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -653,6 +653,7 @@ extern int  pool_read_message_length(POOL_CONNECTION_POOL * cp);
 extern int *pool_read_message_length2(POOL_CONNECTION_POOL * cp);
 extern signed char pool_read_kind(POOL_CONNECTION_POOL * cp);
 extern int     pool_read_int(POOL_CONNECTION_POOL * cp);
+extern void pool_emit_log_for_message_length_diff(int *length_array, char *name);
 
 extern POOL_STATUS SimpleForwardToFrontend(char kind, POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend);
 extern POOL_STATUS SimpleForwardToBackend(char kind, POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend, int len, char *contents);
index b562673470cef49e74583cec464b73b658f75c27..e75d9c68558a4f6b80d9b0a48792d457d06755ef 100644 (file)
@@ -3,7 +3,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2020     PgPool Global Development Group
+ * Copyright (c) 2003-2022     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -969,8 +969,7 @@ ParameterStatus(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
        char       *name;
        char       *value;
        POOL_STATUS status;
-       char            parambuf[1024]; /* parameter + value string buffer. XXX is
-                                                                * this enough? */
+       char            *parambuf = NULL; /* pointer to parameter + value string buffer */
        int                     i;
 
        pool_write(frontend, "S", 1);
@@ -1008,9 +1007,20 @@ ParameterStatus(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
                        if (IS_MASTER_NODE_ID(i))
                        {
                                len1 = len;
+                               parambuf = palloc(len);
                                memcpy(parambuf, p, len);
                                pool_add_param(&CONNECTION(backend, i)->params, name, value);
                        }
+                       else
+                       {
+                               /*
+                                * Except "in_hot_standby" parameter, complain the message length difference.
+                                */
+                               if (strcmp(name, "in_hot_standby"))
+                               {
+                                       pool_emit_log_for_message_length_diff(len_array, name);
+                               }
+                       }
 
 #ifdef DEBUG
                        pool_param_debug_print(&MASTER(backend)->params);
@@ -1018,7 +1028,14 @@ ParameterStatus(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
                }
        }
 
-       status = pool_write(frontend, parambuf, len1);
+       if (parambuf)
+       {
+               status = pool_write(frontend, parambuf, len1);
+               pfree(parambuf);
+       }
+       else
+               ereport(ERROR,
+                               (errmsg("ParameterStatus: failed to obatain parameter name, value from the main node.")));
        return status;
 }