summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2015-08-24 07:18:32 +0000
committerPavan Deolasee2015-08-24 07:18:32 +0000
commitcb8aabd7cb89d30396d38a34ebc73ae72d111b37 (patch)
treed38251362f9a953dd10c3a2f9497139fe298abf4
parent302724f5be8323613993ce3e0d92d24a42db3835 (diff)
Add a timeout to GTM connection request.
This should ensure that backends don't stuck up forever in case GTM is not available. We don't do this when GTM proxies connect to GTM, but only when clients connect to either GTM proxy or GTM
-rw-r--r--contrib/pgxc_ctl/gtm_util.c3
-rw-r--r--contrib/pgxc_ctl/monitor.c3
-rw-r--r--contrib/pgxc_monitor/pgxc_monitor.c3
-rw-r--r--src/backend/access/transam/gtm.c11
4 files changed, 14 insertions, 6 deletions
diff --git a/contrib/pgxc_ctl/gtm_util.c b/contrib/pgxc_ctl/gtm_util.c
index 1abcecf980..20a64071a8 100644
--- a/contrib/pgxc_ctl/gtm_util.c
+++ b/contrib/pgxc_ctl/gtm_util.c
@@ -136,7 +136,8 @@ static GTM_Conn *connectGTM()
{
char connect_str[MAXLINE+1];
- snprintf(connect_str, MAXLINE, "host=%s port=%d node_name=%s remote_type=%d postmaster=0",
+ /* Use 60s as connection timeout */
+ snprintf(connect_str, MAXLINE, "host=%s port=%d node_name=%s remote_type=%d postmaster=0 connect_timeout=60",
sval(VAR_gtmMasterServer), atoi(sval(VAR_gtmMasterPort)), (myname == NULL) ? DefaultName : myname, GTM_NODE_COORDINATOR);
return(PQconnectGTM(connect_str));
}
diff --git a/contrib/pgxc_ctl/monitor.c b/contrib/pgxc_ctl/monitor.c
index f64bbec4e5..bc7608ad5c 100644
--- a/contrib/pgxc_ctl/monitor.c
+++ b/contrib/pgxc_ctl/monitor.c
@@ -457,7 +457,8 @@ do_gtm_ping(char *host, int port)
elog(ERROR, "ERROR: Invalid port number, %d.\n", port);
return -1;
}
- sprintf(connect_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=0",
+ /* Use 60s as connection timeout */
+ sprintf(connect_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=0 connect_timeout=60",
host, port, myName, GTM_NODE_COORDINATOR);
if ((conn = PQconnectGTM(connect_str)) == NULL)
{
diff --git a/contrib/pgxc_monitor/pgxc_monitor.c b/contrib/pgxc_monitor/pgxc_monitor.c
index e1aafae5f2..155cb1718d 100644
--- a/contrib/pgxc_monitor/pgxc_monitor.c
+++ b/contrib/pgxc_monitor/pgxc_monitor.c
@@ -179,7 +179,8 @@ do_gtm_ping(char *host, char* port, nodetype_t nodetype, char *nodename, bool ve
fprintf(stderr, "%s: -p is mandatory for -Z gtm or -Z gtm_proxy\n", progname);
exit(3);
}
- sprintf(connect_str, "host=%s port=%s node_name=%s remote_type=%d postmaster=0",
+ /* Use 60s as connection timeout */
+ sprintf(connect_str, "host=%s port=%s node_name=%s remote_type=%d postmaster=0 connect_timeout=60",
host, port, nodename ? nodename : "pgxc_monitor", GTM_NODE_COORDINATOR);
if ((conn = PQconnectGTM(connect_str)) == NULL)
{
diff --git a/src/backend/access/transam/gtm.c b/src/backend/access/transam/gtm.c
index 2a8e78547a..32e343792c 100644
--- a/src/backend/access/transam/gtm.c
+++ b/src/backend/access/transam/gtm.c
@@ -30,6 +30,7 @@
/* Configuration variables */
char *GtmHost = "localhost";
int GtmPort = 6666;
+static int GtmConnectTimeout = 60;
#ifdef XCP
bool IsXidFromGTM = false;
#endif
@@ -77,15 +78,19 @@ InitGTM(void)
else if (IS_PGXC_DATANODE)
remote_type = GTM_NODE_DATANODE;
- sprintf(conn_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=1",
- GtmHost, GtmPort, PGXCNodeName, remote_type);
+ /* Use 60s as connection timeout */
+ sprintf(conn_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=1 connect_timeout=%d",
+ GtmHost, GtmPort, PGXCNodeName, remote_type,
+ GtmConnectTimeout);
/* Log activity of GTM connections */
elog(DEBUG1, "Postmaster: connection established to GTM with string %s", conn_str);
}
else
{
- sprintf(conn_str, "host=%s port=%d node_name=%s", GtmHost, GtmPort, PGXCNodeName);
+ /* Use 60s as connection timeout */
+ sprintf(conn_str, "host=%s port=%d node_name=%s connect_timeout=%d",
+ GtmHost, GtmPort, PGXCNodeName, GtmConnectTimeout);
/* Log activity of GTM connections */
if (IsAutoVacuumWorkerProcess())