1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

Mega-commit to make heap_open/heap_openr/heap_close take an

additional argument specifying the kind of lock to acquire/release (or
'NoLock' to do no lock processing).  Ensure that all relations are locked
with some appropriate lock level before being examined --- this ensures
that relevant shared-inval messages have been processed and should prevent
problems caused by concurrent VACUUM.  Fix several bugs having to do with
mismatched increment/decrement of relation ref count and mismatched
heap_open/close (which amounts to the same thing).  A bogus ref count on
a relation doesn't matter much *unless* a SI Inval message happens to
arrive at the wrong time, which is probably why we got away with this
sloppiness for so long.  Repair missing grab of AccessExclusiveLock in
DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi.
Recommend 'make clean all' after pulling this update; I modified the
Relation struct layout slightly.
Will post further discussion to pghackers list shortly.
This commit is contained in:
Tom Lane
1999-09-18 19:08:25 +00:00
parent 6c86fd5ba4
commit bd272cace6
70 changed files with 1094 additions and 1215 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.48 1999/07/17 20:18:01 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.49 1999/09/18 19:07:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -130,7 +130,8 @@ CatalogCacheInitializeCache(struct catcache * cache,
/* ----------------
* If no relation was passed we must open it to get access to
* its fields. If one of the other caches has already opened
* it we use heap_open() instead of heap_openr()
* it we use heap_open() instead of heap_openr().
* XXX is that really worth the trouble of checking?
* ----------------
*/
if (!RelationIsValid(relation))
@@ -155,9 +156,9 @@ CatalogCacheInitializeCache(struct catcache * cache,
* ----------------
*/
if (cp)
relation = heap_open(cp->relationId);
relation = heap_open(cp->relationId, NoLock);
else
relation = heap_openr(cache->cc_relname);
relation = heap_openr(cache->cc_relname, NoLock);
didopen = 1;
}
@@ -217,7 +218,7 @@ CatalogCacheInitializeCache(struct catcache * cache,
* ----------------
*/
if (didopen)
heap_close(relation);
heap_close(relation, NoLock);
/* ----------------
* initialize index information for the cache. this
@@ -891,10 +892,10 @@ SearchSysCache(struct catcache * cache,
DLMoveToFront(elt);
#ifdef CACHEDEBUG
relation = heap_open(cache->relationId);
relation = heap_open(cache->relationId, NoLock);
CACHE3_elog(DEBUG, "SearchSysCache(%s): found in bucket %d",
RelationGetRelationName(relation), hash);
heap_close(relation);
heap_close(relation, NoLock);
#endif /* CACHEDEBUG */
return ct->ct_tup;
@@ -925,7 +926,7 @@ SearchSysCache(struct catcache * cache,
* open the relation associated with the cache
* ----------------
*/
relation = heap_open(cache->relationId);
relation = heap_open(cache->relationId, AccessShareLock);
CACHE2_elog(DEBUG, "SearchSysCache(%s)",
RelationGetRelationName(relation));
@@ -1082,7 +1083,7 @@ SearchSysCache(struct catcache * cache,
* and return the tuple we found (or NULL)
* ----------------
*/
heap_close(relation);
heap_close(relation, AccessShareLock);
MemoryContextSwitchTo(oldcxt);
return ntp;
@@ -1146,8 +1147,6 @@ RelationInvalidateCatalogCacheTuple(Relation relation,
(*function) (ccp->id,
CatalogCacheComputeTupleHashIndex(ccp, relation, tuple),
&tuple->t_self);
heap_close(relation);
}
/* ----------------