An injection point with a given <literal>name</literal> is declared using
macro:
<programlisting>
-INJECTION_POINT(name);
+INJECTION_POINT(name, arg);
</programlisting>
There are a few injection points already declared at strategic points
within the server code. After adding a new injection point the code needs
to be compiled in order for that injection point to be available in the
binary. Add-ins written in C-language can declare injection points in
- their own code using the same macro. The injection point names should
- use lower-case characters, with terms separated by dashes.
+ their own code using the same macro. The injection point names should use
+ lower-case characters, with terms separated by
+ dashes. <literal>arg</literal> is an optional argument value given to the
+ callback at run-time.
</para>
<para>
a two-step approach with the following macros:
<programlisting>
INJECTION_POINT_LOAD(name);
-INJECTION_POINT_CACHED(name);
+INJECTION_POINT_CACHED(name, arg);
</programlisting>
Before entering the critical section,
<literal>InjectionPointCallback</literal>:
<programlisting>
static void
-custom_injection_callback(const char *name, const void *private_data)
+custom_injection_callback(const char *name,
+ const void *private_data,
+ void *arg)
{
uint32 wait_event_info = WaitEventInjectionPointNew(name);
local_var = 123;
/* also execute the callback */
- INJECTION_POINT_CACHED("before-foobar");
+ INJECTION_POINT_CACHED("before-foobar", NULL);
}
#endif
</programlisting>
#ifdef USE_INJECTION_POINTS
if (GinPageIsLeaf(BufferGetPage(stack->buffer)))
- INJECTION_POINT("gin-leave-leaf-split-incomplete");
+ INJECTION_POINT("gin-leave-leaf-split-incomplete", NULL);
else
- INJECTION_POINT("gin-leave-internal-split-incomplete");
+ INJECTION_POINT("gin-leave-internal-split-incomplete", NULL);
#endif
/* search parent to lock */
static void
ginFinishOldSplit(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats, int access)
{
- INJECTION_POINT("gin-finish-incomplete-split");
+ INJECTION_POINT("gin-finish-incomplete-split", NULL);
elog(DEBUG1, "finishing incomplete split of block %u in gin index \"%s\"",
stack->blkno, RelationGetRelationName(btree->index));
interesting_attrs = bms_add_members(interesting_attrs, id_attrs);
block = ItemPointerGetBlockNumber(otid);
- INJECTION_POINT("heap_update-before-pin");
+ INJECTION_POINT("heap_update-before-pin", NULL);
buffer = ReadBuffer(relation, block);
page = BufferGetPage(buffer);
if (retries++ > 10000)
elog(ERROR, "giving up after too many tries to overwrite row");
- INJECTION_POINT("inplace-before-pin");
+ INJECTION_POINT("inplace-before-pin", NULL);
scan = systable_beginscan(relation, indexId, indexOK, snapshot,
nkeys, unconstify(ScanKeyData *, key));
oldtup = systable_getnext(scan);
*/
multi = GetNewMultiXactId(nmembers, &offset);
- INJECTION_POINT_CACHED("multixact-create-from-members");
+ INJECTION_POINT_CACHED("multixact-create-from-members", NULL);
/* Make an XLOG entry describing the new MXID. */
xlrec.mid = multi;
LWLockRelease(lock);
CHECK_FOR_INTERRUPTS();
- INJECTION_POINT("multixact-get-members-cv-sleep");
+ INJECTION_POINT("multixact-get-members-cv-sleep", NULL);
ConditionVariableSleep(&MultiXactState->nextoff_cv,
WAIT_EVENT_MULTIXACT_CREATION);
* This location needs to be after CheckPointGuts() to ensure that some
* work has already happened during this checkpoint.
*/
- INJECTION_POINT("create-restart-point");
+ INJECTION_POINT("create-restart-point", NULL);
/*
* Remember the prior checkpoint's redo ptr for
#ifdef USE_INJECTION_POINTS
if (idx->safe)
- INJECTION_POINT("reindex-conc-index-safe");
+ INJECTION_POINT("reindex-conc-index-safe", NULL);
else
- INJECTION_POINT("reindex-conc-index-not-safe");
+ INJECTION_POINT("reindex-conc-index-not-safe", NULL);
#endif
idx->tableId = RelationGetRelid(heapRel);
if (IS_INJECTION_POINT_ATTACHED("hash-aggregate-oversize-table"))
{
nbuckets = memory / TupleHashEntrySize();
- INJECTION_POINT_CACHED("hash-aggregate-oversize-table");
+ INJECTION_POINT_CACHED("hash-aggregate-oversize-table", NULL);
}
#endif
if (IS_INJECTION_POINT_ATTACHED("hash-aggregate-spill-1000"))
{
do_spill = true;
- INJECTION_POINT_CACHED("hash-aggregate-spill-1000");
+ INJECTION_POINT_CACHED("hash-aggregate-spill-1000", NULL);
}
}
#endif
static void
hash_agg_enter_spill_mode(AggState *aggstate)
{
- INJECTION_POINT("hash-aggregate-enter-spill-mode");
+ INJECTION_POINT("hash-aggregate-enter-spill-mode", NULL);
aggstate->hash_spill_mode = true;
hashagg_recompile_expressions(aggstate, aggstate->table_filled, true);
*/
hashagg_recompile_expressions(aggstate, true, true);
- INJECTION_POINT("hash-aggregate-process-batch");
+ INJECTION_POINT("hash-aggregate-process-batch", NULL);
for (;;)
{
TupleTableSlot *spillslot = aggstate->hash_spill_rslot;
{
npartitions = 1;
partition_bits = 0;
- INJECTION_POINT_CACHED("hash-aggregate-single-partition");
+ INJECTION_POINT_CACHED("hash-aggregate-single-partition", NULL);
}
#endif
minor;
gss_cred_id_t delegated_creds;
- INJECTION_POINT("backend-gssapi-startup");
+ INJECTION_POINT("backend-gssapi-startup", NULL);
/*
* Allocate subsidiary Port data for GSSAPI operations.
}
Assert(pq_buffer_remaining_data() == 0);
- INJECTION_POINT("backend-ssl-startup");
+ INJECTION_POINT("backend-ssl-startup", NULL);
r = be_tls_open_server(port);
* This injection point is put in a transaction block to work with a wait
* that uses a condition variable.
*/
- INJECTION_POINT("autovacuum-worker-start");
+ INJECTION_POINT("autovacuum-worker-start", NULL);
/*
* Compute the multixact age for which freezing is urgent. This is
PG_TRY();
{
- InjectionPointCached(injection_point);
+ InjectionPointCached(injection_point, NULL);
}
PG_FINALLY();
{
/* For testing client error handling */
#ifdef USE_INJECTION_POINTS
- INJECTION_POINT("backend-initialize");
+ INJECTION_POINT("backend-initialize", NULL);
if (IS_INJECTION_POINT_ATTACHED("backend-initialize-v2-error"))
{
/*
IdleInTransactionSessionTimeoutPending = false;
if (IdleInTransactionSessionTimeout > 0)
{
- INJECTION_POINT("idle-in-transaction-session-timeout");
+ INJECTION_POINT("idle-in-transaction-session-timeout", NULL);
ereport(FATAL,
(errcode(ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT),
errmsg("terminating connection due to idle-in-transaction timeout")));
TransactionTimeoutPending = false;
if (TransactionTimeout > 0)
{
- INJECTION_POINT("transaction-timeout");
+ INJECTION_POINT("transaction-timeout", NULL);
ereport(FATAL,
(errcode(ERRCODE_TRANSACTION_TIMEOUT),
errmsg("terminating connection due to transaction timeout")));
IdleSessionTimeoutPending = false;
if (IdleSessionTimeout > 0)
{
- INJECTION_POINT("idle-session-timeout");
+ INJECTION_POINT("idle-session-timeout", NULL);
ereport(FATAL,
(errcode(ERRCODE_IDLE_SESSION_TIMEOUT),
errmsg("terminating connection due to idle-session timeout")));
/* Injection point to help testing the recursive invalidation case */
if (first_iter)
{
- INJECTION_POINT("catcache-list-miss-systable-scan-started");
+ INJECTION_POINT("catcache-list-miss-systable-scan-started", NULL);
first_iter = false;
}
/* Must be at top of stack */
Assert(transInvalInfo->my_level == 1 && transInvalInfo->parent == NULL);
- INJECTION_POINT("transaction-end-process-inval");
+ INJECTION_POINT("transaction-end-process-inval", NULL);
if (isCommit)
{
load_domaintype_info(typentry);
}
- INJECTION_POINT("typecache-before-rel-type-cache-insert");
+ INJECTION_POINT("typecache-before-rel-type-cache-insert", NULL);
Assert(in_progress_offset + 1 == in_progress_list_len);
in_progress_list_len--;
if (!bootstrap)
{
pgstat_bestart_initial();
- INJECTION_POINT("init-pre-auth");
+ INJECTION_POINT("init-pre-auth", NULL);
}
/*
* Execute an injection point, if defined.
*/
void
-InjectionPointRun(const char *name)
+InjectionPointRun(const char *name, void *arg)
{
#ifdef USE_INJECTION_POINTS
InjectionPointCacheEntry *cache_entry;
cache_entry = InjectionPointCacheRefresh(name);
if (cache_entry)
- cache_entry->callback(name, cache_entry->private_data);
+ cache_entry->callback(name, cache_entry->private_data, arg);
#else
elog(ERROR, "Injection points are not supported by this build");
#endif
* Execute an injection point directly from the cache, if defined.
*/
void
-InjectionPointCached(const char *name)
+InjectionPointCached(const char *name, void *arg)
{
#ifdef USE_INJECTION_POINTS
InjectionPointCacheEntry *cache_entry;
cache_entry = injection_point_cache_get(name);
if (cache_entry)
- cache_entry->callback(name, cache_entry->private_data);
+ cache_entry->callback(name, cache_entry->private_data, arg);
#else
elog(ERROR, "Injection points are not supported by this build");
#endif
*/
#ifdef USE_INJECTION_POINTS
#define INJECTION_POINT_LOAD(name) InjectionPointLoad(name)
-#define INJECTION_POINT(name) InjectionPointRun(name)
-#define INJECTION_POINT_CACHED(name) InjectionPointCached(name)
+#define INJECTION_POINT(name, arg) InjectionPointRun(name, arg)
+#define INJECTION_POINT_CACHED(name, arg) InjectionPointCached(name, arg)
#define IS_INJECTION_POINT_ATTACHED(name) IsInjectionPointAttached(name)
#else
#define INJECTION_POINT_LOAD(name) ((void) name)
-#define INJECTION_POINT(name) ((void) name)
-#define INJECTION_POINT_CACHED(name) ((void) name)
+#define INJECTION_POINT(name, arg) ((void) name)
+#define INJECTION_POINT_CACHED(name, arg) ((void) name)
#define IS_INJECTION_POINT_ATTACHED(name) (false)
#endif
* Typedef for callback function launched by an injection point.
*/
typedef void (*InjectionPointCallback) (const char *name,
- const void *private_data);
+ const void *private_data,
+ void *arg);
extern Size InjectionPointShmemSize(void);
extern void InjectionPointShmemInit(void);
const void *private_data,
int private_data_size);
extern void InjectionPointLoad(const char *name);
-extern void InjectionPointRun(const char *name);
-extern void InjectionPointCached(const char *name);
+extern void InjectionPointRun(const char *name, void *arg);
+extern void InjectionPointCached(const char *name, void *arg);
extern bool IsInjectionPointAttached(const char *name);
extern bool InjectionPointDetach(const char *name);
static InjectionPointSharedState *inj_state = NULL;
extern PGDLLEXPORT void injection_error(const char *name,
- const void *private_data);
+ const void *private_data,
+ void *arg);
extern PGDLLEXPORT void injection_notice(const char *name,
- const void *private_data);
+ const void *private_data,
+ void *arg);
extern PGDLLEXPORT void injection_wait(const char *name,
- const void *private_data);
+ const void *private_data,
+ void *arg);
/* track if injection points attached in this process are linked to it */
static bool injection_point_local = false;
/* Set of callbacks available to be attached to an injection point. */
void
-injection_error(const char *name, const void *private_data)
+injection_error(const char *name, const void *private_data, void *arg)
{
InjectionPointCondition *condition = (InjectionPointCondition *) private_data;
}
void
-injection_notice(const char *name, const void *private_data)
+injection_notice(const char *name, const void *private_data, void *arg)
{
InjectionPointCondition *condition = (InjectionPointCondition *) private_data;
/* Wait on a condition variable, awaken by injection_points_wakeup() */
void
-injection_wait(const char *name, const void *private_data)
+injection_wait(const char *name, const void *private_data, void *arg)
{
uint32 old_wait_counts = 0;
int index = -1;
char *name = text_to_cstring(PG_GETARG_TEXT_PP(0));
pgstat_report_inj_fixed(0, 0, 1, 0, 0);
- INJECTION_POINT(name);
+ INJECTION_POINT(name, NULL);
PG_RETURN_VOID();
}
char *name = text_to_cstring(PG_GETARG_TEXT_PP(0));
pgstat_report_inj_fixed(0, 0, 0, 1, 0);
- INJECTION_POINT_CACHED(name);
+ INJECTION_POINT_CACHED(name, NULL);
PG_RETURN_VOID();
}
}
#ifdef USE_INJECTION_POINTS
-extern PGDLLEXPORT void inj_io_short_read(const char *name, const void *private_data);
-extern PGDLLEXPORT void inj_io_reopen(const char *name, const void *private_data);
+extern PGDLLEXPORT void inj_io_short_read(const char *name,
+ const void *private_data,
+ void *arg);
+extern PGDLLEXPORT void inj_io_reopen(const char *name,
+ const void *private_data,
+ void *arg);
void
-inj_io_short_read(const char *name, const void *private_data)
+inj_io_short_read(const char *name, const void *private_data, void *arg)
{
PgAioHandle *ioh;
}
void
-inj_io_reopen(const char *name, const void *private_data)
+inj_io_reopen(const char *name, const void *private_data, void *arg)
{
ereport(LOG,
errmsg("reopen injection point called, is enabled: %d",
MultiXactId id = PG_GETARG_TRANSACTIONID(0);
MultiXactMember *members;
- INJECTION_POINT("test-multixact-read");
+ INJECTION_POINT("test-multixact-read", NULL);
/* discard caches */
AtEOXact_MultiXact();