PostgreSQL Source Code  git master
snapmgr.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * snapmgr.h
4  * POSTGRES snapshot manager
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/utils/snapmgr.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef SNAPMGR_H
14 #define SNAPMGR_H
15 
16 #include "access/transam.h"
17 #include "utils/relcache.h"
18 #include "utils/resowner.h"
19 #include "utils/snapshot.h"
20 
21 
22 extern PGDLLIMPORT bool FirstSnapshotSet;
23 
26 
27 /* Variables representing various special snapshot semantics */
31 
32 #define SnapshotSelf (&SnapshotSelfData)
33 #define SnapshotAny (&SnapshotAnyData)
34 
35 /*
36  * We don't provide a static SnapshotDirty variable because it would be
37  * non-reentrant. Instead, users of that snapshot type should declare a
38  * local variable of type SnapshotData, and initialize it with this macro.
39  */
40 #define InitDirtySnapshot(snapshotdata) \
41  ((snapshotdata).snapshot_type = SNAPSHOT_DIRTY)
42 
43 /*
44  * Similarly, some initialization is required for a NonVacuumable snapshot.
45  * The caller must supply the visibility cutoff state to use (c.f.
46  * GlobalVisTestFor()).
47  */
48 #define InitNonVacuumableSnapshot(snapshotdata, vistestp) \
49  ((snapshotdata).snapshot_type = SNAPSHOT_NON_VACUUMABLE, \
50  (snapshotdata).vistest = (vistestp))
51 
52 /*
53  * Similarly, some initialization is required for SnapshotToast. We need
54  * to set lsn and whenTaken correctly to support snapshot_too_old.
55  */
56 #define InitToastSnapshot(snapshotdata, l, w) \
57  ((snapshotdata).snapshot_type = SNAPSHOT_TOAST, \
58  (snapshotdata).lsn = (l), \
59  (snapshotdata).whenTaken = (w))
60 
61 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
62 #define IsMVCCSnapshot(snapshot) \
63  ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \
64  (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
65 
66 extern Snapshot GetTransactionSnapshot(void);
67 extern Snapshot GetLatestSnapshot(void);
68 extern void SnapshotSetCommandId(CommandId curcid);
69 extern Snapshot GetOldestSnapshot(void);
70 
71 extern Snapshot GetCatalogSnapshot(Oid relid);
73 extern void InvalidateCatalogSnapshot(void);
75 
76 extern void PushActiveSnapshot(Snapshot snapshot);
77 extern void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level);
78 extern void PushCopiedSnapshot(Snapshot snapshot);
79 extern void UpdateActiveSnapshotCommandId(void);
80 extern void PopActiveSnapshot(void);
81 extern Snapshot GetActiveSnapshot(void);
82 extern bool ActiveSnapshotSet(void);
83 
84 extern Snapshot RegisterSnapshot(Snapshot snapshot);
85 extern void UnregisterSnapshot(Snapshot snapshot);
87 extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
88 
89 extern void AtSubCommit_Snapshot(int level);
90 extern void AtSubAbort_Snapshot(int level);
91 extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);
92 
93 extern void ImportSnapshot(const char *idstr);
94 extern bool XactHasExportedSnapshots(void);
95 extern void DeleteAllExportedSnapshotFiles(void);
96 extern void WaitForOlderSnapshots(TransactionId limitXmin, bool progress);
97 extern bool ThereAreNoPriorRegisteredSnapshots(void);
98 extern bool HaveRegisteredOrActiveSnapshot(void);
99 
100 extern char *ExportSnapshot(Snapshot snapshot);
101 
102 /*
103  * These live in procarray.c because they're intimately linked to the
104  * procarray contents, but thematically they better fit into snapmgr.h.
105  */
106 typedef struct GlobalVisState GlobalVisState;
114 
115 /*
116  * Utility functions for implementing visibility routines in table AMs.
117  */
118 extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
119 
120 /* Support for catalog timetravel for logical decoding */
121 struct HTAB;
122 extern struct HTAB *HistoricSnapshotGetTupleCids(void);
123 extern void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids);
124 extern void TeardownHistoricSnapshot(bool is_error);
125 extern bool HistoricSnapshotActive(void);
126 
127 extern Size EstimateSnapshotSpace(Snapshot snapshot);
128 extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
129 extern Snapshot RestoreSnapshot(char *start_address);
130 extern void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc);
131 
132 #endif /* SNAPMGR_H */
#define PGDLLIMPORT
Definition: c.h:1303
uint32 CommandId
Definition: c.h:653
uint32 TransactionId
Definition: c.h:639
size_t Size
Definition: c.h:592
int progress
Definition: pgbench.c:261
unsigned int Oid
Definition: postgres_ext.h:31
bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid)
Definition: procarray.c:4206
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:849
bool GlobalVisTestIsRemovableXid(GlobalVisState *state, TransactionId xid)
Definition: procarray.c:4248
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
Definition: procarray.c:4300
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition: snapmgr.c:1678
void AtSubAbort_Snapshot(int level)
Definition: snapmgr.c:959
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1716
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition: snapmgr.c:995
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1856
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:216
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:291
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:1665
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:352
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:836
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:648
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1775
void AtSubCommit_Snapshot(int level)
Definition: snapmgr.c:938
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:712
PGDLLIMPORT TransactionId TransactionXmin
Definition: snapmgr.c:98
TransactionId GlobalVisTestNonRemovableHorizon(GlobalVisState *state)
Definition: procarray.c:4286
char * ExportSnapshot(Snapshot snapshot)
Definition: snapmgr.c:1095
bool HistoricSnapshotActive(void)
Definition: snapmgr.c:1672
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1367
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:782
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition: snapmgr.c:85
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:794
bool XactHasExportedSnapshots(void)
Definition: snapmgr.c:1554
GlobalVisState * GlobalVisTestFor(Relation rel)
Definition: procarray.c:4091
void DeleteAllExportedSnapshotFiles(void)
Definition: snapmgr.c:1567
PGDLLIMPORT SnapshotData CatalogSnapshotData
Definition: snapmgr.c:83
bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid)
Definition: procarray.c:4314
bool HaveRegisteredOrActiveSnapshot(void)
Definition: snapmgr.c:1624
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:443
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition: snapmgr.c:1606
void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc)
Definition: snapmgr.c:1840
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:456
void PopActiveSnapshot(void)
Definition: snapmgr.c:743
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:700
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition: snapmgr.c:84
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1692
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Definition: indexcmds.c:428
void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids)
Definition: snapmgr.c:1649
PGDLLIMPORT bool FirstSnapshotSet
Definition: snapmgr.c:135
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:807
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:422
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Definition: snapmgr.c:662
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition: snapmgr.c:374
FullTransactionId GlobalVisTestNonRemovableFullHorizon(GlobalVisState *state)
Definition: procarray.c:4275
PGDLLIMPORT TransactionId RecentXmin
Definition: snapmgr.c:99
Snapshot GetOldestSnapshot(void)
Definition: snapmgr.c:323
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:770
Definition: dynahash.c:220
Definition: regguts.h:323