From: Tom Lane Date: Wed, 22 Dec 2004 18:45:49 +0000 (+0000) Subject: Awhile back I added some code to StartupCLOG() to forcibly zero out X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=5f02ab0021cd291ca88bcf1d2863a42079ee498d;p=users%2Fbernd%2Fpostgres.git 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. --- diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c index b8d8abd7b4..6d114524f6 100644 --- a/src/backend/access/transam/clog.c +++ b/src/backend/access/transam/clog.c @@ -212,10 +212,6 @@ StartupCLOG(void) { TransactionId xid = ShmemVariableCache->nextXid; int pageno = TransactionIdToPage(xid); - int byteno = TransactionIdToByte(xid); - int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT; - int slotno; - char *byteptr; LWLockAcquire(CLogControlLock, LW_EXCLUSIVE); @@ -232,17 +228,27 @@ StartupCLOG(void) * marked by the previous database lifecycle (since subtransaction * commit writes clog but makes no WAL entry). Let's just be safe. * (We need not worry about pages beyond the current one, since those - * will be zeroed when first used.) + * will be zeroed when first used. For the same reason, there is no + * need to do anything when nextXid is exactly at a page boundary; and + * it's likely that the "current" page doesn't exist yet in that case.) */ - slotno = SimpleLruReadPage(ClogCtl, pageno, xid); - byteptr = ClogCtl->shared->page_buffer[slotno] + byteno; + if (TransactionIdToPgIndex(xid) != 0) + { + int byteno = TransactionIdToByte(xid); + int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT; + int slotno; + char *byteptr; - /* Zero so-far-unused positions in the current byte */ - *byteptr &= (1 << bshift) - 1; - /* Zero the rest of the page */ - MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1); + slotno = SimpleLruReadPage(ClogCtl, pageno, xid); + byteptr = ClogCtl->shared->page_buffer[slotno] + byteno; - ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; + /* Zero so-far-unused positions in the current byte */ + *byteptr &= (1 << bshift) - 1; + /* Zero the rest of the page */ + MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1); + + ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; + } LWLockRelease(CLogControlLock); }