pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Steele <david@pgmasters.net>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Magnus Hagander <magnus@hagander.net>
To: Michael Banck <michael.banck@credativ.de>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andres Freund <andres@anarazel.de>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: pgsql: Validate page level checksums in base backups
Date: Tue, 10 Apr 2018 17:45:12 -0400
Message-ID: <a701f950-30a9-d9b9-d231-82c917420040@pgmasters.net> (raw)
In-Reply-To: <f23e92ec-118d-e6ea-0c81-876ad62a588a@2ndquadrant.com>
References: <20180404121930.GE20852@nighthawk.caipicrew.dd-dns.de>
	<20180404134732.tsxx2osvooolxy24@alvherre.pgsql>
	<CABUevEwrCF7TzAyD=4WPfTyzH+5xaFYf+-=ATW58XLi7b4dURA@mail.gmail.com>
	<20180404182247.GG20852@nighthawk.caipicrew.dd-dns.de>
	<CABUevExp8BOo3ZjEXM5xkz5P0zrjZT4_eM7QM4DLyPorDVUQUQ@mail.gmail.com>
	<20180405124113.GH20852@nighthawk.caipicrew.dd-dns.de>
	<CABUevEzZ55qgLVtMxW=hXhzjHV3oU-gChpeKtufyf_siL-rBWg@mail.gmail.com>
	<f23e92ec-118d-e6ea-0c81-876ad62a588a@2ndquadrant.com>

On 4/10/18 5:24 PM, Tomas Vondra wrote:
> 
> I think there's a bug in sendFile(). We do check checksums on all pages
> that pass this LSN check:
> 
>      /*
>       * Only check pages which have not been modified since the
>       * start of the base backup. Otherwise, they might have been
>       * written only halfway and the checksum would not be valid.
>       * However, replaying WAL would reinstate the correct page in
>       * this case.
>       */
>      if (PageGetLSN(page) < startptr)
>      {
>          ...
>      }
> 
> Now, imagine the page is new, i.e. all-zeroes. That means the LSN is 0/0
> too, and we'll try to verify the checksum - but we actually do not set
> checksums on empty pages.
> 
> So I think it should be something like this:
> 
>      if ((!PageIsNew(page)) && (PageGetLSN(page) < startptr))
>      {
>          ...
>      }
> 
> It might be worth verifying that the page is actually all-zeroes (and
> not just with corrupted pd_upper value. Not sure it's worth it.
> 
> I've found this by fairly trivial stress testing - running pgbench and
> pg_basebackup in a loop. It was failing pretty reliably (~75% of runs).
> With the proposed change I see no further failures.

Good catch, Tomas!

I should have seen this since I had the same issue when I implemented 
this feature in pgBackRest.

Anyway, I agree that your fix looks correct.

Thanks,
-- 
-David
david@pgmasters.net




view thread (23+ messages)  latest in thread

Message-ID: <a701f950-30a9-d9b9-d231-82c917420040@pgmasters.net>
Permalink:  ../a701f950-30a9-d9b9-d231-82c917420040@pgmasters.net/
Also on:    postgresql.org/message-id/a701f950-30a9-d9b9-d231-82c917420040@pgmasters.net

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: david@pgmasters.net, tomas.vondra@2ndquadrant.com, magnus@hagander.net, michael.banck@credativ.de, alvherre@alvh.no-ip.org, tgl@sss.pgh.pa.us, andres@anarazel.de, pgsql-hackers@postgresql.org
  Subject: Re: pgsql: Validate page level checksums in base backups
  In-Reply-To: <a701f950-30a9-d9b9-d231-82c917420040@pgmasters.net>

* 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