PostgreSQL Source Code git master
Loading...
Searching...
No Matches
waitfuncs.c File Reference
#include "postgres.h"
#include "catalog/pg_type.h"
#include "storage/predicate_internals.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/array.h"
#include "utils/fmgrprotos.h"
#include "utils/wait_event.h"
Include dependency graph for waitfuncs.c:

Go to the source code of this file.

Macros

#define UINT32_ACCESS_ONCE(var)   ((uint32)(*((volatile uint32 *)&(var))))
 

Functions

Datum pg_isolation_test_session_is_blocked (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ UINT32_ACCESS_ONCE

#define UINT32_ACCESS_ONCE (   var)    ((uint32)(*((volatile uint32 *)&(var))))

Definition at line 23 of file waitfuncs.c.

Function Documentation

◆ pg_isolation_test_session_is_blocked()

Datum pg_isolation_test_session_is_blocked ( PG_FUNCTION_ARGS  )

Definition at line 39 of file waitfuncs.c.

40{
43 PGPROC *proc;
44 const char *wait_event_type;
50 int dummy;
51 int i,
52 j;
53
54 /* Check if blocked_pid is in an injection point. */
56 if (proc == NULL)
57 PG_RETURN_BOOL(false); /* session gone: definitely unblocked */
60 if (wait_event_type && strcmp("InjectionPoint", wait_event_type) == 0)
61 PG_RETURN_BOOL(true);
62
63 /* Validate the passed-in array */
66 elog(ERROR, "array must not contain nulls");
70
71 /*
72 * Get the PIDs of all sessions blocking the given session's attempt to
73 * acquire heavyweight locks.
74 */
77
83
84 /*
85 * Check if any of these are in the list of interesting PIDs, that being
86 * the sessions that the isolation tester is running. We don't use
87 * "arrayoverlaps" here, because it would lead to cache lookups and one of
88 * our goals is to run quickly with debug_discard_caches > 0. We expect
89 * blocking_pids to be usually empty and otherwise a very small number in
90 * isolation tester cases, so make that the outer loop of a naive search
91 * for a match.
92 */
93 for (i = 0; i < num_blocking_pids; i++)
94 for (j = 0; j < num_interesting_pids; j++)
95 {
97 PG_RETURN_BOOL(true);
98 }
99
100 /*
101 * Check if blocked_pid is waiting for a safe snapshot. We could in
102 * theory check the resulting array of blocker PIDs against the
103 * interesting PIDs list, but since there is no danger of autovacuum
104 * blocking GetSafeSnapshot there seems to be no point in expending cycles
105 * on allocating a buffer and searching for overlap; so it's presently
106 * sufficient for the isolation tester's purposes to use a single element
107 * buffer and check if the number of safe snapshot blockers is non-zero.
108 */
109 if (GetSafeSnapshotBlockingPids(blocked_pid, &dummy, 1) > 0)
110 PG_RETURN_BOOL(true);
111
112 PG_RETURN_BOOL(false);
113}
#define ARR_NDIM(a)
Definition array.h:290
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
#define ARR_DATA_PTR(a)
Definition array.h:322
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define ARR_ELEMTYPE(a)
Definition array.h:292
#define ARR_DIMS(a)
Definition array.h:294
bool array_contains_nulls(const ArrayType *array)
int ArrayGetNItems(int ndim, const int *dims)
Definition arrayutils.c:57
#define Assert(condition)
Definition c.h:873
int32_t int32
Definition c.h:542
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
int j
Definition isn.c:78
int i
Definition isn.c:77
Datum pg_blocking_pids(PG_FUNCTION_ARGS)
Definition lockfuncs.c:466
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
int GetSafeSnapshotBlockingPids(int blocked_pid, int *output, int output_size)
Definition predicate.c:1626
static int fb(int x)
PGPROC * BackendPidGetProc(int pid)
Definition procarray.c:3154
Definition proc.h:180
uint32 wait_event_info
Definition proc.h:296
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition wait_event.c:373
#define UINT32_ACCESS_ONCE(var)
Definition waitfuncs.c:23

References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), Assert, BackendPidGetProc(), DatumGetArrayTypeP, DirectFunctionCall1, elog, ERROR, fb(), GetSafeSnapshotBlockingPids(), i, Int32GetDatum(), j, pg_blocking_pids(), PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_BOOL, pgstat_get_wait_event_type(), UINT32_ACCESS_ONCE, and PGPROC::wait_event_info.