pgsql: Introduce and use infrastructure for interrupt processing during - Mailing list pgsql-committers

From Andres Freund
Subject pgsql: Introduce and use infrastructure for interrupt processing during
Date
Msg-id E1YIl0x-0006Qk-U6@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Introduce and use infrastructure for interrupt processing during client reads.

Up to now large swathes of backend code ran inside signal handlers
while reading commands from the client, to allow for speedy reaction to
asynchronous events. Most prominently shared invalidation and NOTIFY
handling. That means that complex code like the starting/stopping of
transactions is run in signal handlers...  The required code was
fragile and verbose, and is likely to contain bugs.

That approach also severely limited what could be done while
communicating with the client. As the read might be from within
openssl it wasn't safely possible to trigger an error, e.g. to cancel
a backend in idle-in-transaction state. We did that in some cases,
namely fatal errors, nonetheless.

Now that FE/BE communication in the backend employs non-blocking
sockets and latches to block, we can quite simply interrupt reads from
signal handlers by setting the latch. That allows us to signal an
interrupted read, which is supposed to be retried after returning from
within the ssl library.

As signal handlers now only need to set the latch to guarantee timely
interrupt processing, remove a fair amount of complicated & fragile
code from async.c and sinval.c.

We could now actually start to process some kinds of interrupts, like
sinval ones, more often that before, but that seems better done
separately.

This work will hopefully allow to handle cases like being blocked by
sending data, interrupting idle transactions and similar to be
implemented without too much effort.  In addition to allowing getting
rid of ImmediateInterruptOK, that is.

Author: Andres Freund
Reviewed-By: Heikki Linnakangas

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4f85fde8eb860f263384fffdca660e16e77c7f76

Modified Files
--------------
src/backend/commands/async.c          |  199 ++++++-----------------------
src/backend/libpq/be-secure-openssl.c |   28 ++++-
src/backend/libpq/be-secure.c         |   43 ++++++-
src/backend/postmaster/autovacuum.c   |    6 +-
src/backend/storage/ipc/sinval.c      |  223 +++++++--------------------------
src/backend/tcop/postgres.c           |  106 ++++++----------
src/include/commands/async.h          |   12 +-
src/include/storage/sinval.h          |    7 +-
src/include/tcop/tcopprot.h           |    4 +-
9 files changed, 194 insertions(+), 434 deletions(-)


pgsql-committers by date:

Previous
From: Andres Freund
Date:
Subject: pgsql: Use a nonblocking socket for FE/BE communication and block using
Next
From: Andres Freund
Date:
Subject: pgsql: Process 'die' interrupts while reading/writing from the client s