From: Pavan Deolasee Date: Mon, 18 Feb 2019 06:12:07 +0000 (+0530) Subject: Make comm_timeout configurable via GTM proxy GUC X-Git-Tag: XL_10_R1_1~4 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=919f7b72e84b2c7cbbc67d6dfc434d063cb3e795;p=postgres-xl.git Make comm_timeout configurable via GTM proxy GUC The default is now set to 0, which means infinite wait and matches the behaviour before the comm_timeout was introduced via f04b2efc3dbf93b0d004b5ea0493fcfa0046a35f. This patch introduces 2 GUCs on the datanode/coordinator side: gtm_connect_timeout - timeout in seconds for GTM/GTM proxy connection establishment. The default value of this GUC is 60s gtm_comm_timeout - timeout in seconds to wait for a response from the GTM/GTM Proxy. The default value of thie GUC is 0, which means wait forever This patch also introduces 1 GUC on the GTM proxy side: comm_timeout - timeout in seconds to wait for a response from the GTM. The default value of this GUC is 0, which means wait forever. So while the default behaviour remains the same as before the patch, this allows user to tune the values to avoid unpleasant cluster behaviour. --- diff --git a/src/backend/access/transam/gtm.c b/src/backend/access/transam/gtm.c index c304036203..0b19954ff9 100644 --- a/src/backend/access/transam/gtm.c +++ b/src/backend/access/transam/gtm.c @@ -35,8 +35,8 @@ /* Configuration variables */ char *GtmHost = "localhost"; int GtmPort = 6666; -static int GtmConnectTimeout = 60; -static int GtmCommTimeout = 60; +int GtmConnectTimeout = 60; +int GtmCommTimeout = 60; bool IsXidFromGTM = false; bool gtm_backup_barrier = false; extern bool FirstSnapshotSet; diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 261c67318e..fa5b5eb85c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -3178,6 +3178,30 @@ static struct config_int ConfigureNamesInt[] = NULL, NULL, NULL }, + { + {"gtm_connect_timeout", PGC_USERSET, UNGROUPED, + gettext_noop("Timeout in second to wait for GTM connection. " + "0 means wait forever."), + NULL, + 0 + }, + &GtmConnectTimeout, + 60, 0, INT_MAX, + NULL, NULL, NULL + }, + + { + {"gtm_comm_timeout", PGC_USERSET, UNGROUPED, + gettext_noop("Timeout in second to wait for a response from the " + "GTM or the GTM Proxy. 0 means wait forever."), + NULL, + 0 + }, + &GtmCommTimeout, + 0, 0, INT_MAX, + NULL, NULL, NULL + }, + #endif #endif /* PGXC */ diff --git a/src/gtm/proxy/gtm_proxy_opt.c b/src/gtm/proxy/gtm_proxy_opt.c index 6a5bd5edd9..78848573dc 100644 --- a/src/gtm/proxy/gtm_proxy_opt.c +++ b/src/gtm/proxy/gtm_proxy_opt.c @@ -55,6 +55,7 @@ extern int GTMProxyWorkerThreads; extern char *GTMProxyDataDir; extern char *GTMProxyConfigFileName; extern char *GTMConfigFileName; +extern int GTMProxyCommTimeout; /* @@ -220,6 +221,17 @@ struct config_int ConfigureNamesInt[] = GTM_PROXY_DEFAULT_WORKERS, 1, INT_MAX, 0, NULL }, + { + { + GTM_OPTNAME_COMM_TIMEOUT, GTMC_STARTUP, + gettext_noop("Timeout in second to wait for a response from the GTM. 0 means wait forever"), + NULL, + 0 + }, + >MProxyCommTimeout, + 0, 0, INT_MAX, + 0, NULL + }, /* End-of-list marker */ { {NULL, 0, NULL, NULL, 0}, NULL, 0, 0, 0, 0, NULL diff --git a/src/gtm/proxy/proxy_main.c b/src/gtm/proxy/proxy_main.c index b679369f87..1fffdcc8a2 100644 --- a/src/gtm/proxy/proxy_main.c +++ b/src/gtm/proxy/proxy_main.c @@ -69,6 +69,7 @@ static char *progname = "gtm_proxy"; char *ListenAddresses; int GTMProxyPortNumber; int GTMProxyWorkerThreads; +int GTMProxyCommTimeout = PROXY_CLIENT_TIMEOUT; char *GTMProxyDataDir; char *GTMProxyConfigFileName; char *GTMConfigFileName; @@ -1111,7 +1112,7 @@ GTMProxy_ThreadMain(void *argp) */ sprintf(gtm_connect_string, "host=%s port=%d node_name=%s remote_type=%d comm_timeout=%d", GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, - GTM_NODE_GTM_PROXY, PROXY_CLIENT_TIMEOUT); + GTM_NODE_GTM_PROXY, GTMProxyCommTimeout); thrinfo->thr_gtm_conn = PQconnectGTM(gtm_connect_string); @@ -1701,7 +1702,7 @@ HandleGTMError(GTM_Conn *gtm_conn) sprintf(gtm_connect_string, "host=%s port=%d node_name=%s " "remote_type=%d comm_timeout=%d", GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, - GTM_NODE_GTM_PROXY, PROXY_CLIENT_TIMEOUT); + GTM_NODE_GTM_PROXY, GTMProxyCommTimeout); gtm_conn = PQconnectGTM(gtm_connect_string); /* * If reconnect succeeded the connection will be ready to use out of @@ -3140,7 +3141,7 @@ ConnectGTM(void) sprintf(conn_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=1 comm_timeout=%d", GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, - GTM_NODE_GTM_PROXY_POSTMASTER, PROXY_CLIENT_TIMEOUT); + GTM_NODE_GTM_PROXY_POSTMASTER, GTMProxyCommTimeout); conn = PQconnectGTM(conn_str); if (GTMPQstatus(conn) != CONNECTION_OK) @@ -3204,7 +3205,7 @@ workerThreadReconnectToGTM(void) sprintf(gtm_connect_string, "host=%s port=%d node_name=%s remote_type=%d " "client_id=%u comm_timeout=%d", GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, - GTM_NODE_GTM_PROXY, saveMyClientId, PROXY_CLIENT_TIMEOUT); + GTM_NODE_GTM_PROXY, saveMyClientId, GTMProxyCommTimeout); elog(DEBUG1, "Worker thread connecting to %s", gtm_connect_string); GetMyThreadInfo->thr_gtm_conn = PQconnectGTM(gtm_connect_string); diff --git a/src/include/access/gtm.h b/src/include/access/gtm.h index bf7c889c66..01f10cb5e8 100644 --- a/src/include/access/gtm.h +++ b/src/include/access/gtm.h @@ -16,6 +16,8 @@ extern char *GtmHost; extern int GtmPort; extern bool gtm_backup_barrier; +extern int GtmCommTimeout; +extern int GtmConnectTimeout; extern bool IsXidFromGTM; extern GlobalTransactionId currentGxid; diff --git a/src/include/gtm/gtm_opt.h b/src/include/gtm/gtm_opt.h index 3701d1c469..70699f6f7a 100644 --- a/src/include/gtm/gtm_opt.h +++ b/src/include/gtm/gtm_opt.h @@ -348,6 +348,7 @@ const char *const config_type_names[] =\ #define GTM_OPTNAME_STATUS_READER "status_reader" #define GTM_OPTNAME_SYNCHRONOUS_BACKUP "synchronous_backup" #define GTM_OPTNAME_WORKER_THREADS "worker_threads" +#define GTM_OPTNAME_COMM_TIMEOUT "comm_timeout" #endif /* GTM_OPT_H */