1 /*
2  * commit_ts.h
3  *
4  * PostgreSQL commit timestamp manager
5  *
6  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/access/commit_ts.h
10  */
11 #ifndef COMMIT_TS_H
12 #define COMMIT_TS_H
13 
14 #include "access/xlog.h"
15 #include "datatype/timestamp.h"
16 #include "replication/origin.h"
17 #include "storage/sync.h"
18 #include "utils/guc.h"
19 
20 
21 extern PGDLLIMPORT bool track_commit_timestamp;
22 
23 extern bool check_track_commit_timestamp(bool *newval, void **extra,
24 										 GucSource source);
25 
26 extern void TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
27 										   TransactionId *subxids, TimestampTz timestamp,
28 										   RepOriginId nodeid);
29 extern bool TransactionIdGetCommitTsData(TransactionId xid,
30 										 TimestampTz *ts, RepOriginId *nodeid);
31 extern TransactionId GetLatestCommitTsData(TimestampTz *ts,
32 										   RepOriginId *nodeid);
33 
34 extern Size CommitTsShmemBuffers(void);
35 extern Size CommitTsShmemSize(void);
36 extern void CommitTsShmemInit(void);
37 extern void BootStrapCommitTs(void);
38 extern void StartupCommitTs(void);
39 extern void CommitTsParameterChange(bool newvalue, bool oldvalue);
40 extern void CompleteCommitTsInitialization(void);
41 extern void CheckPointCommitTs(void);
42 extern void ExtendCommitTs(TransactionId newestXact);
43 extern void TruncateCommitTs(TransactionId oldestXact);
44 extern void SetCommitTsLimit(TransactionId oldestXact,
45 							 TransactionId newestXact);
46 extern void AdvanceOldestCommitTsXid(TransactionId oldestXact);
47 
48 extern int	committssyncfiletag(const FileTag *ftag, char *path);
49 
50 /* XLOG stuff */
51 #define COMMIT_TS_ZEROPAGE		0x00
52 #define COMMIT_TS_TRUNCATE		0x10
53 
54 typedef struct xl_commit_ts_set
55 {
56 	TimestampTz timestamp;
57 	RepOriginId nodeid;
58 	TransactionId mainxid;
59 	/* subxact Xids follow */
60 }			xl_commit_ts_set;
61 
62 #define SizeOfCommitTsSet	(offsetof(xl_commit_ts_set, mainxid) + \
63 							 sizeof(TransactionId))
64 
65 typedef struct xl_commit_ts_truncate
66 {
67 	int			pageno;
68 	TransactionId oldestXid;
69 } xl_commit_ts_truncate;
70 
71 #define SizeOfCommitTsTruncate	(offsetof(xl_commit_ts_truncate, oldestXid) + \
72 								 sizeof(TransactionId))
73 
74 extern void commit_ts_redo(XLogReaderState *record);
75 extern void commit_ts_desc(StringInfo buf, XLogReaderState *record);
76 extern const char *commit_ts_identify(uint8 info);
77 
78 #endif							/* COMMIT_TS_H */
79