summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2003-07-17 16:45:25 +0000
committerTom Lane2003-07-17 16:45:25 +0000
commit0a49e774b1ba172b9d2387152bb843ea7fb3c622 (patch)
tree0a4ffb48e9f98b3f6fc4e3f8270e374bc8c4577c
parent537c1c1983ad82dfbc101dac5184b7257a3f998c (diff)
Repair boundary-case bug introduced by patch of two months ago that
fixed incorrect initial setting of StartUpID. The logic in XLogWrite() expects that Write->curridx is advanced to the next page as soon as LogwrtResult points to the end of the current page, but StartupXLOG() failed to make that happen when the old WAL ended exactly on a page boundary. Per trouble report from Hannu Krosing.
-rw-r--r--src/backend/access/transam/xlog.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index b5ff63f0fc6..e4961af4307 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.2 2003/05/22 14:39:49 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.109.2.3 2003/07/17 16:45:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2483,6 +2483,7 @@ StartupXLOG(void)
EndOfLog;
XLogRecord *record;
char *buffer;
+ uint32 freespace;
/* Use malloc() to ensure record buffer is MAXALIGNED */
buffer = (char *) malloc(_INTL_MAXLOGRECSZ);
@@ -2678,8 +2679,6 @@ StartupXLOG(void)
memcpy((char *) Insert->currpage, readBuf, BLCKSZ);
Insert->currpos = (char *) Insert->currpage +
(EndOfLog.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
- /* Make sure rest of page is zero */
- MemSet(Insert->currpos, 0, INSERT_FREESPACE(Insert));
LogwrtResult.Write = LogwrtResult.Flush = EndOfLog;
@@ -2690,6 +2689,27 @@ StartupXLOG(void)
XLogCtl->LogwrtRqst.Write = EndOfLog;
XLogCtl->LogwrtRqst.Flush = EndOfLog;
+ freespace = INSERT_FREESPACE(Insert);
+ if (freespace > 0)
+ {
+ /* Make sure rest of page is zero */
+ MemSet(Insert->currpos, 0, freespace);
+ XLogCtl->Write.curridx = 0;
+ }
+ else
+ {
+ /*
+ * Whenever Write.LogwrtResult points to exactly the end of a page,
+ * Write.curridx must point to the *next* page (see XLogWrite()).
+ *
+ * Note: it might seem we should do AdvanceXLInsertBuffer() here,
+ * but we can't since we haven't yet determined the correct StartUpID
+ * to put into the new page's header. The first actual attempt to
+ * insert a log record will advance the insert state.
+ */
+ XLogCtl->Write.curridx = NextBufIdx(0);
+ }
+
#ifdef NOT_USED
/* UNDO */
if (InRecovery)