Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:28 AM
Magnus Hagander
 
Posts: n/a
Default Fix for win32 stat() problems

Attached is a patch that attempts to fix the issues with stat() not
properly updating st_size on win32, as reported in this thread:
http://archives.postgresql.org/pgsql...3/msg01181.php

It has to have a chance to affect things beyond just the
pg_relation_size() function, so this patch fixes all cases where we do
stat() and use the st_size member. It doesn't change all occurances of
stat() since I didn't want to incur the double filesystem lookups
unnecessary cases.

Any objections?

//Magnus


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 06:28 AM
Tom Lane
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Magnus Hagander <magnus@hagander.net> writes:
> + #ifndef WIN32
> if (stat(xlogpath, &stat_buf) == 0)
> + #else
> + if (pgwin32_safestat(xlogpath, &stat_buf) == 0)
> + #endif


Ick. Please do this the way we normally do things when we have to
override broken Windows syscalls, that is put something like

#define stat(...) pgwin32_stat(...)

into the win32 port header file, so the calls don't have to be
nonstandard.

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 06:28 AM
Magnus Hagander
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Tom Lane wrote:
> Magnus Hagander <magnus@hagander.net> writes:
> > + #ifndef WIN32
> > if (stat(xlogpath, &stat_buf) == 0)
> > + #else
> > + if (pgwin32_safestat(xlogpath, &stat_buf) == 0)
> > + #endif

>
> Ick. Please do this the way we normally do things when we have to
> override broken Windows syscalls, that is put something like
>
> #define stat(...) pgwin32_stat(...)
>
> into the win32 port header file, so the calls don't have to be
> nonstandard.


The reason not to do so was to avoid having to do the two filesystem
calls for *every* stat, instead just calling them both when we actually
need to use the st_size member. I take it you don't think that's a good
enough reason, but I just want to be sure you're aware that's why I did
it the way I did.

Or do you by any chance now a better way to accomplish that goal? :-)

//Magnus

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 06:28 AM
Tom Lane
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Magnus Hagander <magnus@hagander.net> writes:
> Tom Lane wrote:
>> Ick.


> The reason not to do so was to avoid having to do the two filesystem
> calls for *every* stat, instead just calling them both when we actually
> need to use the st_size member.


I don't think that's worth (a) the code uglification, or (b) the chance
of a bug later due to someone not knowing they need the special version
of stat(). Are there any stat() calls that are in sufficiently
performance-critical paths that it really matters? How much slower is
the second call, anyway?

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 06:28 AM
Magnus Hagander
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Tom Lane wrote:
> Magnus Hagander <magnus@hagander.net> writes:
> > Tom Lane wrote:
> >> Ick.

>
> > The reason not to do so was to avoid having to do the two filesystem
> > calls for *every* stat, instead just calling them both when we
> > actually need to use the st_size member.

>
> I don't think that's worth (a) the code uglification, or (b) the
> chance of a bug later due to someone not knowing they need the
> special version of stat(). Are there any stat() calls that are in
> sufficiently performance-critical paths that it really matters? How
> much slower is the second call, anyway?


Not sure really, the VM I'm working on now is so slow I can't measure
these things properly anyway. Probably not enough to matter compared to
other things - I'll try it that way to see if I can notice any
significant difference.

Trying to prepare a patch that does it the normal way, but so far I'm
failing rather miserably. The *struct* stat is already redefined on
win32, so whenever I try #undef or so it conflicts with that :-( Since
there is no way to #undef only the parametrized version.

Though right now I have the backend linking properly even though a
bunch of files refer to pgwin32_safestat() and I've actually removed
the implementation of the function, so maybe I just need to go to bed...

//Magnus

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 06:28 AM
Tom Lane
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Magnus Hagander <magnus@hagander.net> writes:
> Trying to prepare a patch that does it the normal way, but so far I'm
> failing rather miserably. The *struct* stat is already redefined on
> win32, so whenever I try #undef or so it conflicts with that :-( Since
> there is no way to #undef only the parametrized version.


I don't follow ... there's no such redefinition in our code AFAICS.
Do you mean that the system header files declare it as a macro?

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 06:28 AM
Magnus Hagander
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Tom Lane wrote:
> Magnus Hagander <magnus@hagander.net> writes:
> > Trying to prepare a patch that does it the normal way, but so far
> > I'm failing rather miserably. The *struct* stat is already
> > redefined on win32, so whenever I try #undef or so it conflicts
> > with that :-( Since there is no way to #undef only the parametrized
> > version.

>
> I don't follow ... there's no such redefinition in our code AFAICS.
> Do you mean that the system header files declare it as a macro?


Yes.

//Magnus

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-19-2008, 06:28 AM
Andrew Dunstan
 
Posts: n/a
Default Re: Fix for win32 stat() problems



Magnus Hagander wrote:
> Tom Lane wrote:
>
>> Magnus Hagander <magnus@hagander.net> writes:
>>
>>> Trying to prepare a patch that does it the normal way, but so far
>>> I'm failing rather miserably. The *struct* stat is already
>>> redefined on win32, so whenever I try #undef or so it conflicts
>>> with that :-( Since there is no way to #undef only the parametrized
>>> version.
>>>

>> I don't follow ... there's no such redefinition in our code AFAICS.
>> Do you mean that the system header files declare it as a macro?
>>

>
> Yes.
>
>
>


How about #defining safe_stat to be pg_win32_safe_stat on Windows and
simply stat elsewhere? Then use safe_stat at the places you consider
critical.

cheers

andrew

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-19-2008, 06:28 AM
Alvaro Herrera
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Andrew Dunstan wrote:

> How about #defining safe_stat to be pg_win32_safe_stat on Windows and
> simply stat elsewhere? Then use safe_stat at the places you consider
> critical.


I would couple this with a pgwin32_unsafe_stat on Windows, which changes
the size value to 0, so that if anyone gets it wrong it's immediately
obvious.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-19-2008, 06:28 AM
Magnus Hagander
 
Posts: n/a
Default Re: Fix for win32 stat() problems

Magnus Hagander wrote:
> Attached is a patch that attempts to fix the issues with stat() not
> properly updating st_size on win32, as reported in this thread:
> http://archives.postgresql.org/pgsql...3/msg01181.php
>
> It has to have a chance to affect things beyond just the
> pg_relation_size() function, so this patch fixes all cases where we do
> stat() and use the st_size member. It doesn't change all occurances of
> stat() since I didn't want to incur the double filesystem lookups
> unnecessary cases.
>
> Any objections?


Updated version. Seems the problem was that the includes came in the
wrong order - figured that out just after I went to bed Here's an
updated patch.

A whole lot simpler patch :-)

//Magnus

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:51 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145