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 1iDqS6-0002Vw-I9 for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2019 13:38: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 1iDqS5-0000sx-As for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2019 13:38:29 +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 1iDqOs-0003o0-NC for pgsql-hackers@lists.postgresql.org; Fri, 27 Sep 2019 13:35:10 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iDqOl-0006It-Nh for pgsql-hackers@postgresql.org; Fri, 27 Sep 2019 13:35:09 +0000 Received: by mail-qt1-x843.google.com with SMTP id u22so7223573qtq.13 for ; Fri, 27 Sep 2019 06:35:03 -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=gcxljjL8nsMHeZjINxqHuE3xC/YKXYdWRRKUKHQc6qI=; b=FxT563latZWFHpdI5TiY1/MPNoLBNUGoNC5+RrDYvhUvmqZZcyFusgoScKzbt1OMVl dkZ5VAdlsNoKDWyt0CAxaGOWedPIzgt5NA/2gARZp7Qvd4ZZUJjVQ/aGWTrykO2M6Mqz g+HQuIgcd/35ceykUGyy/jQJde7GGGHmRoPpfYWiibh9Kw/ZM80wxhTHA1TjicHQ4giJ irEgjO6OclfZ2m2BiGzP1FtY5eIGMEiQxMO4VBcULxVfhk5LtJaVfj/Z2aXpgFO8N17D Y/MaTr+Run0vk31kc95xxegsrhmNtDK1nyMDynCrRgje8l//xAy9u9wnllIArh87MeTH llHA== 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=gcxljjL8nsMHeZjINxqHuE3xC/YKXYdWRRKUKHQc6qI=; b=Ig7uYp38lXcfAh0aWxZ6bU/NLHli9pipWIzIh+IOliQNqV292vyPGRBMOsl5kpp1fg XMNvrAk9i2QstmVb5JkjTIyU1YoejmyjwkwEs4pI4bE/XfqcG4O/rWY+0oP3CddCksYE MpFrzig3jucxlEwMMz022W/fcvtAxm/nO3+eZkKKyKgGyCIhj4TRXCeqwRhf9g+I4pNn G0WwXImYm9jhvQCGf6+JMwDMpoGoHkGVHSbHcpKfdXgg35ctaX5tpPuShb8nXRGaFEA+ GsA3NjqBBkOaWv1gN1c/382jd4a6tIn/Qurf0qViD1GyvQERQDWmq42OMVWqh8GKQ1IJ jnfQ== X-Gm-Message-State: APjAAAVrWT/YlAVSXeFoRRDKFvsIeot7gv2FotmIxRab+Eo8aA/zQTGq bLsWP1xWJnPdlOqgMV5FQWEtNQ== X-Google-Smtp-Source: APXvYqwCMFA1vH4M6qH2Q/rRemIS4B6qraNiPYoFk/uL6lWOfZZlxAyw3bvoX3kRBkoTf6g2Y9+nNw== X-Received: by 2002:ac8:7244:: with SMTP id l4mr9972806qtp.40.1569591302843; Fri, 27 Sep 2019 06:35:02 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([191.125.227.87]) by smtp.gmail.com with ESMTPSA id d127sm1189799qke.54.2019.09.27.06.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 06:35:01 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 0518712088A; Fri, 27 Sep 2019 10:22:10 -0300 (-03) Date: Fri, 27 Sep 2019 10:22: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: <20190927132210.GA18194@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <75115.1569499713@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-26, Antonin Houska wrote: > One comment on the remaining part of the series: > > Before this refactoring, the walsender.c:XLogRead() function contained these > lines > > /* > * After reading into the buffer, check that what we read was valid. We do > * this after reading, because even though the segment was present when we > * opened it, it might get recycled or removed while we read it. The > * read() succeeds in that case, but the data we tried to read might > * already have been overwritten with new WAL records. > */ > XLByteToSeg(startptr, segno, segcxt->ws_segsize); > CheckXLogRemoved(segno, ThisTimeLineID); > > but they don't fit into the new, generic implementation, so I copied these > lines to the two places right after the call of the new XLogRead(). However I > was not sure if ThisTimeLineID was ever correct here. It seems the original > walsender.c:XLogRead() implementation did not update ThisTimeLineID (and > therefore neither the new callback WalSndSegmentOpen() does), so both > logical_read_xlog_page() and XLogSendPhysical() could read the data from > another (historic) timeline. I think we should check the segment we really > read data from: > > CheckXLogRemoved(segno, sendSeg->ws_tli); Hmm, okay. I hope we can get rid of ThisTimeLineID one day. 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. 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'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. > + /* > + * 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? (BTW "is called by the XLOG reader" is a bit strange in code that appears in xlogreader.c). -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services