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 1iCWNb-0002Gq-B8 for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Sep 2019 22:00:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iCWNZ-0003iU-RT for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Sep 2019 22:00:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCWNZ-0003fr-C8 for pgsql-hackers@lists.postgresql.org; Mon, 23 Sep 2019 22:00:21 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iCWNS-0006lh-1a for pgsql-hackers@postgresql.org; Mon, 23 Sep 2019 22:00:19 +0000 Received: by mail-qt1-x841.google.com with SMTP id x5so19099279qtr.7 for ; Mon, 23 Sep 2019 15:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=I8YWnetGBnp7ktBrFtvTU9QYYKtnmRW+msXskDjICqU=; b=udkROai+6sOEFtMeptTPUiVXboF9t3N34MIBuUNrQXzZq1EyZ44GYMRV57/Oxfb49v zIqjMIUWcsftIefOhDCJvrZuhcC4IVhDDs4uGkVW5c/hcGGgxqWGCgH5NfMs7TEMrYt+ N25qXXiHWU/TOkuR2Q3vLMMI3k+H2bRW7WajLSTCuBc2OgtqeP+5/wGY9ohGENjHZocQ wWcG2ZFO1h9u3E58CQuiA0UitAMvKwed+N3ciss7nn/86+yxJuUX2cT8GJZBbCozWO1L vGUTo6oIgoRf3te11xk/fYUSWpgTvxbf+uQNskkC2dVCZrxPz7IgPU2a683dmMEGpijG ZPzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=I8YWnetGBnp7ktBrFtvTU9QYYKtnmRW+msXskDjICqU=; b=aWoiciFDFZb6c9jb054g8kHOTNVLRNE9/DSvRXz4GK+6JVYlUXsvb7NL4qm/O6NqOc NR80TJhyOzh3DbvjVh87Y+bxmeuQ/JZF2p/OdjWX8Q9ECV0LJ+jVRjv+OQTRWmi1fgGW 6ypZBgpSyrgqmGqbPDrY9tjBprcwfp1fngL62qRaual2mUe8aJXClwuNo78IGp3gNlwz HvokWC9mIh9QNmIvF2rR5v6FZVZTFF6cSmdF60IfzElbgueAtGbCwqwlpupZGZ6mUhke YQCKh1SxdUhpbQmVwaPvSug0WdYEZw8cVqmy255RC4sH5nQsKqdK0FwAPOzAR0yVuVuT RXSA== X-Gm-Message-State: APjAAAX9F1HRi1em/igclcT1SaSUETSaRU8upottnozvGNDxTt/GMSVC K/EA9XhYQu0iBs1Gq51A34vHUQ== X-Google-Smtp-Source: APXvYqxNLT3HY/NBZgB4VOpac+Nk+IkIuG1bmpuWdEcivhjGTdw3dZSy6O1knD2T4FEDmC8u6y6oKQ== X-Received: by 2002:ac8:1af3:: with SMTP id h48mr2433705qtk.270.1569276012959; Mon, 23 Sep 2019 15:00:12 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([179.56.55.229]) by smtp.gmail.com with ESMTPSA id j2sm5464466qki.15.2019.09.23.15.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 15:00:12 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 4973E120B3B; Mon, 23 Sep 2019 19:00:10 -0300 (-03) Date: Mon, 23 Sep 2019 19:00:10 -0300 From: Alvaro Herrera To: Antonin Houska Cc: Thomas Munro , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Attempt to consolidate reading of XLOG page Message-ID: <20190923220010.GA23527@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <46647.1569235471@antos> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I spent a couple of hours on this patchset today. I merged 0001 and 0002, and decided the result was still messier than I would have liked, so I played with it a bit more -- see attached. I think this is committable, but I'm afraid it'll cause quite a few conflicts with the rest of your series. I had two gripes, which I feel solved with my changes: 1. I didn't like that "dir" and "wal segment size" were part of the "currently open segment" supporting struct. It seemed that those two were slightly higher-level, since they apply to every segment that's going to be opened, not just the current one. My first thought was to put those as members of XLogReaderState, but that doesn't work because the physical walsender.c code does not use xlogreader at all, even though it is reading WAL. Anyway my solution was to create yet another struct, which for everything that uses xlogreader is just part of that state struct; and for walsender, it's just a separate one alongside sendSeg. All in all, this seems pretty clean. 2. Having the wal dir be #ifdef FRONTEND seemed out of place. I know the backend code does not use that, but eliding it is more "noisy" than just setting it to NULL. Also, the "Finalize the segment pointer" thingy seemed out of place. So my code passes the dir as an argument to XLogReaderAllocate, and if it's null then we just don't allocate it. Everybody else can use it to guide things. This results in cleaner code, because we don't have to handle it externally, which was causing quite some pain to pg_waldump. Note that ws_dir member is a char array in the struct, not just a pointer. This saves trouble trying to allocate it (I mainly did it this way because we don't have pstrdup_extended(MCXT_ALLOC_NO_OOM) ... yes, this could be made with palloc+snprintf, but eh, that doesn't seem worth the trouble.) Separately from those two API-wise points, there was one bug which meant that with your 0002+0003 the recovery tests did not pass -- code placement bug. I suppose the bug disappears with later patches in your series, which probably is why you didn't notice. This is the fix for that: - XLogRead(cur_page, state->seg.size, state->seg.tli, targetPagePtr, - state->seg.tli = pageTLI; + state->seg.ws_tli = pageTLI; + XLogRead(cur_page, state->segcxt.ws_segsize, state->seg.ws_tli, targetPagePtr, XLOG_BLCKSZ); ... Also, yes, I renamed all the struct members. If you don't have any strong dislikes for these changes, I'll push this part and let you rebase the remains on top. Regarding the other patches: 1. I think trying to do palloc(XLogReadError) is a bad idea ... for example, if the read fails because of system pressure, we might return "out of memory" during that palloc instead of the real read error. This particular problem you could forestall by changing to ErrorContext, but I have the impression that it might be better to have the error struct by stack-allocated in the caller stack. This forces you to limit the message string to a maximum size (say 128 bytes or maybe even 1000 bytes like MAX_ERRORMSG_LEN) but I don't have a problem with that. 2. Not a fan of the InvalidTimeLineID stuff offhand. Maybe it's okay ... not convinced yet either way. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services