pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Magnus Hagander <magnus@hagander.net>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: pg_basebackup fails if a data file is removed
Date: Fri, 21 Dec 2012 15:38:10 +0200
Message-ID: <50D46642.6010008@vmware.com> (raw)
In-Reply-To: <CABUevExf8D+pVYujONG3ipvoc=7DyhiB18+SOiMokB4+gDwq-A@mail.gmail.com>
References: <50D463E8.9000000@vmware.com>
	<CABUevExf8D+pVYujONG3ipvoc=7DyhiB18+SOiMokB4+gDwq-A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 21.12.2012 15:30, Magnus Hagander wrote:
> On Fri, Dec 21, 2012 at 2:28 PM, Heikki Linnakangas
> <hlinnakangas@vmware.com>  wrote:
>> When pg_basebackup copies data files, it does basically this:
>>
>>> if (lstat(pathbuf,&statbuf) != 0)
>>> {
>>>          if (errno != ENOENT)
>>>                  ereport(ERROR,
>>>                                  (errcode_for_file_access(),
>>>                                   errmsg("could not stat file or directory
>>> \"%s\": %m",
>>>                                          pathbuf)));
>>>
>>>          /* If the file went away while scanning, it's no error. */
>>>          continue;
>>> }
>>
>>> ...
>>> sendFile(pathbuf, pathbuf + basepathlen + 1,&statbuf);
>>
>> There's a race condition there. If the file is removed after the lstat call,
>> and before sendFile opens the file, the backup fails with an error. It's a
>> fairly tight window, so it's difficult to run into by accident, but by
>> putting a breakpoint with a debugger there it's quite easy to reproduce, by
>> e.g doing a VACUUM FULL on the table about to be copied.
>>
>> A straightforward fix is to allow sendFile() to ignore ENOENT. Patch
>> attached.
>
> Looks good to me.

Ok, committed.

> Nice spot - don't tell me you actually ran into it
> during testing? :)

Heh, no, eyeballing the code.

- Heikki


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



view thread (3+ messages)

Message-ID: <50D46642.6010008@vmware.com>
Permalink:  ../50D46642.6010008@vmware.com/
Also on:    postgresql.org/message-id/50D46642.6010008@vmware.com

 · 

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-bugs@postgresql.org
  Cc: hlinnakangas@vmware.com, magnus@hagander.net
  Subject: Re: pg_basebackup fails if a data file is removed
  In-Reply-To: <50D46642.6010008@vmware.com>
  References: <50D463E8.9000000@vmware.com> <CABUevExf8D+pVYujONG3ipvoc=7DyhiB18+SOiMokB4+gDwq-A@mail.gmail.com> <50D46642.6010008@vmware.com>

* 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