| 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 | |
| 18 | typedef 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 */ |
| 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 *cache, |
| 63 | TransactionId xmin_horizon, XLogRecPtr start_lsn, |
| 64 | bool need_full_snapshot); |
| 65 | extern void FreeSnapshotBuilder(SnapBuild *cache); |
| 66 | |
| 67 | extern void SnapBuildSnapDecRefcount(Snapshot snap); |
| 68 | |
| 69 | extern Snapshot SnapBuildInitialSnapshot(SnapBuild *builder); |
| 70 | extern const char *SnapBuildExportSnapshot(SnapBuild *snapstate); |
| 71 | extern void SnapBuildClearExportedSnapshot(void); |
| 72 | |
| 73 | extern SnapBuildState SnapBuildCurrentState(SnapBuild *snapstate); |
| 74 | extern Snapshot SnapBuildGetOrBuildSnapshot(SnapBuild *builder, |
| 75 | TransactionId xid); |
| 76 | |
| 77 | extern bool SnapBuildXactNeedsSkip(SnapBuild *snapstate, XLogRecPtr ptr); |
| 78 | |
| 79 | extern void SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, |
| 80 | TransactionId xid, int nsubxacts, |
| 81 | TransactionId *subxacts); |
| 82 | extern bool SnapBuildProcessChange(SnapBuild *builder, TransactionId xid, |
| 83 | XLogRecPtr lsn); |
| 84 | extern void SnapBuildProcessNewCid(SnapBuild *builder, TransactionId xid, |
| 85 | XLogRecPtr lsn, struct xl_heap_new_cid *cid); |
| 86 | extern void SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, |
| 87 | struct xl_running_xacts *running); |
| 88 | extern void SnapBuildSerializationPoint(SnapBuild *builder, XLogRecPtr lsn); |
| 89 | |
| 90 | #endif /* SNAPBUILD_H */ |
| 91 | |