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 1qayZh-00Apsm-5G for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Aug 2023 13:16:05 +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 1qayZe-0078pr-FR for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Aug 2023 13:16:02 +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 1qayZe-0078od-4w for pgsql-hackers@lists.postgresql.org; Tue, 29 Aug 2023 13:16:01 +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 1qayZZ-001kDK-5r for pgsql-hackers@postgresql.org; Tue, 29 Aug 2023 13:16:01 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 77B6560299; Tue, 29 Aug 2023 22:15:51 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.9 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 29 Aug 2023 22:15:51 +0900 From: torikoshia To: Kyotaro Horiguchi , cyberdemn@gmail.com Cc: michael@paquier.xyz, pgsql-hackers@postgresql.org, bungina@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: pg_rewind WAL segments deletion pitfall In-Reply-To: <20230824.094538.2107929879048686192.horikyota.ntt@gmail.com> References: <8b385bb6d5f87e54c1c6333fece0444a@oss.nttdata.com> <20230824.094538.2107929879048686192.horikyota.ntt@gmail.com> User-Agent: Roundcube Webmail/1.4.11 Message-ID: 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-24 09:45, Kyotaro Horiguchi wrote: > At Wed, 23 Aug 2023 13:44:52 +0200, Alexander Kukushkin > wrote in >> On Tue, 22 Aug 2023 at 07:32, Michael Paquier >> wrote: >> > 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()? >> >> I think the first version of the patch more or less did that. Not >> necessarily a list, but a hash table of WAL file names that we want to >> keep. But Kyotaro Horiguchi didn't like it and suggested creating >> entries >> in the filemap.c hash table instead. >> But, I agree, doing it directly from the findLastCheckpoint() makes >> the >> code easier to understand. > ... >> > + /* >> > + * 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. >> > >> >> We can revert to the original approach (see >> v1-0001-pg_rewind-wal-deletion.patch from the very first email) if you >> like. > > On the other hand, that approach brings in another source that > suggests the way that file should be handled. I still think that > entry->action should be the only source. +1. Imaging a case when we come to need decide how to treat files based on yet another factor, I feel that a single source of truth is better than creating a list or hash for each factor. > However, it seems I'm in the > minority here. So I'm not tied to that approach. > >> > 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. >> > >> >> Yes, I totally agree, it is on our radar, but meanwhile please see the >> new >> version, just to check if I correctly understood your idea. Thanks for the patch. I tested v4 patch using the script attached below thread and it has successfully finished. https://www.postgresql.org/message-id/2e75ae22dce9a227c3d47fa6d0ed094a%40oss.nttdata.com -- Regards, -- Atsushi Torikoshi NTT DATA Group Corporation