pgpool2.git / summary / log / commit / refs

commit    fcf2f965f58bb0ae596952df65bf9f32ea5c52f5
Author:   Yoshiyuki Asaba <y-asaba at pgfoundry.org>
Date:     Thu Dec 27 02:21:49 2007 +0000

    Allow '%m' character to obtain master node id in failover_command and
    failback_command.


doc/pgpool-en.html | 1 + doc/pgpool-ja.html | 1 + main.c | 32 ++++++++++++++++++++++++-------- pgpool.conf.sample | 2 ++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html index 052b970e2..70e5f77a3 100644 --- a/doc/pgpool-en.html +++ b/doc/pgpool-en.html @@ -484,6 +484,7 @@ pgpool-II replaces special characters to backend information. <tr><td>%p</td><td>Port number of a detached node.</td></tr> <tr><td>%D</td><td>Database cluster directory of a detached node. </td></tr> +<tr><td>%m</td><td>Master node ID.</td></tr> <tr><td>%%</td><td>'%' character</td></tr> </table> </center> diff --git a/doc/pgpool-ja.html b/doc/pgpool-ja.html index 0dc79fbbd..a50ab093d 100644 --- a/doc/pgpool-ja.html +++ b/doc/pgpool-ja.html @@ -491,6 +491,7 @@ prefork$B$9$k(Bpgpool-II$B$N%5!<%P%W%m%;%9$N?t$G$9!%%G%U%)%k%HCM$O(B32$B$K$ <tr><td>%p</td><td>$B@Z$jN%$5$l$?%N!<%I$N%]!<%HHV9f(B</td></tr> <tr><td>%D</td><td>$B@Z$jN%$5$l$?%N!<%I$N%G!<%?%Y!<%9%/%i%9%?%Q%9(B </td></tr> +<tr><td>%m</td><td>$B%^%9%?!<$N%N!<%IHV9f(B</td></tr> <tr><td>%%</td><td>'%'$BJ8;z(B</td></tr> </table> </center> diff --git a/main.c b/main.c index 35fd83791..d829b80bc 100644 --- a/main.c +++ b/main.c @@ -93,6 +93,7 @@ static void reload_config(void); static int pool_pause(struct timeval *timeout); static void pool_sleep(unsigned int second); static void kill_all_children(int sig); +static int get_next_master_node(void); static RETSIGTYPE exit_handler(int sig); static RETSIGTYPE reap_handler(int sig); @@ -1036,6 +1037,19 @@ static RETSIGTYPE exit_handler(int sig) myexit(0); } +/* + * calculate next master node id + */ +static int get_next_master_node(void) +{ + int i; + for (i=0;i<pool_config->backend_desc->num_backends;i++) + { + if (VALID_BACKEND(i)) + break; + } + return i; +} /* * handle SIGUSR1 @@ -1057,6 +1071,7 @@ static void failover(void) { int node_id; int i; + int new_master; pool_debug("failover_handler called"); @@ -1158,19 +1173,15 @@ static void failover(void) } } - for (i=0;i<pool_config->backend_desc->num_backends;i++) - { - if (VALID_BACKEND(i)) - break; - } + new_master = get_next_master_node(); - if (i == pool_config->backend_desc->num_backends) + if (new_master == pool_config->backend_desc->num_backends) { pool_error("failover_handler: no valid DB node found"); } else { - if (Req_info->master_node_id == i && *InRecovery == 0) + if (Req_info->master_node_id == new_master && *InRecovery == 0) { pool_log("failover_handler: do not restart pgpool. same master node %d was selected", i); if (Req_info->kind == NODE_UP_REQUEST) @@ -1193,7 +1204,7 @@ static void failover(void) } pool_log("failover_handler: set new master node: %d", i); - Req_info->master_node_id = i; + Req_info->master_node_id = new_master; } /* kill all children */ @@ -1730,6 +1741,11 @@ static int trigger_failover_command(int node, const char *command_line) string_append_char(exec_cmd, info->backend_hostname); break; + case 'm': /* master node id */ + snprintf(port_buf, sizeof(port_buf), "%d", get_next_master_node()); + string_append_char(exec_cmd, port_buf); + break; + case '%': /* escape */ string_append_char(exec_cmd, "%"); break; diff --git a/pgpool.conf.sample b/pgpool.conf.sample index 7ee499319..b2e8b537e 100644 --- a/pgpool.conf.sample +++ b/pgpool.conf.sample @@ -101,6 +101,7 @@ health_check_user = 'nobody' # %h = host name # %p = port number # %D = database cluster path +# %m = master node id # %% = '%' character # failover_command = '' @@ -110,6 +111,7 @@ failover_command = '' # %h = host name # %p = port number # %D = database cluster path +# %m = master node id # %% = '%' character # failback_command = '' [parent: feaf550d0621]