pgpool2.git / summary / log / commit / refs

commit    9b62eca4042ae5443a9bbbcdaa612ae86c7d8c91
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Fri Apr 15 03:55:17 2016 +0000

    Redirect all user queries to primary server
    
    Up to now some user queries are sent to other than the primary server
    even if load_balance_mode = off. This commit changes the behavior: if
    load_balance_mode = off in streaming replication mode, now all the
    user queries are sent to the primary server only.
    
    See bug 189 for related info.


src/context/pool_session_context.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/context/pool_session_context.c b/src/context/pool_session_context.c index 6e6c5578d..733d98ea5 100644 --- a/src/context/pool_session_context.c +++ b/src/context/pool_session_context.c @@ -45,6 +45,8 @@ static char *dump_sync_map(void); void pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) { session_context = &session_context_d; + ProcessInfo *process_info; + int node_id; /* Get Process context */ session_context->process_context = pool_get_process_context(); @@ -73,22 +75,28 @@ void pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL * /* Initialize sent message list */ init_sent_message_list(); + process_info = pool_get_my_process_info(); + + if (!process_info) + ereport(ERROR, + (errmsg("failed to get process info for current process"))); + /* Choose load balancing node if necessary */ if (pool_config->load_balance_mode) { - ProcessInfo *process_info = pool_get_my_process_info(); - if (!process_info) - ereport(ERROR, - (errmsg("failed to get process info for current process"))); + node_id = select_load_balancing_node(); + } + else + { + node_id = STREAM? PRIMARY_NODE_ID: MASTER_NODE_ID; + } - session_context->load_balance_node_id = - process_info->connection_info->load_balancing_node = - select_load_balancing_node(); + session_context->load_balance_node_id = + process_info->connection_info->load_balancing_node = node_id; - ereport(DEBUG1, + ereport(DEBUG1, (errmsg("initializing session context"), - errdetail("selected load balancing node: %d", backend->info->load_balancing_node))); - } + errdetail("selected load balancing node: %d", backend->info->load_balancing_node))); /* Unset query is in progress */ pool_unset_query_in_progress(); [parent: a5fdf78e6e86]