Re: Win32 rename()/unlink() questionst - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Win32 rename()/unlink() questionst
Date
Msg-id 200209201556.g8KFu2k28023@candle.pha.pa.us
Whole thread Raw
In response to Re: Win32 rename()/unlink() questionst  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > I think we may be best just looping on MoveFileEx() until is succeeds. 
> > We do the pg_pwd writes while holding an exclusive lock on pg_shadow so
> > that will guarantee that no one else will slip an old version of the
> > file in after we have written it.  However, it also prevents pg_shadow
> > access while we are doing the looping.  Yuck.
> 
> Surely you're not evaluating this on the assumption that the pg_shadow
> triggers are the only places that use rename() ?
> 
> I see other places in pgstat and relcache that expect rename() to work
> per Unix spec.

Yes, I know there are others but I think we will need _a_ rename that
works 100% and then replace that in all Win32 rename cases.

Given what I have seen, I think a single rename with a loop that uses
MoveFileEx() may be our best bet.  It is localized, doesn't affect the
open() code, and should work well.  The only downside is that under
heavy read activity the loop will loop around a few times but I just
don't see another solution.

I was initially concerned that the loop in rename could let old renames
update the file overwriting newer contents but I realize now that
rename() itself has the same issue (an old rename could hit in the code
after a newer rename) so in all cases we must already have the proper
locking in place.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-hackers by date:

Previous
From: Mike Mascari
Date:
Subject: Re: Win32 rename()/unlink() questions
Next
From: "Shridhar Daithankar"
Date:
Subject: Improving speed of copy