Add debugging aid to check pending message and backend response.
authorTatsuo Ishii <ishii@postgresql.org>
Sun, 10 Sep 2017 09:06:47 +0000 (18:06 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Sun, 10 Sep 2017 09:06:47 +0000 (18:06 +0900)
New function pool_check_pending_message_and_reply() added.  If pending
message kind and backend reply message kind is not inconsistent, it
prints a debug message. Currently the only client of the function is
read_kind_from_backend().

src/context/pool_session_context.c
src/include/context/pool_session_context.h
src/protocol/pool_process_query.c

index f0afe12e8e5b45528d9c91328601e3bd1a606d42..5d4e2cbe15bd7170e825a329ef93bba7f45c2c80 100644 (file)
@@ -1397,6 +1397,45 @@ const char *pool_pending_message_type_to_string(POOL_MESSAGE_TYPE type)
        return pending_msg_string[type];
 }
 
+/*
+ * Check consistency the message type and backend message kind.
+ * This function is intended to be used for debugging.
+ */
+void pool_check_pending_message_and_reply(POOL_MESSAGE_TYPE type, char kind)
+{
+       /* 
+        * Backend response message sorted by POOL_MESSAGE_TYPE
+        */
+       static char backend_response_kind[] = {
+               '1',    /* POOL_PARSE, parse complete */
+               '2',    /* POOL_BIND, bind complete */
+               '*',    /* POOL_EXECUTE, skip checking */
+               '*',    /* POOL_DESCRIBE, skip checking */
+               '3',    /* POOL_CLOSE, close complete */
+               'Z'     /* POOL_SYNC, ready for query */
+       };
+
+       if (type < POOL_PARSE || type > POOL_SYNC)
+       {
+               ereport(DEBUG1,
+                               (errmsg("pool_check_pending_message_and_reply: type out of range: %d", type)));
+               return;
+       }
+
+       if (backend_response_kind[type] == '*')
+       {
+               return;
+       }
+
+       if (backend_response_kind[type] != kind)
+       {
+               ereport(DEBUG1,
+                               (errmsg("pool_check_pending_message_and_reply: type: %s but is kind: %c",
+                                               pool_pending_message_type_to_string(type), kind)));
+       }
+       return;
+}
+
 /*
  * Find the latest pending message having specified query context.  The
  * returned message is a pointer to the message list. So do not free it using
index ec7a3c335de10327fe2108fbb3b30a5fde4a8350..2956b1d1547ec7592763ee805a73698388615151 100644 (file)
@@ -109,7 +109,7 @@ typedef struct {
  */
 
 typedef enum {
-       POOL_PARSE,
+       POOL_PARSE = 0,
        POOL_BIND,
        POOL_EXECUTE,
        POOL_DESCRIBE,
@@ -301,6 +301,7 @@ extern void pool_pending_message_set_previous_message(POOL_PENDING_MESSAGE *mess
 extern POOL_PENDING_MESSAGE *pool_pending_message_get_previous_message(void);
 extern bool pool_pending_message_exists(void);
 extern const char *pool_pending_message_type_to_string(POOL_MESSAGE_TYPE type);
+extern void pool_check_pending_message_and_reply(POOL_MESSAGE_TYPE type, char kind);
 extern POOL_PENDING_MESSAGE *pool_pending_message_find_lastest_by_query_context(POOL_QUERY_CONTEXT *qc);
 extern void dump_pending_message(void);
 extern void pool_set_major_version(int major);
index 9631a5fb8c331aefd489df946e231f4a9ec5b3b7..50f690c637565cc118138cf1fbe4329cb58db362 100644 (file)
@@ -3641,6 +3641,7 @@ void read_kind_from_backend(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
                                ereport(DEBUG1,
                                                (errmsg("read_kind_from_backend: pending message was pulled out")));
                                pending_message = pool_pending_message_pull_out();
+                               pool_check_pending_message_and_reply(msg->type, *decided_kind);
                        }
 
                        if (pending_message)