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 1nwpYi-00046f-Ot for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jun 2022 18:28:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nwpYg-00069E-UN for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jun 2022 18:28:34 +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 1nwpYg-000694-Ed for pgsql-hackers@lists.postgresql.org; Thu, 02 Jun 2022 18:28:34 +0000 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwpYc-0007Ib-JO for pgsql-hackers@postgresql.org; Thu, 02 Jun 2022 18:28:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1654194511; x=1685730511; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ME2UR0eil7PnU03rQ1UbIEWdLGIJR3WYSFKSgqs0gGM=; b=QQcjnwJ/ROImeiujDzWG0biw9Pynv3PzniTNusKrHiMG8lCIJtq6pASx GSqpLZf7g0UivjLRqWhQYGFkBJkiDHmxBTjBgNi6vL9kq6RePIxf4iLt1 H4VGW4g/toVp3Uxltee9aLWDN7qsSd74gbAc6UznzUfb+rali15kBgpqr Q=; X-IronPort-AV: E=Sophos;i="5.91,272,1647302400"; d="scan'208";a="224790353" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-2520d768.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP; 02 Jun 2022 18:28:28 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2b-2520d768.us-west-2.amazon.com (Postfix) with ESMTPS id 779B242D9E; Thu, 2 Jun 2022 18:28:27 +0000 (UTC) Received: from EX13D11UWC004.ant.amazon.com (10.43.162.101) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Thu, 2 Jun 2022 18:28:27 +0000 Received: from [10.119.125.173] (10.43.161.96) by EX13D11UWC004.ant.amazon.com (10.43.162.101) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Thu, 2 Jun 2022 18:28:26 +0000 Message-ID: <0071e7fe-b1a9-e38c-5706-657913fde1fb@amazon.com> Date: Thu, 2 Jun 2022 11:28:25 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [BUG] Panic due to incorrect missingContrecPtr after promotion Content-Language: en-US To: "Imseih (AWS), Sami" , Kyotaro Horiguchi CC: "alvherre@alvh.no-ip.org" , "pgsql-hackers@postgresql.org" References: <20220527.153735.871115454014517938.horikyota.ntt@gmail.com> From: "Hsu, John" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.43.161.96] X-ClientProxiedBy: EX13D21UWB001.ant.amazon.com (10.43.161.108) To EX13D11UWC004.ant.amazon.com (10.43.162.101) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, As an update we have a test suite running for the last few days with constant workload and failovers/promotions. With the proposed change from Sami we no longer see PANICs due to this. The comment indicates that the abortedRecPtr and missingContRecPtr should only be set when the database is a writer since it's used to write a new record to downstream readers. !StandbyMode is a poor proxy for this as Sami mentioned since there's cases when a replica is going through crash recovery that would then set this record. Thanks, John H On 5/27/22 12:01 PM, Imseih (AWS), Sami wrote: >> So.. I'd like to hear exactly what you did as the testing. >> When standby mode is requested, if crash recovery fails with immature >> contrecord, I think we shouldn't continue recovery. But I'm not sure >> we need to explictly reject that case. Further study is needed.. > > Here is more details about my findings and testing. > > Even with commit 9d92582abf918215d27659d45a4c9e78bda50aff > we still see the issue with post promotion checkpoint > resulting in "request to flush past end of generated WAL;" > > i.e. > > 2022-05-25 00:35:38 UTC::@:[371]:LOG: checkpoint starting: immediate force wait wal time > 2022-05-25 00:35:38 UTC::@:[371]:LOG: request to flush past end of generated WAL; request 10/B1FA3D88, currpos 7/A8000060 > 2022-05-25 00:35:38 UTC::@:[371]:PANIC: xlog flush request 10/B1FA3D88 is not satisfied --- flushed only to 7/A8000060 > 2022-05-25 00:35:38 UTC:172.31.26.238(38610):administrator@postgres:[23433]:ERROR: current transaction is aborted, commands ignored until end of transaction block > > The intent of commit 9d92582abf918215d27659d45a4c9e78bda50aff > was to make sure the standby skips the overwrite contrecord. > > However, we still see "missingContrecPtr" is being set > on the standby before promotion and after the instance is > promoted, the missingContrecPtr is written to WAL > and the subsequent flush throws a "PANIC: xlog flush request" > > To Reproduce using TAP tests; > > 1) apply the attached patch 0001-Patch_to_repro.patch to the head branch. > This patch adds logging when an OverWriteContRecord > is created and comments out the invalidation code > added in commit 9d92582abf918215d27659d45a4c9e78bda50aff > > 2) Run a tap test under "test/recovery" > make check PROVE_TESTS='t/026_overwrite_contrecord.pl' > > 3) What is observed in the logfiles for both the standby > and primary instance in the tap test is > that an overwrite contrecord is created on the primary, > which is correct, but also on the standby after promotion, > which is incorrect. This is incorrect as the contrecord > > simseih@88665a22795f recovery % cat tmp_check/log/*prim* | grep 'creating\|promo' > 2022-05-27 13:17:50.843 CDT [98429] LOG: creating overwrite contrecord at 0/2000058 for aborted_lsn 0/1FFD000 > > simseih@88665a22795f recovery % cat tmp_check/log/*stan* | grep 'creating\|promo' > 2022-05-27 13:17:51.361 CDT [98421] LOG: received promote request > 2022-05-27 13:17:51.394 CDT [98421] LOG: creating overwrite contrecord at 0/2000058 for aborted_lsn 0/1FFD000 > simseih@88665a22795f recovery % > > What we found: > > 1. missingContrecPtr is set when > StandbyMode is false, therefore > only a writer should set this value > and a record is then sent downstream. > > But a standby going through crash > recovery will always have StandbyMode = false, > causing the missingContrecPtr to be incorrectly > set. > > 2. If StandbyModeRequested is checked instead, > we ensure that a standby will not set a > missingContrecPtr. > > 3. After applying the patch below, the tap test succeeded > > diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c > index 5ee90b6..a727aaf 100644 > --- a/src/backend/access/transam/xlogrecovery.c > +++ b/src/backend/access/transam/xlogrecovery.c > @@ -2977,7 +2977,7 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode, > * we'll write a record to indicate to downstream WAL readers that > * that portion is to be ignored. > */ > - if (!StandbyMode && > + if (!StandbyModeRequested && > !XLogRecPtrIsInvalid(xlogreader->abortedRecPtr)) > { > abortedRecPtr = xlogreader->abortedRecPtr; > > So, it might be that the best fix is not the commit in 9d92582abf918215d27659d45a4c9e78bda50aff > but to check StandbyModeRequested = false before setting > missingContrecPtr. > > Thank you > --- > Sami Imseih > Amazon Web Services >