pgpool2.git / summary / log / commit / refs

commit    7355ebb4d9288e7b08517618d96ec02f64a5d5e0
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Fri Mar 31 03:49:59 2017 +0000

    Consider SHOW command as kind of a read query.
    
    In streaming replication mode, if SHOW is issued then subsequent
    SELECTs are sent to the primary node in an explicit transaction. This
    is not a reasonable and unnecessary limitation.
    
    Also fix hang when parse command returns error.


src/context/pool_query_context.c | 7 +++++++ src/protocol/CommandComplete.c | 9 +++++++++ src/protocol/pool_process_query.c | 4 ++++ src/protocol/pool_proto_modules.c | 28 ++++++++++++++++++++++++---- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/context/pool_query_context.c b/src/context/pool_query_context.c index 365429a3f..7b6d7da74 100644 --- a/src/context/pool_query_context.c +++ b/src/context/pool_query_context.c @@ -1387,6 +1387,13 @@ static POOL_DEST send_to_where(Node *node, char *query) */ return POOL_PRIMARY; } + /* + * SHOW + */ + else if (IsA(node, VariableShowStmt)) + { + return POOL_EITHER; + } /* * Other statements are sent to primary diff --git a/src/protocol/CommandComplete.c b/src/protocol/CommandComplete.c index 8974c9e83..ac80ce199 100644 --- a/src/protocol/CommandComplete.c +++ b/src/protocol/CommandComplete.c @@ -68,6 +68,7 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac /* * If operated in streaming replication mode and doing an extended query, * read backend message according to the query context. + * Also we set the transaction state at this point. */ if (STREAM && pool_is_doing_extended_query_message()) { @@ -89,6 +90,14 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac return POOL_END; p1 = palloc(len); memcpy(p1, p, len); + + if (session_context->query_context->parse_tree && + is_start_transaction_query(session_context->query_context->parse_tree)) + TSTATE(backend, i) ='T'; /* we are inside a transaction */ + + ereport(DEBUG1, + (errmsg("processing command complete"), + errdetail("set transaction state to T"))); } } } diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index 93356ebae..567ff0651 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -1080,6 +1080,7 @@ static int * - COPY TO STDOUT * - EXPLAIN * - EXPLAIN ANALYZE and query is SELECT not including writing functions + * - SHOW * * Note that for SELECT this function returns false. */ @@ -1200,6 +1201,9 @@ bool is_select_query(Node *node, char *sql) return true; } } + else if (IsA(node, VariableShowStmt)) /* SHOW command */ + return true; + return false; } diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c index 8c541b26d..00350dfe2 100644 --- a/src/protocol/pool_proto_modules.c +++ b/src/protocol/pool_proto_modules.c @@ -2639,10 +2639,30 @@ POOL_STATUS ProcessBackendResponse(POOL_CONNECTION *frontend, pool_set_ignore_till_sync(); pool_unset_query_in_progress(); - /* Remove all pending messages */ - while (pool_pending_message_pull_out()) - ; - pool_pending_message_reset_previous_message(); + if (STREAM) + { + POOL_PENDING_MESSAGE *pmsg; + int i; + + /* Remove all pending messages */ + do + { + pmsg = pool_pending_message_pull_out(); + pool_pending_message_free_pending_message(pmsg); + } + while (pmsg); + + pool_pending_message_reset_previous_message(); + + /* Discard read buffer */ + for (i=0;i<NUM_BACKENDS;i++) + { + if (VALID_BACKEND(i)) + { + pool_discard_read_buffer(CONNECTION(backend, i)); + } + } + } } break; [parent: 36a34cfe5bb8]