PostgreSQL Source Code  git master
snapbuild.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * snapbuild.h
4  * Exports from replication/logical/snapbuild.c.
5  *
6  * Copyright (c) 2012-2024, PostgreSQL Global Development Group
7  *
8  * src/include/replication/snapbuild.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef SNAPBUILD_H
13 #define SNAPBUILD_H
14 
15 #include "access/xlogdefs.h"
16 #include "utils/snapmgr.h"
17 
18 typedef enum
19 {
20  /*
21  * Initial state, we can't do much yet.
22  */
24 
25  /*
26  * Collecting committed transactions, to build the initial catalog
27  * snapshot.
28  */
30 
31  /*
32  * We have collected enough information to decode tuples in transactions
33  * that started after this.
34  *
35  * Once we reached this we start to collect changes. We cannot apply them
36  * yet, because they might be based on transactions that were still
37  * running when FULL_SNAPSHOT was reached.
38  */
40 
41  /*
42  * Found a point after SNAPBUILD_FULL_SNAPSHOT where all transactions that
43  * were running at that point finished. Till we reach that we hold off
44  * calling any commit callbacks.
45  */
48 
49 /* forward declare so we don't have to expose the struct to the public */
50 struct SnapBuild;
51 typedef struct SnapBuild SnapBuild;
52 
53 /* forward declare so we don't have to include reorderbuffer.h */
54 struct ReorderBuffer;
55 
56 /* forward declare so we don't have to include heapam_xlog.h */
57 struct xl_heap_new_cid;
58 struct xl_running_xacts;
59 
60 extern void CheckPointSnapBuild(void);
61 
62 extern SnapBuild *AllocateSnapshotBuilder(struct ReorderBuffer *reorder,
63  TransactionId xmin_horizon, XLogRecPtr start_lsn,
64  bool need_full_snapshot,
65  bool in_slot_creation,
66  XLogRecPtr two_phase_at);
67 extern void FreeSnapshotBuilder(SnapBuild *builder);
68 
69 extern void SnapBuildSnapDecRefcount(Snapshot snap);
70 
72 extern const char *SnapBuildExportSnapshot(SnapBuild *builder);
73 extern void SnapBuildClearExportedSnapshot(void);
74 extern void SnapBuildResetExportedSnapshotState(void);
75 
78 
79 extern bool SnapBuildXactNeedsSkip(SnapBuild *builder, XLogRecPtr ptr);
81 extern void SnapBuildSetTwoPhaseAt(SnapBuild *builder, XLogRecPtr ptr);
82 
83 extern void SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn,
84  TransactionId xid, int nsubxacts,
85  TransactionId *subxacts, uint32 xinfo);
86 extern bool SnapBuildProcessChange(SnapBuild *builder, TransactionId xid,
87  XLogRecPtr lsn);
88 extern void SnapBuildProcessNewCid(SnapBuild *builder, TransactionId xid,
89  XLogRecPtr lsn,
90  struct xl_heap_new_cid *xlrec);
91 extern void SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn,
92  struct xl_running_xacts *running);
93 extern void SnapBuildSerializationPoint(SnapBuild *builder, XLogRecPtr lsn);
94 
95 extern bool SnapBuildSnapshotExists(XLogRecPtr lsn);
96 
97 #endif /* SNAPBUILD_H */
unsigned int uint32
Definition: c.h:506
uint32 TransactionId
Definition: c.h:652
void SnapBuildProcessNewCid(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn, struct xl_heap_new_cid *xlrec)
Definition: snapbuild.c:828
void SnapBuildSnapDecRefcount(Snapshot snap)
Definition: snapbuild.c:467
bool SnapBuildXactNeedsSkip(SnapBuild *builder, XLogRecPtr ptr)
Definition: snapbuild.c:443
void SnapBuildResetExportedSnapshotState(void)
Definition: snapbuild.c:766
void SnapBuildSetTwoPhaseAt(SnapBuild *builder, XLogRecPtr ptr)
Definition: snapbuild.c:434
bool SnapBuildProcessChange(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn)
Definition: snapbuild.c:778
const char * SnapBuildExportSnapshot(SnapBuild *builder)
Definition: snapbuild.c:678
XLogRecPtr SnapBuildGetTwoPhaseAt(SnapBuild *builder)
Definition: snapbuild.c:425
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:416
void FreeSnapshotBuilder(SnapBuild *builder)
Definition: snapbuild.c:372
bool SnapBuildSnapshotExists(XLogRecPtr lsn)
Definition: snapbuild.c:2159
void CheckPointSnapBuild(void)
Definition: snapbuild.c:2071
Snapshot SnapBuildGetOrBuildSnapshot(SnapBuild *builder)
Definition: snapbuild.c:718
Snapshot SnapBuildInitialSnapshot(SnapBuild *builder)
Definition: snapbuild.c:579
SnapBuildState
Definition: snapbuild.h:19
@ SNAPBUILD_START
Definition: snapbuild.h:23
@ SNAPBUILD_BUILDING_SNAPSHOT
Definition: snapbuild.h:29
@ SNAPBUILD_FULL_SNAPSHOT
Definition: snapbuild.h:39
@ SNAPBUILD_CONSISTENT
Definition: snapbuild.h:46
void SnapBuildSerializationPoint(SnapBuild *builder, XLogRecPtr lsn)
Definition: snapbuild.c:1609
void SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid, int nsubxacts, TransactionId *subxacts, uint32 xinfo)
Definition: snapbuild.c:1034
void SnapBuildClearExportedSnapshot(void)
Definition: snapbuild.c:739
void SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, struct xl_running_xacts *running)
Definition: snapbuild.c:1227
SnapBuild * AllocateSnapshotBuilder(struct ReorderBuffer *reorder, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot, bool in_slot_creation, XLogRecPtr two_phase_at)
Definition: snapbuild.c:324
uint64 XLogRecPtr
Definition: xlogdefs.h:21