Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmPQl-0007h7-Gg for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jun 2020 22:24:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jmPQi-0006hB-Dm for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jun 2020 22:24:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmPQi-0006h4-6o for pgsql-hackers@lists.postgresql.org; Fri, 19 Jun 2020 22:24:12 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jmPQa-0001K9-V3 for pgsql-hackers@lists.postgresql.org; Fri, 19 Jun 2020 22:24:11 +0000 Received: by mail-qk1-x741.google.com with SMTP id g28so10528392qkl.0 for ; Fri, 19 Jun 2020 15:24:04 -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=WriAQoEe7EnydhcymiJrWp16O/Nex7yTmDvwPLtE724=; b=VM+S183xf6S8TgZkoqsMr6z7+pgvFQicFuLrV8YktO2A4pVrcDoqIWOWTfdi9toN2E TBBy+UKkxhnb/UmJmjSt9+e/nvOevB8dLHm5kfV1eXynU6skdxT/ueHIcKGqQDSUqZcm O9Uzk4cCUCVmI/tBVXjPMGupQvMSsO+7/rfCISRL6TnoprtH7ILimwzsTxEVfUZqo/SY WQpP+le9btwffJR+3AUioi4jXoWU+BqsC7BIcMxmFclgsaPyzH68WPFgXJJZqTgBRDzH KvUhNrxxIo26mJHyVQVKbCSNLNJUu9Wg9mkkMMdXnMMYYMbp1tq/GexZc2uZwaj4Beqk J63g== 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=WriAQoEe7EnydhcymiJrWp16O/Nex7yTmDvwPLtE724=; b=lhZwFICezgOrvFZGr7PLxt9ZFeVfhz2WSBKjaCJgb4BD+/VIof9FcgONTB3NdIJ1It l/tg44RdnNgScP4MeGVvZ9hNBej7WfM3oj8lcZrIXdv89w+WMMS7mroABfjmehXybaJ2 GGgjK4j1SF4cb9eUXykNHjKHCHD4y/al2KYheLCO+mi/LJekwP4Jgw61gXC44yUSoBez /mENzcsggWvSKHopVzqM2YwVGnzhRiD54wa2yzXEJAqbtssJarpYWv1DExRq2AS7t6gg Ic+oYVgGp+Y05YHtcQJSwifIC1v9wOpnLLNjfxAG3m8RDHYh5U6cSUeJJhSrOUB8Drzf zP7A== X-Gm-Message-State: AOAM532YCrQMCEp0qnQhAFT2qAwR36CDrFwOy9Cfyg6dPUlZ1kkfAZfw G2C03sD5Q0cloYVFjc+UXQVBnw== X-Google-Smtp-Source: ABdhPJxPwQd0MQgbfvNIiW2ze2oFtCCPdtNxiwoFOiqrZFE3UpqNQMps0xrVkg1IanGRgXEIwDEupw== X-Received: by 2002:ae9:c10d:: with SMTP id z13mr5444747qki.3.1592605442538; Fri, 19 Jun 2020 15:24:02 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id z46sm7036663qtb.57.2020.06.19.15.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 15:24:01 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 52DBF2A3D8C; Fri, 19 Jun 2020 18:23:59 -0400 (-04) Date: Fri, 19 Jun 2020 18:23:59 -0400 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: masao.fujii@oss.nttdata.com, pgsql-hackers@lists.postgresql.org Subject: Re: Review for GetWALAvailability() Message-ID: <20200619222359.GA3559@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200617.135607.687059791532071892.horikyota.ntt@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Jun-17, Kyotaro Horiguchi wrote: > @@ -9524,7 +9533,7 @@ GetWALAvailability(XLogRecPtr targetLSN) > * the first WAL segment file since startup, which causes the status being > * wrong under certain abnormal conditions but that doesn't actually harm. > */ > - oldestSeg = XLogGetLastRemovedSegno() + 1; > + oldestSeg = last_removed_seg + 1; > > /* calculate oldest segment by max_wal_size and wal_keep_segments */ > XLByteToSeg(currpos, currSeg, wal_segment_size); This hunk should have updated the comment two lines above. However: > @@ -272,6 +273,14 @@ pg_get_replication_slots(PG_FUNCTION_ARGS) > rsinfo->setResult = tupstore; > rsinfo->setDesc = tupdesc; > > + /* > + * Remember the last removed segment at this point for the consistency in > + * this table. Since there's no interlock between slot data and > + * checkpointer, the segment can be removed in-between, but that doesn't > + * make any practical difference. > + */ > + last_removed_seg = XLogGetLastRemovedSegno(); I am mystified as to why you added this change. I understand that your point here is to make all slots reported their state as compared to the same LSN, but why do it like that? If a segment is removed in between, it could mean that the view reports more lies than it would if we update the segno for each slot. I mean, suppose two slots are lagging behind and one is reported as 'extended' because when we compute it it's still in range; then a segment is removed. With your coding, we'll report both as extended, but with the original coding, we'll report the new one as lost. By the time the user reads the result, they'll read one incorrect report with the original code, and two incorrect reports with your code. So ... yes it might be more consistent, but what does that buy the user? OTOH it makes GetWALAvailability gain a new argument, which we have to document. > + /* > + * However segments required by the slot has been lost, if walsender is > + * active the walsender can read into the first reserved slot. > + */ > + if (slot_is_active) > + return WALAVAIL_BEING_REMOVED; I don't understand this comment; can you please clarify what you mean? I admit I don't like this slot_is_active argument you propose to add to GetWALAvailability either; previously the function can be called with an LSN coming from anywhere, not just a slot; the new argument implies that the LSN comes from a slot. (Your proposed patch doesn't document this one either.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services