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"
21#include "storage/procarray.h"
22#include "utils/rel.h"
23#include "utils/xid8.h"
24
25/*
26 * removable_cutoff - for syscache-update-pruned.spec
27 *
28 * Wrapper around GetOldestNonRemovableTransactionId(). In general, this can
29 * move backward. runningcheck=false isolation tests can reasonably prevent
30 * that. For the causes of backward movement, see
31 * postgr.es/m/CAEze2Wj%2BV0kTx86xB_YbyaqTr5hnE_igdWAwuhSyjXBYscf5-Q%40mail.gmail.com
32 * and the header comment for ComputeXidHorizons(). One can assume this
33 * doesn't move backward if one (a) passes a shared catalog as the argument
34 * and (b) arranges for concurrent activity not to reach AbortTransaction().
35 * Non-runningcheck tests can control most concurrent activity, except
36 * autovacuum and the isolationtester control connection. AbortTransaction()
37 * in those would justify test failure. Seeing autoanalyze can allocate an
38 * XID in any database, (a) ensures we'll consistently not ignore those XIDs.
39 */
43{
44 Relation rel = NULL;
45 TransactionId xid;
46 FullTransactionId next_fxid_before,
47 next_fxid;
48
49 /* could take other relkinds callee takes, but we've not yet needed it */
50 if (!PG_ARGISNULL(0))
52
53 if (!rel->rd_rel->relisshared && autovacuum_start_daemon)
55 "removable_cutoff(non-shared-rel) can move backward under autovacuum=on");
56
57 /*
58 * No lock or snapshot necessarily prevents oldestXid from advancing past
59 * "xid" while this function runs. That concerns us only in that we must
60 * not ascribe "xid" to the wrong epoch. (That may never arise in
61 * isolation testing, but let's set a good example.) As a crude solution,
62 * retry until nextXid doesn't change.
63 */
64 next_fxid = ReadNextFullTransactionId();
65 do
66 {
68 next_fxid_before = next_fxid;
70 next_fxid = ReadNextFullTransactionId();
71 } while (!FullTransactionIdEquals(next_fxid, next_fxid_before));
72
73 if (rel)
75
77 xid));
78}
bool autovacuum_start_daemon
Definition: autovacuum.c:118
uint32 TransactionId
Definition: c.h:623
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:225
#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:123
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)
Form_pg_class rd_rel
Definition: rel.h:111
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