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 1qYjmx-002WdK-It for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Aug 2023 09:04:31 +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 1qYjmv-00BCSW-Cl for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Aug 2023 09:04:29 +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 1qYjmv-00BCSB-26 for pgsql-hackers@lists.postgresql.org; Wed, 23 Aug 2023 09:04:28 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qYjmq-000XUw-5w for pgsql-hackers@lists.postgresql.org; Wed, 23 Aug 2023 09:04:27 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 9E324609DB; Wed, 23 Aug 2023 18:04:18 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 23 Aug 2023 18:04:18 +0900 From: torikoshia To: Michael Paquier , bungina@gmail.com Cc: Pgsql Hackers , cyberdemn@gmail.com, pgsql-hackers@lists.postgresql.org, Kyotaro Horiguchi Subject: Re: pg_rewind WAL segments deletion pitfall In-Reply-To: References: <20220928.181739.1943880428843903268.horikyota.ntt@gmail.com> <2e75ae22dce9a227c3d47fa6d0ed094a@oss.nttdata.com> <20230629.102533.2256222097295418108.horikyota.ntt@gmail.com> <8b385bb6d5f87e54c1c6333fece0444a@oss.nttdata.com> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <41e7c31b85aad03a4a2cd14daad31acd@oss.nttdata.com> X-Sender: torikoshia@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-08-22 14:32, Michael Paquier wrote: Thanks for your review! > On Fri, Aug 18, 2023 at 03:40:57PM +0900, torikoshia wrote: >> Thanks for the patch, I've marked this as ready-for-committer. >> >> BTW, this issue can be considered a bug, right? >> I think it would be appropriate to provide backpatch. > > Hmm, I agree that there is a good argument in back-patching as we have > the WAL files between the redo LSN and the divergence LSN, but > pg_rewind is not smart enough to keep them around. If the archives of > the primary were not able to catch up, the old primary is as good as > kaput, and restore_command won't help here. True. I also imagine that in the typical failover scenario where the target cluster was shut down soon after the divergence and pg_rewind was executed without much time, we can avoid this kind of 'requested WAL segment has already removed' error by preventing pg_rewind from deleting necessary WALs. > I don't like much this patch. While it takes correctly advantage of > the backward record read logic from SimpleXLogPageRead() able to > handle correctly timeline jumps, it creates a hidden dependency in the > code between the hash table from filemap.c and the page callback. > Wouldn't it be simpler to build a list of the segment names using the > information from WALOpenSegment and build this list in > findLastCheckpoint()? Also, I am wondering if we should be smarter > with any potential conflict handling between the source and the > target, rather than just enforcing a FILE_ACTION_NONE for all these > files. In short, could it be better to copy the WAL file from the > source if it exists there? > > + /* > + * Some entries (WAL segments) already have an action assigned > + * (see SimpleXLogPageRead()). > + */ > + if (entry->action == FILE_ACTION_UNDECIDED) > + entry->action = decide_file_action(entry); > > This change makes me a bit uneasy, per se my previous comment with the > additional code dependencies. > > I think that this scenario deserves a test case. If one wants to > emulate a delay in WAL archiving, it is possible to set > archive_command to a command that we know will fail, for instance. > -- > Michael Bungina, are you going to respond to these comments? -- Regards, -- Atsushi Torikoshi NTT DATA Group Corporation