Minor refactoring

preventConflictingFlags
Onder Kalaci 2020-03-31 21:52:13 +02:00
parent 7bff12571d
commit cd4b9fd004
3 changed files with 33 additions and 51 deletions

View File

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

View File

@ -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 */

View File

@ -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();
}