mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-04 20:36:51 +02:00
Shut down transaction tracking at startup process exit.
Maxim Orlov reported that the shutdown of standby server could result in the following assertion failure. The cause of this issue was that, when the shutdown caused the startup process to exit, recovery-time transaction tracking was not shut down even if it's already initialized, and some locks the tracked transactions were holding could not be released. At this situation, if other process was invoked and the PGPROC entry that the startup process used was assigned to it, it found such unreleased locks and caused the assertion failure, during the initialization of it. TRAP: FailedAssertion("SHMQueueEmpty(&(MyProc->myProcLocks[i]))" This commit fixes this issue by making the startup process shut down transaction tracking and release all locks, at the exit of it. Back-patch to all supported branches. Reported-by: Maxim Orlov Author: Fujii Masao Reviewed-by: Maxim Orlov Discussion: https://postgr.es/m/ad4ce692cc1d89a093b471ab1d969b0b@postgrespro.ru
This commit is contained in:
parent
fd91fed3e8
commit
e7bcfd717e
@ -51,6 +51,9 @@ static volatile sig_atomic_t in_restore_command = false;
|
|||||||
static void StartupProcTriggerHandler(SIGNAL_ARGS);
|
static void StartupProcTriggerHandler(SIGNAL_ARGS);
|
||||||
static void StartupProcSigHupHandler(SIGNAL_ARGS);
|
static void StartupProcSigHupHandler(SIGNAL_ARGS);
|
||||||
|
|
||||||
|
/* Callbacks */
|
||||||
|
static void StartupProcExit(int code, Datum arg);
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------
|
/* --------------------------------
|
||||||
* signal handler routines
|
* signal handler routines
|
||||||
@ -162,6 +165,19 @@ HandleStartupProcInterrupts(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------
|
||||||
|
* signal handler routines
|
||||||
|
* --------------------------------
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
StartupProcExit(int code, Datum arg)
|
||||||
|
{
|
||||||
|
/* Shutdown the recovery environment */
|
||||||
|
if (standbyState != STANDBY_DISABLED)
|
||||||
|
ShutdownRecoveryTransactionEnvironment();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------
|
/* ----------------------------------
|
||||||
* Startup Process main entry point
|
* Startup Process main entry point
|
||||||
* ----------------------------------
|
* ----------------------------------
|
||||||
@ -169,6 +185,9 @@ HandleStartupProcInterrupts(void)
|
|||||||
void
|
void
|
||||||
StartupProcessMain(void)
|
StartupProcessMain(void)
|
||||||
{
|
{
|
||||||
|
/* Arrange to clean up at startup process exit */
|
||||||
|
on_shmem_exit(StartupProcExit, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Properly accept or ignore signals the postmaster might send us.
|
* Properly accept or ignore signals the postmaster might send us.
|
||||||
*/
|
*/
|
||||||
|
@ -126,10 +126,25 @@ InitRecoveryTransactionEnvironment(void)
|
|||||||
*
|
*
|
||||||
* Prepare to switch from hot standby mode to normal operation. Shut down
|
* Prepare to switch from hot standby mode to normal operation. Shut down
|
||||||
* recovery-time transaction tracking.
|
* recovery-time transaction tracking.
|
||||||
|
*
|
||||||
|
* This must be called even in shutdown of startup process if transaction
|
||||||
|
* tracking has been initialized. Otherwise some locks the tracked
|
||||||
|
* transactions were holding will not be released and and may interfere with
|
||||||
|
* the processes still running (but will exit soon later) at the exit of
|
||||||
|
* startup process.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ShutdownRecoveryTransactionEnvironment(void)
|
ShutdownRecoveryTransactionEnvironment(void)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Do nothing if RecoveryLockLists is NULL because which means that
|
||||||
|
* transaction tracking has not been yet initialized or has been already
|
||||||
|
* shutdowned. This prevents transaction tracking from being shutdowned
|
||||||
|
* unexpectedly more than once.
|
||||||
|
*/
|
||||||
|
if (RecoveryLockLists == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Mark all tracked in-progress transactions as finished. */
|
/* Mark all tracked in-progress transactions as finished. */
|
||||||
ExpireAllKnownAssignedTransactionIds();
|
ExpireAllKnownAssignedTransactionIds();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user