pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Maxim Orlov <m.orlov@postgrespro.ru>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Failed assertion on standby while shutdown
Date: Thu, 1 Apr 2021 21:02:09 +0900
Message-ID: <ba2c75e0-22c1-2903-6cb3-18ebc107534d@oss.nttdata.com> (raw)
In-Reply-To: <aab1eaacb409fef145aad0e9e1088e65@postgrespro.ru>
References: <ad4ce692cc1d89a093b471ab1d969b0b@postgrespro.ru>
	<c4c70e9a-297d-feb4-b299-a2e61f6a9920@oss.nttdata.com>
	<161712624344.1180.1891286647778019120.pgcf@coridan.postgresql.org>
	<aab1eaacb409fef145aad0e9e1088e65@postgrespro.ru>



On 2021/03/31 19:51, Maxim Orlov wrote:
> On 2021-03-30 20:44, Maxim Orlov wrote:
>> The following review has been posted through the commitfest application:
>> make installcheck-world:  tested, passed
>> Implements feature:       tested, passed
>> Spec compliant:           not tested
>> Documentation:            not tested
>>
>> All the tests passed successfully.
>>
>> The new status of this patch is: Ready for Committer
> 
> The patch is good. One note, should we put a comment about ShutdownRecoveryTransactionEnvironment not reentrant behaviour? Or maybe rename it to ShutdownRecoveryTransactionEnvironmentOnce?

+1 to add more comments into ShutdownRecoveryTransactionEnvironment().
I did that. What about the attached patch?

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments:

fix_assertion_failure_walreceiver_v2.patch (text/plain, 2.4K) download diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c index 22135d5e07..69077bd207 100644 --- a/src/backend/postmaster/startup.c +++ b/src/backend/postmaster/startup.c @@ -62,6 +62,9 @@ static volatile sig_atomic_t in_restore_command = false; static void StartupProcTriggerHandler(SIGNAL_ARGS); static void StartupProcSigHupHandler(SIGNAL_ARGS); +/* Callbacks */ +static void StartupProcExit(int code, Datum arg); + /* -------------------------------- * signal handler routines @@ -183,6 +186,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 * ---------------------------------- @@ -190,6 +206,9 @@ HandleStartupProcInterrupts(void) 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. */ diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index 17de5a6d0e..1465ee44a1 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -127,10 +127,25 @@ InitRecoveryTransactionEnvironment(void) * * Prepare to switch from hot standby mode to normal operation. Shut down * 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 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. */ ExpireAllKnownAssignedTransactionIds();

view thread (10+ messages)  latest in thread

Message-ID: <ba2c75e0-22c1-2903-6cb3-18ebc107534d@oss.nttdata.com>
Permalink:  ../ba2c75e0-22c1-2903-6cb3-18ebc107534d@oss.nttdata.com/
Also on:    postgresql.org/message-id/ba2c75e0-22c1-2903-6cb3-18ebc107534d@oss.nttdata.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: masao.fujii@oss.nttdata.com, m.orlov@postgrespro.ru, pgsql-hackers@lists.postgresql.org
  Subject: Re: Failed assertion on standby while shutdown
  In-Reply-To: <ba2c75e0-22c1-2903-6cb3-18ebc107534d@oss.nttdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox