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 @@
*
*
* 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)
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
if (WriteBuffer(buf) == STATUS_ERROR)
elog(ERROR, "%s.nextval: WriteBuffer failed", sequence->relname);
WriteBuffer(buf);
relation_close(seqrel, NoLock);
......@@ -581,8 +580,7 @@ do_setval(RangeVar *sequence, int64 next, bool iscalled)
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
if (WriteBuffer(buf) == STATUS_ERROR)
elog(ERROR, "%s.setval: WriteBuffer failed", sequence->relname);
WriteBuffer(buf);
relation_close(seqrel, NoLock);
}
......
......@@ -8,7 +8,7 @@
*
*
* 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);
static int BufferReplace(BufferDesc *bufHdr);
void PrintBufferDescs(void);
static void write_buffer(Buffer buffer, bool unpin);
/*
* ReadBuffer -- returns a buffer containing the requested
......@@ -558,29 +559,22 @@ BufferAlloc(Relation reln,
}
/*
* 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.
* write_buffer -- common functionality for
* WriteBuffer and WriteNoReleaseBuffer
*/
#undef WriteBuffer
int
WriteBuffer(Buffer buffer)
static void
write_buffer(Buffer buffer, bool release)
{
BufferDesc *bufHdr;
if (BufferIsLocal(buffer))
return WriteLocalBuffer(buffer, TRUE);
{
WriteLocalBuffer(buffer, release);
return;
}
if (BAD_BUFFER_ID(buffer))
return FALSE;
elog(ERROR, "write_buffer: bad buffer %d", buffer);
bufHdr = &BufferDescriptors[buffer - 1];
......@@ -589,37 +583,39 @@ WriteBuffer(Buffer buffer)
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
UnpinBuffer(bufHdr);
if (release)
UnpinBuffer(bufHdr);
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
* when the operation is complete.
*/
int
void
WriteNoReleaseBuffer(Buffer buffer)
{
BufferDesc *bufHdr;
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;
write_buffer(buffer, false);
}
......
......@@ -16,7 +16,7 @@
*
*
* 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)
* WriteLocalBuffer -
* writes out a local buffer
*/
int
void
WriteLocalBuffer(Buffer buffer, bool release)
{
int bufid;
......@@ -174,8 +174,6 @@ WriteLocalBuffer(Buffer buffer, bool release)
Assert(LocalRefCount[bufid] > 0);
LocalRefCount[bufid]--;
}
return true;
}
/*
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* 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;
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
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 void LocalBufferSync(void);
extern void ResetLocalBufferPool(void);
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* 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;
*/
extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum);
extern int ReleaseBuffer(Buffer buffer);
extern int WriteBuffer(Buffer buffer);
extern int WriteNoReleaseBuffer(Buffer buffer);
extern void WriteBuffer(Buffer buffer);
extern void WriteNoReleaseBuffer(Buffer buffer);
extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
BlockNumber blockNum);
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