diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html index f3be3d4..e94fa04 100644 --- a/doc/pgpool-en.html +++ b/doc/pgpool-en.html @@ -851,6 +851,20 @@ local0.* /var/log/pgpool.log You need to reload pgpool.conf if you change health_check_retry_delay.

+ +
search_primary_node_timeout V3.3 -
+
+

The parameter specifies the maximum amount of time in seconds to search + for a primary node when a failover scenario occurs. + pgpool-II will search for the primary node for the amount of time given in case of + failover before giving up trying to search for a primary node. + 0 means keep trying forever +

+

+ You need to reload pgpool.conf if you change search_primary_node_timeout. +

+
+

Failover and failback

diff --git a/main.c b/main.c index 61b6ce9..a13e7df 100644 --- a/main.c +++ b/main.c @@ -2872,8 +2872,15 @@ static int find_primary_node_repeatedly(void) return -1; } + /* + * Try to find the new primary node and keep trying for + * search_primary_node_timeout seconds. + * search_primary_node_timeout = 0 means never timeout and keep searching + * indefinitely + */ pool_log("find_primary_node_repeatedly: waiting for finding a primary node"); - for (sec = 0; sec < pool_config->recovery_timeout; sec++) + for (sec = 0; (pool_config->search_primary_node_timeout == 0 || + sec < pool_config->search_primary_node_timeout); sec++) { node_id = find_primary_node(); if (node_id != -1) diff --git a/pgpool.conf b/pgpool.conf index 303ecf3..054b054 100644 --- a/pgpool.conf +++ b/pgpool.conf @@ -393,6 +393,11 @@ fail_over_on_backend_error = on # If set to off, pgpool will report an # error and disconnect the session. +search_primary_node_timeout = 10 + # Timeout in seconds to search for the + # primary node when a failover occurs. + # 0 means no timeout, keep searching + # for a primary node forever. #------------------------------------------------------------------------------ # ONLINE RECOVERY diff --git a/pgpool.conf.sample b/pgpool.conf.sample index 43fc2ab..fbed517 100644 --- a/pgpool.conf.sample +++ b/pgpool.conf.sample @@ -397,6 +397,11 @@ fail_over_on_backend_error = on # If set to off, pgpool will report an # error and disconnect the session. +search_primary_node_timeout = 10 + # Timeout in seconds to search for the + # primary node when a failover occurs. + # 0 means no timeout, keep searching + # for a primary node forever. #------------------------------------------------------------------------------ # ONLINE RECOVERY diff --git a/pgpool.conf.sample-master-slave b/pgpool.conf.sample-master-slave index e7be66f..57ad0ff 100644 --- a/pgpool.conf.sample-master-slave +++ b/pgpool.conf.sample-master-slave @@ -397,6 +397,11 @@ fail_over_on_backend_error = on # If set to off, pgpool will report an # error and disconnect the session. +search_primary_node_timeout = 10 + # Timeout in seconds to search for the + # primary node when a failover occurs. + # 0 means no timeout, keep searching + # for a primary node forever. #------------------------------------------------------------------------------ # ONLINE RECOVERY diff --git a/pgpool.conf.sample-replication b/pgpool.conf.sample-replication index 19589de..49ae922 100644 --- a/pgpool.conf.sample-replication +++ b/pgpool.conf.sample-replication @@ -396,6 +396,11 @@ fail_over_on_backend_error = on # If set to off, pgpool will report an # error and disconnect the session. +search_primary_node_timeout = 10 + # Timeout in seconds to search for the + # primary node when a failover occurs. + # 0 means no timeout, keep searching + # for a primary node forever. #------------------------------------------------------------------------------ # ONLINE RECOVERY diff --git a/pgpool.conf.sample-stream b/pgpool.conf.sample-stream index 0116f24..fd83acf 100644 --- a/pgpool.conf.sample-stream +++ b/pgpool.conf.sample-stream @@ -396,6 +396,11 @@ fail_over_on_backend_error = on # If set to off, pgpool will report an # error and disconnect the session. +search_primary_node_timeout = 10 + # Timeout in seconds to search for the + # primary node when a failover occurs. + # 0 means no timeout, keep searching + # for a primary node forever. #------------------------------------------------------------------------------ # ONLINE RECOVERY diff --git a/pool_config.h b/pool_config.h index d56d785..3abdc71 100644 --- a/pool_config.h +++ b/pool_config.h @@ -147,6 +147,8 @@ typedef struct { char *recovery_1st_stage_command; /* Online recovery command in 1st stage */ char *recovery_2nd_stage_command; /* Online recovery command in 2nd stage */ int recovery_timeout; /* maximum time in seconds to wait for remote start-up */ + int search_primary_node_timeout; /* maximum time in seconds to search for new primary + * node after failover */ int client_idle_limit_in_recovery; /* If > 0, the client is forced to be * disconnected after n seconds idle * This parameter is only valid while in recovery 2nd stage */ diff --git a/pool_config.l b/pool_config.l index 9011656..33ef0f8 100644 --- a/pool_config.l +++ b/pool_config.l @@ -215,6 +215,7 @@ int pool_init_config(void) pool_config->recovery_1st_stage_command = ""; pool_config->recovery_2nd_stage_command = ""; pool_config->recovery_timeout = 90; + pool_config->search_primary_node_timeout = 10; pool_config->client_idle_limit_in_recovery = 0; pool_config->lobj_lock_table = ""; pool_config->ssl = 0; @@ -1443,6 +1444,20 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) pool_config->recovery_timeout = v; } + else if (!strcmp(key, "search_primary_node_timeout") && + CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) + { + int v = atoi(yytext); + + if (token != POOL_INTEGER || v < 0) + { + pool_error("pool_config: %s must be equal or higher than 0 numeric value", key); + fclose(fd); + return(-1); + } + pool_config->search_primary_node_timeout = v; + } + else if (!strcmp(key, "client_idle_limit_in_recovery") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) { diff --git a/pool_process_reporting.c b/pool_process_reporting.c index 7c7005c..357e7d3 100644 --- a/pool_process_reporting.c +++ b/pool_process_reporting.c @@ -570,6 +570,11 @@ POOL_REPORT_CONFIG* get_config(int *nrows) strncpy(status[i].desc, "max time in seconds to wait for the recovering node's postmaster", POOLCONFIG_MAXDESCLEN); i++; + strncpy(status[i].name, "search_primary_node_timeout", POOLCONFIG_MAXNAMELEN); + snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->search_primary_node_timeout); + strncpy(status[i].desc, "max time in seconds to search for primary node after failover", POOLCONFIG_MAXDESCLEN); + i++; + strncpy(status[i].name, "client_idle_limit_in_recovery", POOLCONFIG_MAXNAMELEN); snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->client_idle_limit_in_recovery); strncpy(status[i].desc, "if idle for this seconds, child connection closes in recovery 2nd statge", POOLCONFIG_MAXDESCLEN);