From: Vadim B. Mikheev Date: Thu, 30 Nov 2000 19:03:26 +0000 (+0000) Subject: Hope that this is valid localbuf.c version X-Git-Tag: REL7_1_BETA~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8247f47fc7bdd6374df8ee91c9489d60e5a65f94;p=postgresql Hope that this is valid localbuf.c version --- diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 9400da3805..7978924553 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------- * - * xlog_bufmgr.c + * bufmgr.c * buffer manager interface routines * * Portions Copyright (c) 1996-2000, PostgreSQL, Inc @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.97 2000/11/30 08:46:23 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.98 2000/11/30 19:03:25 vadim Exp $ * *------------------------------------------------------------------------- */ diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index 828523c0b3..1fc704c722 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -14,19 +14,10 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994-5, Regents of the University of California * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.36 2000/11/30 01:39:07 tgl Exp $ - * *------------------------------------------------------------------------- */ - #include "postgres.h" -#ifdef XLOG -#include "xlog_localbuf.c" -#else - #include #include #include @@ -109,7 +100,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) * transaction to touch it doesn't need its contents but has not * flushed it). if that's the case, write it out before reusing it! */ - if (bufHdr->flags & BM_DIRTY) + if (bufHdr->flags & BM_DIRTY || bufHdr->cntxDirty) { Relation bufrel = RelationNodeCacheGetRelation(bufHdr->tag.rnode); @@ -136,6 +127,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) bufHdr->tag.rnode = reln->rd_node; bufHdr->tag.blockNum = blockNum; bufHdr->flags &= ~BM_DIRTY; + bufHdr->cntxDirty = false; /* * lazy memory allocation: allocate space on first use of a buffer. @@ -189,50 +181,6 @@ WriteLocalBuffer(Buffer buffer, bool release) return true; } -/* - * FlushLocalBuffer - - * flushes a local buffer - */ -int -FlushLocalBuffer(Buffer buffer, bool sync, bool release) -{ - int bufid; - Relation bufrel; - BufferDesc *bufHdr; - - Assert(BufferIsLocal(buffer)); - -#ifdef LBDEBUG - fprintf(stderr, "LB FLUSH %d\n", buffer); -#endif - - bufid = -(buffer + 1); - bufHdr = &LocalBufferDescriptors[bufid]; - bufHdr->flags &= ~BM_DIRTY; - bufrel = RelationNodeCacheGetRelation(bufHdr->tag.rnode); - Assert(bufrel != NULL); - - if (sync) - smgrflush(DEFAULT_SMGR, bufrel, bufHdr->tag.blockNum, - (char *) MAKE_PTR(bufHdr->data)); - else - smgrwrite(DEFAULT_SMGR, bufrel, bufHdr->tag.blockNum, - (char *) MAKE_PTR(bufHdr->data)); - - LocalBufferFlushCount++; - - /* drop relcache refcount incremented by RelationNodeCacheGetRelation */ - RelationDecrementReferenceCount(bufrel); - - if (release) - { - Assert(LocalRefCount[bufid] > 0); - LocalRefCount[bufid]--; - } - - return true; -} - /* * InitLocalBuffer - * init the local buffer cache. Since most queries (esp. multi-user ones) @@ -273,6 +221,9 @@ InitLocalBuffer(void) * Flush all dirty buffers in the local buffer cache at commit time. * Since the buffer cache is only used for keeping relations visible * during a transaction, we will not need these buffers again. + * + * Note that we have to *flush* local buffers because of them are not + * visible to checkpoint makers. But we can skip XLOG flush check. */ void LocalBufferSync(void) @@ -284,7 +235,7 @@ LocalBufferSync(void) BufferDesc *buf = &LocalBufferDescriptors[i]; Relation bufrel; - if (buf->flags & BM_DIRTY) + if (buf->flags & BM_DIRTY || buf->cntxDirty) { #ifdef LBDEBUG fprintf(stderr, "LB SYNC %d\n", -i - 1); @@ -295,12 +246,14 @@ LocalBufferSync(void) smgrwrite(DEFAULT_SMGR, bufrel, buf->tag.blockNum, (char *) MAKE_PTR(buf->data)); + smgrmarkdirty(DEFAULT_SMGR, bufrel, buf->tag.blockNum); LocalBufferFlushCount++; /* drop relcache refcount from RelationIdCacheGetRelation */ RelationDecrementReferenceCount(bufrel); buf->flags &= ~BM_DIRTY; + buf->cntxDirty = false; } } @@ -319,10 +272,9 @@ ResetLocalBufferPool(void) buf->tag.rnode.relNode = InvalidOid; buf->flags &= ~BM_DIRTY; + buf->cntxDirty = false; } MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer); nextFreeLocalBuf = 0; } - -#endif /* XLOG */