pgsql: Introduce timeout handling framework

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Introduce timeout handling framework
Date: 2012-07-17 04:03:46
Message-ID: E1Sqz0k-0000iI-Hl@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Introduce timeout handling framework

Management of timeouts was getting a little cumbersome; what we
originally had was more than enough back when we were only concerned
about deadlocks and query cancel; however, when we added timeouts for
standby processes, the code got considerably messier. Since there are
plans to add more complex timeouts, this seems a good time to introduce
a central timeout handling module.

External modules register their timeout handlers during process
initialization, and later enable and disable them as they see fit using
a simple API; timeout.c is in charge of keeping track of which timeouts
are in effect at any time, installing a common SIGALRM signal handler,
and calling setitimer() as appropriate to ensure timely firing of
external handlers.

timeout.c additionally supports pluggable modules to add their own
timeouts, though this capability isn't exercised anywhere yet.

Additionally, as of this commit, walsender processes are aware of
timeouts; we had a preexisting bug there that made those ignore SIGALRM,
thus being subject to unhandled deadlocks, particularly during the
authentication phase. This has already been fixed in back branches in
commit 0bf8eb2a, which see for more details.

Main author: Zoltán Böszörményi
Some review and cleanup by Álvaro Herrera
Extensive reworking by Tom Lane

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/f34c68f09671c4566854c7e20e9253d4f335c0b0

Modified Files
--------------
src/backend/postmaster/autovacuum.c | 9 +-
src/backend/postmaster/postmaster.c | 36 ++-
src/backend/postmaster/startup.c | 22 +-
src/backend/replication/walsender.c | 3 +-
src/backend/storage/ipc/standby.c | 80 ++++--
src/backend/storage/lmgr/proc.c | 435 +-------------------------------
src/backend/tcop/postgres.c | 15 +-
src/backend/utils/init/postinit.c | 33 ++-
src/backend/utils/misc/Makefile | 4 +-
src/backend/utils/misc/timeout.c | 479 +++++++++++++++++++++++++++++++++++
src/include/storage/proc.h | 13 +-
src/include/storage/standby.h | 3 +-
src/include/utils/timeout.h | 54 ++++
13 files changed, 688 insertions(+), 498 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2012-07-17 13:43:44 Re: pgsql: Introduce timeout handling framework
Previous Message Peter Eisentraut 2012-07-16 19:17:15 pgsql: Remove unreachable code