mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08:00
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:
parent
5717dcb8a7
commit
ca05ba2a9d
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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;
|
Buffer buf;
|
||||||
VariableRelationContents var;
|
VariableRelationContents var;
|
||||||
int flushmode;
|
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* We assume that a spinlock has been acquire to guarantee
|
* 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
|
* 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);
|
buf = ReadBuffer(VariableRelation, 0);
|
||||||
@ -120,9 +119,7 @@ VariableRelationPutNextXid(TransactionId xid)
|
|||||||
|
|
||||||
TransactionIdStore(xid, &(var->nextXidData));
|
TransactionIdStore(xid, &(var->nextXidData));
|
||||||
|
|
||||||
flushmode = SetBufferWriteMode(BUFFER_FLUSH_WRITE);
|
FlushBuffer(buf, TRUE);
|
||||||
WriteBuffer(buf);
|
|
||||||
SetBufferWriteMode(flushmode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------
|
/* --------------------------------
|
||||||
|
@ -8,30 +8,31 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* 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
|
* This is used when we are about to reinitialize the
|
||||||
* buffer so don't care what the current disk contents are.
|
* 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.
|
* on a buffer cache miss.
|
||||||
*
|
*
|
||||||
* ReleaseBuffer() -- unpin the buffer
|
* ReleaseBuffer() -- unpin the buffer
|
||||||
*
|
*
|
||||||
* WriteNoReleaseBuffer() -- mark the buffer contents as "dirty"
|
* WriteNoReleaseBuffer() -- mark the buffer contents as "dirty"
|
||||||
* but don't unpin. The disk IO is delayed until buffer
|
* but don't unpin. The disk IO is delayed until buffer
|
||||||
* replacement if WriteMode is BUFFER_LATE_WRITE.
|
* replacement.
|
||||||
*
|
*
|
||||||
* WriteBuffer() -- WriteNoReleaseBuffer() + ReleaseBuffer()
|
* 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.
|
* BufferSync() -- flush all dirty buffers in the buffer pool.
|
||||||
*
|
*
|
||||||
@ -70,11 +71,7 @@ extern long int LocalBufferFlushCount;
|
|||||||
*/
|
*/
|
||||||
bool SharedBufferChanged = false;
|
bool SharedBufferChanged = false;
|
||||||
|
|
||||||
static int WriteMode = BUFFER_LATE_WRITE; /* Delayed write is
|
|
||||||
* default */
|
|
||||||
|
|
||||||
static void WaitIO(BufferDesc *buf, SPINLOCK spinlock);
|
static void WaitIO(BufferDesc *buf, SPINLOCK spinlock);
|
||||||
|
|
||||||
static void StartBufferIO(BufferDesc *buf, bool forInput);
|
static void StartBufferIO(BufferDesc *buf, bool forInput);
|
||||||
static void TerminateBufferIO(BufferDesc *buf);
|
static void TerminateBufferIO(BufferDesc *buf);
|
||||||
static void ContinueBufferIO(BufferDesc *buf, bool forInput);
|
static void ContinueBufferIO(BufferDesc *buf, bool forInput);
|
||||||
@ -97,7 +94,6 @@ static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum,
|
|||||||
bool bufferLockHeld);
|
bool bufferLockHeld);
|
||||||
static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
|
static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
|
||||||
bool *foundPtr, bool bufferLockHeld);
|
bool *foundPtr, bool bufferLockHeld);
|
||||||
static int FlushBuffer(Buffer buffer, bool release);
|
|
||||||
static void BufferSync(void);
|
static void BufferSync(void);
|
||||||
static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld);
|
static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld);
|
||||||
void PrintBufferDescs(void);
|
void PrintBufferDescs(void);
|
||||||
@ -658,8 +654,7 @@ BufferAlloc(Relation reln,
|
|||||||
/*
|
/*
|
||||||
* WriteBuffer
|
* WriteBuffer
|
||||||
*
|
*
|
||||||
* Pushes buffer contents to disk if WriteMode is BUFFER_FLUSH_WRITE.
|
* Marks buffer contents as dirty (actual write happens later).
|
||||||
* Otherwise, marks contents as dirty.
|
|
||||||
*
|
*
|
||||||
* Assume that buffer is pinned. Assume that reln is
|
* Assume that buffer is pinned. Assume that reln is
|
||||||
* valid.
|
* valid.
|
||||||
@ -675,28 +670,23 @@ WriteBuffer(Buffer buffer)
|
|||||||
{
|
{
|
||||||
BufferDesc *bufHdr;
|
BufferDesc *bufHdr;
|
||||||
|
|
||||||
if (WriteMode == BUFFER_FLUSH_WRITE)
|
if (BufferIsLocal(buffer))
|
||||||
return FlushBuffer(buffer, TRUE);
|
return WriteLocalBuffer(buffer, TRUE);
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
if (BufferIsLocal(buffer))
|
if (BAD_BUFFER_ID(buffer))
|
||||||
return WriteLocalBuffer(buffer, TRUE);
|
return FALSE;
|
||||||
|
|
||||||
if (BAD_BUFFER_ID(buffer))
|
bufHdr = &BufferDescriptors[buffer - 1];
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
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;
|
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
|
* 'buffer' is known to be dirty/pinned, so there should not be a
|
||||||
* problem reading the BufferDesc members without the BufMgrLock
|
* problem reading the BufferDesc members without the BufMgrLock
|
||||||
* (nobody should be able to change tags, flags, etc. out from under
|
* (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)
|
FlushBuffer(Buffer buffer, bool release)
|
||||||
{
|
{
|
||||||
BufferDesc *bufHdr;
|
BufferDesc *bufHdr;
|
||||||
@ -850,36 +840,27 @@ FlushBuffer(Buffer buffer, bool release)
|
|||||||
/*
|
/*
|
||||||
* WriteNoReleaseBuffer -- like WriteBuffer, but do not unpin the buffer
|
* WriteNoReleaseBuffer -- like WriteBuffer, but do not unpin the buffer
|
||||||
* when the operation is complete.
|
* 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
|
int
|
||||||
WriteNoReleaseBuffer(Buffer buffer)
|
WriteNoReleaseBuffer(Buffer buffer)
|
||||||
{
|
{
|
||||||
BufferDesc *bufHdr;
|
BufferDesc *bufHdr;
|
||||||
|
|
||||||
if (WriteMode == BUFFER_FLUSH_WRITE)
|
if (BufferIsLocal(buffer))
|
||||||
return FlushBuffer(buffer, FALSE);
|
return WriteLocalBuffer(buffer, FALSE);
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
if (BufferIsLocal(buffer))
|
if (BAD_BUFFER_ID(buffer))
|
||||||
return WriteLocalBuffer(buffer, FALSE);
|
return STATUS_ERROR;
|
||||||
|
|
||||||
if (BAD_BUFFER_ID(buffer))
|
bufHdr = &BufferDescriptors[buffer - 1];
|
||||||
return STATUS_ERROR;
|
|
||||||
|
|
||||||
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;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2002,16 +1983,6 @@ _bm_die(Oid dbId, Oid relId, int blkNo, int bufNo,
|
|||||||
|
|
||||||
#endif /* BMTRACE */
|
#endif /* BMTRACE */
|
||||||
|
|
||||||
int
|
|
||||||
SetBufferWriteMode(int mode)
|
|
||||||
{
|
|
||||||
int old;
|
|
||||||
|
|
||||||
old = WriteMode;
|
|
||||||
WriteMode = mode;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SetBufferCommitInfoNeedsSave(Buffer buffer)
|
SetBufferCommitInfoNeedsSave(Buffer buffer)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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;
|
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
|
* Buffer context lock modes
|
||||||
*/
|
*/
|
||||||
@ -165,6 +159,7 @@ extern int WriteBuffer(Buffer buffer);
|
|||||||
extern int WriteNoReleaseBuffer(Buffer buffer);
|
extern int WriteNoReleaseBuffer(Buffer buffer);
|
||||||
extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
|
extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
|
||||||
BlockNumber blockNum);
|
BlockNumber blockNum);
|
||||||
|
extern int FlushBuffer(Buffer buffer, bool release);
|
||||||
|
|
||||||
extern void InitBufferPool(IPCKey key);
|
extern void InitBufferPool(IPCKey key);
|
||||||
extern void PrintBufferUsage(FILE *statfp);
|
extern void PrintBufferUsage(FILE *statfp);
|
||||||
@ -182,7 +177,6 @@ extern void PrintPinnedBufs(void);
|
|||||||
extern int BufferShmemSize(void);
|
extern int BufferShmemSize(void);
|
||||||
extern int ReleaseBuffer(Buffer buffer);
|
extern int ReleaseBuffer(Buffer buffer);
|
||||||
|
|
||||||
extern int SetBufferWriteMode(int mode);
|
|
||||||
extern void SetBufferCommitInfoNeedsSave(Buffer buffer);
|
extern void SetBufferCommitInfoNeedsSave(Buffer buffer);
|
||||||
|
|
||||||
extern void UnlockBuffers(void);
|
extern void UnlockBuffers(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user