Make comm_timeout configurable via GTM proxy GUC
authorPavan Deolasee <[email protected]>
Mon, 18 Feb 2019 06:12:07 +0000 (11:42 +0530)
committerPavan Deolasee <[email protected]>
Mon, 18 Feb 2019 06:52:23 +0000 (12:22 +0530)
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.

src/backend/access/transam/gtm.c
src/backend/utils/misc/guc.c
src/gtm/proxy/gtm_proxy_opt.c
src/gtm/proxy/proxy_main.c
src/include/access/gtm.h
src/include/gtm/gtm_opt.h

index c30403620305496454612eed47deb8ecf21ceb7a..0b19954ff9dc6a04ecb6479c9ddec4e5fd9c112e 100644 (file)
@@ -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;
index 261c67318e1532200c64b2e646f6efb49de3bc04..fa5b5eb85cf03c4947201b7be2ef92b384eb4f2f 100644 (file)
@@ -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 */
 
index 6a5bd5edd96ad02e8891f7a81f1b7b03106a3045..78848573dc16bb9978164a13077858af5656500a 100644 (file)
@@ -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
+               },
+               &GTMProxyCommTimeout,
+               0, 0, INT_MAX,
+               0, NULL
+       },
        /* End-of-list marker */
        {
                {NULL, 0, NULL, NULL, 0}, NULL, 0, 0, 0, 0, NULL
index b679369f879b356e5dc17d7a48452a5fa55f0bb3..1fffdcc8a2e528d936fc6fdcb4dbf462fd9d3fa2 100644 (file)
@@ -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);
 
index bf7c889c66a76827d313c57f5901387204acc336..01f10cb5e8b40c3a95b685951247f10711b9254c 100644 (file)
@@ -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;
index 3701d1c469b288a4c82aa52960957ce23fdf6d06..70699f6f7a4b179d51a36d3a93b7a51ea4a4f6b7 100644 (file)
@@ -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 */