gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 line
5.8KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * snapmgr.h
  4. * POSTGRES snapshot manager
  5. *
  6. * Portions Copyright (c) 1996-2019, 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. #include "access/transam.h"
  16. #include "fmgr.h"
  17. #include "utils/relcache.h"
  18. #include "utils/resowner.h"
  19. #include "utils/snapshot.h"
  20. /*
  21. * The structure used to map times to TransactionId values for the "snapshot
  22. * too old" feature must have a few entries at the tail to hold old values;
  23. * otherwise the lookup will often fail and the expected early pruning or
  24. * vacuum will not usually occur. It is best if this padding is for a number
  25. * of minutes greater than a thread would normally be stalled, but it's OK if
  26. * early vacuum opportunities are occasionally missed, so there's no need to
  27. * use an extreme value or get too fancy. 10 minutes seems plenty.
  28. */
  29. #define OLD_SNAPSHOT_PADDING_ENTRIES 10
  30. #define OLD_SNAPSHOT_TIME_MAP_ENTRIES (old_snapshot_threshold + OLD_SNAPSHOT_PADDING_ENTRIES)
  31. /*
  32. * Common definition of relation properties that allow early pruning/vacuuming
  33. * when old_snapshot_threshold >= 0.
  34. */
  35. #define RelationAllowsEarlyPruning(rel) \
  36. ( \
  37. RelationNeedsWAL(rel) \
  38. && !IsCatalogRelation(rel) \
  39. && !RelationIsAccessibleInLogicalDecoding(rel) \
  40. )
  41. #define EarlyPruningEnabled(rel) (old_snapshot_threshold >= 0 && RelationAllowsEarlyPruning(rel))
  42. /* GUC variables */
  43. extern PGDLLIMPORT int old_snapshot_threshold;
  44. extern Size SnapMgrShmemSize(void);
  45. extern void SnapMgrInit(void);
  46. extern TimestampTz GetSnapshotCurrentTimestamp(void);
  47. extern TimestampTz GetOldSnapshotThresholdTimestamp(void);
  48. extern bool FirstSnapshotSet;
  49. extern PGDLLIMPORT TransactionId TransactionXmin;
  50. extern PGDLLIMPORT TransactionId RecentXmin;
  51. extern PGDLLIMPORT TransactionId RecentGlobalXmin;
  52. extern PGDLLIMPORT TransactionId RecentGlobalDataXmin;
  53. /* Variables representing various special snapshot semantics */
  54. extern PGDLLIMPORT SnapshotData SnapshotSelfData;
  55. extern PGDLLIMPORT SnapshotData SnapshotAnyData;
  56. extern PGDLLIMPORT SnapshotData CatalogSnapshotData;
  57. #define SnapshotSelf (&SnapshotSelfData)
  58. #define SnapshotAny (&SnapshotAnyData)
  59. /*
  60. * We don't provide a static SnapshotDirty variable because it would be
  61. * non-reentrant. Instead, users of that snapshot type should declare a
  62. * local variable of type SnapshotData, and initialize it with this macro.
  63. */
  64. #define InitDirtySnapshot(snapshotdata) \
  65. ((snapshotdata).snapshot_type = SNAPSHOT_DIRTY)
  66. /*
  67. * Similarly, some initialization is required for a NonVacuumable snapshot.
  68. * The caller must supply the xmin horizon to use (e.g., RecentGlobalXmin).
  69. */
  70. #define InitNonVacuumableSnapshot(snapshotdata, xmin_horizon) \
  71. ((snapshotdata).snapshot_type = SNAPSHOT_NON_VACUUMABLE, \
  72. (snapshotdata).xmin = (xmin_horizon))
  73. /*
  74. * Similarly, some initialization is required for SnapshotToast. We need
  75. * to set lsn and whenTaken correctly to support snapshot_too_old.
  76. */
  77. #define InitToastSnapshot(snapshotdata, l, w) \
  78. ((snapshotdata).snapshot_type = SNAPSHOT_TOAST, \
  79. (snapshotdata).lsn = (l), \
  80. (snapshotdata).whenTaken = (w))
  81. /* This macro encodes the knowledge of which snapshots are MVCC-safe */
  82. #define IsMVCCSnapshot(snapshot) \
  83. ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \
  84. (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
  85. extern Snapshot GetTransactionSnapshot(void);
  86. extern Snapshot GetLatestSnapshot(void);
  87. extern void SnapshotSetCommandId(CommandId curcid);
  88. extern Snapshot GetOldestSnapshot(void);
  89. extern Snapshot GetCatalogSnapshot(Oid relid);
  90. extern Snapshot GetNonHistoricCatalogSnapshot(Oid relid);
  91. extern void InvalidateCatalogSnapshot(void);
  92. extern void InvalidateCatalogSnapshotConditionally(void);
  93. extern void PushActiveSnapshot(Snapshot snapshot);
  94. extern void PushCopiedSnapshot(Snapshot snapshot);
  95. extern void UpdateActiveSnapshotCommandId(void);
  96. extern void PopActiveSnapshot(void);
  97. extern Snapshot GetActiveSnapshot(void);
  98. extern bool ActiveSnapshotSet(void);
  99. extern Snapshot RegisterSnapshot(Snapshot snapshot);
  100. extern void UnregisterSnapshot(Snapshot snapshot);
  101. extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner);
  102. extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
  103. extern FullTransactionId GetFullRecentGlobalXmin(void);
  104. extern void AtSubCommit_Snapshot(int level);
  105. extern void AtSubAbort_Snapshot(int level);
  106. extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);
  107. extern void ImportSnapshot(const char *idstr);
  108. extern bool XactHasExportedSnapshots(void);
  109. extern void DeleteAllExportedSnapshotFiles(void);
  110. extern bool ThereAreNoPriorRegisteredSnapshots(void);
  111. extern TransactionId TransactionIdLimitedForOldSnapshots(TransactionId recentXmin,
  112. Relation relation);
  113. extern void MaintainOldSnapshotTimeMapping(TimestampTz whenTaken,
  114. TransactionId xmin);
  115. extern char *ExportSnapshot(Snapshot snapshot);
  116. /*
  117. * Utility functions for implementing visibility routines in table AMs.
  118. */
  119. extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
  120. /* Support for catalog timetravel for logical decoding */
  121. struct HTAB;
  122. extern struct HTAB *HistoricSnapshotGetTupleCids(void);
  123. extern void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB *tuplecids);
  124. extern void TeardownHistoricSnapshot(bool is_error);
  125. extern bool HistoricSnapshotActive(void);
  126. extern Size EstimateSnapshotSpace(Snapshot snapshot);
  127. extern void SerializeSnapshot(Snapshot snapshot, char *start_address);
  128. extern Snapshot RestoreSnapshot(char *start_address);
  129. extern void RestoreTransactionSnapshot(Snapshot snapshot, void *master_pgproc);
  130. #endif /* SNAPMGR_H */
上海开阖软件有限公司 沪ICP备12045867号-1