]> granicus.if.org Git - postgresql/commit
Be more predictable about reporting "lock timeout" vs "statement timeout".
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 May 2016 14:40:20 +0000 (10:40 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 May 2016 14:40:20 +0000 (10:40 -0400)
commitcea17ba07a93c0185aa9cbbf79ce9d3241b9c547
treee7478a4866dec690d85c7d8ebdbbf4ad202c7375
parent47e59697679a0877e0525c565b1be437487604a7
Be more predictable about reporting "lock timeout" vs "statement timeout".

If both timeout indicators are set when we arrive at ProcessInterrupts,
we've historically just reported "lock timeout".  However, some buildfarm
members have been observed to fail isolationtester's timeouts test by
reporting "lock timeout" when the statement timeout was expected to fire
first.  The cause seems to be that the process is allowed to sleep longer
than expected (probably due to heavy machine load) so that the lock
timeout happens before we reach the point of reporting the error, and
then this arbitrary tiebreak rule does the wrong thing.  We can improve
matters by comparing the scheduled timeout times to decide which error
to report.

I had originally proposed greatly reducing the 1-second window between
the two timeouts in the test cases.  On reflection that is a bad idea,
at least for the case where the lock timeout is expected to fire first,
because that would assume that it takes negligible time to get from
statement start to the beginning of the lock wait.  Thus, this patch
doesn't completely remove the risk of test failures on slow machines.
Empirically, however, the case this handles is the one we are seeing
in the buildfarm.  The explanation may be that the other case requires
the scheduler to take the CPU away from a busy process, whereas the
case fixed here only requires the scheduler to not give the CPU back
right away to a process that has been woken from a multi-second sleep
(and, perhaps, has been swapped out meanwhile).

Back-patch to 9.3 where the isolationtester timeouts test was added.

Discussion: <8693.1464314819@sss.pgh.pa.us>
src/backend/tcop/postgres.c
src/backend/utils/misc/timeout.c
src/include/utils/timeout.h