Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tQa5m-003dQI-MR for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Dec 2024 22:43:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tQa5k-00GGvv-14 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Dec 2024 22:42:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tQa5i-00GGvn-OR for pgsql-hackers@lists.postgresql.org; Wed, 25 Dec 2024 22:42:59 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tQa5e-001cHd-8S for pgsql-hackers@postgresql.org; Wed, 25 Dec 2024 22:42:57 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 2E6CF11400B9; Wed, 25 Dec 2024 17:42:52 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Wed, 25 Dec 2024 17:42:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1735166572; x=1735252972; bh=J77C9MqRAG skkLAPzPBF7GG+nkIdJynpLbZC+efTCqU=; b=lxpowOsjuLyvKZN7u0O3X/nZHL zuB7WdYWklXBxvtNM9oCsoBZvDbJlggbO67CCntD7AFW6B9i1bL/PrUFEEumhqpS asHzqXmu4fZfEArrFODMF78yLhuK0BXGplwd3VgaXCFKq3trhjhyObjbzfPZ8rcI +TkIIuwPm5xnixeks3dPlgt/0YUTNX9MyUeEKrQFXSkB/8NtE0K0WYMUtqUBYl0g WLVks40tGxY+teX9h+YjMYUDFVe5X8heQb5JmC6JSVajKhXUGL++verjR3ESbvaC iyWeMp96apWfLH78Z2GDAx8d6gxw3ESuj/79AZ6yRLslXeusd/l1MgP6KZLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1735166572; x=1735252972; bh=J77C9MqRAGskkLAPzPBF7GG+nkIdJynpLbZ C+efTCqU=; b=X+HqKXKdJNQkt2Y1w2+YKQHTW9C1MYE3bxKIkn+HZsJi3Av8bPg HmG/HWJR+392GWfVV1KVhVkQq2FtNo9I4L18vhQgOkTtKtuQHuaPCMfFX1e3T/pP WaK9fqgtkMbUqg68g5693xJC+3pkuSb9akfh4qTE5GMzXeLA3IVdZI4ya2xqLsoF OFqqfPJg9IEiTqZc8p/zz950UiN37lH85TPxQjoF43wRtm6Dad3kmoGNTAwuGPoF 0EWmmIOPh/dA7AWRbc56aMzf4VPqVAwVdPHz/5q52PV8CIOGHFUbgiPYybdZ+CFS MT/DmLqXL5Z5caGJKZMs+swDSM8YLvCJcIA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddujedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgeff jeevgfevuddvjedtvddtieejheduueelvddufedtgfefjedvkeevkeeivddvnecuffhomh grihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiipd hnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehvrdgu rghvhiguohhvsehpohhsthhgrhgvshhprhhordhruhdprhgtphhtthhopehpghhsqhhlqd hhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Dec 2024 17:42:49 -0500 (EST) Date: Thu, 26 Dec 2024 07:42:34 +0900 From: Michael Paquier To: Vitaly Davydov Cc: pgsql-hackers Subject: Re: An improvement of ProcessTwoPhaseBuffer logic Message-ID: References: <13b5b6-676c3080-4d-531db900@47931709> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="77Lf7YK1DkvgBR66" Content-Disposition: inline In-Reply-To: <13b5b6-676c3080-4d-531db900@47931709> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --77Lf7YK1DkvgBR66 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 25, 2024 at 07:18:18PM +0300, Vitaly Davydov wrote: > I tried your patch and it seems the server is started > successfully. But I've found another problem in my synthetic test - > it can not remove the file with the following message: >=20 > LOG: database system was not properly shut down; automatic recovery in p= rogress > WARNING: removing future two-phase state file for transaction 1045224 > WARNING: could not remove file "pg_twophase/FFFFFFFF000FF2E8": No such f= ile or directory > LOG: redo starts at 0/1762978 That works properly up to v16~. I have slept over this problem and I think that we'd better backpatch the fix for the first problem. Now, I also want to add a test to provide coverage. As you say, that's simple: - Create an empty file with a future XID name - Restart the server. - Scan the logs for the WARNING where the future file is removed. > The fill will never be removed automatically. > I guess, it is because we incorrectly calculate the two-phase file > name using TwoPhaseFilePath in RemoveTwoPhaseFile in this > scenario. It can be fixed if to pass file path directly from > RecoverPreparedTransactions or StandbyRecoverPreparedTransaction > into ProcessTwoPhaseBuffer -> RemoveTwoPhaseFile. Yeah, I've noticed that as well. We are dealing with a second bug that affects 17~ caused by the switch to FullTransactionIds for 2PC file names, which had been introduced in 5a1dfde8334b (pretty sure that it is the culprit, did not bisect). Attempting to remove a future file triggers an assertion failure: #3 0x00007fed046324f0 in __GI_abort () at ./stdlib/abort.c:79 #4 0x0000563e68a9bd07 in ExceptionalCondition (conditionName=3D0x563e68c66fc3 "epoch > 0", fileName=3D0x563e68c66b0b "twophase.c", lineNumber=3D953) at assert.c:66 #5 0x0000563e67683060 in AdjustToFullTransactionId (xid=3D4095) at twophase.c:953 #6 0x0000563e67683092 in TwoPhaseFilePath (path=3D0x7ffcb515b4a0 "h\307!\227>V", xid=3D4095) at twophase.c:963 #7 0x0000563e67686603 in RemoveTwoPhaseFile (xid=3D4095, giveWarning=3Dtrue) at twophase.c:1728 #8 0x0000563e67688989 in ProcessTwoPhaseBuffer (xid=3D4095, prepare_start_lsn=3D0, fromdisk=3Dtrue, setParent=3Dfalse, setNextXid=3Dfal= se) at twophase.c:2219 #9 0x0000563e676872a6 in restoreTwoPhaseData () at twophase.c:1924 #10 0x0000563e676b5c8b in StartupXLOG () at xlog.c:5642=20 So this means that we are dealing with two different bugs, and that we need to fix the assertion failure of the second problem first down to 17, then fix the first problem on all stable branches with a test to cover both the first and second problems. > I did it in the proposed patch > https://www.postgresql.org/message-id/cedbe-65e0c000-1-6db17700%401332698= 62 > (it is incomplete now). I suspect that this can be still dangerous as-is while complicating the code with more possible paths for the removal of the 2PC files, because we may still build a file name from an XID, and that's what's causing this issue.. -- Michael --77Lf7YK1DkvgBR66 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmdsiloACgkQnvQgOdby QH0lzA//TKRvh5hjYdJXHhXQZcsFmZZB7kMUgqz3tg3r9Q9XGKdyW0ZLSp9dYb3V 0TTvrWv3SLD6Hd876hWXBR0G7ky6yWJbJ/u/4j4WA/LYr8fG4QftsnSEL2NrovbP V1/bB3VX7+CK8Pt7KRdB1mKbqx+NBf1v1RAQpXA1FkV7UJ/dpPjCzuBCV8u+Xgin 08bRDcrRfdqnp7ZBQ0HmF4oGYFklR1nrjyjTH0YMEqP2r1eVGPDb0p354I3XkdWK 6icURvopHDnnE/yWC/YSt+j1Wi8nhcBsNzfkPb9HksDk5X6Ws9U0sit8gAwVxGpJ qkpavkrKrJsDOVLnJaqozioEjUBu7Wqfr7JyUShimBkYZf5VNK8DsmdUnm8mDGK0 QM+QEzXJEdFF68YzuMDZe1g8BxubSVxGvduol8VqyfnTeevUXYGBDTR0bqw5WFvP vZPRfA7hkfed46VbTYCVrIbJ521qXmZr5ss03ohu4wtyhkWCE3qopI7lhaaPU0uD TuFoZ+D4YPGR6YzqsTZcPhG3DxEd5YwOq3/z7y0mQK2HAg/Xew3dIImuwvlL4Lqe BYiFn6kgWAeGEpCOJ9/D1wO3DREPmJIGBQMsYGDPocKBehzTzGh5dexYcV0h1EQi ntACBnmMrrWSF6neTPYM/UyvuHnG2zLDqSbLAKwTaUDPn6uvw3U= =zzWq -----END PGP SIGNATURE----- --77Lf7YK1DkvgBR66--