Skip to content

Commit 371f2db

Browse files
committed
Add support for runtime arguments in injection points
The macros INJECTION_POINT() and INJECTION_POINT_CACHED() are extended with an optional argument that can be passed down to the callback attached when an injection point is run, giving to callbacks the possibility to manipulate a stack state given by the caller. The existing callbacks in modules injection_points and test_aio have their declarations adjusted based on that. da72269 (core AIO infrastructure) and 93bc3d7 (test_aio) and been relying on a set of workarounds where a static variable called pgaio_inj_cur_handle is used as runtime argument in the injection point callbacks used by the AIO tests, in combination with a TRY/CATCH block to reset the argument value. The infrastructure introduced in this commit will be reused for the AIO tests, simplifying them. Reviewed-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/Z_y9TtnXubvYAApS@paquier.xyz
1 parent 89372d0 commit 371f2db

File tree

23 files changed

+69
-57
lines changed

23 files changed

+69
-57
lines changed

doc/src/sgml/xfunc.sgml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,15 +3829,17 @@ uint32 WaitEventExtensionNew(const char *wait_event_name)
38293829
An injection point with a given <literal>name</literal> is declared using
38303830
macro:
38313831
<programlisting>
3832-
INJECTION_POINT(name);
3832+
INJECTION_POINT(name, arg);
38333833
</programlisting>
38343834

38353835
There are a few injection points already declared at strategic points
38363836
within the server code. After adding a new injection point the code needs
38373837
to be compiled in order for that injection point to be available in the
38383838
binary. Add-ins written in C-language can declare injection points in
3839-
their own code using the same macro. The injection point names should
3840-
use lower-case characters, with terms separated by dashes.
3839+
their own code using the same macro. The injection point names should use
3840+
lower-case characters, with terms separated by
3841+
dashes. <literal>arg</literal> is an optional argument value given to the
3842+
callback at run-time.
38413843
</para>
38423844

38433845
<para>
@@ -3847,7 +3849,7 @@ INJECTION_POINT(name);
38473849
a two-step approach with the following macros:
38483850
<programlisting>
38493851
INJECTION_POINT_LOAD(name);
3850-
INJECTION_POINT_CACHED(name);
3852+
INJECTION_POINT_CACHED(name, arg);
38513853
</programlisting>
38523854

38533855
Before entering the critical section,
@@ -3880,7 +3882,9 @@ extern void InjectionPointAttach(const char *name,
38803882
<literal>InjectionPointCallback</literal>:
38813883
<programlisting>
38823884
static void
3883-
custom_injection_callback(const char *name, const void *private_data)
3885+
custom_injection_callback(const char *name,
3886+
const void *private_data,
3887+
void *arg)
38843888
{
38853889
uint32 wait_event_info = WaitEventInjectionPointNew(name);
38863890

@@ -3909,7 +3913,7 @@ if (IS_INJECTION_POINT_ATTACHED("before-foobar"))
39093913
local_var = 123;
39103914

39113915
/* also execute the callback */
3912-
INJECTION_POINT_CACHED("before-foobar");
3916+
INJECTION_POINT_CACHED("before-foobar", NULL);
39133917
}
39143918
#endif
39153919
</programlisting>

src/backend/access/gin/ginbtree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,9 @@ ginFinishSplit(GinBtree btree, GinBtreeStack *stack, bool freestack,
685685

686686
#ifdef USE_INJECTION_POINTS
687687
if (GinPageIsLeaf(BufferGetPage(stack->buffer)))
688-
INJECTION_POINT("gin-leave-leaf-split-incomplete");
688+
INJECTION_POINT("gin-leave-leaf-split-incomplete", NULL);
689689
else
690-
INJECTION_POINT("gin-leave-internal-split-incomplete");
690+
INJECTION_POINT("gin-leave-internal-split-incomplete", NULL);
691691
#endif
692692

693693
/* search parent to lock */
@@ -778,7 +778,7 @@ ginFinishSplit(GinBtree btree, GinBtreeStack *stack, bool freestack,
778778
static void
779779
ginFinishOldSplit(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats, int access)
780780
{
781-
INJECTION_POINT("gin-finish-incomplete-split");
781+
INJECTION_POINT("gin-finish-incomplete-split", NULL);
782782
elog(DEBUG1, "finishing incomplete split of block %u in gin index \"%s\"",
783783
stack->blkno, RelationGetRelationName(btree->index));
784784

src/backend/access/heap/heapam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3304,7 +3304,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
33043304
interesting_attrs = bms_add_members(interesting_attrs, id_attrs);
33053305

33063306
block = ItemPointerGetBlockNumber(otid);
3307-
INJECTION_POINT("heap_update-before-pin");
3307+
INJECTION_POINT("heap_update-before-pin", NULL);
33083308
buffer = ReadBuffer(relation, block);
33093309
page = BufferGetPage(buffer);
33103310

src/backend/access/index/genam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ systable_inplace_update_begin(Relation relation,
851851
if (retries++ > 10000)
852852
elog(ERROR, "giving up after too many tries to overwrite row");
853853

854-
INJECTION_POINT("inplace-before-pin");
854+
INJECTION_POINT("inplace-before-pin", NULL);
855855
scan = systable_beginscan(relation, indexId, indexOK, snapshot,
856856
nkeys, unconstify(ScanKeyData *, key));
857857
oldtup = systable_getnext(scan);

src/backend/access/transam/multixact.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
872872
*/
873873
multi = GetNewMultiXactId(nmembers, &offset);
874874

875-
INJECTION_POINT_CACHED("multixact-create-from-members");
875+
INJECTION_POINT_CACHED("multixact-create-from-members", NULL);
876876

877877
/* Make an XLOG entry describing the new MXID. */
878878
xlrec.mid = multi;
@@ -1486,7 +1486,7 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
14861486
LWLockRelease(lock);
14871487
CHECK_FOR_INTERRUPTS();
14881488

1489-
INJECTION_POINT("multixact-get-members-cv-sleep");
1489+
INJECTION_POINT("multixact-get-members-cv-sleep", NULL);
14901490

14911491
ConditionVariableSleep(&MultiXactState->nextoff_cv,
14921492
WAIT_EVENT_MULTIXACT_CREATION);

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7882,7 +7882,7 @@ CreateRestartPoint(int flags)
78827882
* This location needs to be after CheckPointGuts() to ensure that some
78837883
* work has already happened during this checkpoint.
78847884
*/
7885-
INJECTION_POINT("create-restart-point");
7885+
INJECTION_POINT("create-restart-point", NULL);
78867886

78877887
/*
78887888
* Remember the prior checkpoint's redo ptr for

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,9 +3892,9 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
38923892

38933893
#ifdef USE_INJECTION_POINTS
38943894
if (idx->safe)
3895-
INJECTION_POINT("reindex-conc-index-safe");
3895+
INJECTION_POINT("reindex-conc-index-safe", NULL);
38963896
else
3897-
INJECTION_POINT("reindex-conc-index-not-safe");
3897+
INJECTION_POINT("reindex-conc-index-not-safe", NULL);
38983898
#endif
38993899

39003900
idx->tableId = RelationGetRelid(heapRel);

src/backend/executor/nodeAgg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ build_hash_tables(AggState *aggstate)
14921492
if (IS_INJECTION_POINT_ATTACHED("hash-aggregate-oversize-table"))
14931493
{
14941494
nbuckets = memory / TupleHashEntrySize();
1495-
INJECTION_POINT_CACHED("hash-aggregate-oversize-table");
1495+
INJECTION_POINT_CACHED("hash-aggregate-oversize-table", NULL);
14961496
}
14971497
#endif
14981498

@@ -1882,7 +1882,7 @@ hash_agg_check_limits(AggState *aggstate)
18821882
if (IS_INJECTION_POINT_ATTACHED("hash-aggregate-spill-1000"))
18831883
{
18841884
do_spill = true;
1885-
INJECTION_POINT_CACHED("hash-aggregate-spill-1000");
1885+
INJECTION_POINT_CACHED("hash-aggregate-spill-1000", NULL);
18861886
}
18871887
}
18881888
#endif
@@ -1910,7 +1910,7 @@ hash_agg_check_limits(AggState *aggstate)
19101910
static void
19111911
hash_agg_enter_spill_mode(AggState *aggstate)
19121912
{
1913-
INJECTION_POINT("hash-aggregate-enter-spill-mode");
1913+
INJECTION_POINT("hash-aggregate-enter-spill-mode", NULL);
19141914
aggstate->hash_spill_mode = true;
19151915
hashagg_recompile_expressions(aggstate, aggstate->table_filled, true);
19161916

@@ -2739,7 +2739,7 @@ agg_refill_hash_table(AggState *aggstate)
27392739
*/
27402740
hashagg_recompile_expressions(aggstate, true, true);
27412741

2742-
INJECTION_POINT("hash-aggregate-process-batch");
2742+
INJECTION_POINT("hash-aggregate-process-batch", NULL);
27432743
for (;;)
27442744
{
27452745
TupleTableSlot *spillslot = aggstate->hash_spill_rslot;
@@ -2995,7 +2995,7 @@ hashagg_spill_init(HashAggSpill *spill, LogicalTapeSet *tapeset, int used_bits,
29952995
{
29962996
npartitions = 1;
29972997
partition_bits = 0;
2998-
INJECTION_POINT_CACHED("hash-aggregate-single-partition");
2998+
INJECTION_POINT_CACHED("hash-aggregate-single-partition", NULL);
29992999
}
30003000
#endif
30013001

src/backend/libpq/be-secure-gssapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ secure_open_gssapi(Port *port)
500500
minor;
501501
gss_cred_id_t delegated_creds;
502502

503-
INJECTION_POINT("backend-gssapi-startup");
503+
INJECTION_POINT("backend-gssapi-startup", NULL);
504504

505505
/*
506506
* Allocate subsidiary Port data for GSSAPI operations.

src/backend/libpq/be-secure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ secure_open_server(Port *port)
131131
}
132132
Assert(pq_buffer_remaining_data() == 0);
133133

134-
INJECTION_POINT("backend-ssl-startup");
134+
INJECTION_POINT("backend-ssl-startup", NULL);
135135

136136
r = be_tls_open_server(port);
137137

0 commit comments

Comments
 (0)