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 1iDuTT-0003Xe-Mx for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2019 17:56:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDuTS-0005Hs-Ir for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2019 17:56:10 +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 1iDuR5-0006Co-HV for pgsql-hackers@lists.postgresql.org; Fri, 27 Sep 2019 17:53:43 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iDuR2-0005km-Kd for pgsql-hackers@postgresql.org; Fri, 27 Sep 2019 17:53:43 +0000 Received: by mail-wr1-x444.google.com with SMTP id l3so4174158wru.7 for ; Fri, 27 Sep 2019 10:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:comments:mime-version :content-id:date:message-id; bh=YibuI8Lqc+OkP7hI+ArvDm4SXsaVpSFUNsngpxleK/A=; b=N/I6o90U3SEXjSHftBUN3hdq3XeARaGT4k+uot5YGc95C88gjpHztIP7fUX+GyBvGx aOS0wLcUBpmgfb4yfRXjcM4QV0k53lL+ncPYnkksFlTs91ZD2euBeWYx005+T8rDYpt5 JQELjIBvw3/rnwav+iGyaNpnZpWVMd+2sU7qWCdIuswaqKsHw8sqGKFscC8AbSxihldZ IfB6Bk1trfHTuqFTDmTQP2Sy+t/wEVfjeOP73p41iT2uFi8D617oxYEpat2TFVttCifE M7IqftyHTyP8jt3BoRwHCwZDM7NRleQ0l4OkFom9FSwbb1mQm+LQWMnUKVPWi4g2DrwL 6dlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :comments:mime-version:content-id:date:message-id; bh=YibuI8Lqc+OkP7hI+ArvDm4SXsaVpSFUNsngpxleK/A=; b=HdyMuO8xp6JtogalRwIdxgHkbQSeMyfkEuPMSER3bGGeQzsjVxmXXhVtfLOqO2GSzg TFYCggBlVcbMVYcF5LnnzCQ6vXgxEZH6WzdbhqbIP+FFgS+cbg+E5rbkUvdZQzZM+uri kNV8n4rvD2vWVQ1MkYfoyg2KFqhWPV8lvqE/+YQi2g7Q28Yuia2pdlKSWJsR+1hSqepO wQ42SNyOJSNo4rpBag4sDeplqLTl2HHCbG+w4bEqxGeF5PafKnkGqMIKdTAKVD4U/dOZ VF+tFxGVUNayGwaZpFNHyZD1GKJQH1YRj9J/HDP6CUHCcAi/w6D3vTLSEOCwbV3HDcm6 P6og== X-Gm-Message-State: APjAAAUJnCiDWWlrvQf7NuwF+/t4Hb/whIXTsaEIEuVcIc4wCDdC8b7n 1TACEOUWDkGo4OAiU59eLrkHn3dPj5QXUQ== X-Google-Smtp-Source: APXvYqx/DVWPC/hnx5fJ+E0CAkzz5sjLMH/eFG1xqUT33ST6iF9puzyvlktIHOF5geDx9UHDBcow8A== X-Received: by 2002:adf:de0d:: with SMTP id b13mr3851398wrm.140.1569606819243; Fri, 27 Sep 2019 10:53:39 -0700 (PDT) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id w22sm5653732wmc.16.2019.09.27.10.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 10:53:38 -0700 (PDT) From: Antonin Houska To: Alvaro Herrera cc: Thomas Munro , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Attempt to consolidate reading of XLOG page In-reply-to: <20190927132210.GA18194@alvherre.pgsql> References: <20190927132210.GA18194@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Fri, 27 Sep 2019 10:22:10 -0300." X-Mailer: MH-E 8.6+git; nmh 1.7; GNU Emacs 26.2.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5989.1569606865.1@antos> Date: Fri, 27 Sep 2019 19:54:25 +0200 Message-ID: <5990.1569606865@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera wrote: > On 2019-Sep-26, 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; > 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. > I've been wondering if it's really necessary to pass 'seg' to the > openSegment() callback. Only walsender wants that, and it seems ... > weird. Maybe that's not something for this patch series to fix, but it > would be good to find a more decent way to do the TLI switch at some > point. Good point. Since walsender.c already has the "sendSeg" global variable, maybe we can let WalSndSegmentOpen() use this one, and remove the "seg" argument from the callback. > > + /* > > + * If the function is called by the XLOG reader, the reader will > > + * eventually set both "ws_segno" and "ws_off", however the XLOG > > + * reader is not necessarily involved. Furthermore, we need to set > > + * the current values for this function to work. > > + */ > > + seg->ws_segno = nextSegNo; > > + seg->ws_off = 0; > > 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. > (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. -- Antonin Houska Web: https://www.cybertec-postgresql.com