Tatsuo,

Le 09/03/2011 08:43, Tatsuo Ishii a écrit :
> I have applied this patches to the CVS HEAD and got an compile error:
>
> gcc -DHAVE_CONFIG_H -DDEFAULT_CONFIGDIR=\"/usr/local/etc\" -I.  -D_GNU_SOURCE 
> -I /usr/local/pgsql/include   -g -O2 -Wall -Wmissing-prototypes 
> -Wmissing-declarations -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o 
> main.c
> main.c: In function ‘failover’:
> main.c:1654: error: ‘POOL_REQUEST_INFO’ has no member named 
> ‘prefered_primary_node_id’
Oh yes, sorry this is a line from the promote patch, you can safely
remove it. Or if you prefer I've attached the fixed patch.

> I thought I needed pcp_promote_node patch and tried to apply the patch but I 
> got:
>
> $ patch -b -p1 < ../patch-promote.diff 
> patching file main.c
> Hunk #2 succeeded at 167 (offset 2 lines).
> Hunk #4 succeeded at 1376 (offset 2 lines).
> Hunk #6 FAILED at 1604.
> Hunk #7 succeeded at 1660 with fuzz 2 (offset 44 lines).
> Hunk #8 FAILED at 1686.
> Hunk #9 FAILED at 2398.
> Hunk #10 FAILED at 2412.
> Hunk #11 FAILED at 2441.
> 5 out of 11 hunks FAILED -- saving rejects to file main.c.rej
> patching file pcp/Makefile.am
> patching file pcp/Makefile.in
> patching file pcp/pcp.c
> patching file pcp/pcp.h
> patching file pcp/pcp_promote_node.c
> patching file pcp_child.c
> patching file pool_auth.c
> patching file pool.h
> patching file pool_query_context.c
>
> Any help appreciated.
Those 2 patches are working on same parts so hunks on main.c are normal,
you have to applied by hand what have been rejected.

-- 
Gilles Darold
Administrateur de bases de données
http://dalibo.com - http://dalibo.org

diff -Nru pgpool-II-current/main.c pgpool-II-follow/main.c
--- pgpool-II-current/main.c	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/main.c	2011-03-09 09:42:12.000000000 +0100
@@ -106,6 +106,7 @@
 static int pool_pause(struct timeval *timeout);
 static void kill_all_children(int sig);
 static int get_next_master_node(void);
+static pid_t fork_follow_child(void);
 
 static RETSIGTYPE exit_handler(int sig);
 static RETSIGTYPE reap_handler(int sig);
@@ -137,6 +138,7 @@
 static int unix_fd;	/* unix domain socket fd */
 static int inet_fd;	/* inet domain socket fd */
 
+static int follow_pid; /* pid for child process handling follow command */
 static int pcp_pid; /* pid for child process handling PCP */
 static int pcp_unix_fd; /* unix domain socket fd for PCP (not used) */
 static int pcp_inet_fd; /* inet domain socket fd for PCP */
@@ -1597,6 +1599,37 @@
 		Req_info->master_node_id = new_master;
 	}
 
+	/* 
+	In master/slaver streaming replication we start degenerating
+	all backends as they are not replicated anymore
+	*/
+	int follow_cnt = 0;
+	if (MASTER_SLAVE && !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP))
+	{
+		/* Only if the failover is against the current master */
+		if ((Req_info->kind == NODE_DOWN_REQUEST) && (node_id == Req_info->master_node_id)) {
+		      for (i = 0; i < pool_config->backend_desc->num_backends; i++)
+		      {
+			       /* do not degenerate the new master */
+			      if (i != new_master) {
+				      BackendInfo *bkinfo;
+				      bkinfo = pool_get_node_info(i);
+				      pool_log("starting follow degeneration. shutdown host %s(%d)",
+						       bkinfo->backend_hostname,
+						       bkinfo->backend_port);
+				      bkinfo->backend_status = CON_DOWN;      /* set down status */
+				      follow_cnt++;
+			      }
+		      }
+		      if (follow_cnt == 0)
+		      {
+			      pool_log("failover: no follow backends are degenerated");
+		      } else {
+			      pool_log("failover: %d follow backends have been degenerated", follow_cnt);
+		      }
+		}
+	}
+
 /* no need to wait since it will be done in reap_handler */
 #ifdef NOT_USED
 	while (wait(NULL) > 0)
@@ -1609,6 +1642,16 @@
 	memset(Req_info->node_id, -1, sizeof(int) * MAX_NUM_BACKENDS);
 	pool_semaphore_unlock(REQUEST_INFO_SEM);
 
+	/* Save primary node id */
+	if (follow_cnt > 0)
+	{
+		Req_info->primary_node_id = new_master;
+	} else {
+		Req_info->primary_node_id = find_primary_node();
+	}
+	Req_info->master_node_id = Req_info->primary_node_id;
+	pool_log("Primary node id saved: %d", Req_info->primary_node_id);
+
 	/* fork the children */
 	for (i=0;i<pool_config->num_init_children;i++)
 	{
@@ -1629,15 +1672,19 @@
 				 BACKEND_INFO(node_id).backend_port);
 	}
 
-	/* Save primary node id */
-	Req_info->primary_node_id = find_primary_node();
-
 	switching = 0;
 
 	/* kick wakeup_handler in pcp_child to notice that
-	 * faiover/failback done
+	 * failover/failback done
 	 */
 	kill(pcp_pid, SIGUSR2);
+
+	/* exec follow_master_command */
+	if ( (follow_cnt > 0) && (pool_config->follow_master_command) )
+	{
+	      follow_pid = fork_follow_child();
+	}
+
 }
 
 /*
@@ -2344,7 +2391,7 @@
 			return -1;
 		}
 
-		status = do_query(con, "SELECT pg_is_in_recovery() AND pgpool_walrecrunning()",
+		status = do_query(con, "SELECT not pg_is_in_recovery() AND not pgpool_walrecrunning()",
 						  &res, PROTO_MAJOR_V3);
 		if (res->numrows <= 0)
 		{
@@ -2358,7 +2405,7 @@
 		{
 			pool_log("find_primary_node: do_query returns NULL");
 		}
-		if (res->data[0] && !strcmp(res->data[0], "t"))
+		if (res->data[0] && !strcmp(res->data[0], "f"))
 		{
 			is_standby = true;
 		}   
@@ -2387,3 +2434,34 @@
 	pool_log("find_primary_node: primary node id is %d", i);
 	return i;
 }
+
+/*
+* fork a follow child
+*/
+pid_t fork_follow_child(void)
+{
+	pid_t pid;
+	int i;
+
+	pid = fork();
+
+	if (pid == 0)
+	{
+	      for (i = 0; i < pool_config->backend_desc->num_backends; i++)
+	      {
+		      BackendInfo *bkinfo;
+		      bkinfo = pool_get_node_info(i);
+		      pool_log("start triggering follow command.");
+		      if (bkinfo->backend_status == CON_DOWN)
+			      trigger_failover_command(i, pool_config->follow_master_command);
+	      }
+	      exit(0);
+	}
+	else if (pid == -1)
+	{
+	      pool_error("follow fork() failed. reason: %s", strerror(errno));
+	      exit(1);
+	}
+	return pid;
+}
+
diff -Nru pgpool-II-current/pgpool.conf.sample pgpool-II-follow/pgpool.conf.sample
--- pgpool-II-current/pgpool.conf.sample	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pgpool.conf.sample	2011-02-27 17:48:58.000000000 +0100
@@ -278,6 +278,17 @@
                                    #   %M = old master node id
                                    #   %P = old primary node id
                                    #   %% = '%' character
+follow_master_command = ''         # Executes this command after master failover.
+                                   # Special values:
+                                   #   %d = node id
+                                   #   %h = host name
+                                   #   %p = port number
+                                   #   %D = database cluster path
+                                   #   %m = new master node id
+                                   #   %H = hostname of the new master node
+                                   #   %M = old master node id
+                                   #   %P = old primary node id
+                                   #   %% = '%' character
 
 fail_over_on_backend_error = on    # Initiates failover when writing to the
                                    # backend communication socket fails
diff -Nru pgpool-II-current/pgpool.conf.sample-master-slave pgpool-II-follow/pgpool.conf.sample-master-slave
--- pgpool-II-current/pgpool.conf.sample-master-slave	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pgpool.conf.sample-master-slave	2011-02-27 17:48:52.000000000 +0100
@@ -278,6 +278,17 @@
                                    #   %M = old master node id
                                    #   %P = old primary node id
                                    #   %% = '%' character
+follow_master_command = ''         # Executes this command after master failover.
+                                   # Special values:
+                                   #   %d = node id
+                                   #   %h = host name
+                                   #   %p = port number
+                                   #   %D = database cluster path
+                                   #   %m = new master node id
+                                   #   %H = hostname of the new master node
+                                   #   %M = old master node id
+                                   #   %P = old primary node id
+                                   #   %% = '%' character
 
 fail_over_on_backend_error = on    # Initiates failover when writing to the
                                    # backend communication socket fails
diff -Nru pgpool-II-current/pgpool.conf.sample-replication pgpool-II-follow/pgpool.conf.sample-replication
--- pgpool-II-current/pgpool.conf.sample-replication	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pgpool.conf.sample-replication	2011-02-27 17:49:05.000000000 +0100
@@ -278,6 +278,17 @@
                                    #   %M = old master node id
                                    #   %P = old primary node id
                                    #   %% = '%' character
+follow_master_command = ''         # Executes this command after master failover.
+                                   # Special values:
+                                   #   %d = node id
+                                   #   %h = host name
+                                   #   %p = port number
+                                   #   %D = database cluster path
+                                   #   %m = new master node id
+                                   #   %H = hostname of the new master node
+                                   #   %M = old master node id
+                                   #   %P = old primary node id
+                                   #   %% = '%' character
 
 fail_over_on_backend_error = on    # Initiates failover when writing to the
                                    # backend communication socket fails
diff -Nru pgpool-II-current/pgpool.conf.sample-stream pgpool-II-follow/pgpool.conf.sample-stream
--- pgpool-II-current/pgpool.conf.sample-stream	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pgpool.conf.sample-stream	2011-02-27 17:49:10.000000000 +0100
@@ -279,6 +279,17 @@
                                    #   %M = old master node id
                                    #   %P = old primary node id
                                    #   %% = '%' character
+follow_master_command = ''         # Executes this command after master failover.
+                                   # Special values:
+                                   #   %d = node id
+                                   #   %h = host name
+                                   #   %p = port number
+                                   #   %D = database cluster path
+                                   #   %m = new master node id
+                                   #   %H = hostname of the new master node
+                                   #   %M = old master node id
+                                   #   %P = old primary node id
+                                   #   %% = '%' character
 
 fail_over_on_backend_error = on    # Initiates failover when writing to the
                                    # backend communication socket fails
diff -Nru pgpool-II-current/pool_config.c pgpool-II-follow/pool_config.c
--- pgpool-II-current/pool_config.c	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pool_config.c	2011-02-27 17:47:48.000000000 +0100
@@ -1904,6 +1904,7 @@
 	pool_config->health_check_period = 0;
 	pool_config->health_check_user = "nobody";
 	pool_config->failover_command = "";
+	pool_config->follow_master_command = "";
 	pool_config->failback_command = "";
 	pool_config->fail_over_on_backend_error = 1;
 	pool_config->insert_lock = 1;
@@ -2811,6 +2812,26 @@
 			pool_config->failover_command = str;
 		}
 
+		else if (!strcmp(key, "follow_master_command") &&
+				 CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
+		{
+			char *str;
+
+			if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
+			{
+				PARSE_ERROR();
+				fclose(fd);
+				return(-1);
+			}
+			str = extract_string(yytext, token);
+			if (str == NULL)
+			{
+				fclose(fd);
+				return(-1);
+			}
+			pool_config->follow_master_command = str;
+		}
+
 		else if (!strcmp(key, "failback_command") &&
 				 CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
 		{
diff -Nru pgpool-II-current/pool_config.h pgpool-II-follow/pool_config.h
--- pgpool-II-current/pool_config.h	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pool_config.h	2011-02-27 17:47:48.000000000 +0100
@@ -108,6 +108,7 @@
 	int health_check_period;	/* health check period */
 	char *health_check_user;		/* PostgreSQL user name for health check */
 	char *failover_command;     /* execute command when failover happens */
+	char *follow_master_command; /* execute command when failover is ended */
 	char *failback_command;     /* execute command when failback happens */
 
 	/*
diff -Nru pgpool-II-current/pool_config.l pgpool-II-follow/pool_config.l
--- pgpool-II-current/pool_config.l	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pool_config.l	2011-02-27 17:47:48.000000000 +0100
@@ -179,6 +179,7 @@
 	pool_config->health_check_period = 0;
 	pool_config->health_check_user = "nobody";
 	pool_config->failover_command = "";
+	pool_config->follow_master_command = "";
 	pool_config->failback_command = "";
 	pool_config->fail_over_on_backend_error = 1;
 	pool_config->insert_lock = 1;
@@ -1086,6 +1087,26 @@
 			pool_config->failover_command = str;
 		}
 
+		else if (!strcmp(key, "follow_master_command") &&
+				 CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
+		{
+			char *str;
+
+			if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY)
+			{
+				PARSE_ERROR();
+				fclose(fd);
+				return(-1);
+			}
+			str = extract_string(yytext, token);
+			if (str == NULL)
+			{
+				fclose(fd);
+				return(-1);
+			}
+			pool_config->follow_master_command = str;
+		}
+
 		else if (!strcmp(key, "failback_command") &&
 				 CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
 		{
diff -Nru pgpool-II-current/pool_process_reporting.c pgpool-II-follow/pool_process_reporting.c
--- pgpool-II-current/pool_process_reporting.c	2011-02-27 17:36:25.000000000 +0100
+++ pgpool-II-follow/pool_process_reporting.c	2011-02-27 17:47:48.000000000 +0100
@@ -321,6 +321,11 @@
 	strncpy(status[i].desc, "failover command", POOLCONFIG_MAXDESCLEN);
 	i++;
 
+	strncpy(status[i].name, "follow_master_command", POOLCONFIG_MAXNAMELEN);
+	snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", pool_config->follow_master_command);
+	strncpy(status[i].desc, "follow master command", POOLCONFIG_MAXDESCLEN);
+	i++;
+
 	strncpy(status[i].name, "failback_command", POOLCONFIG_MAXNAMELEN);
 	snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", pool_config->failback_command);
 	strncpy(status[i].desc, "failback command", POOLCONFIG_MAXDESCLEN);
_______________________________________________
Pgpool-hackers mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgpool-hackers

Reply via email to