Commit 2e635817 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

I had to change buffer tag: now RelFileNode is used instead of

LockRelId - ie physical information, not logical. It's required
for WAL. Regression tests passed.
parent 8b6b414a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.35 2000/05/31 00:28:26 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.36 2000/10/18 05:50:15 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -67,8 +67,9 @@ long *PrivateRefCount; /* also used in freelist.c */ ...@@ -67,8 +67,9 @@ long *PrivateRefCount; /* also used in freelist.c */
bits8 *BufferLocks; /* flag bits showing locks I have set */ bits8 *BufferLocks; /* flag bits showing locks I have set */
BufferTag *BufferTagLastDirtied; /* tag buffer had when last BufferTag *BufferTagLastDirtied; /* tag buffer had when last
* dirtied by me */ * dirtied by me */
BufferBlindId *BufferBlindLastDirtied; /* and its BlindId too */ BufferBlindId *BufferBlindLastDirtied;
bool *BufferDirtiedByMe; /* T if buf has been dirtied in cur xact */ LockRelId *BufferRelidLastDirtied;
bool *BufferDirtiedByMe; /* T if buf has been dirtied in cur xact */
/* /*
...@@ -251,6 +252,7 @@ InitBufferPool(IPCKey key) ...@@ -251,6 +252,7 @@ InitBufferPool(IPCKey key)
BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8)); BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8));
BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag)); BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag));
BufferBlindLastDirtied = (BufferBlindId *) calloc(NBuffers, sizeof(BufferBlindId)); BufferBlindLastDirtied = (BufferBlindId *) calloc(NBuffers, sizeof(BufferBlindId));
BufferRelidLastDirtied = (LockRelId *) calloc(NBuffers, sizeof(LockRelId));
BufferDirtiedByMe = (bool *) calloc(NBuffers, sizeof(bool)); BufferDirtiedByMe = (bool *) calloc(NBuffers, sizeof(bool));
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.17 2000/05/19 03:22:28 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.18 2000/10/18 05:50:15 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -125,8 +125,8 @@ BufTableDelete(BufferDesc *buf) ...@@ -125,8 +125,8 @@ BufTableDelete(BufferDesc *buf)
* sequential searches through the buffer table won't think the * sequential searches through the buffer table won't think the
* buffer is still valid for its old page. * buffer is still valid for its old page.
*/ */
buf->tag.relId.relId = InvalidOid; buf->tag.rnode.relNode = InvalidOid;
buf->tag.relId.dbId = InvalidOid; buf->tag.rnode.tblNode = InvalidOid;
return TRUE; return TRUE;
} }
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.30 2000/04/12 17:15:34 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.31 2000/10/18 05:50:15 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -60,7 +60,8 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) ...@@ -60,7 +60,8 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
/* a low tech search for now -- not optimized for scans */ /* a low tech search for now -- not optimized for scans */
for (i = 0; i < NLocBuffer; i++) for (i = 0; i < NLocBuffer; i++)
{ {
if (LocalBufferDescriptors[i].tag.relId.relId == RelationGetRelid(reln) && if (LocalBufferDescriptors[i].tag.rnode.relNode ==
reln->rd_node.relNode &&
LocalBufferDescriptors[i].tag.blockNum == blockNum) LocalBufferDescriptors[i].tag.blockNum == blockNum)
{ {
...@@ -102,7 +103,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) ...@@ -102,7 +103,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
*/ */
if (bufHdr->flags & BM_DIRTY) if (bufHdr->flags & BM_DIRTY)
{ {
Relation bufrel = RelationIdCacheGetRelation(bufHdr->tag.relId.relId); Relation bufrel = RelationIdCacheGetRelation(bufHdr->relId.relId);
Assert(bufrel != NULL); Assert(bufrel != NULL);
...@@ -120,9 +121,13 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) ...@@ -120,9 +121,13 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
/* /*
* it's all ours now. * it's all ours now.
*
* We need not in tblNode currently but will in future I think,
* when we'll give up rel->rd_fd to fmgr cache.
*/ */
bufHdr->tag.relId.relId = RelationGetRelid(reln); bufHdr->tag.rnode = reln->rd_node;
bufHdr->tag.blockNum = blockNum; bufHdr->tag.blockNum = blockNum;
bufHdr->relId = reln->rd_lockInfo.lockRelId;
bufHdr->flags &= ~BM_DIRTY; bufHdr->flags &= ~BM_DIRTY;
/* /*
...@@ -187,7 +192,7 @@ FlushLocalBuffer(Buffer buffer, bool release) ...@@ -187,7 +192,7 @@ FlushLocalBuffer(Buffer buffer, bool release)
bufid = -(buffer + 1); bufid = -(buffer + 1);
bufHdr = &LocalBufferDescriptors[bufid]; bufHdr = &LocalBufferDescriptors[bufid];
bufHdr->flags &= ~BM_DIRTY; bufHdr->flags &= ~BM_DIRTY;
bufrel = RelationIdCacheGetRelation(bufHdr->tag.relId.relId); bufrel = RelationIdCacheGetRelation(bufHdr->relId.relId);
Assert(bufrel != NULL); Assert(bufrel != NULL);
smgrflush(DEFAULT_SMGR, bufrel, bufHdr->tag.blockNum, smgrflush(DEFAULT_SMGR, bufrel, bufHdr->tag.blockNum,
...@@ -263,7 +268,7 @@ LocalBufferSync(void) ...@@ -263,7 +268,7 @@ LocalBufferSync(void)
#ifdef LBDEBUG #ifdef LBDEBUG
fprintf(stderr, "LB SYNC %d\n", -i - 1); fprintf(stderr, "LB SYNC %d\n", -i - 1);
#endif #endif
bufrel = RelationIdCacheGetRelation(buf->tag.relId.relId); bufrel = RelationIdCacheGetRelation(buf->relId.relId);
Assert(bufrel != NULL); Assert(bufrel != NULL);
...@@ -274,7 +279,7 @@ LocalBufferSync(void) ...@@ -274,7 +279,7 @@ LocalBufferSync(void)
/* drop relcache refcount from RelationIdCacheGetRelation */ /* drop relcache refcount from RelationIdCacheGetRelation */
RelationDecrementReferenceCount(bufrel); RelationDecrementReferenceCount(bufrel);
buf->tag.relId.relId = InvalidOid; buf->relId.relId = InvalidOid;
buf->flags &= ~BM_DIRTY; buf->flags &= ~BM_DIRTY;
} }
} }
...@@ -292,7 +297,7 @@ ResetLocalBufferPool(void) ...@@ -292,7 +297,7 @@ ResetLocalBufferPool(void)
{ {
BufferDesc *buf = &LocalBufferDescriptors[i]; BufferDesc *buf = &LocalBufferDescriptors[i];
buf->tag.relId.relId = InvalidOid; buf->tag.rnode.relNode = InvalidOid;
buf->flags &= ~BM_DIRTY; buf->flags &= ~BM_DIRTY;
buf->buf_id = -i - 2; buf->buf_id = -i - 2;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -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: buf_internals.h,v 1.38 2000/10/16 14:52:28 vadim Exp $ * $Id: buf_internals.h,v 1.39 2000/10/18 05:50:16 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -44,27 +44,27 @@ typedef long **BufferBlock; ...@@ -44,27 +44,27 @@ typedef long **BufferBlock;
typedef struct buftag typedef struct buftag
{ {
LockRelId relId; RelFileNode rnode;
BlockNumber blockNum; /* blknum relative to begin of reln */ BlockNumber blockNum; /* blknum relative to begin of reln */
} BufferTag; } BufferTag;
#define CLEAR_BUFFERTAG(a) \ #define CLEAR_BUFFERTAG(a) \
( \ ( \
(a)->relId.dbId = InvalidOid, \ (a)->rnode.tblNode = InvalidOid, \
(a)->relId.relId = InvalidOid, \ (a)->rnode.relNode = InvalidOid, \
(a)->blockNum = InvalidBlockNumber \ (a)->blockNum = InvalidBlockNumber \
) )
#define INIT_BUFFERTAG(a,xx_reln,xx_blockNum) \ #define INIT_BUFFERTAG(a,xx_reln,xx_blockNum) \
( \ ( \
(a)->blockNum = (xx_blockNum), \ (a)->blockNum = (xx_blockNum), \
(a)->relId = (xx_reln)->rd_lockInfo.lockRelId \ (a)->rnode = (xx_reln)->rd_node \
) )
#ifdef OLD_FILE_NAMING /*
/* If we have to write a buffer "blind" (without a relcache entry), * We don't need in this data any more but it allows more user
* the BufferTag is not enough information. BufferBlindId carries the * friendly error messages. Feel free to get rid of it
* additional information needed. * (and change a lot of places -:))
*/ */
typedef struct bufblindid typedef struct bufblindid
{ {
...@@ -72,17 +72,6 @@ typedef struct bufblindid ...@@ -72,17 +72,6 @@ typedef struct bufblindid
char relname[NAMEDATALEN]; /* name of reln */ char relname[NAMEDATALEN]; /* name of reln */
} BufferBlindId; } BufferBlindId;
#else
typedef struct bufblindid
{
char dbname[NAMEDATALEN]; /* name of db in which buf belongs */
char relname[NAMEDATALEN]; /* name of reln */
RelFileNode rnode;
} BufferBlindId;
#endif
#define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers) #define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers)
#define INVALID_DESCRIPTOR (-3) #define INVALID_DESCRIPTOR (-3)
...@@ -120,7 +109,22 @@ typedef struct sbufdesc ...@@ -120,7 +109,22 @@ typedef struct sbufdesc
bool ri_lock; /* read-intent lock */ bool ri_lock; /* read-intent lock */
bool w_lock; /* context exclusively locked */ bool w_lock; /* context exclusively locked */
BufferBlindId blind; /* extra info to support blind write */ /*
* This is logical information about relation.
* IT MUST CORRESPOND TO BUFFER TAG!
* If you're going to play with relation file node (ie change relation
* file) then you have to exclusively lock relation, create new one
* (with new relID), make data transformation, flush from pool buffers
* of both files (old and new), flush old relation from cache,
* update relfilenode in pg_class, flush new relation version from
* cache, open it - now you can use relation with new file.
*
* Why we keep relId here? To re-use file descriptors. On rollback
* WAL uses dummy relId - bad (more blind writes - open/close calls),
* but allowable. Obviously we should have another cache in file manager.
*/
LockRelId relId;
BufferBlindId blind; /* was used to support blind write */
} BufferDesc; } BufferDesc;
/* /*
...@@ -187,6 +191,7 @@ extern long *PrivateRefCount; ...@@ -187,6 +191,7 @@ extern long *PrivateRefCount;
extern bits8 *BufferLocks; extern bits8 *BufferLocks;
extern BufferTag *BufferTagLastDirtied; extern BufferTag *BufferTagLastDirtied;
extern BufferBlindId *BufferBlindLastDirtied; extern BufferBlindId *BufferBlindLastDirtied;
extern LockRelId *BufferRelidLastDirtied;
extern bool *BufferDirtiedByMe; extern bool *BufferDirtiedByMe;
extern SPINLOCK BufMgrLock; extern SPINLOCK BufMgrLock;
......
...@@ -15,4 +15,8 @@ typedef struct RelFileNode ...@@ -15,4 +15,8 @@ typedef struct RelFileNode
Oid relNode; /* relation */ Oid relNode; /* relation */
} RelFileNode; } RelFileNode;
#define RelFileNodeEquals(node1, node2) \
((node1).relNode == (node2).relNode && \
(node2).tblNode == (node2).tblNode)
#endif /* RELFILENODE_H */ #endif /* RELFILENODE_H */
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