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

Commit4ed8f09

Browse files
committed
Index SLRUs by 64-bit integers rather than by 32-bit integers
We've had repeated bugs in the area of handling SLRU wraparound in the past,some of which have caused data loss. Switching to an indexing system for SLRUsthat does not wrap around should allow us to get rid of a whole bunchof problems and improve the overall reliability of the system.This particular patch however only changes the indexing and doesn't addressthe wraparound per se. This is going to be done in the following patches.Author: Maxim Orlov, Aleksander Alekseev, Alexander Korotkov, Teodor SigaevAuthor: Nikita Glukhov, Pavel Borisov, Yura SokolovReviewed-by: Jacob Champion, Heikki Linnakangas, Alexander KorotkovReviewed-by: Japin Li, Pavel Borisov, Tom Lane, Peter Eisentraut, Andres FreundReviewed-by: Andrey Borodin, Dilip Kumar, Aleksander AlekseevDiscussion:https://postgr.es/m/CACG%3DezZe1NQSCnfHOr78AtAZxJZeCvxrts0ygrxYwe%3DpyyjVWA%40mail.gmail.comDiscussion:https://postgr.es/m/CAJ7c6TPDOYBYrnCAeyndkBktO0WG2xSdYduTF0nxq%2BvfkmTF5Q%40mail.gmail.com
1 parenta916b47 commit4ed8f09

File tree

18 files changed

+303
-202
lines changed

18 files changed

+303
-202
lines changed

‎src/backend/access/rmgrdesc/clogdesc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ clog_desc(StringInfo buf, XLogReaderState *record)
2525

2626
if (info==CLOG_ZEROPAGE)
2727
{
28-
intpageno;
28+
int64pageno;
2929

30-
memcpy(&pageno,rec,sizeof(int));
31-
appendStringInfo(buf,"page %d",pageno);
30+
memcpy(&pageno,rec,sizeof(pageno));
31+
appendStringInfo(buf,"page %lld", (long long)pageno);
3232
}
3333
elseif (info==CLOG_TRUNCATE)
3434
{
3535
xl_clog_truncatexlrec;
3636

3737
memcpy(&xlrec,rec,sizeof(xl_clog_truncate));
38-
appendStringInfo(buf,"page %d; oldestXact %u",
39-
xlrec.pageno,xlrec.oldestXact);
38+
appendStringInfo(buf,"page %lld; oldestXact %u",
39+
(long long)xlrec.pageno,xlrec.oldestXact);
4040
}
4141
}
4242

‎src/backend/access/rmgrdesc/committsdesc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ commit_ts_desc(StringInfo buf, XLogReaderState *record)
2626

2727
if (info==COMMIT_TS_ZEROPAGE)
2828
{
29-
intpageno;
29+
int64pageno;
3030

31-
memcpy(&pageno,rec,sizeof(int));
32-
appendStringInfo(buf,"%d",pageno);
31+
memcpy(&pageno,rec,sizeof(pageno));
32+
appendStringInfo(buf,"%lld", (long long)pageno);
3333
}
3434
elseif (info==COMMIT_TS_TRUNCATE)
3535
{
3636
xl_commit_ts_truncate*trunc= (xl_commit_ts_truncate*)rec;
3737

38-
appendStringInfo(buf,"pageno %d, oldestXid %u",
39-
trunc->pageno,trunc->oldestXid);
38+
appendStringInfo(buf,"pageno %lld, oldestXid %u",
39+
(long long)trunc->pageno,trunc->oldestXid);
4040
}
4141
}
4242

‎src/backend/access/rmgrdesc/mxactdesc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ multixact_desc(StringInfo buf, XLogReaderState *record)
5555
if (info==XLOG_MULTIXACT_ZERO_OFF_PAGE||
5656
info==XLOG_MULTIXACT_ZERO_MEM_PAGE)
5757
{
58-
intpageno;
58+
int64pageno;
5959

60-
memcpy(&pageno,rec,sizeof(int));
61-
appendStringInfo(buf,"%d",pageno);
60+
memcpy(&pageno,rec,sizeof(pageno));
61+
appendStringInfo(buf,"%lld", (long long)pageno);
6262
}
6363
elseif (info==XLOG_MULTIXACT_CREATE_ID)
6464
{

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

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@
6262
#defineCLOG_XACTS_PER_PAGE (BLCKSZ * CLOG_XACTS_PER_BYTE)
6363
#defineCLOG_XACT_BITMASK((1 << CLOG_BITS_PER_XACT) - 1)
6464

65-
#defineTransactionIdToPage(xid)((xid) / (TransactionId) CLOG_XACTS_PER_PAGE)
65+
66+
/*
67+
* Although we return an int64 the actual value can't currently exceed
68+
* 0xFFFFFFFF/CLOG_XACTS_PER_PAGE.
69+
*/
70+
staticinlineint64
71+
TransactionIdToPage(TransactionIdxid)
72+
{
73+
returnxid / (int64)CLOG_XACTS_PER_PAGE;
74+
}
75+
6676
#defineTransactionIdToPgIndex(xid) ((xid) % (TransactionId) CLOG_XACTS_PER_PAGE)
6777
#defineTransactionIdToByte(xid)(TransactionIdToPgIndex(xid) / CLOG_XACTS_PER_BYTE)
6878
#defineTransactionIdToBIndex(xid)((xid) % (TransactionId) CLOG_XACTS_PER_BYTE)
@@ -89,24 +99,24 @@ static SlruCtlData XactCtlData;
8999
#defineXactCtl (&XactCtlData)
90100

91101

92-
staticintZeroCLOGPage(intpageno,boolwriteXlog);
93-
staticboolCLOGPagePrecedes(intpage1,intpage2);
94-
staticvoidWriteZeroPageXlogRec(intpageno);
95-
staticvoidWriteTruncateXlogRec(intpageno,TransactionIdoldestXact,
102+
staticintZeroCLOGPage(int64pageno,boolwriteXlog);
103+
staticboolCLOGPagePrecedes(int64page1,int64page2);
104+
staticvoidWriteZeroPageXlogRec(int64pageno);
105+
staticvoidWriteTruncateXlogRec(int64pageno,TransactionIdoldestXact,
96106
OidoldestXactDb);
97107
staticvoidTransactionIdSetPageStatus(TransactionIdxid,intnsubxids,
98108
TransactionId*subxids,XidStatusstatus,
99-
XLogRecPtrlsn,intpageno,
109+
XLogRecPtrlsn,int64pageno,
100110
boolall_xact_same_page);
101111
staticvoidTransactionIdSetStatusBit(TransactionIdxid,XidStatusstatus,
102112
XLogRecPtrlsn,intslotno);
103113
staticvoidset_status_by_pages(intnsubxids,TransactionId*subxids,
104114
XidStatusstatus,XLogRecPtrlsn);
105115
staticboolTransactionGroupUpdateXidStatus(TransactionIdxid,
106-
XidStatusstatus,XLogRecPtrlsn,intpageno);
116+
XidStatusstatus,XLogRecPtrlsn,int64pageno);
107117
staticvoidTransactionIdSetPageStatusInternal(TransactionIdxid,intnsubxids,
108118
TransactionId*subxids,XidStatusstatus,
109-
XLogRecPtrlsn,intpageno);
119+
XLogRecPtrlsn,int64pageno);
110120

111121

112122
/*
@@ -162,7 +172,7 @@ void
162172
TransactionIdSetTreeStatus(TransactionIdxid,intnsubxids,
163173
TransactionId*subxids,XidStatusstatus,XLogRecPtrlsn)
164174
{
165-
intpageno=TransactionIdToPage(xid);/* get page of parent */
175+
int64pageno=TransactionIdToPage(xid);/* get page of parent */
166176
inti;
167177

168178
Assert(status==TRANSACTION_STATUS_COMMITTED||
@@ -236,7 +246,7 @@ static void
236246
set_status_by_pages(intnsubxids,TransactionId*subxids,
237247
XidStatusstatus,XLogRecPtrlsn)
238248
{
239-
intpageno=TransactionIdToPage(subxids[0]);
249+
int64pageno=TransactionIdToPage(subxids[0]);
240250
intoffset=0;
241251
inti=0;
242252

@@ -245,7 +255,7 @@ set_status_by_pages(int nsubxids, TransactionId *subxids,
245255
while (i<nsubxids)
246256
{
247257
intnum_on_page=0;
248-
intnextpageno;
258+
int64nextpageno;
249259

250260
do
251261
{
@@ -271,7 +281,7 @@ set_status_by_pages(int nsubxids, TransactionId *subxids,
271281
staticvoid
272282
TransactionIdSetPageStatus(TransactionIdxid,intnsubxids,
273283
TransactionId*subxids,XidStatusstatus,
274-
XLogRecPtrlsn,intpageno,
284+
XLogRecPtrlsn,int64pageno,
275285
boolall_xact_same_page)
276286
{
277287
/* Can't use group update when PGPROC overflows. */
@@ -337,7 +347,7 @@ TransactionIdSetPageStatus(TransactionId xid, int nsubxids,
337347
staticvoid
338348
TransactionIdSetPageStatusInternal(TransactionIdxid,intnsubxids,
339349
TransactionId*subxids,XidStatusstatus,
340-
XLogRecPtrlsn,intpageno)
350+
XLogRecPtrlsn,int64pageno)
341351
{
342352
intslotno;
343353
inti;
@@ -411,7 +421,7 @@ TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids,
411421
*/
412422
staticbool
413423
TransactionGroupUpdateXidStatus(TransactionIdxid,XidStatusstatus,
414-
XLogRecPtrlsn,intpageno)
424+
XLogRecPtrlsn,int64pageno)
415425
{
416426
volatilePROC_HDR*procglobal=ProcGlobal;
417427
PGPROC*proc=MyProc;
@@ -637,7 +647,7 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
637647
XidStatus
638648
TransactionIdGetStatus(TransactionIdxid,XLogRecPtr*lsn)
639649
{
640-
intpageno=TransactionIdToPage(xid);
650+
int64pageno=TransactionIdToPage(xid);
641651
intbyteno=TransactionIdToByte(xid);
642652
intbshift=TransactionIdToBIndex(xid)*CLOG_BITS_PER_XACT;
643653
intslotno;
@@ -697,7 +707,7 @@ CLOGShmemInit(void)
697707
XactCtl->PagePrecedes=CLOGPagePrecedes;
698708
SimpleLruInit(XactCtl,"Xact",CLOGShmemBuffers(),CLOG_LSNS_PER_PAGE,
699709
XactSLRULock,"pg_xact",LWTRANCHE_XACT_BUFFER,
700-
SYNC_HANDLER_CLOG);
710+
SYNC_HANDLER_CLOG, false);
701711
SlruPagePrecedesUnitTests(XactCtl,CLOG_XACTS_PER_PAGE);
702712
}
703713

@@ -734,7 +744,7 @@ BootStrapCLOG(void)
734744
* Control lock must be held at entry, and will be held at exit.
735745
*/
736746
staticint
737-
ZeroCLOGPage(intpageno,boolwriteXlog)
747+
ZeroCLOGPage(int64pageno,boolwriteXlog)
738748
{
739749
intslotno;
740750

@@ -754,7 +764,7 @@ void
754764
StartupCLOG(void)
755765
{
756766
TransactionIdxid=XidFromFullTransactionId(ShmemVariableCache->nextXid);
757-
intpageno=TransactionIdToPage(xid);
767+
int64pageno=TransactionIdToPage(xid);
758768

759769
LWLockAcquire(XactSLRULock,LW_EXCLUSIVE);
760770

@@ -773,7 +783,7 @@ void
773783
TrimCLOG(void)
774784
{
775785
TransactionIdxid=XidFromFullTransactionId(ShmemVariableCache->nextXid);
776-
intpageno=TransactionIdToPage(xid);
786+
int64pageno=TransactionIdToPage(xid);
777787

778788
LWLockAcquire(XactSLRULock,LW_EXCLUSIVE);
779789

@@ -838,7 +848,7 @@ CheckPointCLOG(void)
838848
void
839849
ExtendCLOG(TransactionIdnewestXact)
840850
{
841-
intpageno;
851+
int64pageno;
842852

843853
/*
844854
* No work except at first XID of a page. But beware: just after
@@ -877,7 +887,7 @@ ExtendCLOG(TransactionId newestXact)
877887
void
878888
TruncateCLOG(TransactionIdoldestXact,Oidoldestxid_datoid)
879889
{
880-
intcutoffPage;
890+
int64cutoffPage;
881891

882892
/*
883893
* The cutoff point is the start of the segment containing oldestXact. We
@@ -930,7 +940,7 @@ TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid)
930940
* don't optimize that edge case.
931941
*/
932942
staticbool
933-
CLOGPagePrecedes(intpage1,intpage2)
943+
CLOGPagePrecedes(int64page1,int64page2)
934944
{
935945
TransactionIdxid1;
936946
TransactionIdxid2;
@@ -949,10 +959,10 @@ CLOGPagePrecedes(int page1, int page2)
949959
* Write a ZEROPAGE xlog record
950960
*/
951961
staticvoid
952-
WriteZeroPageXlogRec(intpageno)
962+
WriteZeroPageXlogRec(int64pageno)
953963
{
954964
XLogBeginInsert();
955-
XLogRegisterData((char*) (&pageno),sizeof(int));
965+
XLogRegisterData((char*) (&pageno),sizeof(pageno));
956966
(void)XLogInsert(RM_CLOG_ID,CLOG_ZEROPAGE);
957967
}
958968

@@ -963,7 +973,7 @@ WriteZeroPageXlogRec(int pageno)
963973
* in TruncateCLOG().
964974
*/
965975
staticvoid
966-
WriteTruncateXlogRec(intpageno,TransactionIdoldestXact,OidoldestXactDb)
976+
WriteTruncateXlogRec(int64pageno,TransactionIdoldestXact,OidoldestXactDb)
967977
{
968978
XLogRecPtrrecptr;
969979
xl_clog_truncatexlrec;
@@ -991,10 +1001,10 @@ clog_redo(XLogReaderState *record)
9911001

9921002
if (info==CLOG_ZEROPAGE)
9931003
{
994-
intpageno;
1004+
int64pageno;
9951005
intslotno;
9961006

997-
memcpy(&pageno,XLogRecGetData(record),sizeof(int));
1007+
memcpy(&pageno,XLogRecGetData(record),sizeof(pageno));
9981008

9991009
LWLockAcquire(XactSLRULock,LW_EXCLUSIVE);
10001010

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp