I posted some bufmgr cleanup a few weeks ago, but it conflicted with
some concurrent changes Jan was making to the bufmgr. Here's an
updated version of the patch -- it should apply cleanly to CVS
HEAD and passes the regression tests.
This patch makes the following changes:
- remove the UnlockAndReleaseBuffer() and UnlockAndWriteBuffer()
macros, and replace uses of them with calls to the appropriate
functions.
- remove a bunch of #ifdef BMTRACE code: it is ugly & broken
(i.e. it doesn't compile)
- make BufferReplace() return a bool, not an int
- cleanup some logic in bufmgr.c; should be functionality
equivalent to the previous code, just cleaner now
- remove the BM_PRIVATE flag as it is unused
- improve a few comments, etc.
-Neil
Index: src/backend/access/heap/heapam.c
===
RCS file: /var/lib/cvs/pgsql-server/src/backend/access/heap/heapam.c,v
retrieving revision 1.158
diff -c -r1.158 heapam.c
*** src/backend/access/heap/heapam.c 29 Nov 2003 19:51:40 - 1.158
--- src/backend/access/heap/heapam.c 10 Dec 2003 22:34:31 -
***
*** 2110,2116
if (XLByteLE(lsn, PageGetLSN(page)))
{
! UnlockAndReleaseBuffer(buffer);
return;
}
--- 2110,2117
if (XLByteLE(lsn, PageGetLSN(page)))
{
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! ReleaseBuffer(buffer);
return;
}
***
*** 2135,2141
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID); /* prev sui */
! UnlockAndWriteBuffer(buffer);
}
static void
--- 2136,2143
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID); /* prev sui */
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! WriteBuffer(buffer);
}
static void
***
*** 2170,2176
{
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! UnlockAndReleaseBuffer(buffer);
return;
}
}
--- 2172,2179
{
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! ReleaseBuffer(buffer);
return;
}
}
***
*** 2199,2205
htup->t_ctid = xlrec->target.tid;
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID);
! UnlockAndWriteBuffer(buffer);
return;
}
--- 2202,2209
htup->t_ctid = xlrec->target.tid;
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID);
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! WriteBuffer(buffer);
return;
}
***
*** 2249,2255
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! UnlockAndReleaseBuffer(buffer);
return;
}
--- 2253,2260
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! ReleaseBuffer(buffer);
return;
}
***
*** 2282,2288
elog(PANIC, "heap_insert_redo: failed to add tuple");
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID); /* prev sui */
! UnlockAndWriteBuffer(buffer);
return;
}
--- 2287,2294
elog(PANIC, "heap_insert_redo: failed to add tuple");
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID); /* prev sui */
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! WriteBuffer(buffer);
return;
}
***
*** 2332,2338
{
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! UnlockAndReleaseBuffer(buffer);
if (samepage)
return;
goto newt;
--- 2338,2345
{
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! ReleaseBuffer(buffer);
if (samepage)
return;
goto newt;
***
*** 2378,2384
goto newsame;
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID);
! UnlockAndWriteBuffer(buffer);
goto newt;
}
--- 2385,2392
goto newsame;
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID);
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! WriteBuffer(buffer);
goto newt;
}
***
*** 2421,2427
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! UnlockAndReleaseBuffer(buffer);
return;
}
--- 2429,2436
if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */
{
! LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
! ReleaseBuffer(buffer);
return;
}
***
*** 2474,2480
elog(PANIC, "heap_update_redo: failed to add tuple");
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID); /* prev sui */
! UnlockAndWriteBuffer(buffer);
return;
}
--- 2483,2490
elog(PANIC, "heap_update_redo: failed to add tuple");
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID); /* prev sui */
! LockBuffer(buffer, BUFFER_LOCK_UNLOC