pgsql: Add backend support for injection points

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема pgsql: Add backend support for injection points
Дата
Msg-id E1rRix2-002Vp9-7J@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Add backend support for injection points

Injection points are a new facility that makes possible for developers
to run custom code in pre-defined code paths.  Its goal is to provide
ways to design and run advanced tests, for cases like:
- Race conditions, where processes need to do actions in a controlled
ordered manner.
- Forcing a state, like an ERROR, FATAL or even PANIC for OOM, to force
recovery, etc.
- Arbitrary sleeps.

This implements some basics, and there are plans to extend it more in
the future depending on what's required.  Hence, this commit adds a set
of routines in the backend that allows developers to attach, detach and
run injection points:
- A code path calling an injection point can be declared with the macro
INJECTION_POINT(name).
- InjectionPointAttach() and InjectionPointDetach() to respectively
attach and detach a callback to/from an injection point.  An injection
point name is registered in a shmem hash table with a library name and a
function name, which will be used to load the callback attached to an
injection point when its code path is run.

Injection point names are just strings, so as an injection point can be
declared and run by out-of-core extensions and modules, with callbacks
defined in external libraries.

This facility is hidden behind a dedicated switch for ./configure and
meson, disabled by default.

Note that backends use a local cache to store callbacks already loaded,
cleaning up their cache if a callback has found to be removed on a
best-effort basis.  This could be refined further but any tests but what
we have here was fine with the tests I've written while implementing
these backend APIs.

Author: Michael Paquier, with doc suggestions from Ashutosh Bapat.
Reviewed-by: Ashutosh Bapat, Nathan Bossart, Álvaro Herrera, Dilip
Kumar, Amul Sul, Nazir Bilal Yavuz
Discussion: https://postgr.es/m/ZTiV8tn_MIb_H2rE@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d86d20f0ba79451f19782dbb5fbf206746aaffd1

Modified Files
--------------
configure                                       |  34 +++
configure.ac                                    |   7 +
doc/src/sgml/installation.sgml                  |  30 +++
doc/src/sgml/xfunc.sgml                         |  69 ++++++
meson.build                                     |   1 +
meson_options.txt                               |   3 +
src/Makefile.global.in                          |   1 +
src/backend/storage/ipc/ipci.c                  |   3 +
src/backend/storage/lmgr/lwlocknames.txt        |   1 +
src/backend/utils/activity/wait_event_names.txt |   1 +
src/backend/utils/misc/Makefile                 |   1 +
src/backend/utils/misc/injection_point.c        | 317 ++++++++++++++++++++++++
src/backend/utils/misc/meson.build              |   1 +
src/include/pg_config.h.in                      |   3 +
src/include/utils/injection_point.h             |  37 +++
src/makefiles/meson.build                       |   1 +
src/tools/pgindent/typedefs.list                |   2 +
17 files changed, 512 insertions(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: Re: pgsql: Explore alternative orderings of group-by pathkeys during optimi
Следующее
От: Michael Paquier
Дата:
Сообщение: pgsql: Add test module injection_points