summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-05-31 19:11:14 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-05-31 19:11:14 +0000
commit2e1229671aec11a7a85706d4c69631f525569563 (patch)
tree139085cb903a88ff3fd66c3fa1dd1d0d34bcd56f
parent4f142baf3710814d3fa268020cc7f349ca3c69ea (diff)
downloadpostgresql-2e1229671aec11a7a85706d4c69631f525569563.tar.gz
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 records when a WAL page was only partially written during a system crash.
-rw-r--r--src/backend/access/transam/xlog.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a97f59490b..169d5037ba 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.109.2.4 2004/08/11 04:08:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.109.2.5 2005/05/31 19:11:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -431,8 +431,8 @@ static uint32 readOff = 0;
static char *readBuf = NULL;
/* State information for XLOG reading */
-static XLogRecPtr ReadRecPtr;
-static XLogRecPtr EndRecPtr;
+static XLogRecPtr ReadRecPtr; /* start of last record read */
+static XLogRecPtr EndRecPtr; /* end+1 of last record read */
static XLogRecord *nextRecord = NULL;
static StartUpID lastReadSUI;
@@ -1866,6 +1866,37 @@ got_record:;
RecPtr->xlogid, RecPtr->xrecoff);
goto next_record_is_invalid;
}
+ if (!nextmode)
+ {
+ /*
+ * We can't exactly verify the prev-link, but surely it should be
+ * less than the record's own address.
+ */
+ if (!XLByteLT(record->xl_prev, *RecPtr))
+ {
+ elog(emode,
+ "ReadRecord: record with incorrect prev-link %X/%X at %X/%X",
+ record->xl_prev.xlogid, record->xl_prev.xrecoff,
+ RecPtr->xlogid, RecPtr->xrecoff);
+ goto next_record_is_invalid;
+ }
+ }
+ else
+ {
+ /*
+ * Record's prev-link should exactly match our previous location.
+ * This check guards against torn WAL pages where a stale but
+ * valid-looking WAL record starts on a sector boundary.
+ */
+ if (!XLByteEQ(record->xl_prev, ReadRecPtr))
+ {
+ elog(emode,
+ "record with incorrect prev-link %X/%X at %X/%X",
+ record->xl_prev.xlogid, record->xl_prev.xrecoff,
+ RecPtr->xlogid, RecPtr->xrecoff);
+ goto next_record_is_invalid;
+ }
+ }
/*
* Compute total length of record including any appended backup