Skip to content

Commit 30f1108

Browse files
committed
port multimaster patch for postgres core
1 parent 410aa2d commit 30f1108

File tree

33 files changed

+1289
-237
lines changed

33 files changed

+1289
-237
lines changed

src/backend/access/rmgrdesc/xactdesc.c

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *pars
7676
if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
7777
{
7878
xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
79+
uint8 gidlen = xl_twophase->gidlen;
7980

8081
parsed->twophase_xid = xl_twophase->xid;
82+
data += MinSizeOfXactTwophase;
8183

82-
data += sizeof(xl_xact_twophase);
84+
strcpy(parsed->twophase_gid, data);
85+
data += gidlen;
8386
}
8487

8588
if (parsed->xinfo & XACT_XINFO_HAS_RELFILENODES)
@@ -139,6 +142,16 @@ ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
139142
data += sizeof(xl_xact_xinfo);
140143
}
141144

145+
if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
146+
{
147+
xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
148+
149+
parsed->dbId = xl_dbinfo->dbId;
150+
parsed->tsId = xl_dbinfo->tsId;
151+
152+
data += sizeof(xl_xact_dbinfo);
153+
}
154+
142155
if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
143156
{
144157
xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
@@ -153,10 +166,26 @@ ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
153166
if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
154167
{
155168
xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
169+
uint8 gidlen = xl_twophase->gidlen;
156170

157171
parsed->twophase_xid = xl_twophase->xid;
172+
data += MinSizeOfXactTwophase;
158173

159-
data += sizeof(xl_xact_twophase);
174+
strcpy(parsed->twophase_gid, data);
175+
data += gidlen;
176+
}
177+
178+
if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
179+
{
180+
xl_xact_origin xl_origin;
181+
182+
/* we're only guaranteed 4 byte alignment, so copy onto stack */
183+
memcpy(&xl_origin, data, sizeof(xl_origin));
184+
185+
parsed->origin_lsn = xl_origin.origin_lsn;
186+
parsed->origin_timestamp = xl_origin.origin_timestamp;
187+
188+
data += sizeof(xl_xact_origin);
160189
}
161190

162191
if (parsed->xinfo & XACT_XINFO_HAS_RELFILENODES)
@@ -223,7 +252,7 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId
223252
}
224253

225254
static void
226-
xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
255+
xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
227256
{
228257
xl_xact_parsed_abort parsed;
229258
int i;
@@ -253,6 +282,14 @@ xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
253282
for (i = 0; i < parsed.nsubxacts; i++)
254283
appendStringInfo(buf, " " XID_FMT, parsed.subxacts[i]);
255284
}
285+
if (parsed.xinfo & XACT_XINFO_HAS_ORIGIN)
286+
{
287+
appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s",
288+
origin_id,
289+
(uint32) (parsed.origin_lsn >> 32),
290+
(uint32) parsed.origin_lsn,
291+
timestamptz_to_str(parsed.origin_timestamp));
292+
}
256293
}
257294

258295
static void
@@ -283,7 +320,8 @@ xact_desc(StringInfo buf, XLogReaderState *record)
283320
{
284321
xl_xact_abort *xlrec = (xl_xact_abort *) rec;
285322

286-
xact_desc_abort(buf, XLogRecGetInfo(record), xlrec);
323+
xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
324+
XLogRecGetOrigin(record));
287325
}
288326
else if (info == XLOG_XACT_ASSIGNMENT)
289327
{

src/backend/access/transam/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
1515
OBJS = clog.o commit_ts.o generic_xlog.o multixact.o parallel.o rmgr.o slru.o \
1616
subtrans.o timeline.o transam.o twophase.o twophase_rmgr.o varsup.o \
1717
xact.o xlog.o xlogarchive.o xlogfuncs.o \
18-
xloginsert.o xlogreader.o xlogutils.o
18+
xloginsert.o xlogreader.o xlogutils.o xtm.o
1919

2020
include $(top_srcdir)/src/backend/common.mk
2121

src/backend/access/transam/clog.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "access/xlog.h"
3939
#include "access/xloginsert.h"
4040
#include "access/xlogutils.h"
41+
#include "access/xtm.h"
4142
#include "miscadmin.h"
4243
#include "pg_trace.h"
4344

@@ -91,6 +92,12 @@ static void TransactionIdSetStatusBit(TransactionId xid, XidStatus status,
9192
static void set_status_by_pages(int nsubxids, TransactionId *subxids,
9293
XidStatus status, XLogRecPtr lsn);
9394

95+
void
96+
TransactionIdSetTreeStatus(TransactionId xid, int nsubxids,
97+
TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
98+
{
99+
return TM->SetTransactionStatus(xid, nsubxids, subxids, status, lsn);
100+
}
94101

95102
/*
96103
* TransactionIdSetTreeStatus
@@ -144,7 +151,7 @@ static void set_status_by_pages(int nsubxids, TransactionId *subxids,
144151
* cache yet.
145152
*/
146153
void
147-
TransactionIdSetTreeStatus(TransactionId xid, int nsubxids,
154+
PgTransactionIdSetTreeStatus(TransactionId xid, int nsubxids,
148155
TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
149156
{
150157
int64 pageno = TransactionIdToPage(xid); /* get page of parent */
@@ -344,10 +351,10 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
344351
* Current state change should be from 0 or subcommitted to target state
345352
* or we should already be there when replaying changes during recovery.
346353
*/
347-
Assert(curval == 0 ||
348-
(curval == TRANSACTION_STATUS_SUB_COMMITTED &&
349-
status != TRANSACTION_STATUS_IN_PROGRESS) ||
350-
curval == status);
354+
/* Assert(curval == 0 || */
355+
/* (curval == TRANSACTION_STATUS_SUB_COMMITTED && */
356+
/* status != TRANSACTION_STATUS_IN_PROGRESS) || */
357+
/* curval == status); */
351358

352359
/* note this assumes exclusive access to the clog page */
353360
byteval = *byteptr;
@@ -389,6 +396,12 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
389396
*/
390397
XidStatus
391398
TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
399+
{
400+
return TM->GetTransactionStatus(xid, lsn);
401+
}
402+
403+
XidStatus
404+
PgTransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
392405
{
393406
int64 pageno = TransactionIdToPage(xid);
394407
int byteno = TransactionIdToByte(xid);

0 commit comments

Comments
 (0)