Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6WVz-00077n-3Z for pgsql-hackers@arkaria.postgresql.org; Fri, 05 May 2017 06:14:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d6WVy-0007MT-MB for pgsql-hackers@arkaria.postgresql.org; Fri, 05 May 2017 06:14:54 +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 1d6WUT-0004d6-PG for pgsql-hackers@postgresql.org; Fri, 05 May 2017 06:13:22 +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 1d6WUM-0002Uj-Ga for pgsql-hackers@postgresql.org; Fri, 05 May 2017 06:13:20 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2D86D207DF; Fri, 5 May 2017 02:13:13 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 05 May 2017 02:13:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=X0LddvrrLispf3+5UM FdMdrs8dY4soqaBhvhMkHoqzM=; b=jazQHfqZOu8pedogIDDmQbusUqzPBCYr74 0KuSxumLEpLQXuY151RyrRrurqOTgeCwp2n6hVpQNgCVIwvf7d0uZTZQelQUy/40 OMk8sW9RKDiP/Mr7J7V7esy7z+WFHONgMrchHn/PtzRgry31H/vvlM+RsZ6WADw/ HVrUpnArkqummUdDw6cYix0lqItnmL6ddIvn6Yb0EQTyRLe2QCGx76rLyUPjum25 ztFchtEqM+TKRe91qtECT7DkJ+nl7k7SeWmfytuxTRnsHf5tndUgW0gps21CQ3sQ 4fpwf+IuAUWYiX+CGrg7iM8sFYGT/9ntFSEwGcYsQUGwXrtRJl0A== X-ME-Sender: X-Sasl-enc: exM9q22j6mfbXYKSS6+lLdGqkBFLipOJ7KGHbDAiTUyl 1493964792 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id E3B807E266; Fri, 5 May 2017 02:13:12 -0400 (EDT) Date: Thu, 4 May 2017 23:13:10 -0700 From: Andres Freund To: Amit Kapila Cc: pgsql-hackers , Michael Paquier Subject: Re: Change GetLastImportantRecPtr's definition? (wasSkip checkpoints, archiving on idle systems.) Message-ID: <20170505061310.solmwcb5yo3urwmv@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: 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 On 2017-05-05 11:04:14 +0530, Amit Kapila wrote: > On Fri, May 5, 2017 at 6:54 AM, 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? > > > > If you think it is straightforward to note the end of the record, then > that sounds sensible thing to do. However, note that we remember the > position based on lockno and lock is released before we can determine > the EndPos. I'm not sure I'm following: XLogRecPtr XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn, uint8 flags) { ... /* * Unless record is flagged as not important, update LSN of last * important record in the current slot. When holding all locks, just * update the first one. */ if ((flags & XLOG_MARK_UNIMPORTANT) == 0) { int lockno = holdingAllLocks ? 0 : MyLockNo; WALInsertLocks[lockno].l.lastImportantAt = StartPos; } is the relevant bit - what prevents us from just using EndPos 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