}
}
/*
- * If the down node was a standby node in streaming replication
- * mode, we can avoid calling find_primary_node_repeatedly() and
- * recognize the former primary as the new primary node, which
- * will reduce the time to process standby down.
+ * If the down node was a standby node in streaming replication mode,
+ * we can avoid calling find_primary_node_repeatedly() and recognize
+ * the former primary as the new primary node, which will reduce the
+ * time to process standby down.
+ * This does not apply to the case when no primary node existed
+ * (Req_info->primary_node_id < 0). In this case
+ * find_primary_node_repeatedly() should be called.
*/
else if (SL_MODE &&
reqkind == NODE_DOWN_REQUEST)
{
- if (Req_info->primary_node_id != node_id)
+ if (Req_info->primary_node_id >= 0 && Req_info->primary_node_id != node_id)
{
new_primary = Req_info->primary_node_id;
}
if (*pool_config->follow_master_command != '\0' ||
reqkind == PROMOTE_NODE_REQUEST)
{
- /* only if the failover is against the current primary */
+ /*
+ * follow primary command is executed in following cases:
+ * - failover against the current primary
+ * - no primary exists and new primary is created by failover
+ * - promote node request
+ */
if (((reqkind == NODE_DOWN_REQUEST) &&
Req_info->primary_node_id >= 0 &&
(nodes[Req_info->primary_node_id])) ||
+ (reqkind == NODE_DOWN_REQUEST && Req_info->primary_node_id < 0 && new_primary >= 0) ||
(node_id >= 0 && (reqkind == PROMOTE_NODE_REQUEST) &&
(VALID_BACKEND(node_id))))
{