PostgreSQL Source Code  git master
multixact.h
Go to the documentation of this file.
1 /*
2  * multixact.h
3  *
4  * PostgreSQL multi-transaction-log manager
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/access/multixact.h
10  */
11 #ifndef MULTIXACT_H
12 #define MULTIXACT_H
13 
14 #include "access/xlogreader.h"
15 #include "lib/stringinfo.h"
16 #include "storage/sync.h"
17 
18 
19 /*
20  * The first two MultiXactId values are reserved to store the truncation Xid
21  * and epoch of the first segment, so we start assigning multixact values from
22  * 2.
23  */
24 #define InvalidMultiXactId ((MultiXactId) 0)
25 #define FirstMultiXactId ((MultiXactId) 1)
26 #define MaxMultiXactId ((MultiXactId) 0xFFFFFFFF)
27 
28 #define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId)
29 
30 #define MaxMultiXactOffset ((MultiXactOffset) 0xFFFFFFFF)
31 
32 /*
33  * Possible multixact lock modes ("status"). The first four modes are for
34  * tuple locks (FOR KEY SHARE, FOR SHARE, FOR NO KEY UPDATE, FOR UPDATE); the
35  * next two are used for update and delete modes.
36  */
37 typedef enum
38 {
43  /* an update that doesn't touch "key" columns */
45  /* other updates, and delete */
48 
49 #define MaxMultiXactStatus MultiXactStatusUpdate
50 
51 /* does a status value correspond to a tuple update? */
52 #define ISUPDATE_from_mxstatus(status) \
53  ((status) > MultiXactStatusForUpdate)
54 
55 
56 typedef struct MultiXactMember
57 {
61 
62 
63 /* ----------------
64  * multixact-related XLOG entries
65  * ----------------
66  */
67 
68 #define XLOG_MULTIXACT_ZERO_OFF_PAGE 0x00
69 #define XLOG_MULTIXACT_ZERO_MEM_PAGE 0x10
70 #define XLOG_MULTIXACT_CREATE_ID 0x20
71 #define XLOG_MULTIXACT_TRUNCATE_ID 0x30
72 
73 typedef struct xl_multixact_create
74 {
75  MultiXactId mid; /* new MultiXact's ID */
76  MultiXactOffset moff; /* its starting offset in members file */
77  int32 nmembers; /* number of member XIDs */
80 
81 #define SizeOfMultiXactCreate (offsetof(xl_multixact_create, members))
82 
83 typedef struct xl_multixact_truncate
84 {
86 
87  /* to-be-truncated range of multixact offsets */
88  MultiXactId startTruncOff; /* just for completeness' sake */
90 
91  /* to-be-truncated range of multixact members */
95 
96 #define SizeOfMultiXactTruncate (sizeof(xl_multixact_truncate))
97 
98 
100  MultiXactStatus status1, TransactionId xid2,
101  MultiXactStatus status2);
103  MultiXactStatus status);
104 extern MultiXactId MultiXactIdCreateFromMembers(int nmembers,
105  MultiXactMember *members);
106 
107 extern MultiXactId ReadNextMultiXactId(void);
108 extern void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next);
109 extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
110 extern void MultiXactIdSetOldestMember(void);
111 extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
112  bool from_pgupgrade, bool isLockOnly);
113 extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
114 extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
115  MultiXactId multi2);
116 
117 extern int multixactoffsetssyncfiletag(const FileTag *ftag, char *path);
118 extern int multixactmemberssyncfiletag(const FileTag *ftag, char *path);
119 
120 extern void AtEOXact_MultiXact(void);
121 extern void AtPrepare_MultiXact(void);
122 extern void PostPrepare_MultiXact(TransactionId xid);
123 
124 extern Size MultiXactShmemSize(void);
125 extern void MultiXactShmemInit(void);
126 extern void BootStrapMultiXact(void);
127 extern void StartupMultiXact(void);
128 extern void TrimMultiXact(void);
129 extern void SetMultiXactIdLimit(MultiXactId oldest_datminmxid,
130  Oid oldest_datoid,
131  bool is_startup);
132 extern void MultiXactGetCheckptMulti(bool is_shutdown,
133  MultiXactId *nextMulti,
134  MultiXactOffset *nextMultiOffset,
135  MultiXactId *oldestMulti,
136  Oid *oldestMultiDB);
137 extern void CheckPointMultiXact(void);
138 extern MultiXactId GetOldestMultiXactId(void);
139 extern void TruncateMultiXact(MultiXactId newOldestMulti,
140  Oid newOldestMultiDB);
141 extern void MultiXactSetNextMXact(MultiXactId nextMulti,
142  MultiXactOffset nextMultiOffset);
143 extern void MultiXactAdvanceNextMXact(MultiXactId minMulti,
144  MultiXactOffset minMultiOffset);
145 extern void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB);
146 extern int MultiXactMemberFreezeThreshold(void);
147 
148 extern void multixact_twophase_recover(TransactionId xid, uint16 info,
149  void *recdata, uint32 len);
151  void *recdata, uint32 len);
153  void *recdata, uint32 len);
154 
155 extern void multixact_redo(XLogReaderState *record);
156 extern void multixact_desc(StringInfo buf, XLogReaderState *record);
157 extern const char *multixact_identify(uint8 info);
158 extern char *mxid_to_string(MultiXactId multi, int nmembers,
159  MultiXactMember *members);
160 
161 #endif /* MULTIXACT_H */
static int32 next
Definition: blutils.c:222
unsigned short uint16
Definition: c.h:508
unsigned int uint32
Definition: c.h:509
signed int int32
Definition: c.h:497
uint32 MultiXactOffset
Definition: c.h:667
TransactionId MultiXactId
Definition: c.h:665
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:401
unsigned char uint8
Definition: c.h:507
uint32 TransactionId
Definition: c.h:655
size_t Size
Definition: c.h:608
const char * multixact_identify(uint8 info)
Definition: mxactdesc.c:84
void MultiXactShmemInit(void)
Definition: multixact.c:1964
MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
Definition: multixact.c:487
void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next)
Definition: multixact.c:791
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3317
void multixact_redo(XLogReaderState *record)
Definition: multixact.c:3394
MultiXactStatus
Definition: multixact.h:38
@ MultiXactStatusForShare
Definition: multixact.h:40
@ MultiXactStatusForNoKeyUpdate
Definition: multixact.h:41
@ MultiXactStatusNoKeyUpdate
Definition: multixact.h:44
@ MultiXactStatusUpdate
Definition: multixact.h:46
@ MultiXactStatusForUpdate
Definition: multixact.h:42
@ MultiXactStatusForKeyShare
Definition: multixact.h:39
int multixactoffsetssyncfiletag(const FileTag *ftag, char *path)
Definition: multixact.c:3575
void multixact_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: multixact.c:1920
void MultiXactSetNextMXact(MultiXactId nextMulti, MultiXactOffset nextMultiOffset)
Definition: multixact.c:2328
void multixact_twophase_recover(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: multixact.c:1899
void AtPrepare_MultiXact(void)
Definition: multixact.c:1836
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3331
void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB)
Definition: multixact.c:2536
bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
Definition: multixact.c:599
void MultiXactIdSetOldestMember(void)
Definition: multixact.c:673
void multixact_desc(StringInfo buf, XLogReaderState *record)
Definition: mxactdesc.c:50
void PostPrepare_MultiXact(TransactionId xid)
Definition: multixact.c:1850
Size MultiXactShmemSize(void)
Definition: multixact.c:1947
void multixact_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: multixact.c:1935
void MultiXactGetCheckptMulti(bool is_shutdown, MultiXactId *nextMulti, MultiXactOffset *nextMultiOffset, MultiXactId *oldestMulti, Oid *oldestMultiDB)
Definition: multixact.c:2282
void SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, bool is_startup)
Definition: multixact.c:2362
int multixactmemberssyncfiletag(const FileTag *ftag, char *path)
Definition: multixact.c:3584
MultiXactId GetOldestMultiXactId(void)
Definition: multixact.c:2660
void CheckPointMultiXact(void)
Definition: multixact.c:2304
MultiXactId MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
Definition: multixact.c:815
void TrimMultiXact(void)
Definition: multixact.c:2178
char * mxid_to_string(MultiXactId multi, int nmembers, MultiXactMember *members)
Definition: multixact.c:1777
int MultiXactMemberFreezeThreshold(void)
Definition: multixact.c:2978
void MultiXactAdvanceNextMXact(MultiXactId minMulti, MultiXactOffset minMultiOffset)
Definition: multixact.c:2511
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:771
void BootStrapMultiXact(void)
Definition: multixact.c:2034
MultiXactId MultiXactIdCreate(TransactionId xid1, MultiXactStatus status1, TransactionId xid2, MultiXactStatus status2)
Definition: multixact.c:434
void TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB)
Definition: multixact.c:3102
struct MultiXactMember MultiXactMember
void AtEOXact_MultiXact(void)
Definition: multixact.c:1808
struct xl_multixact_truncate xl_multixact_truncate
void StartupMultiXact(void)
Definition: multixact.c:2153
struct xl_multixact_create xl_multixact_create
int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members, bool from_pgupgrade, bool isLockOnly)
Definition: multixact.c:1299
const void size_t len
static char * buf
Definition: pg_test_fsync.c:73
unsigned int Oid
Definition: postgres_ext.h:31
Definition: sync.h:51
TransactionId xid
Definition: multixact.h:58
MultiXactStatus status
Definition: multixact.h:59
MultiXactId mid
Definition: multixact.h:75
MultiXactMember members[FLEXIBLE_ARRAY_MEMBER]
Definition: multixact.h:78
MultiXactOffset moff
Definition: multixact.h:76
MultiXactId endTruncOff
Definition: multixact.h:89
MultiXactOffset startTruncMemb
Definition: multixact.h:92
MultiXactOffset endTruncMemb
Definition: multixact.h:93
MultiXactId startTruncOff
Definition: multixact.h:88