|
7 | 7 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
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 $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -2440,23 +2440,53 @@ StartupXLOG(void)
|
2440 | 2440 | openLogOff = 0;
|
2441 | 2441 | ControlFile->logId = openLogId;
|
2442 | 2442 | ControlFile->logSeg = openLogSeg + 1;
|
2443 |
| - XLogCtl->xlblocks[0].xlogid = openLogId; |
2444 |
| - XLogCtl->xlblocks[0].xrecoff = |
2445 |
| - ((EndOfLog.xrecoff - 1) / BLCKSZ + 1) * BLCKSZ; |
2446 | 2443 | Insert = &XLogCtl->Insert;
|
| 2444 | + Insert->PrevRecord = LastRec; |
2447 | 2445 |
|
2448 | 2446 | /*
|
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. |
2452 | 2449 | */
|
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 | + } |
2460 | 2490 |
|
2461 | 2491 | LogwrtResult.Write = LogwrtResult.Flush = EndOfLog;
|
2462 | 2492 |
|
|
0 commit comments