Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * multixact.h
 *
 * PostgreSQL multi-transaction-log manager
 *
 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * src/include/access/multixact.h
 */
#ifndef MULTIXACT_H
#define MULTIXACT_H
 
#include "access/transam.h"
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "storage/sync.h"
 
 
/*
 * The first two MultiXactId values are reserved to store the truncation Xid
 * and epoch of the first segment, so we start assigning multixact values from
 * 2.
 */
#define InvalidMultiXactId  ((MultiXactId) 0)
#define FirstMultiXactId    ((MultiXactId) 1)
#define MaxMultiXactId      ((MultiXactId) 0xFFFFFFFF)
 
#define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId)
 
/*
 * Decide which of two MultiXactIds is earlier.
 *
 * XXX do we need to do something special for InvalidMultiXactId?
 * (Doesn't look like it.)
 */
static inline bool
MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
{
    int32       diff = (int32) (multi1 - multi2);
 
    return (diff < 0);
}
 
/*
 * MultiXactIdPrecedesOrEquals -- is multi1 logically <= multi2?
 *
 * XXX do we need to do something special for InvalidMultiXactId?
 * (Doesn't look like it.)
 */
static inline bool
MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
{
    int32       diff = (int32) (multi1 - multi2);
 
    return (diff <= 0);
}
 
/*
 * Possible multixact lock modes ("status").  The first four modes are for
 * tuple locks (FOR KEY SHARE, FOR SHARE, FOR NO KEY UPDATE, FOR UPDATE); the
 * next two are used for update and delete modes.
 */
typedef enum
{
    MultiXactStatusForKeyShare = 0x00,
    MultiXactStatusForShare = 0x01,
    MultiXactStatusForNoKeyUpdate = 0x02,
    MultiXactStatusForUpdate = 0x03,
    /* an update that doesn't touch "key" columns */
    MultiXactStatusNoKeyUpdate = 0x04,
    /* other updates, and delete */
    MultiXactStatusUpdate = 0x05,
} MultiXactStatus;
 
#define MaxMultiXactStatus MultiXactStatusUpdate
 
/* does a status value correspond to a tuple update? */
#define ISUPDATE_from_mxstatus(status) \
            ((status) > MultiXactStatusForUpdate)
 
 
typedef struct MultiXactMember
{
    TransactionId xid;
    MultiXactStatus status;
} MultiXactMember;
 
 
/* ----------------
 *      multixact-related XLOG entries
 * ----------------
 */
 
#define XLOG_MULTIXACT_ZERO_OFF_PAGE    0x00
#define XLOG_MULTIXACT_ZERO_MEM_PAGE    0x10
#define XLOG_MULTIXACT_CREATE_ID        0x20
#define XLOG_MULTIXACT_TRUNCATE_ID      0x30
 
typedef struct xl_multixact_create
{
    MultiXactId mid;            /* new MultiXact's ID */
    MultiXactOffset moff;       /* its starting offset in members file */
    int32       nmembers;       /* number of member XIDs */
    MultiXactMember members[FLEXIBLE_ARRAY_MEMBER];
} xl_multixact_create;
 
#define SizeOfMultiXactCreate (offsetof(xl_multixact_create, members))
 
typedef struct xl_multixact_truncate
{
    Oid         oldestMultiDB;
 
    /* truncate multixact offsets older than this */
    MultiXactId oldestMulti;
 
    /* truncate multixact members older than this */
    MultiXactOffset oldestOffset;
} xl_multixact_truncate;
 
#define SizeOfMultiXactTruncate (sizeof(xl_multixact_truncate))
 
 
extern MultiXactId MultiXactIdCreate(TransactionId xid1,
                                     MultiXactStatus status1, TransactionId xid2,
                                     MultiXactStatus status2);
extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid,
                                     MultiXactStatus status);
extern MultiXactId MultiXactIdCreateFromMembers(int nmembers,
                                                MultiXactMember *members);
 
extern MultiXactId ReadNextMultiXactId(void);
extern void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next);
extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
extern void MultiXactIdSetOldestMember(void);
extern int  GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
                                  bool from_pgupgrade, bool isLockOnly);
extern void GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *nextOffset,
                             MultiXactId *oldestMultiXactId,
                             MultiXactOffset *oldestOffset);
 
extern int  multixactoffsetssyncfiletag(const FileTag *ftag, char *path);
extern int  multixactmemberssyncfiletag(const FileTag *ftag, char *path);
 
extern void AtEOXact_MultiXact(void);
extern void AtPrepare_MultiXact(void);
extern void PostPrepare_MultiXact(FullTransactionId fxid);
 
extern void BootStrapMultiXact(void);
extern void StartupMultiXact(void);
extern void TrimMultiXact(void);
extern void SetMultiXactIdLimit(MultiXactId oldest_datminmxid,
                                Oid oldest_datoid);
extern void MultiXactGetCheckptMulti(bool is_shutdown,
                                     MultiXactId *nextMulti,
                                     MultiXactOffset *nextMultiOffset,
                                     MultiXactId *oldestMulti,
                                     Oid *oldestMultiDB);
extern void CheckPointMultiXact(void);
extern MultiXactId GetOldestMultiXactId(void);
extern void TruncateMultiXact(MultiXactId newOldestMulti,
                              Oid newOldestMultiDB);
extern void MultiXactSetNextMXact(MultiXactId nextMulti,
                                  MultiXactOffset nextMultiOffset);
extern void MultiXactAdvanceNextMXact(MultiXactId minMulti,
                                      MultiXactOffset minMultiOffset);
extern void MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB);
extern int  MultiXactMemberFreezeThreshold(void);
 
extern void multixact_twophase_recover(FullTransactionId fxid, uint16 info,
                                       void *recdata, uint32 len);
extern void multixact_twophase_postcommit(FullTransactionId fxid, uint16 info,
                                          void *recdata, uint32 len);
extern void multixact_twophase_postabort(FullTransactionId fxid, uint16 info,
                                         void *recdata, uint32 len);
 
extern void multixact_redo(XLogReaderState *record);
extern void multixact_desc(StringInfo buf, XLogReaderState *record);
extern const char *multixact_identify(uint8 info);
extern char *mxid_to_string(MultiXactId multi, int nmembers,
                            MultiXactMember *members);
extern char *mxstatus_to_string(MultiXactStatus status);
 
#endif                          /* MULTIXACT_H */