Skip to content

Commit 1ec39c7

Browse files
committed
applied old patch
1 parent f0774ab commit 1ec39c7

File tree

8 files changed

+264
-31
lines changed

8 files changed

+264
-31
lines changed

src/backend/access/rmgrdesc/xactdesc.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *pars
9898
if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
9999
{
100100
xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
101+
uint8 gidlen = xl_twophase->gidlen;
101102

102103
parsed->twophase_xid = xl_twophase->xid;
104+
data += MinSizeOfXactTwophase;
103105

104-
data += sizeof(xl_xact_twophase);
106+
strcpy(parsed->twophase_gid, data);
107+
data += gidlen;
105108
}
106109

107110
if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
@@ -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;
@@ -164,10 +177,13 @@ ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
164177
if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
165178
{
166179
xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
180+
uint8 gidlen = xl_twophase->gidlen;
167181

168182
parsed->twophase_xid = xl_twophase->xid;
183+
data += MinSizeOfXactTwophase;
169184

170-
data += sizeof(xl_xact_twophase);
185+
strcpy(parsed->twophase_gid, data);
186+
data += gidlen;
171187
}
172188
}
173189

src/backend/access/transam/twophase.c

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ int max_prepared_xacts = 0;
130130
* Note that the max value of GIDSIZE must fit in the uint16 gidlen,
131131
* specified in TwoPhaseFileHeader.
132132
*/
133-
#define GIDSIZE 200
134133

135134
typedef struct GlobalTransactionData
136135
{
@@ -188,12 +187,14 @@ static void RecordTransactionCommitPrepared(TransactionId xid,
188187
RelFileNode *rels,
189188
int ninvalmsgs,
190189
SharedInvalidationMessage *invalmsgs,
191-
bool initfileinval);
190+
bool initfileinval,
191+
const char *gid);
192192
static void RecordTransactionAbortPrepared(TransactionId xid,
193193
int nchildren,
194194
TransactionId *children,
195195
int nrels,
196-
RelFileNode *rels);
196+
RelFileNode *rels,
197+
const char *gid);
197198
static void ProcessRecords(char *bufptr, TransactionId xid,
198199
const TwoPhaseCallback callbacks[]);
199200
static void RemoveGXact(GlobalTransaction gxact);
@@ -1236,6 +1237,39 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
12361237
return buf;
12371238
}
12381239

1240+
/*
1241+
* ParsePrepareRecord
1242+
*/
1243+
void
1244+
ParsePrepareRecord(uint8 info, char *xlrec, xl_xact_parsed_prepare *parsed)
1245+
{
1246+
TwoPhaseFileHeader *hdr;
1247+
char *bufptr;
1248+
1249+
hdr = (TwoPhaseFileHeader *) xlrec;
1250+
bufptr = xlrec + MAXALIGN(sizeof(TwoPhaseFileHeader));
1251+
1252+
parsed->twophase_xid = hdr->xid;
1253+
parsed->dbId = hdr->database;
1254+
parsed->nsubxacts = hdr->nsubxacts;
1255+
parsed->nrels = hdr->ncommitrels;
1256+
parsed->nmsgs = hdr->ninvalmsgs;
1257+
1258+
strcpy(parsed->twophase_gid, hdr->gid);
1259+
1260+
parsed->subxacts = (TransactionId *) bufptr;
1261+
bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));
1262+
1263+
parsed->xnodes = (RelFileNode *) bufptr;
1264+
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));
1265+
1266+
/* Ignoring abortrels? */
1267+
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));
1268+
1269+
parsed->msgs = (SharedInvalidationMessage *) bufptr;
1270+
bufptr += MAXALIGN(hdr->ninvalmsgs * sizeof(SharedInvalidationMessage));
1271+
}
1272+
12391273

12401274
/*
12411275
* Reads 2PC data from xlog. During checkpoint this data will be moved to
@@ -1389,11 +1423,12 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
13891423
hdr->nsubxacts, children,
13901424
hdr->ncommitrels, commitrels,
13911425
hdr->ninvalmsgs, invalmsgs,
1392-
hdr->initfileinval);
1426+
hdr->initfileinval, gid);
13931427
else
13941428
RecordTransactionAbortPrepared(xid,
13951429
hdr->nsubxacts, children,
1396-
hdr->nabortrels, abortrels);
1430+
hdr->nabortrels, abortrels,
1431+
gid);
13971432

13981433
ProcArrayRemove(proc, latestXid);
13991434

@@ -2038,7 +2073,8 @@ RecordTransactionCommitPrepared(TransactionId xid,
20382073
RelFileNode *rels,
20392074
int ninvalmsgs,
20402075
SharedInvalidationMessage *invalmsgs,
2041-
bool initfileinval)
2076+
bool initfileinval,
2077+
const char *gid)
20422078
{
20432079
XLogRecPtr recptr;
20442080
TimestampTz committs = GetCurrentTimestamp();
@@ -2061,7 +2097,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
20612097
nchildren, children, nrels, rels,
20622098
ninvalmsgs, invalmsgs,
20632099
initfileinval, false,
2064-
xid);
2100+
xid, gid);
20652101

20662102

20672103
if (replorigin)
@@ -2123,7 +2159,8 @@ RecordTransactionAbortPrepared(TransactionId xid,
21232159
int nchildren,
21242160
TransactionId *children,
21252161
int nrels,
2126-
RelFileNode *rels)
2162+
RelFileNode *rels,
2163+
const char *gid)
21272164
{
21282165
XLogRecPtr recptr;
21292166

@@ -2141,7 +2178,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
21412178
recptr = XactLogAbortRecord(GetCurrentTimestamp(),
21422179
nchildren, children,
21432180
nrels, rels,
2144-
xid);
2181+
xid, gid);
21452182

21462183
/* Always flush, since we're about to remove the 2PC state file */
21472184
XLogFlush(recptr);

src/backend/access/transam/xact.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ RecordTransactionCommit(void)
12301230
nchildren, children, nrels, rels,
12311231
nmsgs, invalMessages,
12321232
RelcacheInitFileInval, forceSyncCommit,
1233-
InvalidTransactionId /* plain commit */ );
1233+
InvalidTransactionId, NULL /* plain commit */ );
12341234

12351235
if (replorigin)
12361236
/* Move LSNs forward for this replication origin */
@@ -1582,7 +1582,7 @@ RecordTransactionAbort(bool isSubXact)
15821582
XactLogAbortRecord(xact_time,
15831583
nchildren, children,
15841584
nrels, rels,
1585-
InvalidTransactionId);
1585+
InvalidTransactionId, NULL);
15861586

15871587
/*
15881588
* Report the latest async abort LSN, so that the WAL writer knows to
@@ -3467,7 +3467,7 @@ BeginTransactionBlock(void)
34673467
* resource owner, etc while executing inside a Portal.
34683468
*/
34693469
bool
3470-
PrepareTransactionBlock(char *gid)
3470+
PrepareTransactionBlock(const char *gid)
34713471
{
34723472
TransactionState s;
34733473
bool result;
@@ -5106,7 +5106,7 @@ XactLogCommitRecord(TimestampTz commit_time,
51065106
int nrels, RelFileNode *rels,
51075107
int nmsgs, SharedInvalidationMessage *msgs,
51085108
bool relcacheInval, bool forceSync,
5109-
TransactionId twophase_xid)
5109+
TransactionId twophase_xid, const char *twophase_gid)
51105110
{
51115111
xl_xact_commit xlrec;
51125112
xl_xact_xinfo xl_xinfo;
@@ -5178,6 +5178,7 @@ XactLogCommitRecord(TimestampTz commit_time,
51785178
{
51795179
xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
51805180
xl_twophase.xid = twophase_xid;
5181+
xl_twophase.gidlen = strlen(twophase_gid) + 1; /* Include '\0' */
51815182
}
51825183

51835184
/* dump transaction origin information */
@@ -5228,7 +5229,10 @@ XactLogCommitRecord(TimestampTz commit_time,
52285229
}
52295230

52305231
if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5231-
XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5232+
{
5233+
XLogRegisterData((char *) (&xl_twophase), MinSizeOfXactTwophase);
5234+
XLogRegisterData((char *) twophase_gid, xl_twophase.gidlen);
5235+
}
52325236

52335237
if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
52345238
XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
@@ -5249,13 +5253,14 @@ XLogRecPtr
52495253
XactLogAbortRecord(TimestampTz abort_time,
52505254
int nsubxacts, TransactionId *subxacts,
52515255
int nrels, RelFileNode *rels,
5252-
TransactionId twophase_xid)
5256+
TransactionId twophase_xid, const char *twophase_gid)
52535257
{
52545258
xl_xact_abort xlrec;
52555259
xl_xact_xinfo xl_xinfo;
52565260
xl_xact_subxacts xl_subxacts;
52575261
xl_xact_relfilenodes xl_relfilenodes;
52585262
xl_xact_twophase xl_twophase;
5263+
xl_xact_dbinfo xl_dbinfo;
52595264

52605265
uint8 info;
52615266

@@ -5290,6 +5295,14 @@ XactLogAbortRecord(TimestampTz abort_time,
52905295
{
52915296
xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
52925297
xl_twophase.xid = twophase_xid;
5298+
xl_twophase.gidlen = strlen(twophase_gid) + 1; /* Include '\0' */
5299+
}
5300+
5301+
if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
5302+
{
5303+
xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5304+
xl_dbinfo.dbId = MyDatabaseId;
5305+
xl_dbinfo.tsId = MyDatabaseTableSpace;
52935306
}
52945307

52955308
if (xl_xinfo.xinfo != 0)
@@ -5304,6 +5317,9 @@ XactLogAbortRecord(TimestampTz abort_time,
53045317
if (xl_xinfo.xinfo != 0)
53055318
XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
53065319

5320+
if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5321+
XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5322+
53075323
if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
53085324
{
53095325
XLogRegisterData((char *) (&xl_subxacts),
@@ -5321,7 +5337,13 @@ XactLogAbortRecord(TimestampTz abort_time,
53215337
}
53225338

53235339
if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5324-
XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5340+
{
5341+
XLogRegisterData((char *) (&xl_twophase), MinSizeOfXactTwophase);
5342+
XLogRegisterData((char *) twophase_gid, xl_twophase.gidlen);
5343+
}
5344+
5345+
if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5346+
XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
53255347

53265348
return XLogInsert(RM_XACT_ID, info);
53275349
}

0 commit comments

Comments
 (0)