injection_points: Add wait and wakeup of processes

This commit adds two features to the in-core module for injection
points:
- A new callback called "wait" that can be attached to an injection
point to make it wait.
- A new SQL function to update the shared state and broadcast the update
using a condition variable.  This function uses an input an injection
point name.

This offers the possibility to stop a process in flight and wake it up
in a controlled manner, which is useful when implementing tests that aim
to trigger scenarios for race conditions (some tests are planned for
integration).  The logic uses a set of counters with a condition
variable to monitor and broadcast the changes.  Up to 8 waits can be
registered in a single run, which should be plenty enough.  Waits can be
monitored in pg_stat_activity, based on the injection point name which
is registered in a custom wait event under the "Extension" category.

The shared memory state used by the module is registered using the DSM
registry, and is optional, so there is no need to load the module with
shared_preload_libraries to be able to use these features.

Author: Michael Paquier
Reviewed-by: Andrey Borodin, Bertrand Drouvot
Discussion: https://postgr.es/m/zdluxbk5hgpol...@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/37b369dc67bc44a3aab5c07e2c0012475efd00f3

Modified Files
--------------
.../injection_points/injection_points--1.0.sql     |  10 ++
.../modules/injection_points/injection_points.c    | 155 +++++++++++++++++++++
src/tools/pgindent/typedefs.list                   |   1 +
3 files changed, 166 insertions(+)

Reply via email to