Get rid of SetBufferWriteMode(), which was an accident waiting to happen.

In the event of an elog() while the mode was set to immediate write,
there was no way for it to be set back to the normal delayed write.
The mechanism was a waste of space and cycles anyway, since the only user
was varsup.c, which could perfectly well call FlushBuffer directly.
Now it does just that, and the notion of a write mode is gone.
This commit is contained in:
Tom Lane 2000-03-31 02:43:31 +00:00
parent 5717dcb8a7
commit ca05ba2a9d
3 changed files with 37 additions and 75 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.26 2000/01/26 05:56:04 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.27 2000/03/31 02:43:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -88,7 +88,6 @@ VariableRelationPutNextXid(TransactionId xid)
{
Buffer buf;
VariableRelationContents var;
int flushmode;
/* ----------------
* We assume that a spinlock has been acquire to guarantee
@ -105,7 +104,7 @@ VariableRelationPutNextXid(TransactionId xid)
/* ----------------
* read the variable page, update the nextXid field and
* write the page back out to disk.
* write the page back out to disk (with immediate write).
* ----------------
*/
buf = ReadBuffer(VariableRelation, 0);
@ -120,9 +119,7 @@ VariableRelationPutNextXid(TransactionId xid)
TransactionIdStore(xid, &(var->nextXidData));
flushmode = SetBufferWriteMode(BUFFER_FLUSH_WRITE);
WriteBuffer(buf);
SetBufferWriteMode(flushmode);
FlushBuffer(buf, TRUE);
}
/* --------------------------------

View File

@ -8,30 +8,31 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.76 2000/03/14 22:46:27 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.77 2000/03/31 02:43:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
*
* BufferAlloc() -- lookup a buffer in the buffer table. If
* it isn't there add it, but do not read it into memory.
* it isn't there add it, but do not read data into memory.
* This is used when we are about to reinitialize the
* buffer so don't care what the current disk contents are.
* BufferAlloc() pins the new buffer in memory.
* BufferAlloc() also pins the new buffer in memory.
*
* ReadBuffer() -- same as BufferAlloc() but reads the data
* ReadBuffer() -- like BufferAlloc() but reads the data
* on a buffer cache miss.
*
* ReleaseBuffer() -- unpin the buffer
*
* WriteNoReleaseBuffer() -- mark the buffer contents as "dirty"
* but don't unpin. The disk IO is delayed until buffer
* replacement if WriteMode is BUFFER_LATE_WRITE.
* replacement.
*
* WriteBuffer() -- WriteNoReleaseBuffer() + ReleaseBuffer()
*
* FlushBuffer() -- as above but never delayed write.
* FlushBuffer() -- Write buffer immediately. Can unpin, or not,
* depending on parameter.
*
* BufferSync() -- flush all dirty buffers in the buffer pool.
*
@ -70,11 +71,7 @@ extern long int LocalBufferFlushCount;
*/
bool SharedBufferChanged = false;
static int WriteMode = BUFFER_LATE_WRITE; /* Delayed write is
* default */
static void WaitIO(BufferDesc *buf, SPINLOCK spinlock);
static void StartBufferIO(BufferDesc *buf, bool forInput);
static void TerminateBufferIO(BufferDesc *buf);
static void ContinueBufferIO(BufferDesc *buf, bool forInput);
@ -97,7 +94,6 @@ static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum,
bool bufferLockHeld);
static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
bool *foundPtr, bool bufferLockHeld);
static int FlushBuffer(Buffer buffer, bool release);
static void BufferSync(void);
static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld);
void PrintBufferDescs(void);
@ -658,8 +654,7 @@ BufferAlloc(Relation reln,
/*
* WriteBuffer
*
* Pushes buffer contents to disk if WriteMode is BUFFER_FLUSH_WRITE.
* Otherwise, marks contents as dirty.
* Marks buffer contents as dirty (actual write happens later).
*
* Assume that buffer is pinned. Assume that reln is
* valid.
@ -675,28 +670,23 @@ WriteBuffer(Buffer buffer)
{
BufferDesc *bufHdr;
if (WriteMode == BUFFER_FLUSH_WRITE)
return FlushBuffer(buffer, TRUE);
else
{
if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, TRUE);
if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, TRUE);
if (BAD_BUFFER_ID(buffer))
return FALSE;
if (BAD_BUFFER_ID(buffer))
return FALSE;
bufHdr = &BufferDescriptors[buffer - 1];
bufHdr = &BufferDescriptors[buffer - 1];
SharedBufferChanged = true;
SharedBufferChanged = true;
SpinAcquire(BufMgrLock);
Assert(bufHdr->refcount > 0);
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
UnpinBuffer(bufHdr);
SpinRelease(BufMgrLock);
CommitInfoNeedsSave[buffer - 1] = 0;
SpinAcquire(BufMgrLock);
Assert(bufHdr->refcount > 0);
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
UnpinBuffer(bufHdr);
SpinRelease(BufMgrLock);
CommitInfoNeedsSave[buffer - 1] = 0;
}
return TRUE;
}
@ -778,9 +768,9 @@ DirtyBufferCopy(Oid dbid, Oid relid, BlockNumber blkno, char *dest)
* 'buffer' is known to be dirty/pinned, so there should not be a
* problem reading the BufferDesc members without the BufMgrLock
* (nobody should be able to change tags, flags, etc. out from under
* us).
* us). Unpin if 'release' is TRUE.
*/
static int
int
FlushBuffer(Buffer buffer, bool release)
{
BufferDesc *bufHdr;
@ -850,36 +840,27 @@ FlushBuffer(Buffer buffer, bool release)
/*
* WriteNoReleaseBuffer -- like WriteBuffer, but do not unpin the buffer
* when the operation is complete.
*
* We know that the buffer is for a relation in our private cache,
* because this routine is called only to write out buffers that
* were changed by the executing backend.
*/
int
WriteNoReleaseBuffer(Buffer buffer)
{
BufferDesc *bufHdr;
if (WriteMode == BUFFER_FLUSH_WRITE)
return FlushBuffer(buffer, FALSE);
else
{
if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, FALSE);
if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, FALSE);
if (BAD_BUFFER_ID(buffer))
return STATUS_ERROR;
if (BAD_BUFFER_ID(buffer))
return STATUS_ERROR;
bufHdr = &BufferDescriptors[buffer - 1];
bufHdr = &BufferDescriptors[buffer - 1];
SharedBufferChanged = true;
SharedBufferChanged = true;
SpinAcquire(BufMgrLock);
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
SpinRelease(BufMgrLock);
CommitInfoNeedsSave[buffer - 1] = 0;
SpinAcquire(BufMgrLock);
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
SpinRelease(BufMgrLock);
CommitInfoNeedsSave[buffer - 1] = 0;
}
return STATUS_OK;
}
@ -2002,16 +1983,6 @@ _bm_die(Oid dbId, Oid relId, int blkNo, int bufNo,
#endif /* BMTRACE */
int
SetBufferWriteMode(int mode)
{
int old;
old = WriteMode;
WriteMode = mode;
return old;
}
void
SetBufferCommitInfoNeedsSave(Buffer buffer)
{

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: bufmgr.h,v 1.34 2000/01/26 05:58:32 momjian Exp $
* $Id: bufmgr.h,v 1.35 2000/03/31 02:43:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -56,12 +56,6 @@ typedef bits16 BufferLock;
extern int ShowPinTrace;
/*
* BufferWriteModes (settable via SetBufferWriteMode)
*/
#define BUFFER_FLUSH_WRITE 0 /* immediate write */
#define BUFFER_LATE_WRITE 1 /* delayed write: mark as DIRTY */
/*
* Buffer context lock modes
*/
@ -165,6 +159,7 @@ extern int WriteBuffer(Buffer buffer);
extern int WriteNoReleaseBuffer(Buffer buffer);
extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
BlockNumber blockNum);
extern int FlushBuffer(Buffer buffer, bool release);
extern void InitBufferPool(IPCKey key);
extern void PrintBufferUsage(FILE *statfp);
@ -182,7 +177,6 @@ extern void PrintPinnedBufs(void);
extern int BufferShmemSize(void);
extern int ReleaseBuffer(Buffer buffer);
extern int SetBufferWriteMode(int mode);
extern void SetBufferCommitInfoNeedsSave(Buffer buffer);
extern void UnlockBuffers(void);