Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d79fv-00047d-Tq for pgsql-hackers@arkaria.postgresql.org; Sun, 07 May 2017 00:03:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d79fv-0001fZ-GW for pgsql-hackers@arkaria.postgresql.org; Sun, 07 May 2017 00:03:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d79eQ-0007Hs-AN for pgsql-hackers@postgresql.org; Sun, 07 May 2017 00:02:14 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d79eM-0006YV-Of for pgsql-hackers@postgresql.org; Sun, 07 May 2017 00:02:13 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BFC182074A; Sat, 6 May 2017 20:02:09 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Sat, 06 May 2017 20:02:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=1uoC9FONgCCxMacwU9 Dr7olaeo7XxOGKKaLHOhO9M+Y=; b=USfH/PpSu7U7EgtpPdM33NDaonm55iy5Mt vNvik/GHXtozeba079R51bBRB0J4+HCr1KK3MqFeyZPjJ+i8cegQ2+zsV1IdT7+p +iP9HxAR0l1FK9tuVfGmudlDquGf+44OFAFqeHyVNCCzTZr6gKnlybmZhuP0BGbY Ks5sNCmo7pieuYg+MXpFBJUIcHDiNAuV5PmLW8pkGCPcgMS4oap0U4o/wUna67vQ OI8E4g9JdkG7zcmtmhkjx/hGjc7hVviVy4l6PLSx8XZzwj3IB9fv16Vten1EDYeo MhroWXHAnsD+4MwiKt/AJ6qBlqvufbkjP7oxS3n+F44BhSXMiFlw== X-ME-Sender: X-Sasl-enc: pZn1A7Wv156fD3vVFZdZcMNYPvbZEOyDnrqgoYLVRPr3 1494115329 Received: from intern.anarazel.de (c-67-180-210-202.hsd1.ca.comcast.net [67.180.210.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 401F37E266; Sat, 6 May 2017 20:02:09 -0400 (EDT) Date: Sat, 6 May 2017 17:01:26 -0700 From: Andres Freund To: pgsql-hackers@postgresql.org, Michael Paquier Subject: Re: Change GetLastImportantRecPtr's definition? (wasSkip checkpoints, archiving on idle systems.) Message-ID: <20170507000126.gnnifm7jywxc5eg6@alap3.anarazel.de> References: <20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, On 2017-05-04 18:24:47 -0700, Andres Freund wrote: > Hi, > > On 2016-12-22 19:33:30 +0000, Andres Freund wrote: > > Skip checkpoints, archiving on idle systems. > > As part of an independent bugfix I noticed that Michael & I appear to > have introduced an off-by-one here. A few locations do comparisons like: > /* > * Only log if enough time has passed and interesting records have > * been inserted since the last snapshot. > */ > if (now >= timeout && > last_snapshot_lsn < GetLastImportantRecPtr()) > { > last_snapshot_lsn = LogStandbySnapshot(); > ... > > which looks reasonable on its face. But LogStandbySnapshot (via XLogInsert()) > * Returns XLOG pointer to end of record (beginning of next record). > * This can be used as LSN for data pages affected by the logged action. > * (LSN is the XLOG point up to which the XLOG must be flushed to disk > * before the data page can be written out. This implements the basic > * WAL rule "write the log before the data".) > > and GetLastImportantRecPtr > * GetLastImportantRecPtr -- Returns the LSN of the last important record > * inserted. All records not explicitly marked as unimportant are considered > * important. > > which means that we'll e.g. not notice if there's exactly a *single* WAL > record since the last logged snapshot (and likely similar in the other > users of GetLastImportantRecPtr()), because XLogInsert() will return > where the next record will most of the time be inserted, and > GetLastImportantRecPtr() returns the beginning of said record. > > This is trivially fixable by replacing < with <=. But I wonder if the > better fix would be to redefine GetLastImportantRecPtr() to point to the > end of the record, too? I don't quite see any upcoming user that'd need > the beginning, and this is a bit failure prone for likely users. Turns out this isn't the better fix, because the checkpoint code compares with the actual record LSN (rather than the end+1 that XLogInsert() returns). We'd start having to do more bookkeeping or more complicated computations (subtracting the checkpoint record's size). Therefore I've pushed the simple fix mentioned above instead. - Andres -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers