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 1nja2B-0004wW-OA for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Apr 2022 05:16:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nja29-0005Kb-Ar for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Apr 2022 05:16:13 +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 1nja28-0005K7-8n for pgsql-hackers@lists.postgresql.org; Wed, 27 Apr 2022 05:16:13 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nja25-00067U-1U for pgsql-hackers@lists.postgresql.org; Wed, 27 Apr 2022 05:16:11 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 4B3803200938; Wed, 27 Apr 2022 01:16:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 27 Apr 2022 01:16:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1651036566; x=1651122966; bh=gimYDCRJHy O6+Z7AJgn7nyGm95wju3/cE0K9dhb2nHY=; b=Y1ASqpXx2yr/8trKsiPgxAdtMi AqWJStECWAeX4YSA03XgryLsfQp7JKREccv1J9mqUDZAyZ4r++nE4obHuOeGWKK2 nYkqCO9A6z8Nt3nSmQuUn1lGsZ9irYChXhzoaGYc19HD2UMlgf3FG5j0VnYS3UUH vFFuASOcGQax0Utv04zCjqqLxzwKG/PbC/xxHCirLyPzjKCB4L1r3BnCGbLCehB9 DmpnuUVFHv/kqGsuiwVfvU+Esgyv/L4g1k0Y8F0eQ/a0LJZyun0ORL3ITJVcCj4U f/079qhyb0bkkJ11R1JFUxCDjeOplKdN19HqRydUcEx2ypYEwPqdKE6NG7IA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1651036566; x= 1651122966; bh=gimYDCRJHyO6+Z7AJgn7nyGm95wju3/cE0K9dhb2nHY=; b=F DbEcEP+ZCeFlqkSULQecNuf7/O58MBSJy4zviMzTsUhXpvv4k1AikN+5MkrQCi/5 N/d/2tfR+6m0ot8y+m2jhoeeaf0knSPvGQ0XaasxnsZKYc7Fk8zq6hdbIfd0W3v2 JrwI0aRjL5RzkfMhgPWZ+GWL3IxSGY8LhWz9nmU6LKu2lJu0RJhdrOyuSuvIw0YP I4Qt7hrKriIbrqJvePNr3qOuaLP8jYoUz5jORGibYNHXPiOezEdT52bWxWwHIrxQ XPa6gr87RSfMoFZFLE0U6XlhhB+ZBnpAFhmTWKjBJy7sOUgmIWnzeg30kkLKcylS pkjWSEW1go/CW0GaWKm5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudeggdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdefhedmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeg geffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Apr 2022 01:16:04 -0400 (EDT) Date: Wed, 27 Apr 2022 14:16:01 +0900 From: Michael Paquier To: Nathan Bossart Cc: Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org, masao.fujii@oss.nttdata.com Subject: Re: Possible corruption by CreateRestartPoint at promotion Message-ID: References: <20220316.102444.2193181487576617583.horikyota.ntt@gmail.com> <20220426183349.GA3002960@nathanxps13> <20220427.104353.691219597727808197.horikyota.ntt@gmail.com> <20220427032609.GA3220948@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sQubAm0nTkyi2d6C" Content-Disposition: inline In-Reply-To: <20220427032609.GA3220948@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --sQubAm0nTkyi2d6C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Apr 26, 2022 at 08:26:09PM -0700, Nathan Bossart wrote: > On Wed, Apr 27, 2022 at 10:43:53AM +0900, Kyotaro Horiguchi wrote: >> At Tue, 26 Apr 2022 11:33:49 -0700, Nathan Bossart wrote in=20 >>> I suspect we'll start seeing this problem more often once end-of-recove= ry >>> checkpoints are removed [0]. Would you mind creating a commitfest entry >>> for this thread? I didn't see one. >>=20 >> I'm not sure the patch makes any change here, because restart points >> don't run while crash recovery, since no checkpoint records seen >> during a crash recovery. Anyway the patch doesn't apply anymore so >> rebased, but only the one for master for the lack of time for now. >=20 > Thanks for the new patch! Yeah, it wouldn't affect crash recovery, but > IIUC Robert's patch also applies to archive recovery. >=20 >> + /* Update pg_control */ >> + LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); >> + >> /* >> * Remember the prior checkpoint's redo ptr for >> * UpdateCheckPointDistanceEstimate() >> */ >> PriorRedoPtr =3D ControlFile->checkPointCopy.redo; >=20 > nitpick: Why move the LWLockAcquire() all the way up here? Yeah, that should not be necessary. InitWalRecovery() is the only place outside the checkpointer that would touch this field, but that happens far too early in the startup sequence to matter with the checkpointer. >> + Assert (PriorRedoPtr < RedoRecPtr); >=20 > I think this could use a short explanation. That's just to make sure that the current redo LSN is always older than the one prior that. It does not seem really necessary to me to add that. >> + /* >> + * Aarchive recovery has ended. Crash recovery ever after should >> + * always recover to the end of WAL >> + */ s/Aarchive/Archive/. >> + ControlFile->minRecoveryPoint =3D InvalidXLogRecPtr; >> + ControlFile->minRecoveryPointTLI =3D 0; >> + >> + /* also update local copy */ >> + LocalMinRecoveryPoint =3D InvalidXLogRecPtr; >> + LocalMinRecoveryPointTLI =3D 0; >=20 > Should this be handled by the code that changes the control file state to > DB_IN_PRODUCTION instead? It looks like this is ordinarily done in the > next checkpoint. It's not clear to me why it is done this way. Anyway, that would be the work of the end-of-recovery checkpoint requested at the end of StartupXLOG() once a promotion happens or of the checkpoint requested by PerformRecoveryXLogAction() in the second case, no? So, I don't quite see why we need to update minRecoveryPoint and minRecoveryPointTLI in the control file here, as much as this does not have to be part of the end-of-recovery code that switches the control file to DB_IN_PRODUCTION. - if (ControlFile->state =3D=3D DB_IN_ARCHIVE_RECOVERY && - ControlFile->checkPointCopy.redo < lastCheckPoint.redo) - { 7ff23c6 has removed the last call to CreateCheckpoint() outside the checkpointer, meaning that there is one less concurrent race to worry about, but I have to admit that this change, to update the control file's checkPoint and checkPointCopy even if we don't check after ControlFile->checkPointCopy.redo < lastCheckPoint.redo would make the code less robust in ~14. So I am questioning whether a backpatch is actually worth the risk here. -- Michael --sQubAm0nTkyi2d6C Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmJo0ZEACgkQnvQgOdby QH2uGQ/8Cr9VQud6pWLsx/A6F8slY3RUKJR/xAoxStCooeGphSPtdROT6gAOYfxF Jtb6ENx3P3QwVhICZdgttj0eAi60QmxtEl1Wl/hlGXOS+7ZwwsWX7WL3uml4eMBv 31+rDlM3FTS6iizXf2IaFRoR20//PiKi9GLzpORcswjzYTFJNysjW0V0CHDPGErf tut05YYbLl9V9rDSGPtvwpjez+tqlhu4G+AJNcP694GGGCifSsk2+obHNy5MOdvX Kb8C00sc6uRYodGMdwjejHAlJZP2zuzbtZc3/smWOio/so46fJMhHKMpArkIQ+4e +5iW1Qf0a54mlZWihZNHfFYXKhZNqJj7zr0cjBxEfp3OJArbqCS6if1vcDI9Liji 98mh+57RXkbMqLv2Ysx58i6knSVDEuzZUh7jK40Xlqk0F+eztRgTHCi/DYwM/BCh r0BaCUJ5ePzuuHXz0Ma65vTJkYl7l4bzpSA7xdrNVDpLw62l/pBTsLwyjXWNnuOT AXEtsTrOHr/HQkvJbWxZCdL7lnyFuu6zlB9MpE6oqPiT73D1E4bccqbc0NyPmrYS lhdIgBxEDRbzrZsiKb1QEZdh64GTYqsOiw7980GRrsvX139MHpR7oSG1QLp95Ytt lZdKlgs4Y7QgkxYURvmrxQlp4XdR5rDFMnuDcw6pWUQBC3kMFjs= =TYoE -----END PGP SIGNATURE----- --sQubAm0nTkyi2d6C--