Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3092869

Browse files
committed
StartupXLOG(): initialize XLogCtl->Insert to new page if there is
no room for a record on last log page.
1 parent 495fe12 commit 3092869

File tree

1 file changed

+44
-14
lines changed
  • src/backend/access/transam

1 file changed

+44
-14
lines changed

src/backend/access/transam/xlog.c

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.63 2001/03/22 03:59:18 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.64 2001/04/05 09:34:32 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2440,23 +2440,53 @@ StartupXLOG(void)
24402440
openLogOff = 0;
24412441
ControlFile->logId = openLogId;
24422442
ControlFile->logSeg = openLogSeg + 1;
2443-
XLogCtl->xlblocks[0].xlogid = openLogId;
2444-
XLogCtl->xlblocks[0].xrecoff =
2445-
((EndOfLog.xrecoff - 1) / BLCKSZ + 1) * BLCKSZ;
24462443
Insert = &XLogCtl->Insert;
2444+
Insert->PrevRecord = LastRec;
24472445

24482446
/*
2449-
* Tricky point here: readBuf contains the *last* block that the
2450-
* LastRec record spans, not the one it starts in, which is what we
2451-
* want.
2447+
* If the next record will go to the new page
2448+
* then initialize for that one.
24522449
*/
2453-
Assert(readOff == (XLogCtl->xlblocks[0].xrecoff - BLCKSZ) % XLogSegSize);
2454-
memcpy((char *) Insert->currpage, readBuf, BLCKSZ);
2455-
Insert->currpos = (char *) Insert->currpage +
2456-
(EndOfLog.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
2457-
/* Make sure rest of page is zero */
2458-
memset(Insert->currpos, 0, INSERT_FREESPACE(Insert));
2459-
Insert->PrevRecord = LastRec;
2450+
if ((BLCKSZ - EndOfLog.xrecoff % BLCKSZ) < SizeOfXLogRecord)
2451+
EndOfLog.xrecoff += (BLCKSZ - EndOfLog.xrecoff % BLCKSZ);
2452+
if (EndOfLog.xrecoff % BLCKSZ == 0)
2453+
{
2454+
if (EndOfLog.xrecoff >= XLogFileSize)
2455+
{
2456+
XLogCtl->xlblocks[0].xlogid = EndOfLog.xlogid + 1;
2457+
XLogCtl->xlblocks[0].xrecoff = BLCKSZ;
2458+
}
2459+
else
2460+
{
2461+
XLogCtl->xlblocks[0].xlogid = EndOfLog.xlogid;
2462+
XLogCtl->xlblocks[0].xrecoff = EndOfLog.xrecoff + BLCKSZ;
2463+
}
2464+
Insert->currpos = (char *) Insert->currpage + SizeOfXLogPHD;
2465+
Insert->currpage->xlp_magic = XLOG_PAGE_MAGIC;
2466+
if (InRecovery)
2467+
Insert->currpage->xlp_sui = ThisStartUpID;
2468+
else
2469+
Insert->currpage->xlp_sui = ThisStartUpID + 1;
2470+
}
2471+
else
2472+
{
2473+
XLogCtl->xlblocks[0].xlogid = openLogId;
2474+
XLogCtl->xlblocks[0].xrecoff =
2475+
((EndOfLog.xrecoff - 1) / BLCKSZ + 1) * BLCKSZ;
2476+
/*
2477+
* Tricky point here: readBuf contains the *last* block that the
2478+
* LastRec record spans, not the one it starts in, which is what we
2479+
* want.
2480+
*
2481+
* XXX - why would we want block LastRec starts in?
2482+
*/
2483+
Assert(readOff == (XLogCtl->xlblocks[0].xrecoff - BLCKSZ) % XLogSegSize);
2484+
memcpy((char *) Insert->currpage, readBuf, BLCKSZ);
2485+
Insert->currpos = (char *) Insert->currpage +
2486+
(EndOfLog.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
2487+
/* Make sure rest of page is zero */
2488+
memset(Insert->currpos, 0, INSERT_FREESPACE(Insert));
2489+
}
24602490

24612491
LogwrtResult.Write = LogwrtResult.Flush = EndOfLog;
24622492

0 commit comments

Comments
 (0)