From 028719bd3bca4d67975a9916b3f29790b0f6ae18 Mon Sep 17 00:00:00 2001 From: Chunling Wang Date: Mon, 5 Sep 2022 15:02:38 +0800 Subject: [PATCH] issue#I5UEWO Cleanup sessions for one database which is conflict with when recovery drop database --- src/gausskernel/storage/ipc/standby.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gausskernel/storage/ipc/standby.cpp b/src/gausskernel/storage/ipc/standby.cpp index 35f61aa40..f7b5b1ef7 100755 --- a/src/gausskernel/storage/ipc/standby.cpp +++ b/src/gausskernel/storage/ipc/standby.cpp @@ -34,6 +34,7 @@ #include "utils/ps_status.h" #include "utils/timestamp.h" #include "utils/snapmgr.h" +#include "pgxc/poolutils.h" #include "replication/walreceiver.h" static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId* waitlist, TransactionId* xminArray, ProcSignalReason reason); @@ -385,14 +386,21 @@ void ResolveRecoveryConflictWithDatabase(Oid dbid) * block during InitPostgres() and then disconnect when they see the * database has been removed. */ - while (CountDBActiveBackends(dbid) > 0) { - CancelDBBackends(dbid, PROCSIG_RECOVERY_CONFLICT_DATABASE, true); - - /* - * Wait awhile for them to die so that we avoid flooding an - * unresponsive backend when system is heavily loaded. - */ - pg_usleep(10000); + if (ENABLE_THREAD_POOL) { + ThreadPoolSessControl *sess_ctrl = g_threadPoolControler->GetSessionCtrl(); + while (sess_ctrl->CountDBSessionsNotCleaned(dbid, InvalidOid) > 0) { + sess_ctrl->CleanDBSessions(dbid, InvalidOid); + pg_usleep(10000); + } + } else { + while (CountDBBackends(dbid) > 0) { + CancelDBBackends(dbid, PROCSIG_RECOVERY_CONFLICT_DATABASE, true); + /* + * Wait awhile for them to die so that we avoid flooding an + * unresponsive backend when system is heavily loaded. + */ + pg_usleep(10000); + } } }