exit(3);
}
/* Use 60s as connection timeout */
- sprintf(connect_str, "host=%s port=%s node_name=%s remote_type=%d postmaster=0 connect_timeout=60",
+ sprintf(connect_str, "host=%s port=%s node_name=%s remote_type=%d postmaster=0 connect_timeout=60 comm_timeout=60",
host, port, nodename ? nodename : "pgxc_monitor", GTM_NODE_COORDINATOR);
if ((conn = PQconnectGTM(connect_str)) == NULL)
{
char *GtmHost = "localhost";
int GtmPort = 6666;
static int GtmConnectTimeout = 60;
+static int GtmCommTimeout = 60;
bool IsXidFromGTM = false;
bool gtm_backup_barrier = false;
extern bool FirstSnapshotSet;
remote_type = GTM_NODE_DATANODE;
/* Use 60s as connection timeout */
- sprintf(conn_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=1 connect_timeout=%d",
+ sprintf(conn_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=1 connect_timeout=%d comm_timeout=%d",
GtmHost, GtmPort, PGXCNodeName, remote_type,
- GtmConnectTimeout);
+ GtmConnectTimeout, GtmCommTimeout);
/* Log activity of GTM connections */
elog(DEBUG1, "Postmaster: connection established to GTM with string %s", conn_str);
else
{
/* Use 60s as connection timeout */
- sprintf(conn_str, "host=%s port=%d node_name=%s connect_timeout=%d",
- GtmHost, GtmPort, PGXCNodeName, GtmConnectTimeout);
+ sprintf(conn_str, "host=%s port=%d node_name=%s connect_timeout=%d comm_timeout=%d",
+ GtmHost, GtmPort, PGXCNodeName, GtmConnectTimeout,
+ GtmCommTimeout);
/* Log activity of GTM connections */
if (IsAutoVacuumWorkerProcess())
{"remote_type", NULL},
{"postmaster", NULL},
{"client_id", NULL},
+ {"comm_timeout", NULL},
/* Terminating entry --- MUST BE LAST */
{NULL, NULL}
};
conn->pgport = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "connect_timeout");
conn->connect_timeout = tmp ? strdup(tmp) : NULL;
+ tmp = conninfo_getval(connOptions, "comm_timeout");
+ conn->comm_timeout = tmp ? atoi(tmp) : 0;
tmp = conninfo_getval(connOptions, "node_name");
conn->gc_node_name = tmp ? strdup(tmp) : NULL;
tmp = conninfo_getval(connOptions, "postmaster");
while ((res = pqParseInput(conn)) == NULL)
{
int flushResult;
+ time_t finish_time;
/*
* If data remains unsent, send it. Else we might be waiting for the
*/
while ((flushResult = gtmpqFlush(conn)) > 0)
{
- if (gtmpqWait(false, true, conn))
+ if (conn->comm_timeout)
+ finish_time = time(NULL) + conn->comm_timeout;
+ else
+ finish_time = -1;
+
+ if (gtmpqWaitTimed(false, true, conn, finish_time))
{
- flushResult = -1;
- break;
+ /*
+ * conn->errorMessage has been set by gtmpqWait or
+ * gtmpqReadData.
+ */
+ return NULL;
}
}
+ /*
+ * By now we should have sent all pending data. If gtmpqFlush returned
+ * failure (< 0), then this is an error condition.
+ */
+ if (flushResult)
+ return NULL;
+
+ if (conn->comm_timeout)
+ finish_time = time(NULL) + conn->comm_timeout;
+ else
+ finish_time = -1;
+
/* Wait for some more data, and load it. */
- if (flushResult ||
- gtmpqWait(true, false, conn) ||
+ if (gtmpqWaitTimed(true, false, conn, finish_time) ||
gtmpqReadData(conn) < 0)
{
/*
#ifdef GTM_DEBUG
#define PROXY_CLIENT_TIMEOUT 3600
#else
-#define PROXY_CLIENT_TIMEOUT 20
+#define PROXY_CLIENT_TIMEOUT 60
#endif
#endif
/*
* Set up connection with the GTM server
*/
- sprintf(gtm_connect_string, "host=%s port=%d node_name=%s remote_type=%d",
- GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, GTM_NODE_GTM_PROXY);
+ 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);
thrinfo->thr_gtm_conn = PQconnectGTM(gtm_connect_string);
/* 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);
+ 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_conn = PQconnectGTM(gtm_connect_string);
/*
* If reconnect succeeded the connection will be ready to use out of
if (gtmpqFlush(master_conn))
goto failed;
- finish_time = time(NULL) + PROXY_CLIENT_TIMEOUT;
+ if (master_conn->comm_timeout)
+ finish_time = time(NULL) + master_conn->comm_timeout;
+ else
+ finish_time = -1;
+
if (gtmpqWaitTimed(true, false, master_conn, finish_time) ||
gtmpqReadData(master_conn) < 0)
goto failed;
if (gtmpqFlush(master_conn))
goto failed;
- finish_time = time(NULL) + PROXY_CLIENT_TIMEOUT;
+ if (master_conn->comm_timeout)
+ finish_time = time(NULL) + master_conn->comm_timeout;
+ else
+ finish_time = -1;
+
if (gtmpqWaitTimed(true, false, master_conn, finish_time) ||
gtmpqReadData(master_conn) < 0)
{
char conn_str[256];
GTM_Conn *conn;
- sprintf(conn_str, "host=%s port=%d node_name=%s remote_type=%d postmaster=1",
- GTMServerHost, GTMServerPortNumber, GTMProxyNodeName, GTM_NODE_GTM_PROXY_POSTMASTER);
+ 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);
conn = PQconnectGTM(conn_str);
if (GTMPQstatus(conn) != CONNECTION_OK)
GTMPQfinish(GetMyThreadInfo->thr_gtm_conn);
}
- sprintf(gtm_connect_string, "host=%s port=%d node_name=%s remote_type=%d client_id=%u",
+ 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);
+ GTM_NODE_GTM_PROXY, saveMyClientId, PROXY_CLIENT_TIMEOUT);
elog(DEBUG1, "Worker thread connecting to %s", gtm_connect_string);
GetMyThreadInfo->thr_gtm_conn = PQconnectGTM(gtm_connect_string);
* over above. */
char *pgport; /* the server's communication port */
char *connect_timeout; /* connection timeout (numeric string) */
+ int comm_timeout; /* communication timeout, 0 means infinite */
char *gc_node_name; /* PGXC Node Name */
int remote_type; /* is this a connection to/from a proxy ? */
int is_postmaster; /* is this connection to/from a postmaster instance */