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

Commit bfa5f30

Browse files
committed
Awhile back I added some code to StartupCLOG() to forcibly zero out
the remainder of the current clog page during system startup. While this was a good idea, it turns out the code fails if nextXid is exactly at a page boundary, because we won't have created the "current" clog page yet in that case. Since the page will be correctly zeroed when we execute the first transaction on it, the solution is just to do nothing when exactly at a page boundary. Per trouble report from Dave Hartwig.
1 parent 766b0bb commit bfa5f30

File tree

1 file changed

+19
-13
lines changed
  • src/backend/access/transam

1 file changed

+19
-13
lines changed

src/backend/access/transam/clog.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
2525
* Portions Copyright (c) 1994, Regents of the University of California
2626
*
27-
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.26 2004/08/30 19:00:42 tgl Exp $
27+
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.27 2004/12/22 18:45:49 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -212,10 +212,6 @@ StartupCLOG(void)
212212
{
213213
TransactionId xid = ShmemVariableCache->nextXid;
214214
int pageno = TransactionIdToPage(xid);
215-
int byteno = TransactionIdToByte(xid);
216-
int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT;
217-
int slotno;
218-
char *byteptr;
219215

220216
LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
221217

@@ -232,17 +228,27 @@ StartupCLOG(void)
232228
* marked by the previous database lifecycle (since subtransaction
233229
* commit writes clog but makes no WAL entry). Let's just be safe.
234230
* (We need not worry about pages beyond the current one, since those
235-
* will be zeroed when first used.)
231+
* will be zeroed when first used. For the same reason, there is no
232+
* need to do anything when nextXid is exactly at a page boundary; and
233+
* it's likely that the "current" page doesn't exist yet in that case.)
236234
*/
237-
slotno = SimpleLruReadPage(ClogCtl, pageno, xid);
238-
byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
235+
if (TransactionIdToPgIndex(xid) != 0)
236+
{
237+
int byteno = TransactionIdToByte(xid);
238+
int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT;
239+
int slotno;
240+
char *byteptr;
239241

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);
242+
slotno = SimpleLruReadPage(ClogCtl, pageno, xid);
243+
byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
244244

245-
ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY;
245+
/* Zero so-far-unused positions in the current byte */
246+
*byteptr &= (1 << bshift) - 1;
247+
/* Zero the rest of the page */
248+
MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
249+
250+
ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY;
251+
}
246252

247253
LWLockRelease(CLogControlLock);
248254
}

0 commit comments

Comments
 (0)