Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxVWy-0002Od-DB for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Jan 2021 13:40:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kxVWR-0001eL-QS for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Jan 2021 13:40:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxVWR-0001eE-8T for pgsql-hackers@lists.postgresql.org; Thu, 07 Jan 2021 13:40:15 +0000 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxVWK-0002Vk-5b for pgsql-hackers@postgresql.org; Thu, 07 Jan 2021 13:40:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1610026808; x=1641562808; h=to:cc:references:from:message-id:date:mime-version: in-reply-to:content-transfer-encoding:subject; bh=xMcp76uYk2ad65DqgRVRCbWWIB/CILTCTUURTAdK+TQ=; b=v8fLjicxxOiFyFtgZd/xZZ9IdnJeUbaQ/7YeA8rYlVNVvHoWeSpNZqfK iZ3RIf9IUB68HI/a5NL6edhvNiMJc7Z/gYXANYozl3badKG1Ywb2mBD/g O6X9mhs+PYADwlRGhPYVrZBw97qFIxtBjyAdjlF6ZivcXmC8Rf2s0nWKv I=; X-IronPort-AV: E=Sophos;i="5.79,329,1602547200"; d="scan'208";a="101952462" Subject: Re: Add Information during standby recovery conflicts Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 07 Jan 2021 13:40:00 +0000 Received: from EX13D03EUC003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com (Postfix) with ESMTPS id EEC05A2018; Thu, 7 Jan 2021 13:39:58 +0000 (UTC) Received: from 38f9d36c4abb.ant.amazon.com (10.43.160.48) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 7 Jan 2021 13:39:55 +0000 To: Fujii Masao , Masahiko Sawada CC: Alvaro Herrera , Masahiko Sawada , Kyotaro Horiguchi , PostgreSQL-development References: <20201130182528.GA1854@alvherre.pgsql> <594f4419-62aa-c272-ef7d-4287e5c6b654@amazon.com> <627f702d-a04c-b72b-b94f-214f448e2935@oss.nttdata.com> <73037867-b688-c5cc-5f6d-ad73db6ab94d@amazon.com> <02b17df8-cf11-7e5a-31e3-d94c87b28775@oss.nttdata.com> From: "Drouvot, Bertrand" Message-ID: <5517bbfd-27ad-3e97-51e2-cb9ffb8f8a8d@amazon.com> Date: Thu, 7 Jan 2021 14:39:50 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.43.160.48] X-ClientProxiedBy: EX13D28UWB004.ant.amazon.com (10.43.161.56) To EX13D03EUC003.ant.amazon.com (10.43.164.192) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 1/6/21 6:31 PM, Fujii Masao wrote: > CAUTION: This email originated from outside of the organization. Do > not click links or open attachments unless you can confirm the sender > and know the content is safe. > > > > On 2020/12/15 0:20, Fujii Masao wrote: >> >> >> On 2020/12/14 21:31, Fujii Masao wrote: >>> >>> >>> On 2020/12/05 12:38, Masahiko Sawada wrote: >>>> On Fri, Dec 4, 2020 at 7:22 PM Drouvot, Bertrand >>>> wrote: >>>>> >>>>> Hi, >>>>> >>>>> On 12/4/20 2:21 AM, Fujii Masao wrote: >>>>>> >>>>>> On 2020/12/04 9:28, Masahiko Sawada wrote: >>>>>>> On Fri, Dec 4, 2020 at 2:54 AM Fujii Masao >>>>>>> wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On 2020/12/01 17:29, Drouvot, Bertrand wrote: >>>>>>>>> Hi, >>>>>>>>> >>>>>>>>> On 12/1/20 12:35 AM, Masahiko Sawada wrote: >>>>>>>>>> CAUTION: This email originated from outside of the organization. >>>>>>>>>> Do not click links or open attachments unless you can confirm >>>>>>>>>> the >>>>>>>>>> sender and know the content is safe. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Tue, Dec 1, 2020 at 3:25 AM Alvaro Herrera >>>>>>>>>> wrote: >>>>>>>>>>> On 2020-Dec-01, Fujii Masao wrote: >>>>>>>>>>> >>>>>>>>>>>> + if (proc) >>>>>>>>>>>> +                     { >>>>>>>>>>>> +                             if (nprocs == 0) >>>>>>>>>>>> + appendStringInfo(&buf, "%d", proc->pid); >>>>>>>>>>>> +                             else >>>>>>>>>>>> + appendStringInfo(&buf, ", %d", proc->pid); >>>>>>>>>>>> + >>>>>>>>>>>> +                             nprocs++; >>>>>>>>>>>> >>>>>>>>>>>> What happens if all the backends in wait_list have gone? In >>>>>>>>>>>> other words, >>>>>>>>>>>> how should we handle the case where nprocs == 0 (i.e., nprocs >>>>>>>>>>>> has not been >>>>>>>>>>>> incrmented at all)? This would very rarely happen, but can >>>>>>>>>>>> happen. >>>>>>>>>>>> In this case, since buf.data is empty, at least there seems no >>>>>>>>>>>> need to log >>>>>>>>>>>> the list of conflicting processes in detail message. >>>>>>>>>>> Yes, I noticed this too; this can be simplified by changing the >>>>>>>>>>> condition in the ereport() call to be "nprocs > 0" (rather than >>>>>>>>>>> wait_list being null), otherwise not print the errdetail.  (You >>>>>>>>>>> could >>>>>>>>>>> test buf.data or buf.len instead, but that seems uglier to me.) >>>>>>>>>> +1 >>>>>>>>>> >>>>>>>>>> Maybe we can also improve the comment of this function from: >>>>>>>>>> >>>>>>>>>> + * This function also reports the details about the conflicting >>>>>>>>>> + * process ids if *wait_list is not NULL. >>>>>>>>>> >>>>>>>>>> to " This function also reports the details about the >>>>>>>>>> conflicting >>>>>>>>>> process ids if exist" or something. >>>>>>>>>> >>>>>>>>> Thank you all for the review/remarks. >>>>>>>>> >>>>>>>>> They have been addressed in the new attached patch version. >>>>>>>> >>>>>>>> Thanks for updating the patch! I read through the patch again >>>>>>>> and applied the following chages to it. Attached is the updated >>>>>>>> version of the patch. Could you review this version? If there is >>>>>>>> no issue in it, I'm thinking to commit this version. >>>>>>> >>>>>>> Thank you for updating the patch! I have one question. >>>>>>> >>>>>>>> >>>>>>>> +                       timeouts[cnt].id = STANDBY_TIMEOUT; >>>>>>>> +                       timeouts[cnt].type = TMPARAM_AFTER; >>>>>>>> +                       timeouts[cnt].delay_ms = DeadlockTimeout; >>>>>>>> >>>>>>>> Maybe STANDBY_TIMEOUT should be STANDBY_DEADLOCK_TIMEOUT here? >>>>>>>> I changed the code that way. >>>>>>> >>>>>>> As the comment of ResolveRecoveryConflictWithLock() says the >>>>>>> following, a deadlock is detected by the ordinary backend process: >>>>>>> >>>>>>>    * Deadlocks involving the Startup process and an ordinary >>>>>>> backend >>>>>>> proces >>>>>>>    * will be detected by the deadlock detector within the ordinary >>>>>>> backend. >>>>>>> >>>>>>> If we use STANDBY_DEADLOCK_TIMEOUT, >>>>>>> SendRecoveryConflictWithBufferPin() will be called after >>>>>>> DeadlockTimeout passed, but I think it's not necessary for the >>>>>>> startup >>>>>>> process in this case. >>>>>> >>>>>> Thanks for pointing this! You are right. >>>>>> >>>>>> >>>>>>> If we want to just wake up the startup process >>>>>>> maybe we can use STANDBY_TIMEOUT here? >>>>>> >>>>> Thanks for the patch updates! Except what we are still discussing >>>>> below, >>>>> it looks good to me. >>>>> >>>>>> When STANDBY_TIMEOUT happens, a request to release conflicting >>>>>> buffer >>>>>> pins is sent. Right? If so, we should not also use >>>>>> STANDBY_TIMEOUT there? >>>>> >>>>> Agree >>>>> >>>>>> >>>>>> Or, first of all, we don't need to enable the deadlock timer at all? >>>>>> Since what we'd like to do is to wake up after deadlock_timeout >>>>>> passes, we can do that by changing ProcWaitForSignal() so that it >>>>>> can >>>>>> accept the timeout and giving the deadlock_timeout to it. If we do >>>>>> this, maybe we can get rid of STANDBY_LOCK_TIMEOUT from >>>>>> ResolveRecoveryConflictWithLock(). Thought? >>>> >>>> Where do we enable deadlock timeout in hot standby case? You meant to >>>> enable it in ProcWaitForSignal() or where we set a timer for not hot >>>> standby case, in ProcSleep()? >>> >>> No, what I tried to say is to change >>> ResolveRecoveryConflictWithLock() so that it does >>> >>> 1. calculate the "minimum" timeout from deadlock_timeout and >>> max_standby_xxx_delay >>> 2. give the calculated timeout value to ProcWaitForSignal() >>> 3. wait for signal and timeout on ProcWaitForSignal() >>> >>> Since ProcWaitForSignal() calls WaitLatch(), seems it's not so >>> difficult to make ProcWaitForSignal() handle the timeout. If we do >>> this, I was thinking that we can get rid of enable_timeouts() from >>> ResolveRecoveryConflictWithLock(). >>> >>> >>>> >>>>> >>>>> Why not simply use (again) the STANDBY_LOCK_TIMEOUT one? (as it >>>>> triggers >>>>> a call to StandbyLockTimeoutHandler() which does nothing, except >>>>> waking >>>>> up. That's what we want, right?) >>>> >>>> Right, what I wanted to mean is STANDBY_LOCK_TIMEOUT. The startup >>>> process can wake up and do nothing. Thank you for pointing out. >>> >>> Okay, understood! Firstly I was thinking that enabling the same type >>> (i.e., STANDBY_LOCK_TIMEOUT) of lock twice doesn't work properly, >>> but as far as I read the code, it works. In that case, only the >>> shorter timeout would be activated in enable_timeouts(). So I agree >>> to use STANDBY_LOCK_TIMEOUT. >> >> So I renamed the argument "deadlock_timer" in >> ResolveRecoveryConflictWithLock() >> because it's not the timer for deadlock and is confusing. Attached is >> the >> updated version of the patch. Barring any objection, I will commit >> this version. > > Since the recent commit 8900b5a9d5 changed the recovery conflict code, > I updated the patch. Attached is the updated version of the patch. > Thanks for those updates! I had a look and the patch does look good to me. As far the other threads regarding: - "maybe_log_conflict" and "maybe_update_title" naming: I don’t have strong opinions about it but I am more inclined to stay with the “maybe” naming (as it is currently in this patch version) as it better reflects that this may or not occur. - the errdetail log message format in LogRecoveryConflict() (currently looks like “Conflicting process: 25118.”) : I don’t have strong opinions about it but I am more inclined to stay as it is, as it looks similar as the format being used in ProcSleep() (even if we can find different formats in other places though). Bertrand