pgpool2.git / summary / log / commit / refs

commit    d416a58af4c03e4d07982ba9ccc0a33788f96e53
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Sun Dec 06 08:46:34 2009 +0000

    Add new configuration parameter fail_over_on_backend_error which
    controls the behavior when write to backend socket fails.
    
    Also add pool_log when postmaster administrative shutdown detected.


pgpool.conf.sample | 6 ++++++ pool.h | 9 +++++++++ pool_config.c | 15 +++++++++++++++ pool_config.l | 15 +++++++++++++++ pool_process_query.c | 1 + pool_process_reporting.c | 5 +++++ pool_stream.c | 16 +++++++++++----- 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/pgpool.conf.sample b/pgpool.conf.sample index 78655d74a..35cac9ea3 100644 --- a/pgpool.conf.sample +++ b/pgpool.conf.sample @@ -120,6 +120,12 @@ failover_command = '' # failback_command = '' +# If true, trigger fail over when writing to the backend communication +# socket fails. This is the same behavior of pgpool-II 2.2.x or +# earlier. If set to false, pgpool will report an error and disconnect +# the session. +fail_over_on_backend_error = true + # If true, automatically locks a table with INSERT statements to keep # SERIAL data consistency. If the data does not have SERIAL data # type, no lock will be issued. An /*INSERT LOCK*/ comment has the diff --git a/pool.h b/pool.h index 1bb2caf2d..bddbe6909 100644 --- a/pool.h +++ b/pool.h @@ -161,6 +161,15 @@ typedef struct { char *health_check_user; /* PostgreSQL user name for health check */ char *failover_command; /* execute command when failover happens */ char *failback_command; /* execute command when failback happens */ + + /* + * If true, trigger fail over when writing to the backend + * communication socket fails. This is the same behavior of + * pgpool-II 2.2.x or earlier. If set to false, pgpool will report + * an error and disconnect the session. + */ + int fail_over_on_backend_error; + char *recovery_user; /* PostgreSQL user name for online recovery */ char *recovery_password; /* PostgreSQL user password for online recovery */ char *recovery_1st_stage_command; /* Online recovery command in 1st stage */ diff --git a/pool_config.c b/pool_config.c index fa423cf06..eb5ffb26a 100644 --- a/pool_config.c +++ b/pool_config.c @@ -1883,6 +1883,7 @@ int pool_init_config(void) pool_config->health_check_user = "nobody"; pool_config->failover_command = ""; pool_config->failback_command = ""; + pool_config->fail_over_on_backend_error = 1; pool_config->insert_lock = 1; pool_config->ignore_leading_white_space = 1; pool_config->parallel_mode = 0; @@ -2476,6 +2477,20 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) pool_config->failback_command = str; } + else if (!strcmp(key, "fail_over_on_backend_error") && + CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) + { + int v = eval_logical(yytext); + + if (v < 0) + { + pool_error("pool_config: invalid value %s for %s", yytext, key); + fclose(fd); + return(-1); + } + pool_config->fail_over_on_backend_error = v; + } + else if (!strcmp(key, "recovery_user") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) { diff --git a/pool_config.l b/pool_config.l index 1a6b46df9..650ff281f 100644 --- a/pool_config.l +++ b/pool_config.l @@ -158,6 +158,7 @@ int pool_init_config(void) pool_config->health_check_user = "nobody"; pool_config->failover_command = ""; pool_config->failback_command = ""; + pool_config->fail_over_on_backend_error = 1; pool_config->insert_lock = 1; pool_config->ignore_leading_white_space = 1; pool_config->parallel_mode = 0; @@ -751,6 +752,20 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) pool_config->failback_command = str; } + else if (!strcmp(key, "fail_over_on_backend_error") && + CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) + { + int v = eval_logical(yytext); + + if (v < 0) + { + pool_error("pool_config: invalid value %s for %s", yytext, key); + fclose(fd); + return(-1); + } + pool_config->fail_over_on_backend_error = v; + } + else if (!strcmp(key, "recovery_user") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) { diff --git a/pool_process_query.c b/pool_process_query.c index e94dd3192..f50ade14f 100644 --- a/pool_process_query.c +++ b/pool_process_query.c @@ -282,6 +282,7 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend, */ if (detect_postmaster_down_error(CONNECTION(backend, i), MAJOR(backend)) == SPECIFIED_ERROR) { + pool_log("postmaster on DB node %d was shutdown by administrative command", i); /* detach backend node. */ was_error = 1; if (!VALID_BACKEND(i)) diff --git a/pool_process_reporting.c b/pool_process_reporting.c index ce4865ed1..34ab9c83c 100644 --- a/pool_process_reporting.c +++ b/pool_process_reporting.c @@ -200,6 +200,11 @@ void process_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend) strncpy(status[i].desc, "failback command", POOLCONFIG_MAXDESCLEN); i++; + strncpy(status[i].name, "fail_over_on_backend_error", POOLCONFIG_MAXNAMELEN); + snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->insert_lock); + strncpy(status[i].desc, "fail_over_on_backend_error", POOLCONFIG_MAXDESCLEN); + i++; + strncpy(status[i].name, "insert_lock", POOLCONFIG_MAXNAMELEN); snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->insert_lock); strncpy(status[i].desc, "insert lock", POOLCONFIG_MAXDESCLEN); diff --git a/pool_stream.c b/pool_stream.c index 5e1c4691d..fe5ff9845 100644 --- a/pool_stream.c +++ b/pool_stream.c @@ -442,10 +442,10 @@ int pool_flush_it(POOL_CONNECTION *cp) * just report debug message. */ if (cp->isbackend) - pool_error("pool_flush_it: write failed to backend (%s) offset: %d wlen: %d", - strerror(errno), offset, wlen); + pool_error("pool_flush_it: write failed to backend (%d). reason: %s offset: %d wlen: %d", + cp->db_node_id, strerror(errno), offset, wlen); else - pool_debug("pool_flush_it: write failed to frontend (%s) offset: %d wlen: %d", + pool_debug("pool_flush_it: write failed to frontend. reason: %s offset: %d wlen: %d", strerror(errno), offset, wlen); cp->wbufpo = 0; @@ -467,8 +467,14 @@ int pool_flush(POOL_CONNECTION *cp) { if (cp->isbackend) { - notice_backend_error(cp->db_node_id); - child_exit(1); + /* if fail_over_on_backend_erro is true, then trigger failover */ + if (pool_config->fail_over_on_backend_error) + { + notice_backend_error(cp->db_node_id); + child_exit(1); + } + else + return -1; } else { [parent: ba0d1230d351]