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 1iDvkU-0006jg-59 for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2019 19:17:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDvkS-0004Fg-Fd for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2019 19:17:48 +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 1iDvkR-0004FE-IV for pgsql-hackers@lists.postgresql.org; Fri, 27 Sep 2019 19:17:47 +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 1iDvkK-00014c-H9 for pgsql-hackers@postgresql.org; Fri, 27 Sep 2019 19:17:46 +0000 Received: by mail-qt1-x841.google.com with SMTP id n7so8642221qtb.6 for ; Fri, 27 Sep 2019 12:17:40 -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=DY7npg5RRqS6KJRND9B6Fwa2N/oY9YlpxmC5mhxCGJI=; b=IdjnlkV3TUXzusTPAPhHk5Dcls2AgrpKXKd3d+hkzpOUm8mJrqtx+1wMgUQxgJt0mt 1Czdakukt9o9k2j4tRRh2pE5WHnWbMsjTntyHZkWX3mXA0pAuXOkD/XUupPzRNG4bbMq KlZzL9ouZq5yDpakrd2r9Wt58MY7ooZ9sq/2/AnC8HT/9GEsRzwVr59y1mVMynTMrMHR awYCl1JVrJQSsgzaxttOSjrusZkCDlldLSLCOKQEvsAzPNZy96q0bZvx8hR5BrCdv7zw fvsQE4stcqY7KdW9zlangs5eRYePqhhc86j1ZOYljHgdo7B0spGA6kUltH1ieJoo4ofW WmSw== 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=DY7npg5RRqS6KJRND9B6Fwa2N/oY9YlpxmC5mhxCGJI=; b=jXEipJaQNucmhJqE7thpMST6VOlKfeyFZ1jmd3h7pr1wM4mIuwEAXCNsMsf/jTq5Hq icW60Ou3r8JUAsI6T8mSdd4/yBPg33VkOMK9qXeUXUXRIy8MrSCEjGFrGFZ6O2/M0m1m IvNSkWtZHYMXhC75HdpkF0/dGmSg1baWvg31Qf85rAuH2nI1AndQqVpW1axHimfJPbr6 A0OA+/VM8B0+1e4wtviBtrs4NqRBxA5nRtNTyuDvBBWFBtFzY5pdC/B13mzRdg2XRbPr qPZ/sMgr7GmqvIODBFDJVuVHeRA/BkH/9p7I2Ur0jnnoBsGwk01esHv/5WxTaAs/Acmm vOXQ== X-Gm-Message-State: APjAAAWfwjYTn3DTO5eWbO7jpc95tOwclfLToJdxH54jHbtMkqqp21A7 1GmJxLorNh9VAbMUTBDhx+0raw== X-Google-Smtp-Source: APXvYqyi40/NUTLHJA8w9Hsdm6efeeVFMqqd8uiNRn9zyKkI+xLILNsyJsG/0JfvsKmmY+QVjd24iw== X-Received: by 2002:ac8:4153:: with SMTP id e19mr10460450qtm.166.1569611859610; Fri, 27 Sep 2019 12:17:39 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([191.125.99.215]) by smtp.gmail.com with ESMTPSA id d134sm1554771qkg.133.2019.09.27.12.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 12:17:39 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 39041120DD8; Fri, 27 Sep 2019 16:17:36 -0300 (-03) Date: Fri, 27 Sep 2019 16:17:36 -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: <20190927191736.GA13447@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5990.1569606865@antos> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Sep-27, Antonin Houska wrote: > > You placed the errinfo in XLogRead's stack rather than its callers' ... > > I don't think that works, because as soon as XLogRead returns that > > memory is no longer guaranteed to exist. > > I was aware of this problem, therefore I defined the field as static: > > +XLogReadError * > +XLogRead(char *buf, XLogRecPtr startptr, Size count, TimeLineID *tli_p, > + WALOpenSegment *seg, WALSegmentContext *segcxt, > + WALSegmentOpen openSegment) > +{ > + char *p; > + XLogRecPtr recptr; > + Size nbytes; > + static XLogReadError errinfo; I see. > > You need to allocate the struct in the callers stacks and pass its address > > to XLogRead. XLogRead can return NULL if everything's okay or the pointer > > to the errinfo struct. > > I didn't choose this approach because that would add one more argument to the > function. Yeah, the signature does seem a bit unwieldy. But I wonder if that's too terrible a problem, considering that this code is incurring a bunch of syscalls in the best case anyway. BTW that tli_p business to the openSegment callback is horribly inconsistent. Some callers accept a NULL tli_p, others will outright crash, even though the API docs say that the callback must determine the timeline. This is made more complicated by us having the TLI in "seg" also. Unless I misread, the problem is again that the walsender code is doing nasty stuff with globals (endSegNo). As a very minor stylistic point, we prefer to have out params at the end of the signature. > > Why do we leave this responsibility to ReadPageInternal? Wouldn't it > > make more sense to leave XLogRead be always responsible for setting > > these correctly, and remove those lines from ReadPageInternal? > > I think there's no rule that ReadPageInternal() must use XLogRead(). If we do > what you suggest, we need make this responsibility documented. I'll consider > that. Hmm. Thanks. > > (BTW "is called by the XLOG reader" is a bit strange in code that appears in > > xlogreader.c). > > ok, "called by XLogPageReadCB callback" would be more accurate. Not sure if > we'll eventually need this phrase in the comment at all. I think that would be slightly clearer. But if we can force this code into actually making sense, that would be much better. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services