pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Soumyadeep Chakraborty <soumyadeep2007@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Delay of standby shutdown
Date: Thu, 12 Nov 2020 12:24:48 +0900
Message-ID: <87b9d893-101e-664f-270e-6029b1fe7a0c@oss.nttdata.com> (raw)
In-Reply-To: <CAE-ML+9T19+hsy3c7MdRsjsMvnj+2yn6UxuAj1OzVmKsn0VUaA@mail.gmail.com>
References: <9d7e6ab0-8a53-ddb9-63cd-289bcb25fe0e@oss.nttdata.com>
	<CAE-ML+9T19+hsy3c7MdRsjsMvnj+2yn6UxuAj1OzVmKsn0VUaA@mail.gmail.com>



On 2020/11/04 9:35, Soumyadeep Chakraborty wrote:
> Hello Fujii,
> 
> On Thu, Sep 17, 2020 at 6:49 AM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
> 
> As far as I understand after debugging, the problem is as follows:

Yes.


> 
> 1. After the primary is stopped, and the standby startup process is
> waiting inside:
> 
> (void) WaitLatch(&XLogCtl->recoveryWakeupLatch,
> WL_LATCH_SET | WL_TIMEOUT |
> WL_EXIT_ON_PM_DEATH,
> wait_time,
> WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL);
> 
> it receives SIGTERM on account of stopping the standby and it leads to
> the WaitLatch call returning with WL_LATCH_SET.
> 
> 2. WaitForWALToBecomeAvailable() then will return true after calling
> XLogFileReadAnyTLI() and eventually, XLogReadRecord() will return NULL
> since there is no new WAL to read, which means ReadRecord() will loop
> back and perform another XLogReadRecord().
> 
> 3. The additional XLogReadRecord() will lead to a 5s wait inside
> WaitForWALToBecomeAvailable() - a different WaitLatch() call this time:
> 
> /*
>   * Wait for more WAL to arrive. Time out after 5 seconds
>   * to react to a trigger file promptly and to check if the
>   * WAL receiver is still active.
>   */
> (void) WaitLatch(&XLogCtl->recoveryWakeupLatch,
> WL_LATCH_SET | WL_TIMEOUT |
> WL_EXIT_ON_PM_DEATH,
> 5000L, WAIT_EVENT_RECOVERY_WAL_STREAM);
> 
> 4. And then eventually, the code will handle interrupts here inside
> WaitForWALToBecomeAvailable() after the 5s wait:
> 
> /*
>   * This possibly-long loop needs to handle interrupts of startup
>   * process.
>   */
> HandleStartupProcInterrupts();
> 
>> To avoid this issue, I think that ReadRecord() should call
>> HandleStartupProcInterrupts() whenever looping back to retry.
> 
> Alternatively, perhaps we can place it inside
> WaitForWALToBecomeAvailable() (which already has a similar call),
> since it is more semantically aligned to checking for interrupts, rather
> than ReadRecord()? Like this:

Yes. Your approach looks better to me.
Attached is the updated version of the patch implementing that.

Regards,

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

Attachments:

shutdown_in_standby_v2.patch (text/plain, 583B) download diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index aa63f37615..7d97b96e72 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -12225,6 +12225,9 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL); ResetLatch(MyLatch); now = GetCurrentTimestamp(); + + /* Handle interrupt signals of startup process */ + HandleStartupProcInterrupts(); } last_fail_time = now; currentSource = XLOG_FROM_ARCHIVE;

view thread (5+ messages)  latest in thread

Message-ID: <87b9d893-101e-664f-270e-6029b1fe7a0c@oss.nttdata.com>
Permalink:  ../87b9d893-101e-664f-270e-6029b1fe7a0c@oss.nttdata.com/
Also on:    postgresql.org/message-id/87b9d893-101e-664f-270e-6029b1fe7a0c@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: masao.fujii@oss.nttdata.com, soumyadeep2007@gmail.com
  Subject: Re: Delay of standby shutdown
  In-Reply-To: <87b9d893-101e-664f-270e-6029b1fe7a0c@oss.nttdata.com>
  References: <9d7e6ab0-8a53-ddb9-63cd-289bcb25fe0e@oss.nttdata.com> <CAE-ML+9T19+hsy3c7MdRsjsMvnj+2yn6UxuAj1OzVmKsn0VUaA@mail.gmail.com> <87b9d893-101e-664f-270e-6029b1fe7a0c@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