[pgpool-hackers: 411] Test node before attache

Sergey Logvinov serge.logvinov at gmail.com
Mon Nov 18 14:32:49 JST 2013


Hi pgpool hackers.

If we attache down node (set status NODE_UP) pgpool restart all workers
when new client are connecting.

In automatic scripts, we need to test down node before attache.
I add new feature. Pgpool test attaching node, and return error if node
down.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.sraoss.jp/pipermail/pgpool-hackers/attachments/20131118/47ab31dc/attachment.html>
-------------- next part --------------
diff --git a/pcp_child.c b/pcp_child.c
index b279071..1607a49 100644
--- a/pcp_child.c
+++ b/pcp_child.c
@@ -780,16 +780,74 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
 			{
 				int node_id;
 				int wsize;
-				char code[] = "CommandComplete";
-
+				int alive = 1;
 				node_id = atoi(buf);
-				pool_debug("pcp_child: attaching Node ID %d", node_id);
-				send_failback_request(node_id);
 
-				pcp_write(frontend, "c", 1);
-				wsize = htonl(sizeof(code) + sizeof(int));
-				pcp_write(frontend, &wsize, sizeof(int));
-				pcp_write(frontend, code, sizeof(code));
+				if (pool_config->health_check_period > 0 || pool_config->sr_check_period > 0)
+				{
+					BackendInfo *bkinfo;
+					POOL_CONNECTION_POOL_SLOT *slot = NULL;
+					bkinfo = pool_get_node_info(node_id);
+
+					if (!bkinfo)
+					{
+						slot = NULL;
+					}
+					else if (pool_config->health_check_period > 0)
+					{
+						slot = make_persistent_db_connection(bkinfo->backend_hostname,
+												 bkinfo->backend_port,
+												 "postgres",
+												 pool_config->health_check_user,
+												 pool_config->health_check_password, true);
+						if (!slot)
+							slot = make_persistent_db_connection(bkinfo->backend_hostname,
+												 bkinfo->backend_port,
+												 "template1",
+												 pool_config->health_check_user,
+												 pool_config->health_check_password, true);
+					}
+					else if (MASTER_SLAVE && !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP))
+					{
+						slot = make_persistent_db_connection(bkinfo->backend_hostname,
+												 bkinfo->backend_port,
+												 "postgres",
+												 pool_config->sr_check_user,
+												 pool_config->sr_check_password, true);
+						bkinfo->standby_delay = pool_config->delay_threshold + 1;
+					}
+
+					if (!slot)
+					{
+						alive = 0;
+					}
+					else
+					{
+						alive = 1;
+						discard_persistent_db_connection(slot);
+					}
+				}
+
+				if (alive)
+				{
+					char code[] = "CommandComplete";
+					pool_debug("pcp_child: attaching Node ID %d", node_id);
+					send_failback_request(node_id);
+					pcp_write(frontend, "c", 1);
+					wsize = htonl(sizeof(code) + sizeof(int));
+					pcp_write(frontend, &wsize, sizeof(int));
+					pcp_write(frontend, code, sizeof(code));
+				}
+				else
+				{
+					char code[] = "TestNodeFailed";
+					pool_debug("pcp_child: attaching Node ID %d failed", node_id);
+					pcp_write(frontend, "e", 1);
+					wsize = htonl(sizeof(code) + sizeof(int));
+					pcp_write(frontend, &wsize, sizeof(int));
+					pcp_write(frontend, code, sizeof(code));
+				}
+
 				if (pcp_flush(frontend) < 0)
 				{
 					pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));


More information about the pgpool-hackers mailing list