pgpool2.git / summary / log / commit / refs
commit d114c19ba15e6e2e36d1e35ad187b7208107679e
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Sun Sep 10 09:06:47 2017 +0000
Add debugging aid to check pending message and backend response.
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 | 39 ++++++++++++++++++++++++++++++
src/include/context/pool_session_context.h | 3 ++-
src/protocol/pool_process_query.c | 1 +
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/src/context/pool_session_context.c b/src/context/pool_session_context.c
index f0afe12e8..5d4e2cbe1 100644
--- a/src/context/pool_session_context.c
+++ b/src/context/pool_session_context.c
@@ -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
diff --git a/src/include/context/pool_session_context.h b/src/include/context/pool_session_context.h
index ec7a3c335..2956b1d15 100644
--- a/src/include/context/pool_session_context.h
+++ b/src/include/context/pool_session_context.h
@@ -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);
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index 9631a5fb8..50f690c63 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -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)
[parent: 0f75428cf805]