Re: [PATCHES] [BUGS] BUG #2569: statement_timeout bug on Windows
Re: [PATCHES] [BUGS] BUG #2569: statement_timeout bug on Windows
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Bruce Momjian writes: ! /* WaitForSingleObjectEx() uses milliseconds */ > ! waittime = timerCommArea.value.it_value.tv_usec / 1000 + timerCommArea.value.it_value.tv_sec * 1000; Seems like this probably ought to round up not down: waittime = (timerCommArea.value.it_value.tv_usec + 999) / 1000 + timerCommArea.value.it_value.tv_sec * 1000; Otherwise, an attempt to wait for 100 usec would convert to waittime 0, which seems like a bad thing. In general the semantics of timed waits are always supposed to be "you wait at least this long". regards, tom lane
Re: [PATCHES] [BUGS] BUG #2569: statement_timeout bug on Windows
От:
Bruce Momjian <bruce@momjian.us>
Дата:
Tom Lane wrote:
> Bruce Momjian writes:
> ! /* WaitForSingleObjectEx() uses milliseconds */
> > ! waittime = timerCommArea.value.it_value.tv_usec / 1000 + timerCommArea.value.it_value.tv_sec * 1000;
>
> Seems like this probably ought to round up not down:
>
> waittime = (timerCommArea.value.it_value.tv_usec + 999) / 1000 + timerCommArea.value.it_value.tv_sec * 1000;
>
> Otherwise, an attempt to wait for 100 usec would convert to waittime 0,
> which seems like a bad thing. In general the semantics of timed waits
> are always supposed to be "you wait at least this long".
I thought about that, but because statement_timeout is in millis, and
not micros, we can't have a value that gets rounded down. I am
thinking a cleaner solution is to check for secs and if that is 0 and
microsecs < 1000, you set millis = 1.
Patch attached and applied to head and 8.1.X.
--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Index: src/backend/port/win32/timer.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/port/win32/timer.c,v
retrieving revision 1.10
diff -c -c -r1.10 timer.c
*** src/backend/port/win32/timer.c 9 Aug 2006 17:47:03 -0000 1.10
--- src/backend/port/win32/timer.c 9 Aug 2006 20:39:16 -0000
***************
*** 56,63 ****
--- 56,69 ----
timerCommArea.value.it_value.tv_usec == 0)
waittime = INFINITE; /* Cancel the interrupt */
else
+ {
+ /* Minimum wait time is 1ms */
+ if (timerCommArea.value.it_value.tv_sec == 0 &&
+ timerCommArea.value.it_value.tv_usec < 1000)
+ timerCommArea.value.it_value.tv_usec = 1000;
/* WaitForSingleObjectEx() uses milliseconds */
waittime = timerCommArea.value.it_value.tv_usec / 1000 + timerCommArea.value.it_value.tv_sec * 1000;
+ }
ResetEvent(timerCommArea.event);
LeaveCriticalSection(&timerCommArea.crit_sec);
}
Re: [PATCHES] [BUGS] BUG #2569: statement_timeout bug on Windows
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Bruce Momjian writes: > Tom Lane wrote: >> Seems like this probably ought to round up not down: > I thought about that, but because statement_timeout is in millis, and > not micros, we can't have a value that gets rounded down. I am > thinking a cleaner solution is to check for secs and if that is 0 and > microsecs < 1000, you set millis = 1. This is much uglier, probably slower, and fixes the problem only for the zero case --- it is just as wrong to wait 1 msec when the caller asked for 1.5 msec. And per your own observation, statement_timeout is not the only source of the wait values, so this code must not assume that the value is a multiple of 1msec. Please do it the other way. regards, tom lane
Re: [PATCHES] [BUGS] BUG #2569: statement_timeout bug on
От:
Bruce Momjian <bruce@momjian.us>
Дата:
OK, done. --------------------------------------------------------------------------- Tom Lane wrote: > Bruce Momjian writes: > > Tom Lane wrote: > >> Seems like this probably ought to round up not down: > > > I thought about that, but because statement_timeout is in millis, and > > not micros, we can't have a value that gets rounded down. I am > > thinking a cleaner solution is to check for secs and if that is 0 and > > microsecs < 1000, you set millis = 1. > > This is much uglier, probably slower, and fixes the problem only for > the zero case --- it is just as wrong to wait 1 msec when the caller > asked for 1.5 msec. And per your own observation, statement_timeout > is not the only source of the wait values, so this code must not > assume that the value is a multiple of 1msec. > > Please do it the other way. > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings -- Bruce Momjian bruce@momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +