Commit b4a607c9 authored by Tom Lane's avatar Tom Lane

Modify RelationFlushRelation so that if the relcache entry

has positive refcount, it is rebuilt from pg_class data.  This ensures
that relcache entries will track changes made by other backends.  Formerly,
a shared inval report would just be ignored if it happened to arrive while
the relcache entry was in use.  Also, fix relcache to reset ref counts
to zero during transaction abort.  Finally, change LockRelation() so that
it checks for shared inval reports after obtaining the lock.  In this way,
once any kind of lock has been obtained on a rel, we can trust the relcache
entry to be up-to-date.
parent 8add6d71
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.47 1999/08/08 20:12:52 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.48 1999/09/04 18:42:15 tgl Exp $
* *
* NOTES * NOTES
* Transaction aborts can now occur two ways: * Transaction aborts can now occur two ways:
...@@ -755,6 +755,7 @@ static void ...@@ -755,6 +755,7 @@ static void
AtAbort_Cache() AtAbort_Cache()
{ {
RegisterInvalid(false); RegisterInvalid(false);
RelationCacheAbort();
} }
/* -------------------------------- /* --------------------------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.33 1999/07/17 20:17:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.34 1999/09/04 18:42:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "postgres.h" #include "postgres.h"
#include "access/transam.h" #include "access/transam.h"
#include "catalog/catalog.h" #include "catalog/catalog.h"
#include "utils/inval.h"
extern Oid MyDatabaseId; extern Oid MyDatabaseId;
...@@ -161,7 +162,16 @@ LockRelation(Relation relation, LOCKMODE lockmode) ...@@ -161,7 +162,16 @@ LockRelation(Relation relation, LOCKMODE lockmode)
tag.objId.blkno = InvalidBlockNumber; tag.objId.blkno = InvalidBlockNumber;
LockAcquire(LockTableId, &tag, lockmode); LockAcquire(LockTableId, &tag, lockmode);
return;
/*
* Check to see if the relcache entry has been invalidated
* while we were waiting to lock it. If so, rebuild it,
* or elog() trying. Increment the refcount to ensure that
* RelationFlushRelation will rebuild it and not just delete it.
*/
RelationIncrementReferenceCount(relation);
DiscardInvalid();
RelationDecrementReferenceCount(relation);
} }
/* /*
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: relcache.h,v 1.13 1999/07/15 23:04:23 momjian Exp $ * $Id: relcache.h,v 1.14 1999/09/04 18:42:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,6 +34,8 @@ extern void RelationRegisterRelation(Relation relation); ...@@ -34,6 +34,8 @@ extern void RelationRegisterRelation(Relation relation);
extern void RelationPurgeLocalRelation(bool xactComitted); extern void RelationPurgeLocalRelation(bool xactComitted);
extern void RelationInitialize(void); extern void RelationInitialize(void);
extern void RelationCacheAbort(void);
/* /*
* both vacuum.c and relcache.c need to know the name of the relcache init file * both vacuum.c and relcache.c need to know the name of the relcache init file
*/ */
......
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