1/*-------------------------------------------------------------------------
2 *
3 * snapbuild.h
4 * Exports from replication/logical/snapbuild.c.
5 *
6 * Copyright (c) 2012-2019, 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
18typedef enum
19{
20 /*
21 * Initial state, we can't do much yet.
22 */
23 SNAPBUILD_START = -1,
24
25 /*
26 * Collecting committed transactions, to build the initial catalog
27 * snapshot.
28 */
29 SNAPBUILD_BUILDING_SNAPSHOT = 0,
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 */
39 SNAPBUILD_FULL_SNAPSHOT = 1,
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 */
46 SNAPBUILD_CONSISTENT = 2
47} SnapBuildState;
48
49/* forward declare so we don't have to expose the struct to the public */
50struct SnapBuild;
51typedef struct SnapBuild SnapBuild;
52
53/* forward declare so we don't have to include reorderbuffer.h */
54struct ReorderBuffer;
55
56/* forward declare so we don't have to include heapam_xlog.h */
57struct xl_heap_new_cid;
58struct xl_running_xacts;
59
60extern void CheckPointSnapBuild(void);
61
62extern SnapBuild *AllocateSnapshotBuilder(struct ReorderBuffer *cache,
63 TransactionId xmin_horizon, XLogRecPtr start_lsn,
64 bool need_full_snapshot);
65extern void FreeSnapshotBuilder(SnapBuild *cache);
66
67extern void SnapBuildSnapDecRefcount(Snapshot snap);
68
69extern Snapshot SnapBuildInitialSnapshot(SnapBuild *builder);
70extern const char *SnapBuildExportSnapshot(SnapBuild *snapstate);
71extern void SnapBuildClearExportedSnapshot(void);
72
73extern SnapBuildState SnapBuildCurrentState(SnapBuild *snapstate);
74extern Snapshot SnapBuildGetOrBuildSnapshot(SnapBuild *builder,
75 TransactionId xid);
76
77extern bool SnapBuildXactNeedsSkip(SnapBuild *snapstate, XLogRecPtr ptr);
78
79extern void SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn,
80 TransactionId xid, int nsubxacts,
81 TransactionId *subxacts);
82extern bool SnapBuildProcessChange(SnapBuild *builder, TransactionId xid,
83 XLogRecPtr lsn);
84extern void SnapBuildProcessNewCid(SnapBuild *builder, TransactionId xid,
85 XLogRecPtr lsn, struct xl_heap_new_cid *cid);
86extern void SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn,
87 struct xl_running_xacts *running);
88extern void SnapBuildSerializationPoint(SnapBuild *builder, XLogRecPtr lsn);
89
90#endif /* SNAPBUILD_H */
91