Re: [PATCH] Atomic pgrename on Windows

From: Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Atomic pgrename on Windows
Date: 2017-11-28 14:52:09
Message-ID: CAPpHfdsxeBX_baMS4R1MkiZ8T5FWxDioDwzfAVdJmo-bdNdjgg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 28, 2017 at 3:59 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:

> On 2017-11-28 09:47:45 +0900, Michael Paquier wrote:
> > On Mon, Nov 27, 2017 at 3:28 PM, Alexander Korotkov
> > <a(dot)korotkov(at)postgrespro(dot)ru> wrote:
> > > Attached patch atomic-pgrename-windows-1.patch fixes this problem. It
> > > appears to be possible to atomically replace file on Windows –
> ReplaceFile()
> > > does that. ReplaceFiles() requires target file to exist, this is why
> we
> > > still need to call MoveFileEx() when it doesn't exist.
> >
> > Do you think that it could be safer to unlink the target file first
> > with pgunlink()? This way you make sure that the target file is
> > removed and not locked. This change makes me worrying about the
> > introduction of more race conditions.
>
> That seems like a *seriously* bad idea. What if we crash inbetween the
> unlink and the rename?
>
>
> I'm confused about the need for this. Shouldn't normally
> opening all files FILE_SHARE_DELETE take care of this? See
> https://msdn.microsoft.com/en-us/library/windows/desktop/
> aa363858(v=vs.85).aspx
> "Note Delete access allows both delete and rename operations."
>
> Is there an external process active that doesn't set that flag?

I'm quite sure there was no such processed during my experimentation. No
antivirus or other disturbers. Moreover, error reproduces only with
artificial delay in pgstat_read_statsfiles(). So, it's clearly related to
lock placed by this function.

> Are we missing setting it somewhere?
>

That's curious, but at least pgstat_read_statsfiles() seems to open file
with that flag.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2017-11-28 14:57:00 Re: new function for tsquery creartion
Previous Message Dilip Kumar 2017-11-28 14:45:09 Re: ERROR: too many dynamic shared memory segments