aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/sequence.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-03-31 23:32:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-03-31 23:32:07 +0000
commita8b8f4db23cff16af50a2b960cb8d20d39b761cf (patch)
tree224f8cb0da7e2e17ccfd7b8a030db1664acd46c1 /src/backend/commands/sequence.c
parent89395bfa6f2fafccec10be377fcf759030910654 (diff)
downloadpostgresql-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/commands/sequence.c')
-rw-r--r--src/backend/commands/sequence.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 0e448271e13..10ebe56b6a9 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.131 2006/03/29 21:17:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.132 2006/03/31 23:32:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -249,6 +249,8 @@ DefineSequence(CreateSeqStmt *seq)
tuple->t_data->t_infomask |= HEAP_XMIN_COMMITTED;
}
+ MarkBufferDirty(buf);
+
/* XLOG stuff */
if (!rel->rd_istemp)
{
@@ -281,8 +283,8 @@ DefineSequence(CreateSeqStmt *seq)
END_CRIT_SECTION();
- LockBuffer(buf, BUFFER_LOCK_UNLOCK);
- WriteBuffer(buf);
+ UnlockReleaseBuffer(buf);
+
heap_close(rel, NoLock);
}
@@ -331,6 +333,8 @@ AlterSequence(AlterSeqStmt *stmt)
START_CRIT_SECTION();
+ MarkBufferDirty(buf);
+
/* XLOG stuff */
if (!seqrel->rd_istemp)
{
@@ -358,9 +362,7 @@ AlterSequence(AlterSeqStmt *stmt)
END_CRIT_SECTION();
- LockBuffer(buf, BUFFER_LOCK_UNLOCK);
-
- WriteBuffer(buf);
+ UnlockReleaseBuffer(buf);
relation_close(seqrel, NoLock);
}
@@ -550,6 +552,8 @@ nextval_internal(Oid relid)
START_CRIT_SECTION();
+ MarkBufferDirty(buf);
+
/* XLOG stuff */
if (logit && !seqrel->rd_istemp)
{
@@ -587,9 +591,7 @@ nextval_internal(Oid relid)
END_CRIT_SECTION();
- LockBuffer(buf, BUFFER_LOCK_UNLOCK);
-
- WriteBuffer(buf);
+ UnlockReleaseBuffer(buf);
relation_close(seqrel, NoLock);
@@ -720,6 +722,8 @@ do_setval(Oid relid, int64 next, bool iscalled)
START_CRIT_SECTION();
+ MarkBufferDirty(buf);
+
/* XLOG stuff */
if (!seqrel->rd_istemp)
{
@@ -758,9 +762,7 @@ do_setval(Oid relid, int64 next, bool iscalled)
END_CRIT_SECTION();
- LockBuffer(buf, BUFFER_LOCK_UNLOCK);
-
- WriteBuffer(buf);
+ UnlockReleaseBuffer(buf);
relation_close(seqrel, NoLock);
}
@@ -1159,8 +1161,8 @@ seq_redo(XLogRecPtr lsn, XLogRecord *record)
PageSetLSN(page, lsn);
PageSetTLI(page, ThisTimeLineID);
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
- WriteBuffer(buffer);
+ MarkBufferDirty(buffer);
+ UnlockReleaseBuffer(buffer);
}
void