|
24 | 24 | * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
25 | 25 | * Portions Copyright (c) 1994, Regents of the University of California
|
26 | 26 | *
|
27 |
| - * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.25 2004/08/29 05:06:40 momjian Exp $ |
| 27 | + * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.26 2004/08/30 19:00:42 tgl Exp $ |
28 | 28 | *
|
29 | 29 | *-------------------------------------------------------------------------
|
30 | 30 | */
|
@@ -210,10 +210,41 @@ ZeroCLOGPage(int pageno, bool writeXlog)
|
210 | 210 | void
|
211 | 211 | StartupCLOG(void)
|
212 | 212 | {
|
| 213 | + TransactionId xid = ShmemVariableCache->nextXid; |
| 214 | + int pageno = TransactionIdToPage(xid); |
| 215 | + int byteno = TransactionIdToByte(xid); |
| 216 | + int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT; |
| 217 | + int slotno; |
| 218 | + char *byteptr; |
| 219 | + |
| 220 | + LWLockAcquire(CLogControlLock, LW_EXCLUSIVE); |
| 221 | + |
213 | 222 | /*
|
214 | 223 | * Initialize our idea of the latest page number.
|
215 | 224 | */
|
216 |
| - ClogCtl->shared->latest_page_number = TransactionIdToPage(ShmemVariableCache->nextXid); |
| 225 | + ClogCtl->shared->latest_page_number = pageno; |
| 226 | + |
| 227 | + /* |
| 228 | + * Zero out the remainder of the current clog page. Under normal |
| 229 | + * circumstances it should be zeroes already, but it seems at least |
| 230 | + * theoretically possible that XLOG replay will have settled on a |
| 231 | + * nextXID value that is less than the last XID actually used and |
| 232 | + * marked by the previous database lifecycle (since subtransaction |
| 233 | + * commit writes clog but makes no WAL entry). Let's just be safe. |
| 234 | + * (We need not worry about pages beyond the current one, since those |
| 235 | + * will be zeroed when first used.) |
| 236 | + */ |
| 237 | + slotno = SimpleLruReadPage(ClogCtl, pageno, xid); |
| 238 | + byteptr = ClogCtl->shared->page_buffer[slotno] + byteno; |
| 239 | + |
| 240 | + /* Zero so-far-unused positions in the current byte */ |
| 241 | + *byteptr &= (1 << bshift) - 1; |
| 242 | + /* Zero the rest of the page */ |
| 243 | + MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1); |
| 244 | + |
| 245 | + ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; |
| 246 | + |
| 247 | + LWLockRelease(CLogControlLock); |
217 | 248 | }
|
218 | 249 |
|
219 | 250 | /*
|
|
0 commit comments