pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-hackers@postgresql.org
To: Michael Paquier <michael.paquier@gmail.com>
Subject: Change GetLastImportantRecPtr's definition? (wasSkip checkpoints, archiving on idle systems.)
Date: Thu, 4 May 2017 18:24:47 -0700
Message-ID: <20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de> (raw)
In-Reply-To: <E1cK97K-0003Lh-E7@gemulon.postgresql.org>
References: <E1cK97K-0003Lh-E7@gemulon.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

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.

- Andres


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (8+ messages)  latest in thread

Message-ID: <20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de>
Permalink:  ../20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de, pgsql-hackers@postgresql.org, michael.paquier@gmail.com
  Subject: Re: Change GetLastImportantRecPtr's definition? (wasSkip checkpoints, archiving on idle systems.)
  In-Reply-To: <20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de>
  References: <E1cK97K-0003Lh-E7@gemulon.postgresql.org> <20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox