Обсуждение: Extend injection_points_attach() to accept a user-defined function

Поиск
Список
Период
Сортировка

Extend injection_points_attach() to accept a user-defined function

От
Rahila Syed
Дата:
Hi,

I would like to propose providing a sql interface to link a
user-defined function to an injection point.
Currently, if a user wants an injection point to invoke a custom
function, they must first define an SQL
function that attaches the injection point to the target/custom
function. This SQL function can then be called
in sql tests to attach to the injection point before running the tests.

The attached patch simplifies this by extending the
injection_points_attach() function to support a new
action type called "func".
The new "func" action enables users to attach a user-defined function
to an injection point.
When "func" is specified as action, the caller must provide:

1. the module name

2. the function name

as additional arguments to injection_points_attach(). These arguments
default to NULL when the
action is not "func".
This approach aims to simplify the process of assigning user-defined
functions to injection points,
eliminating the need to create separate SQL functions to attach each
injection point individually.

Thank you,
Rahila Syed

Вложения

Re: Extend injection_points_attach() to accept a user-defined function

От
Michael Paquier
Дата:
On Tue, Oct 28, 2025 at 06:11:25PM +0530, Rahila Syed wrote:
> I would like to propose providing a sql interface to link a
> user-defined function to an injection point.
> Currently, if a user wants an injection point to invoke a custom
> function, they must first define an SQL
> function that attaches the injection point to the target/custom
> function. This SQL function can then be called
> in sql tests to attach to the injection point before running the tests.
> The attached patch simplifies this by extending the
> injection_points_attach() function to support a new
> action type called "func".

@@ -354,6 +354,7 @@ injection_points_attach(PG_FUNCTION_ARGS)
+    char       *mod_name;
[...]
@@ -362,6 +363,15 @@ injection_points_attach(PG_FUNCTION_ARGS)
         function = "injection_notice";
     else if (strcmp(action, "wait") == 0)
         function = "injection_wait";
+    else if (strcmp(action, "func") == 0)

How about a simpler injection_points_attach(point_name text, func
text, module text) with a second SQL function, but a different number
of arguments?   Using a new hardcoded action for this purpose is
confusing as your point is to introduce a SQL wrapper on top of
InjectionPointAttach(), and using input arguments that match with the
C function is an attractive option.
--
Michael

Вложения

Re: Extend injection_points_attach() to accept a user-defined function

От
Rahila Syed
Дата:
Hi,

> How about a simpler injection_points_attach(point_name text, func
> text, module text) with a second SQL function, but a different number
> of arguments?   Using a new hardcoded action for this purpose is
> confusing as your point is to introduce a SQL wrapper on top of
> InjectionPointAttach(), and using input arguments that match with the
> C function is an attractive option.

Thank you for the suggestion.
I agree that having a separate SQL function for this would make the design
easier to understand.

Please find attached a patch that implements this.

Thank you,
Rahila Syed

Вложения

Re: Extend injection_points_attach() to accept a user-defined function

От
Mihail Nikalayeu
Дата:
Hello!

I thought it may help me to implement some kind of notice+wait
required for [1] in order to stabilize the tests.

Is it possible to do something like this in the attached function?

    RAISE NOTICE 'going to wait';
    SELECT injection_points_run(some_point_with_wait"); -- wait called
inside injection point handler

Also, I think it is a good idea to add some tests to injection_points.sql.

Best regards,
Mikhail.

[1]:
https://www.postgresql.org/message-id/flat/CADzfLwWRVj7wDy4Qj3CJTuWy6fvv9TTDBTHsUjC7F1SAN0LpeA%40mail.gmail.com#52c7659bf9c8c5ff484e3b470a4cfb8a



Re: Extend injection_points_attach() to accept a user-defined function

От
Rahila Syed
Дата:
Hi Mihail,

Thank you for looking into this thread.

>
> I thought it may help me to implement some kind of notice+wait
> required for [1] in order to stabilize the tests.
>
> Is it possible to do something like this in the attached function?
>
>     RAISE NOTICE 'going to wait';
>     SELECT injection_points_run(some_point_with_wait"); -- wait called
> inside injection point handler
>

One way to achieve this using the proposed SQL function is to create a
C function in a module like injection_points, which combines injection_notice
and injection_wait. You can then pass this combined function as an argument
to the proposed injection_points_attach() function.

Something as follows:

SELECT injection_points_attach('TestInjectionNoticeFunc',
'injection_points', 'injection_notice_and_wait');

> Also, I think it is a good idea to add some tests to injection_points.sql.
>

PFA a rebased patch that contains the test.
The tests use the newly added SQL function to attach the injection_notice
function to an injection point


Thank you,
Rahila Syed

Вложения