pgpool2.git / summary / log / commit / refs

commit    83c84034b844864ff3760de192ee9bc3d545ab5a
Author:   Tatsuo Ishii <ishii@postgresql.org>
Commit:   Muhammad Usama <m.usama@gmail.com>
Date:     Mon Feb 24 04:49:11 2014 +0000

    Avoid to send queries to unrelated nodes in streaming replication mode.
    
    Pgpool-II sends certain queries, such as BEGIN, END and SET commands to
    all of DB nodes. However in streaming replication mode, only primary
    node and at most one standby node are only concerned (if primacy node
    is selected as the load balance node, only 1 node is concerned).
    
    Think about 3 nodes cluster. Node 0 is primary, node 1 and 2 are
    standby servers. Node 1 is selected as the load balance node. In this
    case no query is needed to be sent to node 2, because DMLs are sent to
    node 0 while SELECTs are sent to node 1.
    
    For this purpose pool_setall_node_to_be_sent() is modified to only set
    related nodes on the where_to_send node map. See [pgpool-hackers: 464]
    for more details.


src/context/pool_query_context.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/context/pool_query_context.c b/src/context/pool_query_context.c index 11d01bf32..3d5600f59 100644 --- a/src/context/pool_query_context.c +++ b/src/context/pool_query_context.c @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2013 PgPool Global Development Group + * Copyright (c) 2003-2014 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -178,6 +178,14 @@ void pool_clear_node_to_be_sent(POOL_QUERY_CONTEXT *query_context) void pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT *query_context) { int i; + POOL_SESSION_CONTEXT *sc; + + sc = pool_get_session_context(); + if (!sc) + { + pool_error("pool_setall_node_to_be_sent: no session context"); + return; + } if (!query_context) { @@ -189,7 +197,20 @@ void pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT *query_context) { if (private_backend_status[i] == CON_UP || (private_backend_status[i] == CON_CONNECT_WAIT)) + { + /* + * In streaming replication mode, if the node is not + * primary node nor load balance node, there's no point to + * send query. + */ + if (pool_config->master_slave_mode && + !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP) && + i != PRIMARY_NODE_ID && i != sc->load_balance_node_id) + { + continue; + } query_context->where_to_send[i] = true; + } } return; } [parent: 201f5285e9c8]