injection_points: Add wait and wakeup of processes
authorMichael Paquier <michael@paquier.xyz>
Mon, 4 Mar 2024 00:19:13 +0000 (09:19 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 4 Mar 2024 00:19:13 +0000 (09:19 +0900)
commit37b369dc67bc44a3aab5c07e2c0012475efd00f3
treeb42a6f23b9ddadf63291cf6ec7f61b9d0c605121
parent024c521117579a6d356050ad3d78fdc95e44eefa
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/ZdLuxBk5hGpol91B@paquier.xyz
src/test/modules/injection_points/injection_points--1.0.sql
src/test/modules/injection_points/injection_points.c
src/tools/pgindent/typedefs.list