pgpool2.git / summary / log / commit / refs
commit 48adaa369c4dbb2213a00543e4bf6507a29bc0c3
Author: Tatsuo Ishii <ishii at sraoss.co.jp>
Date: Tue Aug 18 08:41:36 2009 +0000
Change wait_for_query_response() so that it sends NOTICE message to
frontend periodically. It appears that pgpool-II 2.2.3 unconditionaly
sends param packet to client even it uses version 2 protocol, which
is apparentlt wrong. Also tweak checking period from 1 second to
30 seconds since 1 second seems too aggressive.
Note that you need to edit pool_process_query.c to define
SEND_NOTICE_ON_PROTO2 around line 879 to enable this feature in
version 2 protocol.
pool_process_query.c | 61 ++++++++++++++++++++++++++++++++++++----------------
pool_proto_modules.c | 16 +++++++-------
pool_proto_modules.h | 2 +-
3 files changed, 52 insertions(+), 27 deletions(-)
diff --git a/pool_process_query.c b/pool_process_query.c
index fb77786c0..1e735d0f8 100644
--- a/pool_process_query.c
+++ b/pool_process_query.c
@@ -827,7 +827,7 @@ POOL_STATUS send_simplequery_message(POOL_CONNECTION *backend, int len, char *st
* seccond, and if the connection broke, returns error since there's
* no point in that waiting until backend returns response.
*/
-POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, char *string)
+POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, char *string, int protoVersion)
{
#define DUMMY_PARAMETER "pgpool_dummy_param"
#define DUMMY_VALUE "pgpool_dummy_value"
@@ -840,7 +840,7 @@ POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *
for (;;)
{
/* Check to see if data from backend is ready */
- pool_set_timeout(1);
+ pool_set_timeout(30);
status = pool_check_fd(backend);
pool_set_timeout(0);
@@ -848,28 +848,53 @@ POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *
{
pool_error("wait_for_query_response: backend error occured while waiting for backend response");
return POOL_END;
- } else if (status > 0) /* data is not ready */
+ }
+ else if (status > 0) /* data is not ready */
{
- /* Write dummy parameter staus packet to check if the socket to frontend is ok */
- if (pool_write(frontend, "S", 1) < 0)
- return POOL_END;
- plen = sizeof(DUMMY_PARAMETER)+sizeof(DUMMY_VALUE)+sizeof(plen);
- plen = htonl(plen);
- if (pool_write(frontend, &plen, sizeof(plen)) < 0)
- return POOL_END;
- if (pool_write(frontend, DUMMY_PARAMETER, sizeof(DUMMY_PARAMETER)) < 0)
- return POOL_END;
- if (pool_write(frontend, DUMMY_VALUE, sizeof(DUMMY_VALUE)) < 0)
- return POOL_END;
- if (pool_flush_it(frontend) < 0)
+ if (protoVersion == PROTO_MAJOR_V3)
{
- pool_error("wait_for_query_response: frontend error ouccured while waiting for backend reply");
- return POOL_END;
+ /* Write dummy parameter staus packet to check if the socket to frontend is ok */
+ if (pool_write(frontend, "S", 1) < 0)
+ return POOL_END;
+ plen = sizeof(DUMMY_PARAMETER)+sizeof(DUMMY_VALUE)+sizeof(plen);
+ plen = htonl(plen);
+ if (pool_write(frontend, &plen, sizeof(plen)) < 0)
+ return POOL_END;
+ if (pool_write(frontend, DUMMY_PARAMETER, sizeof(DUMMY_PARAMETER)) < 0)
+ return POOL_END;
+ if (pool_write(frontend, DUMMY_VALUE, sizeof(DUMMY_VALUE)) < 0)
+ return POOL_END;
+ if (pool_flush_it(frontend) < 0)
+ {
+ pool_error("wait_for_query_response: frontend error occured while waiting for backend reply");
+ return POOL_END;
+ }
+
+ } else /* Protocol version 2 */
+ {
+/*
+ * If you want to monitor client connection even if you are using V2 protocol,
+ * define following
+ */
+#define SEND_NOTICE_ON_PROTO2
+#ifdef SEND_NOTICE_ON_PROTO2
+ static char *notice_message = {"keep alive checking from pgpool-II"};
+
+ /* Write notice message packet to check if the socket to frontend is ok */
+ if (pool_write(frontend, "N", 1) < 0)
+ return POOL_END;
+ if (pool_write(frontend, notice_message, strlen(notice_message)+1) < 0)
+ return POOL_END;
+ if (pool_flush_it(frontend) < 0)
+ {
+ pool_error("wait_for_query_response: frontend error occured while waiting for backend reply");
+ return POOL_END;
+ }
+#endif
}
}
else
break;
-
}
return POOL_CONTINUE;
diff --git a/pool_proto_modules.c b/pool_proto_modules.c
index bf0b038cf..978bb09f8 100644
--- a/pool_proto_modules.c
+++ b/pool_proto_modules.c
@@ -530,7 +530,7 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
if (send_simplequery_message(MASTER(backend), len, string, MAJOR(backend)) != POOL_CONTINUE)
return POOL_END;
- if (wait_for_query_response(frontend, MASTER(backend), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, MASTER(backend), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -572,7 +572,7 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
if (!VALID_BACKEND(i) || IS_MASTER_NODE_ID(i))
continue;
- if (wait_for_query_response(frontend, CONNECTION(backend, i), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, CONNECTION(backend, i), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -592,7 +592,7 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
if (send_simplequery_message(MASTER(backend), len, string, MAJOR(backend)) != POOL_CONTINUE)
return POOL_END;
- if (wait_for_query_response(frontend, MASTER(backend), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, MASTER(backend), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -615,7 +615,7 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
if (send_simplequery_message(MASTER(backend), len, string, MAJOR(backend)) != POOL_CONTINUE)
return POOL_END;
- if (wait_for_query_response(frontend, MASTER(backend), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, MASTER(backend), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -744,7 +744,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
if (send_execute_message(backend, MASTER_NODE_ID, len, string) != POOL_CONTINUE)
return POOL_END;
- if (wait_for_query_response(frontend, MASTER(backend), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, MASTER(backend), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -792,7 +792,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
if (!VALID_BACKEND(i) || IS_MASTER_NODE_ID(i))
continue;
- if (wait_for_query_response(frontend, CONNECTION(backend, i), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, CONNECTION(backend, i), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -812,7 +812,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
if (send_execute_message(backend, MASTER_NODE_ID, len, string) != POOL_CONTINUE)
return POOL_END;
- if (wait_for_query_response(frontend, MASTER(backend), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, MASTER(backend), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
@@ -831,7 +831,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
if (send_execute_message(backend, MASTER_NODE_ID, len, string) != POOL_CONTINUE)
return POOL_END;
- if (wait_for_query_response(frontend, MASTER(backend), string) != POOL_CONTINUE)
+ if (wait_for_query_response(frontend, MASTER(backend), string, MAJOR(backend)) != POOL_CONTINUE)
{
/* Cancel current transaction */
CancelPacket cancel_packet;
diff --git a/pool_proto_modules.h b/pool_proto_modules.h
index 9f9f2456d..415f80fea 100644
--- a/pool_proto_modules.h
+++ b/pool_proto_modules.h
@@ -141,7 +141,7 @@ extern POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
POOL_CONNECTION_POOL *backend);
-extern POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, char *string);
+extern POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, char *string, int protoVersion);
extern int is_select_query(Node *node, char *sql);
extern int is_sequence_query(Node *node);
extern int is_start_transaction_query(Node *node);
[parent: 9306fba4fe57]