PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
regress_injection.c
Go to the documentation of this file.
1/*--------------------------------------------------------------------------
2 *
3 * regress_injection.c
4 * Functions supporting test-specific subject matter.
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/test/modules/injection_points/regress_injection.c
11 *
12 * -------------------------------------------------------------------------
13 */
14
15#include "postgres.h"
16
17#include "access/table.h"
18#include "fmgr.h"
19#include "miscadmin.h"
20#include "storage/procarray.h"
21#include "utils/xid8.h"
22
23/*
24 * removable_cutoff - for syscache-update-pruned.spec
25 *
26 * Wrapper around GetOldestNonRemovableTransactionId(). In general, this can
27 * move backward. runningcheck=false isolation tests can reasonably prevent
28 * that. For the causes of backward movement, see
29 * postgr.es/m/CAEze2Wj%2BV0kTx86xB_YbyaqTr5hnE_igdWAwuhSyjXBYscf5-Q%40mail.gmail.com
30 * and the header comment for ComputeXidHorizons(). One can assume this
31 * doesn't move backward if one arranges for concurrent activity not to reach
32 * AbortTransaction() and not to allocate an XID while connected to another
33 * database. Non-runningcheck tests can control most concurrent activity,
34 * except autovacuum and the isolationtester control connection. Neither
35 * allocates XIDs, and AbortTransaction() in those would justify test failure.
36 */
40{
41 Relation rel = NULL;
42 TransactionId xid;
43 FullTransactionId next_fxid_before,
44 next_fxid;
45
46 /* could take other relkinds callee takes, but we've not yet needed it */
47 if (!PG_ARGISNULL(0))
49
50 /*
51 * No lock or snapshot necessarily prevents oldestXid from advancing past
52 * "xid" while this function runs. That concerns us only in that we must
53 * not ascribe "xid" to the wrong epoch. (That may never arise in
54 * isolation testing, but let's set a good example.) As a crude solution,
55 * retry until nextXid doesn't change.
56 */
57 next_fxid = ReadNextFullTransactionId();
58 do
59 {
61 next_fxid_before = next_fxid;
63 next_fxid = ReadNextFullTransactionId();
64 } while (!FullTransactionIdEquals(next_fxid, next_fxid_before));
65
66 if (rel)
68
70 xid));
71}
uint32 TransactionId
Definition: c.h:623
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define AccessShareLock
Definition: lockdefs.h:36
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
uintptr_t Datum
Definition: postgres.h:69
TransactionId GetOldestNonRemovableTransactionId(Relation rel)
Definition: procarray.c:2005
Datum removable_cutoff(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(removable_cutoff)
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50
static FullTransactionId FullTransactionIdFromAllowableAt(FullTransactionId nextFullXid, TransactionId xid)
Definition: transam.h:381
FullTransactionId ReadNextFullTransactionId(void)
Definition: varsup.c:288
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:30