Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hFwsf-0005Xa-7n for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2019 08:22:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hFwsc-0003yZ-BZ for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2019 08:22:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hFwsc-0003yS-2v for pgsql-hackers@lists.postgresql.org; Mon, 15 Apr 2019 08:22:18 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hFwsZ-00062w-7Q for pgsql-hackers@postgresql.org; Mon, 15 Apr 2019 08:22:17 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 2F2FBA1208; Mon, 15 Apr 2019 10:22:14 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id zRIncxJlzPvV; Mon, 15 Apr 2019 10:22:09 +0200 (CEST) From: Antonin Houska To: Kyotaro HORIGUCHI cc: pgsql-hackers@postgresql.org Subject: Re: Attempt to consolidate reading of XLOG page In-reply-to: <20190412.122711.158276916.horiguchi.kyotaro@lab.ntt.co.jp> References: <14984.1554998742@spoje.net> <20190412.122711.158276916.horiguchi.kyotaro@lab.ntt.co.jp> Comments: In-reply-to Kyotaro HORIGUCHI message dated "Fri, 12 Apr 2019 12:27:11 +0900." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12353.1555316525.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Mon, 15 Apr 2019 10:22:05 +0200 Message-ID: <12354.1555316525@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kyotaro HORIGUCHI wrote: > Hello. > = > At Thu, 11 Apr 2019 18:05:42 +0200, Antonin Houska wrot= e in <14984.1554998742@spoje.net> > > While working on the instance encryption I found it annoying to apply > > decyption of XLOG page to three different functions. Attached is a pat= ch that > > tries to merge them all into one function, XLogRead(). The existing > > implementations differ in the way new segment is opened. So I added a = pointer > > to callback function as a new argument. This callback handles the spec= ific > > ways to determine segment file name and to open the file. > > = > > I can split the patch into multiple diffs to make detailed review easi= er, but > > first I'd like to hear if anything is seriously wrong about this > > design. Thanks. > = > This patch changes XLogRead to allow using other than > BasicOpenFile to open a segment, Good point. The acceptable ways to open file on both frontend and backend = side need to be documented. > and use XLogReaderState.private to hold a new struct XLogReadPos for the > segment reader. The new struct is heavily duplicated with XLogReaderStat= e > and I'm not sure the rason why the XLogReadPos is needed. ok, I missed the fact that XLogReaderState already contains most of the in= fo that I put into XLogReadPos. So XLogReadPos is not needed. > Anyway, in the first place, such two distinct-but-highly-related > callbacks makes things too complex. Heikki said that the log > reader stuff is better not using callbacks and I agree to that. I > did that once for my own but the code is no longer > applicable. But it seems to be the time to do that. > = > https://www.postgresql.org/message-id/47215279-228d-f30d-35d1-16af695e53= f3@iki.fi Thanks for the link. My understanding is that the drawback of the XLogReaderState.read_page callback is that it cannot easily switch between XLOG sources in order to handle failure because the caller of XLogReadReco= rd() usually controls those sources too. However the callback I pass to XLogRead() is different: if it fails, it si= mply raises ERROR. Since this indicates rather low-level problem, there's no re= ason for this callback to try to recover from the failure. > That would seems like follows. That refactoring separates log > reader and page reader. > = > = > for(;;) > { > rc =3D XLogReadRecord(reader, startptr, errormsg); > = > if (rc =3D=3D XLREAD_SUCCESS) > { > /* great, got record */ > } > if (rc =3D=3D XLREAD_INVALID_PAGE || XLREAD_INVALID_RECORD) > { > elog(ERROR, "invalid record"); > } > if (rc =3D=3D XLREAD_NEED_DATA) > { > /* > * Read a page from disk, and place it into reader->readBuf > */ > XLogPageRead(reader->readPagePtr, /* page to read */ > reader->reqLen /* # of bytes to read */ ); > /* > * Now that we have read the data that XLogReadRecord() > * requested, call it again. > */ > continue; > } > } > = > DecodingContextFindStartpoint(ctx) > do > { > read_local_xlog_page(....); > rc =3D XLogReadRecord (reader); > while (rc =3D=3D XLREAD_NEED_DATA); > = > I'm going to do that again. > = > = > Any other opinions, or thoughts? I don't see an overlap between what you do and what I do. It seems that ev= en if you change the XLOG reader API, you don't care what read_local_xlog_pag= e() does internally. What I try to fix is XLogRead(), and that is actually a subroutine of read_local_xlog_page(). -- = Antonin Houska Web: https://www.cybertec-postgresql.com