mirror of https://github.com/citusdata/citus.git
Merge pull request #3052 from citusdata/fix/internal_connection_caching
Avoid caching connections from backends that service internal connectionspull/3059/head
commit
2d1639ad9d
|
@ -89,7 +89,7 @@ ResetConnParams()
|
|||
|
||||
InvalidateConnParamsHashEntries();
|
||||
|
||||
AddConnParam("fallback_application_name", "citus");
|
||||
AddConnParam("fallback_application_name", CITUS_APPLICATION_NAME);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1046,6 +1046,18 @@ AfterXactHostConnectionHandling(ConnectionHashEntry *entry, bool isCommit)
|
|||
{
|
||||
dlist_mutable_iter iter;
|
||||
int cachedConnectionCount = 0;
|
||||
bool isCitusInitiatedBackend = false;
|
||||
|
||||
/*
|
||||
* When we are in a backend that was created to service an internal connection
|
||||
* from the coordinator or another worker, we disable connection caching to avoid
|
||||
* escalating the number of cached connections. We can recognize such backends
|
||||
* from their application name.
|
||||
*/
|
||||
if (application_name != NULL && strcmp(application_name, CITUS_APPLICATION_NAME) == 0)
|
||||
{
|
||||
isCitusInitiatedBackend = true;
|
||||
}
|
||||
|
||||
dlist_foreach_modify(iter, entry->connections)
|
||||
{
|
||||
|
@ -1067,7 +1079,8 @@ AfterXactHostConnectionHandling(ConnectionHashEntry *entry, bool isCommit)
|
|||
/*
|
||||
* Preserve session lifespan connections if they are still healthy.
|
||||
*/
|
||||
if (cachedConnectionCount >= MaxCachedConnectionsPerWorker ||
|
||||
if (isCitusInitiatedBackend ||
|
||||
cachedConnectionCount >= MaxCachedConnectionsPerWorker ||
|
||||
connection->forceCloseAtTransactionEnd ||
|
||||
PQstatus(connection->pgConn) != CONNECTION_OK ||
|
||||
!RemoteTransactionIdle(connection))
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
/* default notice level */
|
||||
#define DEFAULT_CITUS_NOTICE_LEVEL DEBUG1
|
||||
|
||||
/* application name used for internal connections in Citus */
|
||||
#define CITUS_APPLICATION_NAME "citus"
|
||||
|
||||
/* forward declare, to avoid forcing large headers on everyone */
|
||||
struct pg_conn; /* target of the PGconn typedef */
|
||||
struct MemoryContextData;
|
||||
|
|
Loading…
Reference in New Issue