Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67b9b3c

Browse files
committed
Provide XLogRecGetFullXid().
In order to be able to work with FullTransactionId values during replaywithout increasing the size of the WAL, infer the epoch. In general wecan't do that safely, but during replay we can because we know thatnextFullXid can't advance concurrently.Prevent frontend code from seeing this new function, due to the aboverestriction. Perhaps in future it will be possible to extract the valueentirely from independent WAL records, and then this restriction can belifted.Author: Thomas Munro, based on earlier code from Andres FreundDiscussion:https://postgr.es/m/CA%2BhUKG%2BmLmuDjMi6o1dxkKvGRL56Y2Rz%2BiXAcrZV03G9ZuFQ8Q%40mail.gmail.com
1 parent5925e55 commit67b9b3c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

‎src/backend/access/transam/xlogreader.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include"replication/origin.h"
2727

2828
#ifndefFRONTEND
29+
#include"miscadmin.h"
2930
#include"utils/memutils.h"
3031
#endif
3132

@@ -1443,3 +1444,37 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
14431444

14441445
return true;
14451446
}
1447+
1448+
#ifndefFRONTEND
1449+
1450+
/*
1451+
* Extract the FullTransactionId from a WAL record.
1452+
*/
1453+
FullTransactionId
1454+
XLogRecGetFullXid(XLogReaderState*record)
1455+
{
1456+
TransactionIdxid,
1457+
next_xid;
1458+
uint32epoch;
1459+
1460+
/*
1461+
* This function is only safe during replay, because it depends on the
1462+
* replay state. See AdvanceNextFullTransactionIdPastXid() for more.
1463+
*/
1464+
Assert(AmStartupProcess()|| !IsUnderPostmaster);
1465+
1466+
xid=XLogRecGetXid(record);
1467+
next_xid=XidFromFullTransactionId(ShmemVariableCache->nextFullXid);
1468+
epoch=EpochFromFullTransactionId(ShmemVariableCache->nextFullXid);
1469+
1470+
/*
1471+
* If xid is numerically greater than next_xid, it has to be from the
1472+
* last epoch.
1473+
*/
1474+
if (unlikely(xid>next_xid))
1475+
--epoch;
1476+
1477+
returnFullTransactionIdFromEpochAndXid(epoch,xid);
1478+
};
1479+
1480+
#endif

‎src/include/access/xlogreader.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#ifndefXLOGREADER_H
2626
#defineXLOGREADER_H
2727

28+
#ifndefFRONTEND
29+
#include"access/transam.h"
30+
#endif
31+
2832
#include"access/xlogrecord.h"
2933

3034
typedefstructXLogReaderStateXLogReaderState;
@@ -240,6 +244,10 @@ extern bool DecodeXLogRecord(XLogReaderState *state, XLogRecord *record,
240244
#defineXLogRecBlockImageApply(decoder,block_id) \
241245
((decoder)->blocks[block_id].apply_image)
242246

247+
#ifndefFRONTEND
248+
externFullTransactionIdXLogRecGetFullXid(XLogReaderState*record);
249+
#endif
250+
243251
externboolRestoreBlockImage(XLogReaderState*recoder,uint8block_id,char*dst);
244252
externchar*XLogRecGetBlockData(XLogReaderState*record,uint8block_id,Size*len);
245253
externboolXLogRecGetBlockTag(XLogReaderState*record,uint8block_id,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp