From d23f0af72058dc844940006db149ac9460414ffd Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 14 Aug 2020 18:00:55 +0900 Subject: [PATCH] Fix error stats. 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 | 36 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index 8d6f765f0..ca6c172f4 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -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) { /* -- 2.39.5