diff options
| author | Michael Paquier | 2023-08-14 05:47:27 +0000 |
|---|---|---|
| committer | Michael Paquier | 2023-08-14 05:47:27 +0000 |
| commit | af720b4c50a122647182f4a030bb0ea8f750fe2f (patch) | |
| tree | a2a689afb11be2e90fc25d8cc3996ed3196440b8 /src/include/utils | |
| parent | 2a8b40e3681921943a2989fd4ec6cdbf8766566c (diff) | |
Change custom wait events to use dynamic shared hash tables
Currently, the names of the custom wait event must be registered for
each backend, requiring all these to link to the shared memory area of
an extension, even if these are not loaded with
shared_preload_libraries.
This patch relaxes the constraints related to this infrastructure by
storing the wait events and their names in two dynamic hash tables in
shared memory. This has the advantage to simplify the registration of
custom wait events to a single routine call that returns an event ID
ready for consumption:
uint32 WaitEventExtensionNew(const char *wait_event_name);
The caller of this routine can then cache locally the ID returned, to be
used for pgstat_report_wait_start(), WaitLatch() or a similar routine.
The implementation uses two hash tables: one with a key based on the
event name to avoid duplicates and a second using the event ID as key
for event lookups, like on pg_stat_activity. These tables can hold a
minimum of 16 entries, and a maximum of 128 entries, which should be plenty
enough.
The code changes done in worker_spi show how things are simplified (most
of the code removed in this commit comes from there):
- worker_spi_init() is gone.
- No more shared memory hooks required (size requested and
initialization).
- The custom wait event ID is cached in the process that needs to set
it, with one single call to WaitEventExtensionNew() to retrieve it.
Per suggestion from Andres Freund.
Author: Masahiro Ikeda, with a few tweaks from me.
Discussion: https://postgr.es/m/20230801032349.aaiuvhtrcvvcwzcx@awork3.anarazel.de
Diffstat (limited to 'src/include/utils')
| -rw-r--r-- | src/include/utils/wait_event.h | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/include/utils/wait_event.h b/src/include/utils/wait_event.h index aad8bc08fa0..3eebdfad38b 100644 --- a/src/include/utils/wait_event.h +++ b/src/include/utils/wait_event.h @@ -44,12 +44,14 @@ extern PGDLLIMPORT uint32 *my_wait_event_info; * Use this category when the server process is waiting for some condition * defined by an extension module. * - * Extensions can define their own wait events in this category. First, - * they should call WaitEventExtensionNew() to get one or more wait event - * IDs that are allocated from a shared counter. These can be used directly - * with pgstat_report_wait_start() or equivalent. Next, each individual - * process should call WaitEventExtensionRegisterName() to associate a wait - * event string to the number allocated previously. + * Extensions can define their own wait events in this category. They should + * call WaitEventExtensionNew() with a wait event string. If the wait event + * associated to a string is already allocated, it returns the wait event + * information to use. If not, it gets one wait event ID allocated from + * a shared counter, associates the string to the ID in the shared dynamic + * hash and returns the wait event information. + * + * The ID retrieved can be used with pgstat_report_wait_start() or equivalent. */ typedef enum { @@ -60,9 +62,7 @@ typedef enum extern void WaitEventExtensionShmemInit(void); extern Size WaitEventExtensionShmemSize(void); -extern uint32 WaitEventExtensionNew(void); -extern void WaitEventExtensionRegisterName(uint32 wait_event_info, - const char *wait_event_name); +extern uint32 WaitEventExtensionNew(const char *wait_event_name); /* ---------- * pgstat_report_wait_start() - |
