1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Introduce private data area for injection points

This commit extends the backend-side infrastructure of injection points
so as it becomes possible to register some input data when attaching a
point.  This private data can be registered with the function name and
the library name of the callback when attaching a point, then it is
given as input argument to the callback.  This gives the possibility for
modules to pass down custom data at runtime when attaching a point
without managing that internally, in a manner consistent with the
callback entry retrieved from the hash shmem table storing the injection
point data.

InjectionPointAttach() gains two arguments, to be able to define the
private data contents and its size.

A follow-up commit will rely on this infrastructure to close a race
condition with the injection point detach in the module
injection_points.

While on it, this changes InjectionPointDetach() to return a boolean,
returning false if a point cannot be detached.  This has been mentioned
by Noah as useful when it comes to implement more complex tests with
concurrent point detach, solid with the automatic detach done for local
points in the test module.

Documentation is adjusted in consequence.

Per discussion with Noah Misch.

Reviewed-by: Noah Misch
Discussion: https://postgr.es/m/20240509031553.47@rfd.leadboat.com
This commit is contained in:
Michael Paquier
2024-05-12 18:53:06 +09:00
parent 407e0b023c
commit 33181b48fd
5 changed files with 74 additions and 28 deletions

View File

@ -3624,12 +3624,16 @@ INJECTION_POINT(name);
<programlisting>
extern void InjectionPointAttach(const char *name,
const char *library,
const char *function);
const char *function,
const void *private_data,
int private_data_size);
</programlisting>
<literal>name</literal> is the name of the injection point, which when
reached during execution will execute the <literal>function</literal>
loaded from <literal>library</literal>.
loaded from <literal>library</literal>. <literal>private_data</literal>
is a private area of data of size <literal>private_data_size</literal>
given as argument to the callback when executed.
</para>
<para>
@ -3637,7 +3641,7 @@ extern void InjectionPointAttach(const char *name,
<literal>InjectionPointCallback</literal>:
<programlisting>
static void
custom_injection_callback(const char *name)
custom_injection_callback(const char *name, const void *private_data)
{
elog(NOTICE, "%s: executed custom callback", name);
}
@ -3650,8 +3654,10 @@ custom_injection_callback(const char *name)
<para>
Optionally, it is possible to detach an injection point by calling:
<programlisting>
extern void InjectionPointDetach(const char *name);
extern bool InjectionPointDetach(const char *name);
</programlisting>
On success, <literal>true</literal> is returned, <literal>false</literal>
otherwise.
</para>
<para>