8000 injection_points: Add injection_points_list() · postgres/postgres@4eca711 · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit 4eca711

Browse files
committed
injection_points: Add injection_points_list()
This function can be used to retrieve the information about all the injection points attached to a cluster, providing coverage for InjectionPointList() introduced in 7b2eb72. The original proposal turned around a system function, but that would not be backpatchable to stable branches. It was also a bit weird to have a system function that fails depending on if the build allows injection points or not. Reviewed-by: Aleksander Alekseev <aleksander@timescale.com> Reviewed-by: Rahila Syed <rahilasyed90@gmail.com> Discussion: https://postgr.es/m/Z_xYkA21KyLEHvWR@paquier.xyz
1 parent 48a23f6 commit 4eca711

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

src/test/modules/injection_points/expected/injection_points.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ SELECT injection_points_attach('TestInjectionLog2', 'notice');
3939

4040
(1 row)
4141

42+
SELECT point_name, library, function FROM injection_points_list()
43+
ORDER BY point_name COLLATE "C";
44+
point_name | library | function
45+
--------------------+------------------+------------------
46+
TestInjectionError | injection_points | injection_error
47+
TestInjectionLog | injection_points | injection_notice
48+
TestInjectionLog2 | injection_points | injection_notice
49+
(3 rows)
50+
4251
SELECT injection_points_run('TestInjectionBooh'); -- nothing
4352
injection_points_run
4453
----------------------
@@ -298,5 +307,12 @@ SELECT injection_points_detach('TestConditionLocal1');
298307

299308
(1 row)
300309

310+
-- No points should be left around.
311+
SELECT point_name, library, function FROM injection_points_list()
312+
ORDER BY point_name COLLATE "C";
313+
point_name | library | function
314+
------------+---------+----------
315+
(0 rows)
316+
301317
DROP EXTENSION injection_points;
302318
DROP FUNCTION wait_pid;

src/test/modules/injection_points/injection_points--1.0.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ RETURNS void
7777
AS 'MODULE_PATHNAME', 'injection_points_detach'
7878
LANGUAGE C STRICT PARALLEL UNSAFE;
7979

80+
--
81+
-- injection_points_list()
82+
--
83+
-- List of all the injection points currently attached.
84+
--
85+
CREATE FUNCTION injection_points_list(OUT point_name text,
86+
OUT library text,
87+
OUT function text)
88+
RETURNS SETOF record
89+
AS 'MODULE_PATHNAME', 'injection_points_list'
90+
LANGUAGE C STRICT VOLATILE PARALLEL RESTRICTED;
91+
8092
--
8193
-- injection_points_stats_numcalls()
8294
--

src/test/modules/injection_points/injection_points.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "postgres.h"
1919

2020
#include "fmgr.h"
21+
#include "funcapi.h"
2122
#include "injection_stats.h"
2223
#include "miscadmin.h"
2324
#include "nodes/pg_list.h"
@@ -545,6 +546,44 @@ injection_points_detach(PG_FUNCTION_ARGS)
545546
PG_RETURN_VOID();
546547
}
547548

549+
/*
550+
* SQL function for listing all the injection points attached.
551+
*/
552+
PG_FUNCTION_INFO_V1(injection_points_list);
553+
Datum
554+
injection_points_list(PG_FUNCTION_ARGS)
555+
{
556+
#define NUM_INJECTION_POINTS_LIST 3
557+
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
558+
List *inj_points;
559+
ListCell *lc;
560+
561+
/* Build a tuplestore to return our results in */
562+
InitMaterializedSRF(fcinfo, 0);
563+
564+
inj_points = InjectionPointList();
565+
566+
foreach(lc, inj_points)
567+
{
568+
Datum values[NUM_INJECTION_POINTS_LIST];
569+
bool nulls[NUM_INJECTION_POINTS_LIST];
570+
InjectionPointData *inj_point = lfirst(lc);
571+
572+
memset(values, 0, sizeof(values));
573+
memset(nulls, 0, sizeof(nulls));
574+
575+
values[0] = PointerGetDatum(cstring_to_text(inj_point->name));
576+
values[1] = PointerGetDatum(cstring_to_text(inj_point->library));
577+
values[2] = PointerGetDatum(cstring_to_text(inj_point->function));
578+
579+
/* shove row into tuplestore */
580+
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
581+
}
582+
583+
return (Datum) 0;
584+
#undef NUM_INJECTION_POINTS_LIST
585+
}
586+
548587

549588
void
550589
_PG_init(void)

src/test/modules/injection_points/sql/injection_points.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ SELECT injection_points_attach('TestInjectionError', 'error');
1818
SELECT injection_points_attach('TestInjectionLog', 'notice');
1919
SELECT injection_points_attach('TestInjectionLog2', 'notice');
2020

21+
SELECT point_name, library, function FROM injection_points_list()
22+
ORDER BY point_name COLLATE "C";
23+
2124
SELECT injection_points_run('TestInjectionBooh'); -- nothing
2225
SELECT injection_points_run('TestInjectionLog2'); -- notice
2326
SELECT injection_points_run('TestInjectionLog2', NULL); -- notice
@@ -85,5 +88,9 @@ SELECT injection_points_detach('TestConditionError');
8588
SELECT injection_points_attach('TestConditionLocal1', 'error');
8689
SELECT injection_points_detach('TestConditionLocal1');
8790

91+
-- No points should be left around.
92+
SELECT point_name, library, function FROM injection_points_list()
93+
ORDER BY point_name COLLATE "C";
94+
8895
DROP EXTENSION injection_points;
8996
DROP FUNCTION wait_pid;

0 commit comments

Comments
 (0)
0