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

Commita91fa39

Browse files
committed
Add test to WAL replay to verify that xl_prev points back to the previous
WAL record; this is necessary to be sure we recognize stale WAL recordswhen a WAL page was only partially written during a system crash.
1 parent5b3625f commita91fa39

File tree

1 file changed

+34
-3
lines changed
  • src/backend/access/transam

1 file changed

+34
-3
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.193 2005/05/20 14:53:25 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.194 2005/05/31 19:10:28 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -417,8 +417,8 @@ static char *readRecordBuf = NULL;
417417
staticuint32readRecordBufSize=0;
418418

419419
/* State information for XLOG reading */
420-
staticXLogRecPtrReadRecPtr;
421-
staticXLogRecPtrEndRecPtr;
420+
staticXLogRecPtrReadRecPtr;/* start of last record read */
421+
staticXLogRecPtrEndRecPtr;/* end+1 of last record read */
422422
staticXLogRecord*nextRecord=NULL;
423423
staticTimeLineIDlastPageTLI=0;
424424

@@ -2525,6 +2525,37 @@ got_record:;
25252525
record->xl_rmid,RecPtr->xlogid,RecPtr->xrecoff)));
25262526
gotonext_record_is_invalid;
25272527
}
2528+
if (randAccess)
2529+
{
2530+
/*
2531+
* We can't exactly verify the prev-link, but surely it should be
2532+
* less than the record's own address.
2533+
*/
2534+
if (!XLByteLT(record->xl_prev,*RecPtr))
2535+
{
2536+
ereport(emode,
2537+
(errmsg("record with incorrect prev-link %X/%X at %X/%X",
2538+
record->xl_prev.xlogid,record->xl_prev.xrecoff,
2539+
RecPtr->xlogid,RecPtr->xrecoff)));
2540+
gotonext_record_is_invalid;
2541+
}
2542+
}
2543+
else
2544+
{
2545+
/*
2546+
* Record's prev-link should exactly match our previous location.
2547+
* This check guards against torn WAL pages where a stale but
2548+
* valid-looking WAL record starts on a sector boundary.
2549+
*/
2550+
if (!XLByteEQ(record->xl_prev,ReadRecPtr))
2551+
{
2552+
ereport(emode,
2553+
(errmsg("record with incorrect prev-link %X/%X at %X/%X",
2554+
record->xl_prev.xlogid,record->xl_prev.xrecoff,
2555+
RecPtr->xlogid,RecPtr->xrecoff)));
2556+
gotonext_record_is_invalid;
2557+
}
2558+
}
25282559

25292560
/*
25302561
* Compute total length of record including any appended backup

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp