Fix error stats.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 14 Aug 2020 09:00:55 +0000 (18:00 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 14 Aug 2020 09:00:55 +0000 (18:00 +0900)
Error stats was only collected from Master node. It is possible that
error occurred in multiple backends (for example, in native
replication mode, INSERT is accepted by the parser but target table
does not exist).  Change the place where to collect error stats from
SimpleForwardToFrontend() to read_kind_from_backend().

src/protocol/pool_process_query.c

index 8d6f765f0684b3e127a6abf0393f3cee16c4e7b7..ca6c172f4d592ac8815cc5c79f918dedc4367866 100644 (file)
@@ -718,11 +718,6 @@ SimpleForwardToFrontend(char kind, POOL_CONNECTION * frontend,
        p1 = palloc(len);
        memcpy(p1, p, len);
 
-       if (kind == 'E')
-       {
-               error_stat_count_up(MASTER_NODE_ID, extract_error_kind(p1, PROTO_MAJOR_V3));
-       }
-
        /*
         * If we received a notification message in master/slave mode, other
         * backends will not receive the message. So we should skip other nodes
@@ -3423,6 +3418,37 @@ read_kind_from_backend(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backen
                        (errmsg("read_kind_from_backend max_count:%f num_executed_nodes:%d",
                                        max_count, num_executed_nodes)));
 
+       /*
+        * If kind is ERROR Response, accumulate statistics data.
+        */
+       for (i = 0; i < NUM_BACKENDS; i++)
+       {
+               int     unread_len;
+               char *unread_p;
+               char *p;
+               int     len;
+
+               if (VALID_BACKEND(i))
+               {
+                       if (kind_list[i] == 'E')
+                       {
+                               pool_read(CONNECTION(backend, i), &len, sizeof(len));
+                               unread_len = sizeof(len);
+                               unread_p = palloc(ntohl(len));
+                               memcpy(unread_p, &len, sizeof(len));
+                               len = ntohl(len);
+                               len -= 4;
+                               unread_p = repalloc(unread_p, sizeof(len) + len);
+                               p = pool_read2(CONNECTION(backend, i), len);
+                               memcpy(unread_p + sizeof(len), p, len);
+                               unread_len += len;
+                               error_stat_count_up(i, extract_error_kind(unread_p + sizeof(len), PROTO_MAJOR_V3));
+                               pool_unread(CONNECTION(backend, i), unread_p, unread_len);
+                               pfree(unread_p);
+                       }
+               }
+       }
+
        if (max_count != num_executed_nodes)
        {
                /*