Commit 6e8a1a67 authored by Bruce Momjian's avatar Bruce Momjian

WriteBuffer return value:

>I'd vote for changing WriteBuffer to
>return void, and have it elog() on bad argument.

Manfred Koizar
parent 82b14b62
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.80 2002/06/15 19:54:23 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.81 2002/06/15 19:59:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -468,8 +468,7 @@ nextval(PG_FUNCTION_ARGS) ...@@ -468,8 +468,7 @@ nextval(PG_FUNCTION_ARGS)
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
if (WriteBuffer(buf) == STATUS_ERROR) WriteBuffer(buf);
elog(ERROR, "%s.nextval: WriteBuffer failed", sequence->relname);
relation_close(seqrel, NoLock); relation_close(seqrel, NoLock);
...@@ -581,8 +580,7 @@ do_setval(RangeVar *sequence, int64 next, bool iscalled) ...@@ -581,8 +580,7 @@ do_setval(RangeVar *sequence, int64 next, bool iscalled)
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
if (WriteBuffer(buf) == STATUS_ERROR) WriteBuffer(buf);
elog(ERROR, "%s.setval: WriteBuffer failed", sequence->relname);
relation_close(seqrel, NoLock); relation_close(seqrel, NoLock);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.124 2002/06/15 19:55:37 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.125 2002/06/15 19:59:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -87,6 +87,7 @@ static int ReleaseBufferWithBufferLock(Buffer buffer); ...@@ -87,6 +87,7 @@ static int ReleaseBufferWithBufferLock(Buffer buffer);
static int BufferReplace(BufferDesc *bufHdr); static int BufferReplace(BufferDesc *bufHdr);
void PrintBufferDescs(void); void PrintBufferDescs(void);
static void write_buffer(Buffer buffer, bool unpin);
/* /*
* ReadBuffer -- returns a buffer containing the requested * ReadBuffer -- returns a buffer containing the requested
...@@ -558,29 +559,22 @@ BufferAlloc(Relation reln, ...@@ -558,29 +559,22 @@ BufferAlloc(Relation reln,
} }
/* /*
* WriteBuffer * write_buffer -- common functionality for
* * WriteBuffer and WriteNoReleaseBuffer
* Marks buffer contents as dirty (actual write happens later).
*
* Assume that buffer is pinned. Assume that reln is
* valid.
*
* Side Effects:
* Pin count is decremented.
*/ */
static void
#undef WriteBuffer write_buffer(Buffer buffer, bool release)
int
WriteBuffer(Buffer buffer)
{ {
BufferDesc *bufHdr; BufferDesc *bufHdr;
if (BufferIsLocal(buffer)) if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, TRUE); {
WriteLocalBuffer(buffer, release);
return;
}
if (BAD_BUFFER_ID(buffer)) if (BAD_BUFFER_ID(buffer))
return FALSE; elog(ERROR, "write_buffer: bad buffer %d", buffer);
bufHdr = &BufferDescriptors[buffer - 1]; bufHdr = &BufferDescriptors[buffer - 1];
...@@ -589,37 +583,39 @@ WriteBuffer(Buffer buffer) ...@@ -589,37 +583,39 @@ WriteBuffer(Buffer buffer)
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED); bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
UnpinBuffer(bufHdr); if (release)
UnpinBuffer(bufHdr);
LWLockRelease(BufMgrLock); LWLockRelease(BufMgrLock);
}
return TRUE; /*
* WriteBuffer
*
* Marks buffer contents as dirty (actual write happens later).
*
* Assume that buffer is pinned. Assume that reln is
* valid.
*
* Side Effects:
* Pin count is decremented.
*/
#undef WriteBuffer
void
WriteBuffer(Buffer buffer)
{
write_buffer(buffer, true);
} }
/* /*
* 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.
*/ */
int void
WriteNoReleaseBuffer(Buffer buffer) WriteNoReleaseBuffer(Buffer buffer)
{ {
BufferDesc *bufHdr; write_buffer(buffer, false);
if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, FALSE);
if (BAD_BUFFER_ID(buffer))
return STATUS_ERROR;
bufHdr = &BufferDescriptors[buffer - 1];
LWLockAcquire(BufMgrLock, LW_EXCLUSIVE);
Assert(bufHdr->refcount > 0);
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
LWLockRelease(BufMgrLock);
return STATUS_OK;
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.42 2002/05/03 17:42:11 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.43 2002/06/15 19:59:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -155,7 +155,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) ...@@ -155,7 +155,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
* WriteLocalBuffer - * WriteLocalBuffer -
* writes out a local buffer * writes out a local buffer
*/ */
int void
WriteLocalBuffer(Buffer buffer, bool release) WriteLocalBuffer(Buffer buffer, bool release)
{ {
int bufid; int bufid;
...@@ -174,8 +174,6 @@ WriteLocalBuffer(Buffer buffer, bool release) ...@@ -174,8 +174,6 @@ WriteLocalBuffer(Buffer buffer, bool release)
Assert(LocalRefCount[bufid] > 0); Assert(LocalRefCount[bufid] > 0);
LocalRefCount[bufid]--; LocalRefCount[bufid]--;
} }
return true;
} }
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: buf_internals.h,v 1.55 2002/06/15 19:55:38 momjian Exp $ * $Id: buf_internals.h,v 1.56 2002/06/15 19:59:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -176,7 +176,7 @@ extern BufferDesc *LocalBufferDescriptors; ...@@ -176,7 +176,7 @@ extern BufferDesc *LocalBufferDescriptors;
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum, extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
bool *foundPtr); bool *foundPtr);
extern int WriteLocalBuffer(Buffer buffer, bool release); extern void WriteLocalBuffer(Buffer buffer, bool release);
extern int FlushLocalBuffer(Buffer buffer, bool sync, bool release); extern int FlushLocalBuffer(Buffer buffer, bool sync, bool release);
extern void LocalBufferSync(void); extern void LocalBufferSync(void);
extern void ResetLocalBufferPool(void); extern void ResetLocalBufferPool(void);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* 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.58 2002/04/15 23:47:12 momjian Exp $ * $Id: bufmgr.h,v 1.59 2002/06/15 19:59:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -148,8 +148,8 @@ extern long *LocalRefCount; ...@@ -148,8 +148,8 @@ extern long *LocalRefCount;
*/ */
extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum);
extern int ReleaseBuffer(Buffer buffer); extern int ReleaseBuffer(Buffer buffer);
extern int WriteBuffer(Buffer buffer); extern void WriteBuffer(Buffer buffer);
extern int WriteNoReleaseBuffer(Buffer buffer); extern void 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 sync, bool release); extern int FlushBuffer(Buffer buffer, bool sync, bool release);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment