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 1iFBd4-0000rP-JX for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Oct 2019 06:27:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFBd2-0003vl-Jz for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Oct 2019 06:27:20 +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 1iFBd2-0003vc-B9 for pgsql-hackers@lists.postgresql.org; Tue, 01 Oct 2019 06:27:20 +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 1iFBcz-0002h5-Ee for pgsql-hackers@postgresql.org; Tue, 01 Oct 2019 06:27:19 +0000 Received: by mail-wr1-x444.google.com with SMTP id w12so13901774wro.5 for ; Mon, 30 Sep 2019 23:27:16 -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:content-transfer-encoding:date:message-id; bh=pSHSyrlWo+/FzInrwlNurA8f2SEiJSG7vmWEuHBDX3w=; b=Ule/9OspdJ8F0J25SjPWOeCNKYohtZDhGSK4ViROAbV/O+pl1581aSi6z/KEgX4K6s 4v48qjn+TZ22IjDu5zyHmmCOeY5sHYYpHRJxCreX/kzwNhu/42W3ubShv1c9s5ahowiR j/zYWv25VqbEaOUYfgzQB2sCj/jTPOzsvAohLqL48fL4Z7rsLbib/OkFj3oNtF4Xzc+7 8FEHn/Jl9HOrmBFK6p86JPDF/u5zsQOLhWnMFqbUvIDKjkZm6/+71g23Zsrekmlvebhe MSg/mZGBEoifYWl5wuYvz+fLqSXYujkYXiT9ZZVf+yppuAUCknUHvl9xHJdzNRYUw5DB wqwg== 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:content-transfer-encoding:date :message-id; bh=pSHSyrlWo+/FzInrwlNurA8f2SEiJSG7vmWEuHBDX3w=; b=iUSVGzszofjkN1gLf7vdgAcQ/7+7emkeBr6VK6nfy63fLb00CgeJMIYeptTBUiC06N cUudjN3u4xVARmRdMotkcYXq4sKo7VgbkQLFpsWJ7IwlUiOEvBnoMcjTDzzxKpF8Aryi AVEmKRI6o8o6XFtTtj96rsp+TqRQBI10zxxBwqBrwzeORwxvBtqvO6whMIixWFziMEIr 1ic5gW/JzrCuvgHh7V2UhwYlyWVpXkzCfAWR6di6Fw//6tjJZ3ZFxWyqB6wvHl7wkwTy 4xGR1az++kpSOq++FEne7J0TgTvbPt+SEn4Np6iPD7yYvN9r9rSMXBDmhIdooVZvepaq BWRg== X-Gm-Message-State: APjAAAVMyixIBadeBXO4tLYaXTNkgCRtJcLpDGlzEqZh8JBHr8q4+mRw /vk1Yb4PPjGQjN11nIYbkmhvgw== X-Google-Smtp-Source: APXvYqz8iGFLRy8d3Hp6cQUL87HS4qs5HhNsvqk1M3A2mty6OkP5NwVtE8RFXSNVTcxVSO1wO3C2eA== X-Received: by 2002:a5d:4f11:: with SMTP id c17mr2900707wru.227.1569911236152; Mon, 30 Sep 2019 23:27:16 -0700 (PDT) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id r2sm3086886wma.1.2019.09.30.23.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 23:27:15 -0700 (PDT) From: Antonin Houska To: Kyotaro Horiguchi cc: alvherre@2ndquadrant.com, thomas.munro@gmail.com, robertmhaas@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Attempt to consolidate reading of XLOG page In-reply-to: <20191001.122227.209046280.horikyota.ntt@gmail.com> References: <20190927191736.GA13447@alvherre.pgsql> <7753.1569658465@antos> <9236.1569675635@antos> <20191001.122227.209046280.horikyota.ntt@gmail.com> Comments: In-reply-to Kyotaro Horiguchi message dated "Tue, 01 Oct 2019 12:22:27 +0900." 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: <2187.1569911283.1@antos> Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Oct 2019 08:28:03 +0200 Message-ID: <2188.1569911283@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kyotaro Horiguchi wrote: > At Sat, 28 Sep 2019 15:00:35 +0200, Antonin Houska wrot= e in <9236.1569675635@antos> > > Antonin Houska wrote: > > = > > > Alvaro Herrera wrote: > > > = > > > > BTW that tli_p business to the openSegment callback is horribly > > > > inconsistent. Some callers accept a NULL tli_p, others will outri= ght > > > > crash, even though the API docs say that the callback must determi= ne 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 c= ode is > > > > doing nasty stuff with globals (endSegNo). As a very minor stylis= tic > > > > point, we prefer to have out params at the end of the signature. > > > = > > > XLogRead() tests for NULL so it should not crash but I don't insist = on doing > > > it this way. XLogRead() actually does not have to care whether the "= open > > > segment callback" determines the TLI or not, so it (XLogRead) can al= ways > > > receive a valid pointer to seg.ws_tli. > > = > > This is actually wrong - seg.ws_tli is not always the correct value to > > pass. If seg.ws_tli refers to the segment from which data was read las= t time, > > then XLogRead() still needs a separate argument to specify from which = TLI the > > current call should read. If these two differ, new file needs to be op= ened. > = > openSegment represents the file *currently* opened. I suppose you mean the "seg" argument. > XLogRead needs the TLI *to be* opened. If they are different, as far as = wal > logical wal sender and pg_waldump is concerned, XLogRead switches to the= new > TLI and the new TLI is set to openSegment.ws_tli. Yes, it works in these cases. > So, it seems to me that the parameter doesn't need to be inout? It is en= ough > that it is an "in" parameter. I did consider "TimeLineID *tli_p" to be "in" parameter in the last patch version. The reason I used pointer was the special meaning of the NULL val= ue: if NULL is passed, then the timeline should be ignored (because of the oth= er cases, see below). > > The problem of walsender.c is that its implementation of XLogRead() do= es not > > care about the TLI of the previous read. If the behavior of the new, g= eneric > > implementation should be exactly the same, we need to tell XLogRead() = that in > > some cases it also should not compare the current TLI to the previous > > one. That's why I tried to use the NULL pointer, or the InvalidTimeLin= eID > > earlier. > = > Physical wal sender doesn't switch TLI. So I don't think the > behavior doesn't harm (or doesn't fire). openSegment holds the > TLI set at the first call. (Even if future wal sender switches > TLI, the behavior should be needed.) Note that walsender.c:XLogRead() has no TLI argument, however the XLogRead= () introduced by the patch does have one. What should be passed for TLI to th= e new implementation if it's called from walsender.c? If the check for a seg= ment change looks like this (here "tli" is the argument representing the desire= d TLI) if (seg->ws_file < 0 || !XLByteInSeg(recptr, seg->ws_segno, segcxt->ws_segsize) || tli !=3D seg->ws_tli) { XLogSegNo nextSegNo; /* Switch to another logfile segment */ if (seg->ws_file >=3D 0) close(seg->ws_file); then any valid TLI can result in accidental closing of the current segment file. Since this is only refactoring patch, we should not allow such a cha= nge of behavior even if it seems that the same segment will be reopened immediately. -- = Antonin Houska Web: https://www.cybertec-postgresql.com