diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 44e5a0610ef..e845677313a 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -200,12 +200,11 @@ static XLogRecPtr flushedUpto = 0; static TimeLineID receiveTLI = 0; /* - * abortedRecPtr is the start pointer of a broken record at end of WAL when - * recovery completes; missingContrecPtr is the location of the first - * contrecord that went missing. See CreateOverwriteContrecordRecord for - * details. + * missingContrecPtr is the location of the first contrecord that went missing. + * XLogCtl->lastReplayedEndRecPtr will be the start pointer of a broken record + * at end of WAL when recovery completes. See CreateOverwriteContrecordRecord + * for details. */ -static XLogRecPtr abortedRecPtr; static XLogRecPtr missingContrecPtr; /* @@ -4428,11 +4427,8 @@ ReadRecord(XLogReaderState *xlogreader, int emode, * that portion is to be ignored. */ if (!StandbyMode && - !XLogRecPtrIsInvalid(xlogreader->abortedRecPtr)) - { - abortedRecPtr = xlogreader->abortedRecPtr; + !XLogRecPtrIsInvalid(xlogreader->missingContrecPtr)) missingContrecPtr = xlogreader->missingContrecPtr; - } if (readFile >= 0) { @@ -7194,7 +7190,6 @@ StartupXLOG(void) /* * Start recovery assuming that the final record isn't lost. */ - abortedRecPtr = InvalidXLogRecPtr; missingContrecPtr = InvalidXLogRecPtr; /* REDO */ @@ -7961,10 +7956,7 @@ StartupXLOG(void) * we'll do as soon as we're open for writing new WAL.) */ if (!XLogRecPtrIsInvalid(missingContrecPtr)) - { - Assert(!XLogRecPtrIsInvalid(abortedRecPtr)); EndOfLog = missingContrecPtr; - } /* * Prepare to write WAL starting at EndOfLog location, and init xlog @@ -8021,11 +8013,25 @@ StartupXLOG(void) LocalSetXLogInsertAllowed(); /* If necessary, write overwrite-contrecord before doing anything else */ - if (!XLogRecPtrIsInvalid(abortedRecPtr)) + if (!XLogRecPtrIsInvalid(missingContrecPtr)) { - Assert(!XLogRecPtrIsInvalid(missingContrecPtr)); - CreateOverwriteContrecordRecord(abortedRecPtr); - abortedRecPtr = InvalidXLogRecPtr; + uint64 bytepos; + XLogRecPtr recPtr; + + Assert(!XLogRecPtrIsInvalid(XLogCtl->lastReplayedEndRecPtr)); + + /* + * lastReplayedEndRecPtr is pointing to the end+1 of the previous + * replayed WAL record. If that were at a page boundary, then the start + * of the broken record is on the next page. To calculate the correct + * start point of the broken record, we must skip over the page header. + * Therefore, firstly calculate "usable byte position" from + * lastReplayedEndRecPtr, then convert that to record pointer. + */ + bytepos = XLogRecPtrToBytePos(XLogCtl->lastReplayedEndRecPtr); + recPtr = XLogBytePosToRecPtr(bytepos); + + CreateOverwriteContrecordRecord(recPtr); missingContrecPtr = InvalidXLogRecPtr; } diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 4b03577dccd..516124ecd5f 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -294,7 +294,6 @@ XLogReadRecord(XLogReaderState *state, char **errormsg) state->errormsg_buf[0] = '\0'; ResetDecoder(state); - state->abortedRecPtr = InvalidXLogRecPtr; state->missingContrecPtr = InvalidXLogRecPtr; RecPtr = state->EndRecPtr; @@ -586,7 +585,6 @@ err: * in turn signal downstream WAL consumers that the broken WAL record * is to be ignored. */ - state->abortedRecPtr = RecPtr; state->missingContrecPtr = targetPagePtr; } diff --git a/src/include/access/xlogreader.h b/src/include/access/xlogreader.h index de6fd791fe6..d876e25de7f 100644 --- a/src/include/access/xlogreader.h +++ b/src/include/access/xlogreader.h @@ -176,11 +176,9 @@ struct XLogReaderState XLogRecPtr EndRecPtr; /* end+1 of last record read */ /* - * Set at the end of recovery: the start point of a partial record at the - * end of WAL (InvalidXLogRecPtr if there wasn't one), and the start - * location of its first contrecord that went missing. + * Set at the end of recovery: the start location of its first contrecord + * that went missing. */ - XLogRecPtr abortedRecPtr; XLogRecPtr missingContrecPtr; /* Set when XLP_FIRST_IS_OVERWRITE_CONTRECORD is found */ XLogRecPtr overwrittenRecPtr;