pgsql: Stabilize the results of pg_notification_queue_usage(). - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Stabilize the results of pg_notification_queue_usage().
Date
Msg-id E1iYxGT-0007t6-70@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Stabilize the results of pg_notification_queue_usage().

This function wasn't touched in commit 51004c717, but that turns out
to be a bad idea, because its results now include any dead space
that exists in the NOTIFY queue on account of our being lazy about
advancing the queue tail.  Notably, the isolation tests now fail
if run twice without a server restart between, because async-notify's
first test of the function will already show a positive value.
It seems likely that end users would be equally unhappy about the
result's instability.  To fix, just make the function call
asyncQueueAdvanceTail before computing its result.  That should end
in producing the same value as before, and it's hard to believe that
there's any practical use-case where pg_notification_queue_usage()
is called so often as to create a performance degradation, especially
compared to what we did before.

Out of paranoia, also mark this function parallel-restricted (it
was volatile, but parallel-safe by default, before).  Although the
code seems to work fine when run in a parallel worker, that's outside
the design scope of async.c, and it's a bit scary to have intentional
side-effects happening in a parallel worker.  There seems no plausible
use-case where it'd be important to try to parallelize this, so let's
not take any risk of introducing new bugs.

In passing, re-pgindent async.c and run reformat-dat-files on
pg_proc.dat, just because I'm a neatnik.

Discussion: https://postgr.es/m/13881.1574557302@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8b7ae5a82d04312672c919ecea3c30b1ec7faaf2

Modified Files
--------------
src/backend/commands/async.c     | 18 ++++++++++--------
src/include/catalog/catversion.h |  2 +-
src/include/catalog/pg_proc.dat  | 18 ++++++++----------
3 files changed, 19 insertions(+), 19 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Remove a couple of unnecessary if-tests.
Next
From: Tom Lane
Date:
Subject: pgsql: Stabilize NOTIFY behavior by transmitting notifies before ReadyF