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 1iFYsA-0008KV-Im for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Oct 2019 07:16:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFYrB-0007Qb-AD for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Oct 2019 07:15:29 +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 1iFYrA-0007Q9-Qn for pgsql-hackers@lists.postgresql.org; Wed, 02 Oct 2019 07:15:29 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFYr7-0000QA-IV for pgsql-hackers@postgresql.org; Wed, 02 Oct 2019 07:15:28 +0000 Received: by mail-wr1-x443.google.com with SMTP id r3so18307185wrj.6 for ; Wed, 02 Oct 2019 00:15:25 -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=Gb7qqRtP74eO1iZlQxsxEucibCMwZDXA14ILUfWvt74=; b=F58Me6DbXXgtlijcimHpc9F2CIZEn7LklKe73anIsVUKi+fzmdxT+osz57mm5AiU0O dA1oQQDKGjm12seeICRmHg0vd9UQiEQxtqJgQtkziNcd07n3SOFuXLst2ckIiVX5gLNt qgBkDbW/6PrL5dQXF+anwpth4yT3Tj3m09Ds6sMd5KiYGW2KVzSMA8aU4f2IFq9P1Y6q lXJk6ALZ3FEeVRgjCg02+XSK5+YE3dOuOQDGouxFzlTWt+hvD+4rqLt7+u7M+3PfLm1x HHepaGF3EOPyNI7n9lXRnku0ZyA+1Pc2TIYSf4e9MdmfA5TZYJmdSmQZLRHMcSwN+pvP DCkQ== 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=Gb7qqRtP74eO1iZlQxsxEucibCMwZDXA14ILUfWvt74=; b=JrL2akb/WE/k/IwcqWHI2Y9kjTzjv1/QEqPkLgJyYI3RpKfisa44WYX1idk9Kxygkh 0ddb4mqD9o3X1CVs28rX10aI/YEuFSfaqcldWl9eqnD/ImYiWJKFc2lRbS33cqI1V3ir nY1TezEiNudu4Mm6/sJfWezZ+3P4jdAZy94P5E6NU5Z1hYgUPxF4PUZy+JVJSFeVwozT QwagmVylx5szhnaTz0YAuh2bZfHgWh336wHz0O89A4pOWT+i3+5GDPhRwHrWHUYHBXAP WgqA73ioB0ih3oU3QoH+5yOOrJ2f67X7n2ZHdKouPQZlEyKIjoLuTRi9+YP8Xc1KMfGF 0jEA== X-Gm-Message-State: APjAAAXC5Ii8/a3sVQWXGQtfrcK1n0D0awkDnZ+ojBB62Xpu+ivj2/iO r4BoO8W/EiuDq5MjbZdJWW2vUg== X-Google-Smtp-Source: APXvYqxWxPhtX1d1+D3txGrxz+6R51+lIGEVFVV4aZStMXqjrdrSZITFOWwLgaF1YAaHc2q7Vc1SfQ== X-Received: by 2002:adf:f60b:: with SMTP id t11mr1272832wrp.179.1570000523702; Wed, 02 Oct 2019 00:15:23 -0700 (PDT) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id g3sm2025999wro.14.2019.10.02.00.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2019 00:15:23 -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.174822.208675030.horikyota.ntt@gmail.com> References: <9236.1569675635@antos> <20191001.122227.209046280.horikyota.ntt@gmail.com> <2188.1569911283@antos> <20191001.174822.208675030.horikyota.ntt@gmail.com> Comments: In-reply-to Kyotaro Horiguchi message dated "Tue, 01 Oct 2019 17:48:22 +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: <27139.1570000570.1@antos> Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Oct 2019 09:16:10 +0200 Message-ID: <27140.1570000570@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kyotaro Horiguchi wrote: > At Tue, 01 Oct 2019 08:28:03 +0200, Antonin Houska wrot= e in <2188.1569911283@antos> > > Kyotaro Horiguchi wrote: > > > > The problem of walsender.c is that its implementation of XLogRead(= ) does not > > > > care about the TLI of the previous read. If the behavior of the ne= w, generic > > > > implementation should be exactly the same, we need to tell XLogRea= d() that in > > > > some cases it also should not compare the current TLI to the previ= ous > > > > one. That's why I tried to use the NULL pointer, or the InvalidTim= eLineID > > > > 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 XLog= Read() > > introduced by the patch does have one. What should be passed for TLI t= o the > > new implementation if it's called from walsender.c? I f the check for = a segment > > change looks like this (here "tli" is the argument representing the de= sired > > TLI) > = > TLI is mandatory to generate a wal file name so it must be passed > to the function anyways. In the current code it is sendTimeLine > for the walsender.c:XLogRead(). logical_read_xlog_page sets the > variable very time immediately before calling > XLogRead(). CreateReplicationSlot and StartReplication set the > variable to desired TLI immediately before calling and once it is > set by StartReplication, it is not changed by XLogSendPhysical > and wal sender ends at the end of the current timeline. In the > XLogRead, the value is copied to sendSeg->ws_tli when the file > for the new timeline is read. Are you saying that we should pass sendTimeLine to XLogRead()? I think it'= s not always correct because sendSeg->ws_tli is sometimes assigned sendTimeLineNextTLI, so the test "tli !=3D seg->ws_tli" in > > if (seg->ws_file < 0 || > > !XLByteInSeg(recptr, seg->ws_segno, segcxt->ws_segsize) || > > tli !=3D seg->ws_tli) > > { > > XLogSegNo nextSegNo; could pass occasionally. > Mmm. ws_file must be -1 in the case? tli !=3D seg->ws_tli is true > but seg->ws_file < 0 is also always true at the time. In other > words, the "tli !=3D seg->ws_tli" is not even evaluated. > = > If wal sender had an open file (ws_file >=3D 0) and the new TLI is > different from ws_tli, it would be the sign of a serious bug. So we can probably pass ws_tli as the "new TLI" when calling the new XLogRead() from walsender.c. Is that what you try to say? I need to think about it more but it sounds like a good idea. -- = Antonin Houska Web: https://www.cybertec-postgresql.com