diff options
author | Michael Paquier | 2012-07-12 04:43:07 +0000 |
---|---|---|
committer | Michael Paquier | 2012-07-12 04:43:07 +0000 |
commit | e93517a5a0a104643f3a3e1d1329afc5dd658489 (patch) | |
tree | 007733ebd4916b87df36122764161ef92a1f7060 | |
parent | 135d0bb4d2e7c95e7379091afd9e8063419e1e41 (diff) |
Simplify reconnection protocol of GTM-Proxy to GTM
With this commit, reconnection of a GTM-Proxy to a GTM instance
is controlled only with the interval time between 2 reconnections.
While being in reconnection waiting process, it is possible to
specify new GTM connection information with gtm_ctl reconnect.
In consequence, 5 setting parameters of GTM-Proxy are removed here:
- err_wait_count
- err_wait_interval
- err_wait_idle
- gtm_connect_retry_count
- gtm_connect_retry_idle
Related information and documentation also is removed.
-rw-r--r-- | src/gtm/proxy/gtm_proxy.conf.sample | 11 | ||||
-rw-r--r-- | src/gtm/proxy/gtm_proxy_opt.c | 73 | ||||
-rw-r--r-- | src/gtm/proxy/proxy_main.c | 167 | ||||
-rw-r--r-- | src/include/gtm/gtm_opt.h | 5 | ||||
-rw-r--r-- | src/include/gtm/libpq-int.h | 5 |
5 files changed, 36 insertions, 225 deletions
diff --git a/src/gtm/proxy/gtm_proxy.conf.sample b/src/gtm/proxy/gtm_proxy.conf.sample index 3b275a43e6..b29c4dea57 100644 --- a/src/gtm/proxy/gtm_proxy.conf.sample +++ b/src/gtm/proxy/gtm_proxy.conf.sample @@ -53,19 +53,8 @@ #------------------------------------------------------------------------------ # Behavior at GTM communication error #------------------------------------------------------------------------------ -#gtm_connect_retry_idle = 0 # How long (in secs) to wait before GTM proxy - # retries to connect to GTM. -#gtm_connect_retry_count = 0 # How many times GTM proxy retries to connect - # to GTM. #gtm_connect_retry_interval = 0 # How long (in secs) to wait until the next # retry to connect to GTM. -#err_wait_idle = 0 # How long (in secs) GTM proxy should wait - # before it detects reconnect from gtm_ctl. -#err_wait_count = 0 # How many times GTM should detect reconnect - # from gtm_ctl. -#err_wait_interval = 0 # How long (in secs) GTM proxy should wait - # until next detection of reconnect from - # gtm_ctl. # # #------------------------------------------------------------------------------ diff --git a/src/gtm/proxy/gtm_proxy_opt.c b/src/gtm/proxy/gtm_proxy_opt.c index 7459e29de1..4ed7722f93 100644 --- a/src/gtm/proxy/gtm_proxy_opt.c +++ b/src/gtm/proxy/gtm_proxy_opt.c @@ -49,19 +49,8 @@ extern int tcp_keepalives_count; extern int tcp_keepalives_interval; extern char *GTMServerHost; extern int GTMProxyPortNumber; -extern bool IsGTMConnectRetryRequired; -extern int GTMConnectRetryIdle; -extern int GTMConnectRetryCount; extern int GTMConnectRetryInterval; extern int GTMServerPortNumber; -/* -extern int GTMServerKeepalivesIdle; -extern int GTMServerKeepalivesInterval; -extern int GTMServerKeepalivesCount; -*/ -extern int GTMErrorWaitIdle; -extern int GTMErrorWaitInterval; -extern int GTMErrorWaitCount; extern int GTMProxyWorkerThreads; extern char *GTMProxyDataDir; extern char *GTMProxyConfigFileName; @@ -185,36 +174,13 @@ struct config_int ConfigureNamesInt[] = }, { { - GTM_OPTNAME_CONNECT_RETRY_COUNT, GTMC_SIGHUP, - gettext_noop("Retry count to try to reconnect to GTM."), - NULL, - 0 - }, - >MConnectRetryCount, - 0, 0, INT_MAX, - 0, NULL - }, - { - { - GTM_OPTNAME_CONNECT_RETRY_IDLE, GTMC_SIGHUP, - gettext_noop("Idle time in second before GTM standby retries " - "connection to GTM."), - NULL, - GTMOPT_UNIT_TIME - }, - >MConnectRetryIdle, - 0, 0, INT_MAX, - 0, NULL - }, - { - { GTM_OPTNAME_CONNECT_RETRY_INTERVAL, GTMC_SIGHUP, gettext_noop("Interval in second to detect reconnect command."), NULL, GTMOPT_UNIT_TIME }, >MConnectRetryInterval, - 0, 0, INT_MAX, + 60, 0, INT_MAX, 0, NULL }, { @@ -252,43 +218,6 @@ struct config_int ConfigureNamesInt[] = }, { { - GTM_OPTNAME_ERR_WAIT_IDLE, GTMC_SIGHUP, - gettext_noop("Time duration after connection to GTM failed and " - "wait for reconnect command begins."), - gettext_noop("This parameter determines GTM Proxy behavior " - "when GTM communication error is encountered."), - 0 - }, - >MErrorWaitIdle, - 0, 0, INT_MAX, - 0, NULL - }, - { - { - GTM_OPTNAME_ERR_WAIT_INTERVAL, GTMC_SIGHUP, - gettext_noop("Wait interval to wait for reconnect."), - gettext_noop("This parameter determines GTM Proxy behavior " - "when GTM communication error is encountered."), - 0 - }, - >MErrorWaitInterval, - 0, 0, INT_MAX, - 0, NULL - }, - { - { - GTM_OPTNAME_ERR_WAIT_COUNT, GTMC_SIGHUP, - gettext_noop("Number of err_wait_interval to wait for reconnect."), - gettext_noop("This parameter determines GTM Prox behavior " - "when GTM communication error is encountered."), - 0 - }, - >MErrorWaitCount, - 0, 0, INT_MAX, - 0, NULL - }, - { - { GTM_OPTNAME_WORKER_THREADS, GTMC_STARTUP, gettext_noop("Number of worker thread."), NULL, diff --git a/src/gtm/proxy/proxy_main.c b/src/gtm/proxy/proxy_main.c index 2cc78f7dfd..9de9d0c7a2 100644 --- a/src/gtm/proxy/proxy_main.c +++ b/src/gtm/proxy/proxy_main.c @@ -71,18 +71,10 @@ char *GTMProxyDataDir; char *GTMProxyConfigFileName; char *GTMConfigFileName; -/* GTM communication error handling options */ -int GTMErrorWaitIdle = 0; -int GTMErrorWaitInterval = 0; /* Duration of each wait */ -int GTMErrorWaitCount = 0; /* How many durations to wait */ - char *GTMServerHost; int GTMServerPortNumber; -/* GTM connection retry info */ -int GTMConnectRetryIdle = 0; -int GTMConnectRetryCount = 0; -int GTMConnectRetryInterval = 0; +int GTMConnectRetryInterval = 60; /* * Keepalives setup for the connection with GTM server @@ -579,8 +571,6 @@ main(int argc, char *argv[]) char *log_file = NULL; char *gtm_host = NULL; char *gtm_port = NULL; - char *gtm_err_wait_secs = NULL; - char *gtm_err_wait_count = NULL; isStartUp = true; @@ -612,7 +602,7 @@ main(int argc, char *argv[]) /* * Parse the command like options and set variables */ - while ((opt = getopt(argc, argv, "h:i:p:n:D:l:s:t:w:z:")) != -1) + while ((opt = getopt(argc, argv, "h:i:p:n:D:l:s:t:")) != -1) { switch (opt) { @@ -672,20 +662,6 @@ main(int argc, char *argv[]) gtm_port = strdup(optarg); break; - case 'w': - /* Duration to wait at GTM communication error */ - if (gtm_err_wait_secs) - free(gtm_err_wait_secs); - gtm_err_wait_secs = strdup(optarg); - break; - - case 'z': - /* How many durations to wait */ - if (gtm_err_wait_count) - free(gtm_err_wait_count); - gtm_err_wait_count = strdup(optarg); - break; - default: write_stderr("Try \"%s --help\" for more information.\n", progname); @@ -754,18 +730,6 @@ main(int argc, char *argv[]) free(gtm_port); gtm_port = NULL; } - if (gtm_err_wait_secs) - { - SetConfigOption(GTM_OPTNAME_ERR_WAIT_INTERVAL, gtm_err_wait_secs, GTMC_STARTUP, GTMC_S_OVERRIDE); - free(gtm_err_wait_secs); - gtm_err_wait_secs = NULL; - } - if (gtm_err_wait_count) - { - SetConfigOption(GTM_OPTNAME_ERR_WAIT_COUNT, gtm_err_wait_count, GTMC_STARTUP, GTMC_S_OVERRIDE); - free(gtm_err_wait_count); - gtm_err_wait_count = NULL; - } /* @@ -1157,13 +1121,6 @@ GTMProxy_ThreadMain(void *argp) initStringInfo(&input_message); - /* - * Set GTM communication error handling options. - */ - thrinfo->thr_gtm_conn->gtmErrorWaitIdle = GTMErrorWaitIdle; - thrinfo->thr_gtm_conn->gtmErrorWaitInterval = GTMErrorWaitInterval; - thrinfo->thr_gtm_conn->gtmErrorWaitCount = GTMErrorWaitCount; - thrinfo->reconnect_issued = FALSE; /* @@ -1665,100 +1622,51 @@ ProcessCommand(GTMProxy_ConnectionInfo *conninfo, GTM_Conn *gtm_conn, static GTM_Conn * HandleGTMError(GTM_Conn *gtm_conn) { - GTM_Conn *new_gtm_conn; - int ii; - Assert(gtm_conn && gtm_conn->last_errno != 0); - if (GTMConnectRetryCount > 0) + elog(NOTICE, + "GTM communication error was detected. Retrying connection, interval = %d.", + GTMConnectRetryInterval); + for (;;) { - int ii; char gtm_connect_string[1024]; - elog(NOTICE, - "GTM communication error was detected. Retrying connection. idle: %d, count = %d, interval = %d.", - GTMConnectRetryIdle, GTMConnectRetryCount, GTMConnectRetryInterval); + /* Wait and retry reconnect */ + elog(DEBUG1, "Waiting %d secs.", GTMConnectRetryInterval); + pg_usleep((long)GTMConnectRetryInterval * 1000000L); + + /* + * Connect retry + * Because this proxy has been registered to current + * GTM, we don't re-register it. + * + * Please note that GTM-Proxy accepts "reconnect" from gtm_ctl + * even while it is retrying to connect to GTM. + */ + elog(DEBUG1, "Try to reconnect to GTM"); + /* Make sure RECONNECT command would not come while we reconnecting */ + Disable_Longjmp(); + /* Close and free previous connection object if still active */ GTMPQfinish(gtm_conn); + /* Reconnect */ sprintf(gtm_connect_string, "host=%s port=%d node_name=%s remote_type=%d", GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, GTM_NODE_GTM_PROXY); - /* Wait and retry reconnect */ - if (GTMConnectRetryIdle > 0) { - elog(DEBUG1, "Waiting %d secs.", GTMConnectRetryIdle); - pg_usleep((long)GTMConnectRetryIdle * 1000000L); - } - /* GTM connection retry */ - for (ii = 0; ii < GTMConnectRetryCount; ii++) - { - /* - * Connect retry - * Because this proxy has been registered to current - * GTM, we don't re-register it. - * - * Please note that GTM-Proxy accepts "reconnect" from gtm_ctl - * even while it is retrying to connect to GTM. - */ - elog(DEBUG1, "Try to reconnect to GTM, count %d.", ii); - Disable_Longjmp(); - new_gtm_conn = PQconnectGTM(gtm_connect_string); - Enable_Longjmp(); - if (new_gtm_conn != NULL) { - elog(NOTICE, "GTM connection retry succeeded, count %d.", ii); - break; - } - /* Wait if not successful */ - elog(DEBUG1, "Reconnect failed. Sleeping %d secs.", GTMConnectRetryInterval); - Disable_Longjmp(); - pg_usleep((long)GTMConnectRetryInterval * 1000000L); - Enable_Longjmp(); - } - if (new_gtm_conn != NULL) - { - GetMyThreadInfo->thr_gtm_conn = new_gtm_conn; - return(new_gtm_conn); - } - elog(NOTICE, "GTM connection retry failed."); - } - if (GTMErrorWaitIdle == 0 && GTMErrorWaitInterval == 0 && GTMErrorWaitCount == 0) - { + gtm_conn = PQconnectGTM(gtm_connect_string); /* - * GTM communication error detected, retry failed - * but cannot wait for reconnect. + * If reconnect succeeded the connection will be ready to use out of + * there, otherwise thr_gtm_conn will be set to NULL preventing double + * free. */ - elog(FATAL, - "No action specified to wait for reconnect."); - exit(1); /* Just in case */ - } - /* - * Now wait for reconnect, SIGUSR2. - * - * All the controls are done by Disable_Logjmp() and Enable_Longjmp(). - * No longjump occurs after Disable_longjmp() and before Enable_longjmp(). - * Longjmp occurs inside Enable_longjmp(), only when SIGUSR2 was handled - * correctly. - * - * For details, see gtm_proxy.h. - */ - elog(NOTICE, - "Waiting for reconnect action from gtm_ctl. idie: %d, count: %d, interval:%d", - GTMErrorWaitIdle, GTMErrorWaitCount, GTMErrorWaitInterval); - Disable_Longjmp(); - elog(DEBUG1, "Witing %d secs.", GTMErrorWaitIdle); - pg_usleep((long)GTMErrorWaitIdle * 1000000L); - Enable_Longjmp(); - - for (ii = 0; ii < GTMErrorWaitCount; ii++) - { - Disable_Longjmp(); - elog(DEBUG1, "Waiting %d secs, count %d.", GTMErrorWaitInterval, ii); - pg_usleep((long)GTMErrorWaitInterval * 1000000L); + GetMyThreadInfo->thr_gtm_conn = gtm_conn; Enable_Longjmp(); + if (gtm_conn) + { + /* Success, update thread info and return new connection */ + elog(NOTICE, "GTM connection retry succeeded."); + return gtm_conn; + } + elog(NOTICE, "GTM connection retry failed."); } - /* - * No reconnect received. - */ - elog(FATAL, - "No reconnect command recdeived frm gtm_ctl."); - exit(1); /* Just in case */ } static GTM_Conn * @@ -3387,11 +3295,6 @@ workerThreadReconnectToGTM(void) elog(FATAL, "Worker thread GTM connection failed."); elog(LOG, "Worker thread connection done."); - /* Set GTM communication error handling option */ - GetMyThreadInfo->thr_gtm_conn->gtmErrorWaitIdle = GTMErrorWaitIdle; - GetMyThreadInfo->thr_gtm_conn->gtmErrorWaitInterval = GTMErrorWaitInterval; - GetMyThreadInfo->thr_gtm_conn->gtmErrorWaitCount = GTMErrorWaitCount; - /* Initialize the command processing */ GetMyThreadInfo->reconnect_issued = FALSE; } diff --git a/src/include/gtm/gtm_opt.h b/src/include/gtm/gtm_opt.h index 6d33782055..3701d1c469 100644 --- a/src/include/gtm/gtm_opt.h +++ b/src/include/gtm/gtm_opt.h @@ -332,12 +332,7 @@ const char *const config_type_names[] =\ #define GTM_OPTNAME_ACTIVE_PORT "active_port" #define GTM_OPTNAME_CONFIG_FILE "config_file" #define GTM_OPTNAME_DATA_DIR "data_dir" -#define GTM_OPTNAME_ERR_WAIT_COUNT "err_wait_count" -#define GTM_OPTNAME_ERR_WAIT_INTERVAL "err_wait_interval" -#define GTM_OPTNAME_ERR_WAIT_IDLE "err_wait_idle" #define GTM_OPTNAME_ERROR_REPORTER "error_reporter" -#define GTM_OPTNAME_CONNECT_RETRY_COUNT "gtm_connect_retry_count" -#define GTM_OPTNAME_CONNECT_RETRY_IDLE "gtm_connect_retry_idle" #define GTM_OPTNAME_CONNECT_RETRY_INTERVAL "gtm_connect_retry_interval" #define GTM_OPTNAME_GTM_HOST "gtm_host" #define GTM_OPTNAME_GTM_PORT "gtm_port" diff --git a/src/include/gtm/libpq-int.h b/src/include/gtm/libpq-int.h index 0861560a61..692bf201dc 100644 --- a/src/include/gtm/libpq-int.h +++ b/src/include/gtm/libpq-int.h @@ -90,11 +90,6 @@ struct gtm_conn /* Buffer for receiving various parts of messages */ PQExpBufferData workBuffer; /* expansible string */ - /* Options to handle GTM communication error */ - int gtmErrorWaitIdle; /* If true, wait reconnect signal. */ - int gtmErrorWaitInterval; /* Duration of the wait time in second */ - int gtmErrorWaitCount; /* How many durations to wait */ - /* Pointer to the result of last operation */ GTM_Result *result; }; |