mirror of https://github.com/citusdata/citus.git
Minor refactoring
parent
7bff12571d
commit
cd4b9fd004
|
@ -55,8 +55,6 @@ static bool ShouldShutdownConnection(MultiConnection *connection, const int
|
||||||
cachedConnectionCount);
|
cachedConnectionCount);
|
||||||
static void ResetConnection(MultiConnection *connection);
|
static void ResetConnection(MultiConnection *connection);
|
||||||
static void DefaultCitusNoticeProcessor(void *arg, const char *message);
|
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 MultiConnection * FindAvailableConnection(dlist_head *connections, uint32 flags);
|
||||||
static bool RemoteTransactionIdle(MultiConnection *connection);
|
static bool RemoteTransactionIdle(MultiConnection *connection);
|
||||||
static int EventSetSizeForConnectionList(List *connections);
|
static int EventSetSizeForConnectionList(List *connections);
|
||||||
|
@ -349,42 +347,10 @@ StartNodeUserDatabaseConnection(uint32 flags, const char *hostname, int32 port,
|
||||||
|
|
||||||
ResetShardPlacementAssociation(connection);
|
ResetShardPlacementAssociation(connection);
|
||||||
|
|
||||||
RegisterConnectionCleanup();
|
|
||||||
|
|
||||||
return connection;
|
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
|
* FindAvailableConnection searches the given list of connections for one that
|
||||||
* is not claimed exclusively.
|
* is not claimed exclusively.
|
||||||
|
|
|
@ -48,17 +48,6 @@ typedef struct ConnectionStatsSharedData
|
||||||
char *sharedConnectionHashTrancheName;
|
char *sharedConnectionHashTrancheName;
|
||||||
|
|
||||||
LWLock sharedConnectionHashLock;
|
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;
|
} ConnectionStatsSharedData;
|
||||||
|
|
||||||
typedef struct SharedConnStatsHashKey
|
typedef struct SharedConnStatsHashKey
|
||||||
|
@ -436,8 +425,6 @@ static void
|
||||||
LockConnectionSharedMemory(LWLockMode lockMode)
|
LockConnectionSharedMemory(LWLockMode lockMode)
|
||||||
{
|
{
|
||||||
LWLockAcquire(&ConnectionStatsSharedState->sharedConnectionHashLock, lockMode);
|
LWLockAcquire(&ConnectionStatsSharedState->sharedConnectionHashLock, lockMode);
|
||||||
|
|
||||||
/* SpinLockAcquire(&ConnectionStatsSharedState->mutex); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -449,8 +436,6 @@ static void
|
||||||
UnLockConnectionSharedMemory(void)
|
UnLockConnectionSharedMemory(void)
|
||||||
{
|
{
|
||||||
LWLockRelease(&ConnectionStatsSharedState->sharedConnectionHashLock);
|
LWLockRelease(&ConnectionStatsSharedState->sharedConnectionHashLock);
|
||||||
|
|
||||||
/* SpinLockRelease(&ConnectionStatsSharedState->mutex); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -535,8 +520,6 @@ SharedConnectionStatsShmemInit(void)
|
||||||
|
|
||||||
LWLockInitialize(&ConnectionStatsSharedState->sharedConnectionHashLock,
|
LWLockInitialize(&ConnectionStatsSharedState->sharedConnectionHashLock,
|
||||||
ConnectionStatsSharedState->sharedConnectionHashTrancheId);
|
ConnectionStatsSharedState->sharedConnectionHashTrancheId);
|
||||||
|
|
||||||
/* SpinLockInit(&ConnectionStatsSharedState->mutex); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate hash table */
|
/* allocate hash table */
|
||||||
|
|
|
@ -91,6 +91,8 @@ void _PG_init(void);
|
||||||
|
|
||||||
static void ResizeStackToMaximumDepth(void);
|
static void ResizeStackToMaximumDepth(void);
|
||||||
static void multi_log_hook(ErrorData *edata);
|
static void multi_log_hook(ErrorData *edata);
|
||||||
|
static void RegisterConnectionCleanup(void);
|
||||||
|
static void CitusCleanupConnectionsAtExit(int code, Datum arg);
|
||||||
static void CreateRequiredDirectories(void);
|
static void CreateRequiredDirectories(void);
|
||||||
static void RegisterCitusConfigVariables(void);
|
static void RegisterCitusConfigVariables(void);
|
||||||
static bool ErrorIfNotASuitableDeadlockFactor(double *newval, void **extra,
|
static bool ErrorIfNotASuitableDeadlockFactor(double *newval, void **extra,
|
||||||
|
@ -369,6 +371,37 @@ StartupCitusBackend(void)
|
||||||
{
|
{
|
||||||
InitializeMaintenanceDaemonBackend();
|
InitializeMaintenanceDaemonBackend();
|
||||||
InitializeBackendData();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue