}
need_to_restart_pcp = true;
}
+
+ pool_semaphore_lock(REQUEST_INFO_SEM);
switching = 0;
Req_info->switching = false;
+ pool_semaphore_unlock(REQUEST_INFO_SEM);
/*
* kick wakeup_handler in pcp_child to notice that failover/failback done
if (strlen(exec_cmd->data) != 0)
{
+ pool_sigset_t oldmask;
ereport(LOG,
(errmsg("execute command: %s", exec_cmd->data)));
+ POOL_SETMASK2(&UnBlockSig, &oldmask);
r = system(exec_cmd->data);
+ POOL_SETMASK(&oldmask);
}
free_string(exec_cmd);
return -1;
}
+ /*
+ * If follow primary command is ongoing, skip primary node check. Just
+ * return current primary node to avoid deadlock between pgpool main
+ * failover() and follow primary process.
+ */
+ if (Req_info->follow_primary_ongoing)
+ {
+ ereport(LOG,
+ (errmsg("find_primary_node_repeatedly: follow primary is ongoing. return current primary: %d",
+ Req_info->primary_node_id)));
+
+ return Req_info->primary_node_id;
+ }
+
/*
* If all of the backends are down, there's no point to keep on searching
* primary node.
on_exit_reset();
SetProcessGlobalVaraibles(PT_FOLLOWCHILD);
pool_acquire_follow_primary_lock(true);
+ Req_info->follow_primary_ongoing = true;
ereport(LOG,
(errmsg("start triggering follow command.")));
for (i = 0; i < pool_config->backend_desc->num_backends; i++)
trigger_failover_command(i, pool_config->follow_primary_command,
old_main_node, new_primary, old_primary);
}
+ Req_info->follow_primary_ongoing = false;
pool_release_follow_primary_lock();
exit(0);
}
--- /dev/null
+#!/usr/bin/env bash
+#-------------------------------------------------------------------
+# test script for a case: detach primary node left down node.
+#
+# reported: https://www.pgpool.net/pipermail/pgpool-hackers/2021-June/003916.html
+
+source $TESTLIBS
+WHOAMI=`whoami`
+TESTDIR=testdir
+
+rm -fr $TESTDIR
+mkdir $TESTDIR
+cd $TESTDIR
+
+# create test environment
+echo -n "creating test environment..."
+$PGPOOL_SETUP -n 4 || exit 1
+echo "done."
+
+source ./bashrc.ports
+export PGPORT=$PGPOOL_PORT
+
+./startall
+wait_for_pgpool_startup
+
+# detach node 0
+$PGPOOL_INSTALL_DIR/bin/pcp_detach_node -w -p $PCP_PORT 0
+wait_for_pgpool_startup
+
+# check to see if alll nodes are up
+echo -n "starting to check follow primary results: "
+date
+cnt=60
+while [ $cnt -gt 0 ]
+do
+ $PGBIN/psql -c "show pool_nodes" test|grep down
+ if [ $? != 0 ];then
+ echo "test succeeded"
+ ./shutdownall
+ exit 0
+ fi
+ cnt=`expr $cnt - 1`
+ echo "cnt: $cnt"
+ sleep 1
+done
+echo "test failed".
+./shutdownall
+
+exit 1