> -----Original Message-----
> From: Merlin Moncure [mailto:merlin.moncure@rcsonline.com] 
> Sent: Monday, February 03, 2003 3:00 PM
> To: Andrew Dunstan
> Cc: pgsql-hackers@postgresql.org
> Subject: Re: [HACKERS] Win32 and fsync()
> 
> 
> >I'm having difficulty digging up the reference, but I think I recall
> seeing >something that said, roughly, on W32 there are 2 sets 
> of buffers
> - those in >the user level library and those in the kernel 
> level driver, and >FlushFileBuffers drains the first, while 
> _commit drains both (it includes a >call to FlushFileBuffers).
> 
> You were correct: here is the source.
> 
> 
> int __cdecl _commit (
>         int filedes
>         )
> {
>         int retval;
> 
>         /* if filedes out of range, complain */
>         if ( ((unsigned)filedes >= (unsigned)_nhandle) ||
>              !(_osfile(filedes) & FOPEN) )
>         {
>                 errno = EBADF;
>                 return (-1);
>         }
> 
>         _lock_fh(filedes);
> 
>         /* if filedes open, try to commit, else fall through to bad */
>         if (_osfile(filedes) & FOPEN) {
> 
>                 if ( 
> !FlushFileBuffers((HANDLE)_get_osfhandle(filedes))
> ) {
>                         retval = GetLastError();
>                 } else {
>                         retval = 0;     /* return success */
>                 }
> 
>                 /* map the OS return code to C errno value 
> and return code */
>                 if (retval == 0) {
>                         goto good;
>                 } else {
>                         _doserrno = retval;
>                         goto bad;
>                 }
> 
>         }
> 
> bad :
>         errno = EBADF;
>         retval = -1;
> good :
>         _unlock_fh(filedes);
>         return (retval);
> }

Where is the "other" flush besides FlushFileBuffers()?

Mon, 3 Feb 2003 15:24:02 -0800
"Dann Corbit" <DCorbit@connx.com>
Re: Win32 and fsync()
On Mon, 3 Feb 2003, Dann Corbit wrote:

> > -----Original Message-----
> > From: Merlin Moncure [mailto:merlin.moncure@rcsonline.com] 
> > Sent: Monday, February 03, 2003 3:00 PM
> > To: Andrew Dunstan
> > Cc: pgsql-hackers@postgresql.org
> > Subject: Re: [HACKERS] Win32 and fsync()
> > 
> > 
> > >I'm having difficulty digging up the reference, but I think I recall
> > seeing >something that said, roughly, on W32 there are 2 sets 
> > of buffers
> > - those in >the user level library and those in the kernel 
> > level driver, and >FlushFileBuffers drains the first, while 
> > _commit drains both (it includes a >call to FlushFileBuffers).
> > 
> > You were correct: here is the source.
> > 
> > 
> > int __cdecl _commit (
> >         int filedes
> >         )
> > {
> >         int retval;
> > 
> >         /* if filedes out of range, complain */
> >         if ( ((unsigned)filedes >= (unsigned)_nhandle) ||
> >              !(_osfile(filedes) & FOPEN) )
> >         {
> >                 errno = EBADF;
> >                 return (-1);
> >         }
> > 
> >         _lock_fh(filedes);
> > 
> >         /* if filedes open, try to commit, else fall through to bad */
> >         if (_osfile(filedes) & FOPEN) {
> > 
> >                 if ( 
> > !FlushFileBuffers((HANDLE)_get_osfhandle(filedes))
> > ) {
> >                         retval = GetLastError();
> >                 } else {
> >                         retval = 0;     /* return success */
> >                 }
> > 
> >                 /* map the OS return code to C errno value 
> > and return code */
> >                 if (retval == 0) {
> >                         goto good;
> >                 } else {
> >                         _doserrno = retval;
> >                         goto bad;
> >                 }
> > 
> >         }
> > 
> > bad :
> >         errno = EBADF;
> >         retval = -1;
> > good :
> >         _unlock_fh(filedes);
> >         return (retval);
> > }
> 
> Where is the "other" flush besides FlushFileBuffers()?

The only real code there is, it seems, an exclusive look on the file
descriptor. (Provided of course that that is what _lock_fh(filedes) does).

Gavin



Tue, 4 Feb 2003 10:29:23 +1100 (EST)
Gavin Sherry <swm@linuxworld.com.au>
Re: Win32 and fsync()
I'm not sure what the provenance of this code for _commit is - I thought it
was in the standard MS libs - have they finally seen the light and open
sourced it? ;-)

andrew

----- Original Message -----
From: "Dann Corbit" <DCorbit@connx.com>
To: "Merlin Moncure" <merlin.moncure@rcsonline.com>; "Andrew Dunstan"
<andrew@dunslane.net>
Cc: <pgsql-hackers@postgresql.org>
Sent: Monday, February 03, 2003 6:24 PM
Subject: Re: [HACKERS] Win32 and fsync()


> > -----Original Message-----
> > From: Merlin Moncure [mailto:merlin.moncure@rcsonline.com]
> > Sent: Monday, February 03, 2003 3:00 PM
> > To: Andrew Dunstan
> > Cc: pgsql-hackers@postgresql.org
> > Subject: Re: [HACKERS] Win32 and fsync()
> >
> >
> > >I'm having difficulty digging up the reference, but I think I recall
> > seeing >something that said, roughly, on W32 there are 2 sets
> > of buffers
> > - those in >the user level library and those in the kernel
> > level driver, and >FlushFileBuffers drains the first, while
> > _commit drains both (it includes a >call to FlushFileBuffers).
> >
> > You were correct: here is the source.
> >
> >
> > int __cdecl _commit (
> >         int filedes
> >         )
> > {
> >         int retval;
> >
> >         /* if filedes out of range, complain */
> >         if ( ((unsigned)filedes >= (unsigned)_nhandle) ||
> >              !(_osfile(filedes) & FOPEN) )
> >         {
> >                 errno = EBADF;
> >                 return (-1);
> >         }
> >
> >         _lock_fh(filedes);
> >
> >         /* if filedes open, try to commit, else fall through to bad */
> >         if (_osfile(filedes) & FOPEN) {
> >
> >                 if (
> > !FlushFileBuffers((HANDLE)_get_osfhandle(filedes))
> > ) {
> >                         retval = GetLastError();
> >                 } else {
> >                         retval = 0;     /* return success */
> >                 }
> >
> >                 /* map the OS return code to C errno value
> > and return code */
> >                 if (retval == 0) {
> >                         goto good;
> >                 } else {
> >                         _doserrno = retval;
> >                         goto bad;
> >                 }
> >
> >         }
> >
> > bad :
> >         errno = EBADF;
> >         retval = -1;
> > good :
> >         _unlock_fh(filedes);
> >         return (retval);
> > }
>
> Where is the "other" flush besides FlushFileBuffers()?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


Mon, 3 Feb 2003 18:31:23 -0500
"Andrew Dunstan" <andrew@dunslane.net>
Re: Win32 and fsync()

----- Original Message -----
From: "Gavin Sherry" <swm@linuxworld.com.au>
[snip]
> > Where is the "other" flush besides FlushFileBuffers()?
>
> The only real code there is, it seems, an exclusive look on the file
> descriptor. (Provided of course that that is what _lock_fh(filedes) does).
>

yes, it looks that way.

I wonder what whould happen to reliability and performance if the files were
opened using Windows' write through cache flag (FILE_FLAG_WRITE_THROUGH).
Also, this article might be relevant:

http://support.microsoft.com/default.aspx?scid=kb;en-us;332023

although I see the Windows tests were done on W2000/SP3, so maybe not.

andrew



Tue, 4 Feb 2003 08:05:40 -0500
"Andrew Dunstan" <andrew@dunslane.net>
Re: Win32 and fsync()