diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-03-31 23:32:07 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-03-31 23:32:07 +0000 |
commit | a8b8f4db23cff16af50a2b960cb8d20d39b761cf (patch) | |
tree | 224f8cb0da7e2e17ccfd7b8a030db1664acd46c1 /src/backend/access/gist/gistxlog.c | |
parent | 89395bfa6f2fafccec10be377fcf759030910654 (diff) | |
download | postgresql-a8b8f4db23cff16af50a2b960cb8d20d39b761cf.tar.gz postgresql-a8b8f4db23cff16af50a2b960cb8d20d39b761cf.zip |
Clean up WAL/buffer interactions as per my recent proposal. Get rid of the
misleadingly-named WriteBuffer routine, and instead require routines that
change buffer pages to call MarkBufferDirty (which does exactly what it says).
We also require that they do so before calling XLogInsert; this takes care of
the synchronization requirement documented in SyncOneBuffer. Note that
because bufmgr takes the buffer content lock (in shared mode) while writing
out any buffer, it doesn't matter whether MarkBufferDirty is executed before
the buffer content change is complete, so long as the content change is
completed before releasing exclusive lock on the buffer. So it's OK to set
the dirtybit before we fill in the LSN.
This eliminates the former kluge of needing to set the dirtybit in LockBuffer.
Aside from making the code more transparent, we can also add some new
debugging assertions, in particular that the caller of MarkBufferDirty must
hold the buffer content lock, not merely a pin.
Diffstat (limited to 'src/backend/access/gist/gistxlog.c')
-rw-r--r-- | src/backend/access/gist/gistxlog.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c index 12a521c75c9..fbceae29a96 100644 --- a/src/backend/access/gist/gistxlog.c +++ b/src/backend/access/gist/gistxlog.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.13 2006/03/30 23:03:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.14 2006/03/31 23:32:05 tgl Exp $ *------------------------------------------------------------------------- */ #include "postgres.h" @@ -192,8 +192,7 @@ gistRedoPageUpdateRecord(XLogRecPtr lsn, XLogRecord *record, bool isnewroot) if (XLByteLE(lsn, PageGetLSN(page))) { - LockBuffer(buffer, BUFFER_LOCK_UNLOCK); - ReleaseBuffer(buffer); + UnlockReleaseBuffer(buffer); return; } @@ -236,8 +235,8 @@ gistRedoPageUpdateRecord(XLogRecPtr lsn, XLogRecord *record, bool isnewroot) GistPageGetOpaque(page)->rightlink = InvalidBlockNumber; PageSetLSN(page, lsn); PageSetTLI(page, ThisTimeLineID); - LockBuffer(buffer, BUFFER_LOCK_UNLOCK); - WriteBuffer(buffer); + MarkBufferDirty(buffer); + UnlockReleaseBuffer(buffer); if (ItemPointerIsValid(&(xlrec.data->key))) { @@ -313,8 +312,8 @@ gistRedoPageSplitRecord(XLogRecPtr lsn, XLogRecord *record) PageSetLSN(page, lsn); PageSetTLI(page, ThisTimeLineID); - LockBuffer(buffer, BUFFER_LOCK_UNLOCK); - WriteBuffer(buffer); + MarkBufferDirty(buffer); + UnlockReleaseBuffer(buffer); } if (ItemPointerIsValid(&(xlrec.data->key))) @@ -346,8 +345,8 @@ gistRedoCreateIndex(XLogRecPtr lsn, XLogRecord *record) PageSetLSN(page, lsn); PageSetTLI(page, ThisTimeLineID); - LockBuffer(buffer, BUFFER_LOCK_UNLOCK); - WriteBuffer(buffer); + MarkBufferDirty(buffer); + UnlockReleaseBuffer(buffer); } static void @@ -561,8 +560,8 @@ gistContinueInsert(gistIncompleteInsert *insert) PageSetLSN(page, insert->lsn); PageSetTLI(page, ThisTimeLineID); - LockBuffer(buffer, BUFFER_LOCK_UNLOCK); - WriteBuffer(buffer); + MarkBufferDirty(buffer); + UnlockReleaseBuffer(buffer); /* * XXX fall out to avoid making LOG message at bottom of routine. @@ -598,8 +597,7 @@ gistContinueInsert(gistIncompleteInsert *insert) if (XLByteLE(insert->lsn, PageGetLSN(pages[numbuffer - 1]))) { - LockBuffer(buffers[numbuffer - 1], BUFFER_LOCK_UNLOCK); - ReleaseBuffer(buffers[numbuffer - 1]); + UnlockReleaseBuffer(buffers[numbuffer - 1]); return; } @@ -685,8 +683,8 @@ gistContinueInsert(gistIncompleteInsert *insert) PageSetLSN(pages[j], insert->lsn); PageSetTLI(pages[j], ThisTimeLineID); GistPageGetOpaque(pages[j])->rightlink = InvalidBlockNumber; - LockBuffer(buffers[j], BUFFER_LOCK_UNLOCK); - WriteBuffer(buffers[j]); + MarkBufferDirty(buffers[j]); + UnlockReleaseBuffer(buffers[j]); } } } |