diff --git a/src/backend/distributed/connection/connection_management.c b/src/backend/distributed/connection/connection_management.c index aa2b4f359..080511a7b 100644 --- a/src/backend/distributed/connection/connection_management.c +++ b/src/backend/distributed/connection/connection_management.c @@ -55,8 +55,6 @@ static bool ShouldShutdownConnection(MultiConnection *connection, const int cachedConnectionCount); static void ResetConnection(MultiConnection *connection); static void DefaultCitusNoticeProcessor(void *arg, const char *message); -static void RegisterConnectionCleanup(void); -static void CitusCleanupConnectionsAtExit(int code, Datum arg); static MultiConnection * FindAvailableConnection(dlist_head *connections, uint32 flags); static bool RemoteTransactionIdle(MultiConnection *connection); static int EventSetSizeForConnectionList(List *connections); @@ -349,42 +347,10 @@ StartNodeUserDatabaseConnection(uint32 flags, const char *hostname, int32 port, ResetShardPlacementAssociation(connection); - RegisterConnectionCleanup(); - return connection; } -/* - * RegisterConnectionCleanup cleans up any resources left at the end of the - * session. We prefer to cleanup before shared memory exit to make sure that - * this session properly releases anything hold in the shared memory. - */ -static void -RegisterConnectionCleanup(void) -{ - static bool registeredCleanup = false; - if (registeredCleanup == false) - { - before_shmem_exit(CitusCleanupConnectionsAtExit, 0); - - registeredCleanup = true; - } -} - - -/* - * CitusCleanupConnectionsAtExit is called before_shmem_exit() of the - * backend for the purposes of any clean-up needed. - */ -static void -CitusCleanupConnectionsAtExit(int code, Datum arg) -{ - /* properly close all the cached connections */ - ShutdownAllConnections(); -} - - /* * FindAvailableConnection searches the given list of connections for one that * is not claimed exclusively. diff --git a/src/backend/distributed/connection/shared_connection_stats.c b/src/backend/distributed/connection/shared_connection_stats.c index 0cad7efdf..dfe197be3 100644 --- a/src/backend/distributed/connection/shared_connection_stats.c +++ b/src/backend/distributed/connection/shared_connection_stats.c @@ -48,17 +48,6 @@ typedef struct ConnectionStatsSharedData char *sharedConnectionHashTrancheName; LWLock sharedConnectionHashLock; - -/* / * */ -/* * We prefer mutex over LwLocks for two reasons: */ -/* * - The operations we perform while holding the lock is very tiny, and */ -/* * performance wise, mutex is encouraged by Postgres for such cases */ -/* * - We have to acquire the lock "atexit" callback, and LwLocks requires */ -/* * MyProc to be avaliable to acquire the lock. However, "atexit", it is */ -/* * not guranteed to have MyProc avaliable. On the other hand, "mutex" is */ -/* * independent from MyProc. */ -/* * / */ -/* slock_t mutex; */ } ConnectionStatsSharedData; typedef struct SharedConnStatsHashKey @@ -436,8 +425,6 @@ static void LockConnectionSharedMemory(LWLockMode lockMode) { LWLockAcquire(&ConnectionStatsSharedState->sharedConnectionHashLock, lockMode); - - /* SpinLockAcquire(&ConnectionStatsSharedState->mutex); */ } @@ -449,8 +436,6 @@ static void UnLockConnectionSharedMemory(void) { LWLockRelease(&ConnectionStatsSharedState->sharedConnectionHashLock); - - /* SpinLockRelease(&ConnectionStatsSharedState->mutex); */ } @@ -535,8 +520,6 @@ SharedConnectionStatsShmemInit(void) LWLockInitialize(&ConnectionStatsSharedState->sharedConnectionHashLock, ConnectionStatsSharedState->sharedConnectionHashTrancheId); - - /* SpinLockInit(&ConnectionStatsSharedState->mutex); */ } /* allocate hash table */ diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index 3e6ba708e..7292e1872 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -91,6 +91,8 @@ void _PG_init(void); static void ResizeStackToMaximumDepth(void); static void multi_log_hook(ErrorData *edata); +static void RegisterConnectionCleanup(void); +static void CitusCleanupConnectionsAtExit(int code, Datum arg); static void CreateRequiredDirectories(void); static void RegisterCitusConfigVariables(void); static bool ErrorIfNotASuitableDeadlockFactor(double *newval, void **extra, @@ -369,6 +371,37 @@ StartupCitusBackend(void) { InitializeMaintenanceDaemonBackend(); InitializeBackendData(); + RegisterConnectionCleanup(); +} + + +/* + * RegisterConnectionCleanup cleans up any resources left at the end of the + * session. We prefer to cleanup before shared memory exit to make sure that + * this session properly releases anything hold in the shared memory. + */ +static void +RegisterConnectionCleanup(void) +{ + static bool registeredCleanup = false; + if (registeredCleanup == false) + { + before_shmem_exit(CitusCleanupConnectionsAtExit, 0); + + registeredCleanup = true; + } +} + + +/* + * CitusCleanupConnectionsAtExit is called before_shmem_exit() of the + * backend for the purposes of any clean-up needed. + */ +static void +CitusCleanupConnectionsAtExit(int code, Datum arg) +{ + /* properly close all the cached connections */ + ShutdownAllConnections(); }