PostgreSQL Source Code: src/include/utils/snapmgr.h Source File

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-2025, 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
22extern PGDLLIMPORT bool FirstSnapshotSet;
23
24extern PGDLLIMPORT TransactionId TransactionXmin;
25extern PGDLLIMPORT TransactionId RecentXmin;
26
27/* Variables representing various special snapshot semantics */
28extern PGDLLIMPORT SnapshotData SnapshotSelfData;
29extern PGDLLIMPORT SnapshotData SnapshotAnyData;
30extern PGDLLIMPORT SnapshotData SnapshotToastData;
31
32 #define SnapshotSelf (&SnapshotSelfData)
33 #define SnapshotAny (&SnapshotAnyData)
34
35/* Use get_toast_snapshot() for the TOAST snapshot */
36
37/*
38 * We don't provide a static SnapshotDirty variable because it would be
39 * non-reentrant. Instead, users of that snapshot type should declare a
40 * local variable of type SnapshotData, and initialize it with this macro.
41 */
42 #define InitDirtySnapshot(snapshotdata) \
43 ((snapshotdata).snapshot_type = SNAPSHOT_DIRTY)
44
45/*
46 * Similarly, some initialization is required for a NonVacuumable snapshot.
47 * The caller must supply the visibility cutoff state to use (c.f.
48 * GlobalVisTestFor()).
49 */
50 #define InitNonVacuumableSnapshot(snapshotdata, vistestp) \
51 ((snapshotdata).snapshot_type = SNAPSHOT_NON_VACUUMABLE, \
52 (snapshotdata).vistest = (vistestp))
53
54/* This macro encodes the knowledge of which snapshots are MVCC-safe */
55 #define IsMVCCSnapshot(snapshot) \
56 ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \
57 (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
58
59 #define IsHistoricMVCCSnapshot(snapshot) \
60 ((snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
61
62extern Snapshot GetTransactionSnapshot(void);
63extern Snapshot GetLatestSnapshot(void);
64extern void SnapshotSetCommandId(CommandId curcid);
65
66extern Snapshot GetCatalogSnapshot(Oid relid);
67extern Snapshot GetNonHistoricCatalogSnapshot(Oid relid);
68extern void InvalidateCatalogSnapshot(void);
69extern void InvalidateCatalogSnapshotConditionally(void);
70
71extern void PushActiveSnapshot(Snapshot snapshot);
72extern void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level);
73extern void PushCopiedSnapshot(Snapshot snapshot);
74extern void UpdateActiveSnapshotCommandId(void);
75extern void PopActiveSnapshot(void);
76extern Snapshot GetActiveSnapshot(void);
77extern bool ActiveSnapshotSet(void);
78
79extern Snapshot RegisterSnapshot(Snapshot snapshot);
80extern void UnregisterSnapshot(Snapshot snapshot);
81extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner);
82extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
83
84extern void AtSubCommit_Snapshot(int level);
85extern void AtSubAbort_Snapshot(int level);
86extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);
87
88extern void ImportSnapshot(const char *idstr);
89extern bool XactHasExportedSnapshots(void);
90extern void DeleteAllExportedSnapshotFiles(void);
91extern void WaitForOlderSnapshots(TransactionId limitXmin, bool progress);
92extern bool ThereAreNoPriorRegisteredSnapshots(void);
93extern bool HaveRegisteredOrActiveSnapshot(void);
94
95extern char *ExportSnapshot(Snapshot snapshot);
96
97/*
98 * These live in procarray.c because they're intimately linked to the
99 * procarray contents, but thematically they better fit into snapmgr.h.
100 */
101 typedef struct GlobalVisState GlobalVisState;
102extern GlobalVisState *GlobalVisTestFor(Relation rel);
103extern bool GlobalVisTestIsRemovableXid(GlobalVisState *state, TransactionId xid);
104extern bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid);
105extern bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid);
106extern bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid);
107
108/*
109 * Utility functions for implementing visibility routines in table AMs.
110 */
111extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
112
113/* Support for catalog timetravel for logical decoding */
114struct HTAB;
115extern struct HTAB *HistoricSnapshotGetTupleCids(void);
116extern void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids);
117extern void TeardownHistoricSnapshot(bool is_error);
118extern bool HistoricSnapshotActive(void);
119
120extern Size EstimateSnapshotSpace(Snapshot snapshot);
121extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
122extern Snapshot RestoreSnapshot(char *start_address);
123extern void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc);
124
125#endif /* SNAPMGR_H */
#define PGDLLIMPORT
Definition: c.h:1319
uint32 CommandId
Definition: c.h:671
uint32 TransactionId
Definition: c.h:657
size_t Size
Definition: c.h:610
static int progress
Definition: pgbench.c:262
unsigned int Oid
Definition: postgres_ext.h:32
bool GlobalVisTestIsRemovableFullXid(GlobalVisState *state, FullTransactionId fxid)
Definition: procarray.c:4184
void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:877
struct HTAB * HistoricSnapshotGetTupleCids(void)
Definition: snapmgr.c:1696
bool GlobalVisTestIsRemovableXid(GlobalVisState *state, TransactionId xid)
Definition: procarray.c:4226
bool GlobalVisCheckRemovableFullXid(Relation rel, FullTransactionId fxid)
Definition: procarray.c:4248
void AtSubAbort_Snapshot(int level)
Definition: snapmgr.c:980
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1734
void AtEOXact_Snapshot(bool isCommit, bool resetXmin)
Definition: snapmgr.c:1014
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: snapmgr.c:1870
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:271
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:353
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:1683
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:384
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:864
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:680
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1791
void AtSubCommit_Snapshot(int level)
Definition: snapmgr.c:959
PGDLLIMPORT SnapshotData SnapshotToastData
Definition: snapmgr.c:145
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:742
PGDLLIMPORT TransactionId TransactionXmin
Definition: snapmgr.c:158
bool HistoricSnapshotActive(void)
Definition: snapmgr.c:1690
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1385
bool ActiveSnapshotSet(void)
Definition: snapmgr.c:810
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition: snapmgr.c:144
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:822
bool XactHasExportedSnapshots(void)
Definition: snapmgr.c:1572
void DeleteAllExportedSnapshotFiles(void)
Definition: snapmgr.c:1585
bool GlobalVisCheckRemovableXid(Relation rel, TransactionId xid)
Definition: procarray.c:4262
bool HaveRegisteredOrActiveSnapshot(void)
Definition: snapmgr.c:1642
void InvalidateCatalogSnapshotConditionally(void)
Definition: snapmgr.c:475
bool ThereAreNoPriorRegisteredSnapshots(void)
Definition: snapmgr.c:1624
void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc)
Definition: snapmgr.c:1854
GlobalVisState * GlobalVisTestFor(Relation rel)
Definition: procarray.c:4069
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:488
void PopActiveSnapshot(void)
Definition: snapmgr.c:773
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:730
char * ExportSnapshot(Snapshot snapshot)
Definition: snapmgr.c:1113
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition: snapmgr.c:143
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1710
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Definition: indexcmds.c:434
void SetupHistoricSnapshot(Snapshot historic_snapshot, struct HTAB *tuplecids)
Definition: snapmgr.c:1667
PGDLLIMPORT bool FirstSnapshotSet
Definition: snapmgr.c:192
Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)
Definition: snapmgr.c:835
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:454
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Definition: snapmgr.c:694
Snapshot GetNonHistoricCatalogSnapshot(Oid relid)
Definition: snapmgr.c:406
PGDLLIMPORT TransactionId RecentXmin
Definition: snapmgr.c:159
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:798
Definition: dynahash.c:222
Definition: rel.h:56
Definition: regguts.h:323

AltStyle によって変換されたページ (->オリジナル) /