pgpool2.git / summary / log / commit / refs

commit    57752e4ab330a60642292fed7cef2c3e6d77939a
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Wed May 31 01:15:42 2017 +0000

    Fix query cache hang when used by node.js.
    
    node.js sends a query in following pattern:
    
    Parse
    Bind
    Describe
    Execute
    Flush
    Sync
    
    Notice the "Flush" message. This is unnecessary message and Pgpool-II
    did not prepare for it. Since Pgpool-I supposed that next message to
    Execute is "Sync" in pool_fetch_from_memory_cache(), it actually read
    the "Flush" message and forwarded to backend, then discarded
    subsequent "Ready for query" message, which was actually a "Sync"
    message. That results in no "ready for query" message from backend.
    
    Fix is, do not have any assumption regarding messages after Execute,
    instead returns to the message processing loop. This way, whatever
    messages coming after Execute should be properly processed.
    
    Following is the test data for pgproto.
    
    'Q'	"DROP TABLE IF EXISTS pgproto_test1"
    'Y'
    'Q'	"CREATE TABLE pgproto_test1(i INT)"
    'Y'
    'Q'	"INSERT INTO pgproto_test1 VALUES(1)"
    'Y'
    
    'P'	"S2"	"SELECT 1 FROM pgproto_test1"	0
    'B'	""	"S2"	0	0	0
    'D'	'S'	"S2"
    'E'	""	0
    'H'
    'C'	'S'	"S2"
    'S'
    'Y'
    
    'P'	"S2"	"SELECT 1 FROM pgproto_test1"	0
    'B'	""	"S2"	0	0	0
    'D'	'S'	"S2"
    'E'	""	0
    'H'
    'C'	'S'	"S2"
    'S'
    'Y'
    'X'
    
    Discussion: http://www.pgpool.net/pipermail/pgpool-general/2017-May/005569.html


src/query_cache/pool_memqcache.c | 43 +++------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/src/query_cache/pool_memqcache.c b/src/query_cache/pool_memqcache.c index eee34dafb..73b9751a4 100644 --- a/src/query_cache/pool_memqcache.c +++ b/src/query_cache/pool_memqcache.c @@ -645,43 +645,9 @@ POOL_STATUS pool_fetch_from_memory_cache(POOL_CONNECTION *frontend, pfree(qcache); /* - * If we are doing extended query, forward sync message from frontend to - * backend. This is necessary to prevent receiving Sync message after - * Sending Ready for query. + * Send a "READY FOR QUERY" if not in extended query. */ - if (pool_is_doing_extended_query_message()) - { - char kind; - int32 len; - POOL_SESSION_CONTEXT *session_context; - POOL_CONNECTION *target_backend; - char buf[5]; - - if (pool_flush(frontend)) - return POOL_END; - if (pool_read(frontend, &kind, 1)) - return POOL_END; - - ereport(DEBUG2, - (errmsg("memcache: fetching from memory cache: expecting sync: kind '%c'", kind))); - if (pool_read(frontend, &len, sizeof(len))) - return POOL_END; - - /* Forward "Sync" message to backend */ - session_context = pool_get_session_context(true); - target_backend = CONNECTION(backend, session_context->load_balance_node_id); - pool_write(target_backend, &kind, 1); - pool_write_and_flush(target_backend, &len, sizeof(len)); - - /* Read and discard "Ready for query" message from backend */ - pool_read(target_backend, &kind, 1); - pool_read(target_backend, buf, sizeof(buf)); - } - - /* - * send a "READY FOR QUERY" - */ - if (MAJOR(backend) == PROTO_MAJOR_V3) + if (!pool_is_doing_extended_query_message() && MAJOR(backend) == PROTO_MAJOR_V3) { signed char state; @@ -691,10 +657,7 @@ POOL_STATUS pool_fetch_from_memory_cache(POOL_CONNECTION *frontend, state = MASTER(backend)->tstate; send_message(frontend, 'Z', 5, (char *)&state); } - else - { - pool_write(frontend, "Z", 1); - } + if (pool_flush(frontend)) { return POOL_END; [parent: 087d7f72382b]