From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Mike Mascari <mascarm(at)mascari(dot)com> |
Cc: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Win32 rename()/unlink() questionst |
Date: | 2002-09-20 15:04:53 |
Message-ID: | 200209201504.g8KF4rj17150@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
It is good that moving the file out of the way works, but it doesn't
completely solve the problem.
What we have now with Unix rename is ideal:
1) old opens continue seeing the old contents
2) new opens see the new contents
3) the file always exists under the fixed name
We have that with MoveFileEx(), but we have to loop over the routine
until is succeeds. If we move the old file out of the way, we loose the
ability to know the file always exists and then we have to loop over
open() until is succeeds.
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.
---------------------------------------------------------------------------
Mike Mascari wrote:
> Stephan Szabo wrote:
> > On Fri, 20 Sep 2002, Mike Mascari wrote:
> >>Bruce Momjian wrote:
> >>>Mike Mascari wrote:
> >>>>Actually, looking at the pg_pwd code, you want to determine a
> >>>>way for:
> >>>>
> >>>>1. Process 1 opens "foo"
> >>>>2. Process 2 opens "foo"
> >>>>3. Process 1 creates "bar"
> >>>>4. Process 1 renames "bar" to "foo"
> >>>>5. Process 2 can continue to read data from the open file handle
> >>>>and get the original "foo" data.
> >>>
> >>>
> >>>Yep, that's it.
> >>>
> >>
> >>So far, MoveFileEx("foo", "bar", MOVEFILE_REPLACE_EXISTING)
> >>returns "Access Denied" when Process 1 attempts the rename. But
> >>I'm continuing to investigate the possibilities...
> >
> >
> > Does a sequence like
> > Process 1 opens "foo"
> > Process 2 opens "foo"
> > Process 1 creates "bar"
> > Process 1 renames "foo" to <something>
> > - where something is generated to not overlap an existing file
> > Process 1 renames "bar" to "foo"
> > Process 2 continues reading
> > let you do the replace and keep reading (at the penalty that
> > you've now got to have a way to know when to remove the
> > various <something>s)
>
> Yes! Indeed that does work.
>
> Mike Mascari
> mascarm(at)mascari(dot)com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2002-09-20 15:05:38 | Re: Win32 rename()/unlink() questions |
Previous Message | Andrew Sullivan | 2002-09-20 15:02:05 | Re: SCSI Error |