Fix relcache query sometimes sent to other than primary.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 6 Sep 2020 10:52:56 +0000 (19:52 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 6 Sep 2020 10:52:56 +0000 (19:52 +0900)
In streaming replication mode, relcache queries are supposed to be
sent to the primary node.  But actually they were not sent the primary
node if primary node was not the master node. Typically this could
happen when the primary is not node 0.

src/utils/pool_relcache.c

index e4b995f96fcae8be353cb0edcbf86fa8ef887567..abf5ed70f00f27684ab6e7831d01bd7ec094fb29 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2019     PgPool Global Development Group
+ * Copyright (c) 2003-2020     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -153,7 +153,15 @@ pool_search_relcache(POOL_RELCACHE * relcache, POOL_CONNECTION_POOL * backend, c
        else
        {
                dbname = MASTER_CONNECTION(backend)->sp->database;
-               node_id = MASTER_NODE_ID;
+
+               /*
+                * If in streaming replication mode, prefer to send query to the
+                * primary node if it exists.
+                */
+               if (STREAM && PRIMARY_NODE_ID >= 0)
+                       node_id = PRIMARY_NODE_ID;
+               else
+                       node_id = MASTER_NODE_ID;
        }
 
        now = time(NULL);