Fix pcp_promote_node bug that fails promoting node 0
authorYugo Nagata <nagata@sraoss.co.jp>
Thu, 9 Mar 2017 02:34:12 +0000 (11:34 +0900)
committerYugo Nagata <nagata@sraoss.co.jp>
Thu, 9 Mar 2017 08:31:14 +0000 (17:31 +0900)
The master node could not be promoted by pcp_promote_node with
the following error;

 FATAL: invalid pgpool mode for process recovery request
 DETAIL: specified node is already primary node, can't promote node id 0

In streaming replication mode, there is a case that Pgpool-II
regards the status of primary node as "standby" for some reasons,
for example, when pg_ctl promote is executed manually during
Pgpool-II is running, in which case, it seems to Pgpool-II
that the primary node doesn't exist.

This status mismatch should be fixe by pcp_promote_node, but when the node
is the master node (the first alive node), it fails as mentioned above.

The reason is as following. before changing the status, pcp_promote_node
checks if the specified node is already primary or not by comparing the
node id with PRIMARY_NODE_ID. However, if the primary doesn't exist from
Pgpool-II's view, PRIMARY_NODE_ID is set to 0, which is same as MASTER_NODE_ID.
Hence, when the master node is specified to be promoted, pcp_promote_node
is confused that this node is already primary and doesn't have to be
promoted, and it exits with the error.

To fix this, pcp_promote_node should check the node id by using
REAL_PRIMARY_NODE_ID, which is set -1 when the primary doesn't exist,
rather than PRIMARY_NODE_ID.

pcp_child.c

index 2601ab0224b8dfffe5f11dff57e6136c8ed39973..26ba43be6e3bd76e05c232786a22d5c79268bca0 100644 (file)
@@ -1098,7 +1098,7 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
                                        exit(1);
                                }
 
-                               if (node_id == PRIMARY_NODE_ID)
+                               if (node_id == REAL_PRIMARY_NODE_ID)
                                {
                                        char code[] = "NodeIdAlreadyPrimary";
                                        pool_error("pcp_child: specified node is already primary node, can't promote node id %d", node_id);