From 19ef42bc292f777624e82353358341c0bd2023d3 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 15 Apr 2016 13:17:23 +0900 Subject: [PATCH] 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. --- pool.h | 4 +++- pool_session_context.c | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pool.h b/pool.h index c0242263f..31da771f0 100644 --- a/pool.h +++ b/pool.h @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2014 PgPool Global Development Group + * Copyright (c) 2003-2016 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -311,6 +311,8 @@ extern int my_master_node_id; #define REPLICATION (pool_config->replication_mode) #define MASTER_SLAVE (pool_config->master_slave_mode) +#define STREAM (MASTER_SLAVE && !strcmp("stream", pool_config->master_slave_sub_mode)) +#define SLONY (MASTER_SLAVE && !strcmp("slony", pool_config->master_slave_sub_mode)) #define DUAL_MODE (REPLICATION || MASTER_SLAVE) #define PARALLEL_MODE (pool_config->parallel_mode) #define RAW_MODE (!REPLICATION && !PARALLEL_MODE && !MASTER_SLAVE) diff --git a/pool_session_context.c b/pool_session_context.c index 5fa1581ae..5e310d169 100644 --- a/pool_session_context.c +++ b/pool_session_context.c @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2011 PgPool Global Development Group + * Copyright (c) 2003-2016 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -40,6 +40,7 @@ static bool can_query_context_destroy(POOL_QUERY_CONTEXT *qc); void pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) { session_context = &session_context_d; + int node_id; /* Get Process context */ session_context->process_context = pool_get_process_context(); @@ -68,19 +69,17 @@ void pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL * /* Choose load balancing node if neccessary */ if (pool_config->load_balance_mode) { - ProcessInfo *process_info = pool_get_my_process_info(); - if (!process_info) - { - pool_error("pool_init_session_context: pool_get_my_process_info failed"); - return; - } + 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; - pool_debug("selected load balancing node: %d", backend->info->load_balancing_node); - } + pool_debug("selected load balancing node: %d", backend->info->load_balancing_node); /* Unset query is in progress */ pool_unset_query_in_progress(); -- 2.39.5