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-2023, 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:1326
uint32 CommandId
Definition: c.h:655
uint32 TransactionId
Definition: c.h:641
size_t Size
Definition: c.h:594
int progress
Definition: pgbench.c:261
unsigned int Oid
Definition: postgres_ext.h:31
bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid)
Definition: procarray.c:4126
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:830
bool GlobalVisTestIsRemovableXid(GlobalVisState *state, TransactionId xid)
Definition: procarray.c:4168
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
Definition: procarray.c:4220
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition: snapmgr.c:1653
void AtSubAbort_Snapshot(int level)
Definition: snapmgr.c:935
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1691
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition: snapmgr.c:971
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1831
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:197
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:272
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:1640
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:333
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:817
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:629
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1750
void AtSubCommit_Snapshot(int level)
Definition: snapmgr.c:914
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:693
PGDLLIMPORT TransactionId TransactionXmin
Definition: snapmgr.c:104
TransactionId GlobalVisTestNonRemovableHorizon(GlobalVisState *state)
Definition: procarray.c:4206
char * ExportSnapshot(Snapshot snapshot)
Definition: snapmgr.c:1071
bool HistoricSnapshotActive(void)
Definition: snapmgr.c:1647
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1342
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:763
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition: snapmgr.c:91
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:775
bool XactHasExportedSnapshots(void)
Definition: snapmgr.c:1529
GlobalVisState * GlobalVisTestFor(Relation rel)
Definition: procarray.c:4011
void DeleteAllExportedSnapshotFiles(void)
Definition: snapmgr.c:1542
PGDLLIMPORT SnapshotData CatalogSnapshotData
Definition: snapmgr.c:89
bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid)
Definition: procarray.c:4234
bool HaveRegisteredOrActiveSnapshot(void)
Definition: snapmgr.c:1599
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:424
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition: snapmgr.c:1581
void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc)
Definition: snapmgr.c:1815
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:437
void PopActiveSnapshot(void)
Definition: snapmgr.c:724
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:681
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition: snapmgr.c:90
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1667
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Definition: indexcmds.c:418
void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids)
Definition: snapmgr.c:1624
PGDLLIMPORT bool FirstSnapshotSet
Definition: snapmgr.c:141
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:788
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:403
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Definition: snapmgr.c:643
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition: snapmgr.c:355
FullTransactionId GlobalVisTestNonRemovableFullHorizon(GlobalVisState *state)
Definition: procarray.c:4195
PGDLLIMPORT TransactionId RecentXmin
Definition: snapmgr.c:105
Snapshot GetOldestSnapshot(void)
Definition: snapmgr.c:304
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:751
Definition: dynahash.c:220
Definition: regguts.h:323