Introduce and use infrastructure for interrupt processing during client reads

Enterprise / PostgreSQL - Andres Freund [anarazel.de] - 3 February 2015 15:25 UTC

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

4f85fde Introduce and use infrastructure for interrupt processing during client reads.
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(-)

Upstream: git.postgresql.org


  • Share