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 1td6ke-004tna-FK for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jan 2025 12:01:01 +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 1td6kd-006h2j-GF for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jan 2025 12:00: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 1td6kd-006h2b-1n for pgsql-hackers@lists.postgresql.org; Wed, 29 Jan 2025 12:00:59 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1td6ka-002AEp-0A for pgsql-hackers@postgresql.org; Wed, 29 Jan 2025 12:00:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1738152054; bh=6HhGLnE4DhPoylbmx0HvRYfELohhz8feFXCd0F3axH0=; h=From:In-Reply-To:References:Date:To:Message-ID:Subject:User-Agent: From; b=YgCpYjd6Q2E/lbzlQ2vUsGZxtSB94e1zDKfRS5HDL7mLCcS4QDF57gL7NoCBh+H/9 oxEheyf8ktoDs4NcudJ1jejNZsC7+zwX0drYs58VYrSsxlHc23rViUfrEdRgWWk3S1 nFdN0b+12clwkC7Yjsamy2AyvlTe0w09SjhUrg4wQ5y2Sxo9Vvpl0ztqXhCxhZ8GON e6EAge1JrYODN0+hiLJ6QKd4Hp91PsfAU027oEIJw0v5mYlMKIPzysJjRgxFJl1bqT SPWeRJ4B5SKiR/9Bu2//w6VPZUohykNV5PvSWaRhqY4Bazjr6nzLzwOovzououNbH3 VYS2tla+he2PA== Received: from sogo.postgrespro.ru (sogo.l.postgrespro.ru [192.168.2.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mail.postgrespro.ru (Postfix/587) with ESMTPS id B1E9760511 for ; Wed, 29 Jan 2025 15:00:54 +0300 (MSK) From: "Vitaly Davydov" In-Reply-To: Content-Type: text/plain; charset="utf-8" X-Forward: 46.39.228.226 References: <16aa85-676ec500-3d-23db9b40@59039559> <20250116010051.f3.nmisch@google.com> <20250116205254.65.nmisch@google.com> <20250117005221.05.nmisch@google.com> <20250117024416.8c.nmisch@google.com> <3ebed0-6790e880-3-24447380@20764243> Date: Wed, 29 Jan 2025 15:00:54 +0300 To: "pgsql-hackers" MIME-Version: 1.0 Message-ID: <96951-679a1880-17-e255290@36905887> Subject: =?utf-8?q?Re=3A?= An improvement of ProcessTwoPhaseBuffer logic User-Agent: SOGoMail 5.11.2 Content-Transfer-Encoding: quoted-printable X-KSMG-AntiPhishing: NotDetected, bases: 2025/01/29 10:56:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/01/29 10:29:00 #27146660 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk It seems, there are much deeper problems with twophase transactions as = I thought. I'm interested in fixing twophase transactions, because I su= pport a solution which actively uses twophase transactions. I'm interes= ted to get more deeply into the twophase functionality. Below, I just w= ant to clarify some ideas behind twophase transactions. I appreciate, i= f you comment my point of view, or just ignore this email if you find i= t too naive and boring. Two phase files are created after checkpoint to keep twophase states on= disk after WAL truncation. For transactions, that are inside the check= point horizon, we do not create two phase files because the states are = currently stored in the WAL. Based on the thesis above, I guess, we have to read only those twophase= files which are related to the transactions before the latest checkpoi= nt. Its full xid should be lesser than TransamVariables->nextXid (which= is the same as ControlFile->checkPointCopy.nextXid at the moment of St= artupXLOG -> restoreTwoPhaseData call). The files with greater (or equa= l) full xids, should be ignored and removed. That's all what we need in= restoreTwoPhaseData, I believe. In the current implementation, such check is applied in restoreTwoPhase= Data -> ProcessTwoPhaseBuffer but after checking for xid in CLOG. I'm n= ot sure, why we check CLOG here. Once we truncate the WAL on checkpoint= and save twophase states into pg=5Ftwophase, these files must store st= ates of real transactions from past. I mean, if someone creates a stub = file with full xid < TransamVariables->nextXid, we have no means (excep= t CLOG ?) to check that this file belongs to a real transaction from pa= st. CLOG check seems to be a weak attempt to deal with it. At this poin= t, I'm not sure that CLOG may contain states for all full xids of exist= ing twophase files. I guess, we should call restoreTwoPhaseData at star= t of recovery but we shouldn't check CLOG at this stage. May be it is r= easonable to check some not so old xids which are greater than the curr= ent CLOG horizon, but I'm not sure how CLOG segments are managed and ho= w the horizon is moving. There is another question about the loading order of twophase files but= I think it doesn't matter in which order we load these files. But I wo= uld prefer to load it in full xid ascending order. On Tuesday, January 28, 2025 08:02 MSK, Michael Paquier wrote: > Noah's > proposal at [1] is much closer to the long-term picture that would > look adapted. > - The CLOG lookups that can happen in ProcessTwoPhaseBuffer() during > recovery while a consistent state is not reached are still possible > (planning to start a different thread about this specific issue). >=20 > [1]: https://www.postgresql.org/message-id/20250116205254.65.nmisch@g= oogle.com Agree, thank you, but my simple patch with some adjustments and swappin= g of checks in ProcessTwoPhaseBuffer may be back-ported. It doesn't fix= all the problems but may help to fix the problem with twophase files r= elated to broken latest WAL segments. With best regards, Vitaly