Merge pull request #3052 from citusdata/fix/internal_connection_caching

Avoid caching connections from backends that service internal connections
pull/3059/head
Marco Slot 2019-09-30 17:07:03 +02:00 committed by GitHub
commit 2d1639ad9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -89,7 +89,7 @@ ResetConnParams()
InvalidateConnParamsHashEntries();
AddConnParam("fallback_application_name", "citus");
AddConnParam("fallback_application_name", CITUS_APPLICATION_NAME);
}

View File

@ -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))

View File

@ -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;