Redirect all user queries to primary server
authorTatsuo Ishii <ishii@postgresql.org>
Fri, 15 Apr 2016 04:17:23 +0000 (13:17 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Fri, 15 Apr 2016 04:25:49 +0000 (13:25 +0900)
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
pool_session_context.c

diff --git a/pool.h b/pool.h
index c0242263fb4d1967dc5b09edcc4ee2ca5f4e8c6d..31da771f045a65b592a945fd84a88a541cd126d4 100644 (file)
--- 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)
index 5fa1581ae37add35fd6d777c0a8596d2361ce2e6..5e310d169d49614016a7507b4527bf0c26590823 100644 (file)
@@ -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();