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-2020, 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 /* Number of SLRU buffers to use for multixact */
33 #define NUM_MULTIXACTOFFSET_BUFFERS 8
34 #define NUM_MULTIXACTMEMBER_BUFFERS 16
35 
36 /*
37  * Possible multixact lock modes ("status"). The first four modes are for
38  * tuple locks (FOR KEY SHARE, FOR SHARE, FOR NO KEY UPDATE, FOR UPDATE); the
39  * next two are used for update and delete modes.
40  */
41 typedef enum
42 {
47  /* an update that doesn't touch "key" columns */
49  /* other updates, and delete */
52 
53 #define MaxMultiXactStatus MultiXactStatusUpdate
54 
55 /* does a status value correspond to a tuple update? */
56 #define ISUPDATE_from_mxstatus(status) \
57  ((status) > MultiXactStatusForUpdate)
58 
59 
60 typedef struct MultiXactMember
61 {
65 
66 
67 /* ----------------
68  * multixact-related XLOG entries
69  * ----------------
70  */
71 
72 #define XLOG_MULTIXACT_ZERO_OFF_PAGE 0x00
73 #define XLOG_MULTIXACT_ZERO_MEM_PAGE 0x10
74 #define XLOG_MULTIXACT_CREATE_ID 0x20
75 #define XLOG_MULTIXACT_TRUNCATE_ID 0x30
76 
77 typedef struct xl_multixact_create
78 {
79  MultiXactId mid; /* new MultiXact's ID */
80  MultiXactOffset moff; /* its starting offset in members file */
81  int32 nmembers; /* number of member XIDs */
84 
85 #define SizeOfMultiXactCreate (offsetof(xl_multixact_create, members))
86 
87 typedef struct xl_multixact_truncate
88 {
90 
91  /* to-be-truncated range of multixact offsets */
92  MultiXactId startTruncOff; /* just for completeness' sake */
94 
95  /* to-be-truncated range of multixact members */
99 
100 #define SizeOfMultiXactTruncate (sizeof(xl_multixact_truncate))
101 
102 
104  MultiXactStatus status1, TransactionId xid2,
105  MultiXactStatus status2);
108 extern MultiXactId MultiXactIdCreateFromMembers(int nmembers,
109  MultiXactMember *members);
110 
111 extern MultiXactId ReadNextMultiXactId(void);
112 extern void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next);
113 extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
114 extern void MultiXactIdSetOldestMember(void);
115 extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
116  bool allow_old, bool isLockOnly);
117 extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
118 extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
119  MultiXactId multi2);
120 
121 extern int multixactoffsetssyncfiletag(const FileTag *ftag, char *path);
122 extern int multixactmemberssyncfiletag(const FileTag *ftag, char *path);
123 
124 extern void AtEOXact_MultiXact(void);
125 extern void AtPrepare_MultiXact(void);
127 
128 extern Size MultiXactShmemSize(void);
129 extern void MultiXactShmemInit(void);
130 extern void BootStrapMultiXact(void);
131 extern void StartupMultiXact(void);
132 extern void TrimMultiXact(void);
133 extern void ShutdownMultiXact(void);
134 extern void SetMultiXactIdLimit(MultiXactId oldest_datminmxid,
135  Oid oldest_datoid,
136  bool is_startup);
137 extern void MultiXactGetCheckptMulti(bool is_shutdown,
138  MultiXactId *nextMulti,
139  MultiXactOffset *nextMultiOffset,
140  MultiXactId *oldestMulti,
141  Oid *oldestMultiDB);
142 extern void CheckPointMultiXact(void);
143 extern MultiXactId GetOldestMultiXactId(void);
144 extern void TruncateMultiXact(MultiXactId oldestMulti, Oid oldestMultiDB);
145 extern void MultiXactSetNextMXact(MultiXactId nextMulti,
146  MultiXactOffset nextMultiOffset);
147 extern void MultiXactAdvanceNextMXact(MultiXactId minMulti,
148  MultiXactOffset minMultiOffset);
149 extern void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB);
150 extern int MultiXactMemberFreezeThreshold(void);
151 
153  void *recdata, uint32 len);
155  void *recdata, uint32 len);
157  void *recdata, uint32 len);
158 
159 extern void multixact_redo(XLogReaderState *record);
160 extern void multixact_desc(StringInfo buf, XLogReaderState *record);
161 extern const char *multixact_identify(uint8 info);
162 extern char *mxid_to_string(MultiXactId multi, int nmembers,
163  MultiXactMember *members);
164 
165 #endif /* MULTIXACT_H */
MultiXactId MultiXactIdCreate(TransactionId xid1, MultiXactStatus status1, TransactionId xid2, MultiXactStatus status2)
Definition: multixact.c:386
Size MultiXactShmemSize(void)
Definition: multixact.c:1824
MultiXactStatus
Definition: multixact.h:41
void MultiXactSetNextMXact(MultiXactId nextMulti, MultiXactOffset nextMultiOffset)
Definition: multixact.c:2174
static int32 next
Definition: blutils.c:219
uint32 MultiXactOffset
Definition: c.h:533
uint32 TransactionId
Definition: c.h:521
struct xl_multixact_create xl_multixact_create
void AtEOXact_MultiXact(void)
Definition: multixact.c:1683
void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB)
Definition: multixact.c:2382
unsigned char uint8
Definition: c.h:373
MultiXactId GetOldestMultiXactId(void)
Definition: multixact.c:2501
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:284
void TrimMultiXact(void)
Definition: multixact.c:2026
void multixact_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: multixact.c:1797
unsigned int Oid
Definition: postgres_ext.h:31
void StartupMultiXact(void)
Definition: multixact.c:2003
char * mxid_to_string(MultiXactId multi, int nmembers, MultiXactMember *members)
Definition: multixact.c:1652
signed int int32
Definition: c.h:363
void BootStrapMultiXact(void)
Definition: multixact.c:1889
bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
Definition: multixact.c:551
unsigned short uint16
Definition: c.h:374
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:723
TransactionId xid
Definition: multixact.h:62
MultiXactId MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
Definition: multixact.c:767
const char * multixact_identify(uint8 info)
Definition: mxactdesc.c:84
MultiXactOffset moff
Definition: multixact.h:80
void multixact_desc(StringInfo buf, XLogReaderState *record)
Definition: mxactdesc.c:50
void MultiXactGetCheckptMulti(bool is_shutdown, MultiXactId *nextMulti, MultiXactOffset *nextMultiOffset, MultiXactId *oldestMulti, Oid *oldestMultiDB)
Definition: multixact.c:2128
void MultiXactIdSetOldestMember(void)
Definition: multixact.c:625
static char * buf
Definition: pg_test_fsync.c:68
MultiXactStatus status
Definition: multixact.h:63
unsigned int uint32
Definition: c.h:375
MultiXactOffset endTruncMemb
Definition: multixact.h:97
int multixactmemberssyncfiletag(const FileTag *ftag, char *path)
Definition: multixact.c:3411
void ShutdownMultiXact(void)
MultiXactOffset startTruncMemb
Definition: multixact.h:96
int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids, bool allow_old, bool isLockOnly)
Definition: multixact.c:1223
void AtPrepare_MultiXact(void)
Definition: multixact.c:1712
void MultiXactAdvanceNextMXact(MultiXactId minMulti, MultiXactOffset minMultiOffset)
Definition: multixact.c:2357
TransactionId MultiXactId
Definition: c.h:531
MultiXactId mid
Definition: multixact.h:79
void PostPrepare_MultiXact(TransactionId xid)
Definition: multixact.c:1726
void CheckPointMultiXact(void)
Definition: multixact.c:2150
struct MultiXactMember MultiXactMember
size_t Size
Definition: c.h:474
void multixact_twophase_recover(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: multixact.c:1776
MultiXactId startTruncOff
Definition: multixact.h:92
int MultiXactMemberFreezeThreshold(void)
Definition: multixact.c:2823
void MultiXactShmemInit(void)
Definition: multixact.c:1841
void SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, bool is_startup)
Definition: multixact.c:2208
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3160
int multixactoffsetssyncfiletag(const FileTag *ftag, char *path)
Definition: multixact.c:3402
struct xl_multixact_truncate xl_multixact_truncate
void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next)
Definition: multixact.c:743
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3146
MultiXactId endTruncOff
Definition: multixact.h:93
MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
Definition: multixact.c:439
void multixact_redo(XLogReaderState *record)
Definition: multixact.c:3223
void multixact_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
Definition: multixact.c:1812
Definition: sync.h:50
void TruncateMultiXact(MultiXactId oldestMulti, Oid oldestMultiDB)
Definition: multixact.c:2939