View Issue Details

IDProjectCategoryView StatusLast Update
0000292Pgpool-IIBugpublic2017-03-13 19:25
ReporternagataAssigned Tonagata 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000292: pcp_promote_node fails when trying promoting node 0
DescriptionIn streaming replication mode, there is a case that Pgpool-II are regarding the primary node as standby for some reason, for example, when pg_ctl promote is executed manually during Pgpool-II is running.

pcp_promote_node should be able fix it, but when the node is master (the first alive node), it fails. See "Steps To Reproduce" for details.

The reason is as following. pcp_promote_node check if the specified node is already primary or not by comparing the node id with PRIMARY_NODE_ID. However, if there is not primary from Pgpool-II's view, PRIMARY_NODE_ID is 0 which is same as MASTER_NODE_ID, so in this situation, master node cannot be promoted by pcp_promote_node. Instead, REAL_PRIMARY_NODE_ID should be used.

Attached is the patch to fix it.
Steps To Reproduce1. Make a 2-node streaming replication configuration by pgpool_setup.

$ ./startall
$ psql -p 11000 -h localhost -c "show pool_nodes" test
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0 | /tmp | 11002 | up | 0.500000 | primary | 0 | true | 0
 1 | /tmp | 11003 | up | 0.500000 | standby | 0 | false | 0
(2 rows)

2. Force node0 to run as standby

$ ./shutdownall
$ cp data1/recovery.conf data0
$ ./startall
$ psql -p 11000 -h localhost -c "show pool_nodes" test
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0 | /tmp | 11002 | up | 0.500000 | standby | 0 | true | 0
 1 | /tmp | 11003 | up | 0.500000 | standby | 0 | false | 0
(2 rows)

3. promote node0 manually

$ pg_ctl -D data0 promote

4. run pcp_promote_node

$ pcp_promote_node -p 11001 -w 0
FATAL: invalid pgpool mode for process recovery request
DETAIL: specified node is already primary node, can't promote node id 0

TagsNo tags attached.

Activities

nagata

2017-03-03 19:18

developer  

pcp_promote_node.patch (418 bytes)
diff --git a/src/pcp_con/pcp_worker.c b/src/pcp_con/pcp_worker.c
index 900ad7f..e50a576 100644
--- a/src/pcp_con/pcp_worker.c
+++ b/src/pcp_con/pcp_worker.c
@@ -1059,7 +1059,7 @@ process_promote_node(PCP_CONNECTION *frontend, char *buf, char tos)
 		
 	}
 
-	if (node_id == PRIMARY_NODE_ID)
+	if (node_id == REAL_PRIMARY_NODE_ID)
 	{
 		ereport(FATAL,
 				(errmsg("invalid pgpool mode for process recovery request"),

t-ishii

2017-03-06 17:59

developer   ~0001374

It seems it's a reasonable fix to me. I have assigned you to the person in charge because you are a Pgpool-II developer.

Please go ahead and apply the patch to all supported branches.

nagata

2017-03-13 19:25

developer   ~0001376

fixed
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=8c18444cd84709eb17204b8d108ab93f695c990f

Issue History

Date Modified Username Field Change
2017-03-03 19:18 nagata New Issue
2017-03-03 19:18 nagata File Added: pcp_promote_node.patch
2017-03-06 17:59 t-ishii Assigned To => nagata
2017-03-06 17:59 t-ishii Status new => assigned
2017-03-06 17:59 t-ishii Note Added: 0001374
2017-03-13 19:25 nagata Status assigned => resolved
2017-03-13 19:25 nagata Resolution open => fixed
2017-03-13 19:25 nagata Note Added: 0001376