diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-07-18 09:50:41 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-07-18 09:50:41 +0900 |
commit | a0a5869a8598cdeae1d2f2d632038d26dcc69d19 (patch) | |
tree | f8d31f1d376c1fc8bc26f434ba66e8de7ec2ee75 /src/backend/utils/misc/injection_point.c | |
parent | 6159331acfbe2d08361947324e09e446138c7bc1 (diff) | |
download | postgresql-a0a5869a8598cdeae1d2f2d632038d26dcc69d19.tar.gz postgresql-a0a5869a8598cdeae1d2f2d632038d26dcc69d19.zip |
Add INJECTION_POINT_CACHED() to run injection points directly from cache
This new macro is able to perform a direct lookup from the local cache
of injection points (refreshed each time a point is loaded or run),
without touching the shared memory state of injection points at all.
This works in combination with INJECTION_POINT_LOAD(), and it is better
than INJECTION_POINT() in a critical section due to the fact that it
would avoid all memory allocations should a concurrent detach happen
since a LOAD(), as it retrieves a callback from the backend-private
memory.
The documentation is updated to describe in more details how to use this
new macro with a load. Some tests are added to the module
injection_points based on a new SQL function that acts as a wrapper of
INJECTION_POINT_CACHED().
Based on a suggestion from Heikki Linnakangas.
Author: Heikki Linnakangas, Michael Paquier
Discussion: https://postgr.es/m/58d588d0-e63f-432f-9181-bed29313dece@iki.fi
Diffstat (limited to 'src/backend/utils/misc/injection_point.c')
-rw-r--r-- | src/backend/utils/misc/injection_point.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/utils/misc/injection_point.c b/src/backend/utils/misc/injection_point.c index 84ad5e470d7..8ad0c27bc8a 100644 --- a/src/backend/utils/misc/injection_point.c +++ b/src/backend/utils/misc/injection_point.c @@ -553,3 +553,20 @@ InjectionPointRun(const char *name) elog(ERROR, "Injection points are not supported by this build"); #endif } + +/* + * Execute an injection point directly from the cache, if defined. + */ +void +InjectionPointCached(const char *name) +{ +#ifdef USE_INJECTION_POINTS + InjectionPointCacheEntry *cache_entry; + + cache_entry = injection_point_cache_get(name); + if (cache_entry) + cache_entry->callback(name, cache_entry->private_data); +#else + elog(ERROR, "Injection points are not supported by this build"); +#endif +} |