mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
injection_points: Add variant for injection_point_attach()
This new function is able to take in input more data than the existing injection_point_attach(): - A library name. - A function name. - Some private data. This gives more flexibility for tests so as these would not need to reinvent a wrapper for InjectionPointAttach() when attaching a callback from a library other than "injection_points". injection_point_detach() can be used with both versions of injection_point_attach(). Author: Rahila Syed <rahilasyed.90@gmail.com> Reviewed-by: Mihail Nikalayeu <mihailnikalayeu@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAH2L28sOG2b_TKkZU51dy+pWJtny1mqDmeFiFoUASGa0X0iiKQ@mail.gmail.com
This commit is contained in:
@@ -307,7 +307,40 @@ SELECT injection_points_detach('TestConditionLocal1');
|
||||
|
||||
(1 row)
|
||||
|
||||
-- No points should be left around.
|
||||
-- Function variant for attach.
|
||||
SELECT injection_points_attach(NULL, NULL, NULL, NULL);
|
||||
ERROR: injection point name cannot be NULL
|
||||
SELECT injection_points_attach('injection_points', NULL, NULL, NULL);
|
||||
ERROR: injection point library cannot be NULL
|
||||
SELECT injection_points_attach('injection_points', 'injection_notice', NULL, NULL);
|
||||
ERROR: injection point function cannot be NULL
|
||||
SELECT injection_points_attach('TestInjectionNoticeFunc',
|
||||
'injection_points', 'injection_notice', NULL);
|
||||
injection_points_attach
|
||||
-------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT point_name, library, function FROM injection_points_list()
|
||||
ORDER BY point_name COLLATE "C";
|
||||
point_name | library | function
|
||||
-------------------------+------------------+------------------
|
||||
TestInjectionNoticeFunc | injection_points | injection_notice
|
||||
(1 row)
|
||||
|
||||
SELECT injection_points_run('TestInjectionNoticeFunc', NULL); -- notice
|
||||
NOTICE: notice triggered for injection point TestInjectionNoticeFunc
|
||||
injection_points_run
|
||||
----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT injection_points_detach('TestInjectionNoticeFunc');
|
||||
injection_points_detach
|
||||
-------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT point_name, library, function FROM injection_points_list()
|
||||
ORDER BY point_name COLLATE "C";
|
||||
point_name | library | function
|
||||
|
||||
@@ -14,6 +14,18 @@ RETURNS void
|
||||
AS 'MODULE_PATHNAME', 'injection_points_attach'
|
||||
LANGUAGE C STRICT PARALLEL UNSAFE;
|
||||
|
||||
--
|
||||
-- injection_points_attach()
|
||||
--
|
||||
-- Attaches a function to the given injection point, with library name,
|
||||
-- function name and private data.
|
||||
--
|
||||
CREATE FUNCTION injection_points_attach(IN point_name TEXT,
|
||||
IN library_name TEXT, IN function_name TEXT, IN private_data BYTEA)
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME', 'injection_points_attach_func'
|
||||
LANGUAGE C PARALLEL UNSAFE;
|
||||
|
||||
--
|
||||
-- injection_points_load()
|
||||
--
|
||||
|
||||
@@ -391,6 +391,47 @@ injection_points_attach(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for creating an injection point with library name, function
|
||||
* name and private data.
|
||||
*/
|
||||
PG_FUNCTION_INFO_V1(injection_points_attach_func);
|
||||
Datum
|
||||
injection_points_attach_func(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *name;
|
||||
char *lib_name;
|
||||
char *function;
|
||||
bytea *private_data = NULL;
|
||||
int private_data_size = 0;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
elog(ERROR, "injection point name cannot be NULL");
|
||||
if (PG_ARGISNULL(1))
|
||||
elog(ERROR, "injection point library cannot be NULL");
|
||||
if (PG_ARGISNULL(2))
|
||||
elog(ERROR, "injection point function cannot be NULL");
|
||||
|
||||
name = text_to_cstring(PG_GETARG_TEXT_PP(0));
|
||||
lib_name = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||
function = text_to_cstring(PG_GETARG_TEXT_PP(2));
|
||||
|
||||
if (!PG_ARGISNULL(3))
|
||||
{
|
||||
private_data = PG_GETARG_BYTEA_PP(3);
|
||||
private_data_size = VARSIZE_ANY_EXHDR(private_data);
|
||||
}
|
||||
|
||||
pgstat_report_inj_fixed(1, 0, 0, 0, 0);
|
||||
if (private_data != NULL)
|
||||
InjectionPointAttach(name, lib_name, function, VARDATA_ANY(private_data),
|
||||
private_data_size);
|
||||
else
|
||||
InjectionPointAttach(name, lib_name, function, NULL,
|
||||
0);
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for loading an injection point.
|
||||
*/
|
||||
|
||||
@@ -88,7 +88,16 @@ SELECT injection_points_detach('TestConditionError');
|
||||
SELECT injection_points_attach('TestConditionLocal1', 'error');
|
||||
SELECT injection_points_detach('TestConditionLocal1');
|
||||
|
||||
-- No points should be left around.
|
||||
-- Function variant for attach.
|
||||
SELECT injection_points_attach(NULL, NULL, NULL, NULL);
|
||||
SELECT injection_points_attach('injection_points', NULL, NULL, NULL);
|
||||
SELECT injection_points_attach('injection_points', 'injection_notice', NULL, NULL);
|
||||
SELECT injection_points_attach('TestInjectionNoticeFunc',
|
||||
'injection_points', 'injection_notice', NULL);
|
||||
SELECT point_name, library, function FROM injection_points_list()
|
||||
ORDER BY point_name COLLATE "C";
|
||||
SELECT injection_points_run('TestInjectionNoticeFunc', NULL); -- notice
|
||||
SELECT injection_points_detach('TestInjectionNoticeFunc');
|
||||
SELECT point_name, library, function FROM injection_points_list()
|
||||
ORDER BY point_name COLLATE "C";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user