diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-09-18 19:08:25 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-09-18 19:08:25 +0000 |
commit | bd272cace63effa23d68a6b344a07e326b6a41e2 (patch) | |
tree | 3026c545c238bd38eadc7fb1fac89d636cf51673 /src/backend/utils/cache/syscache.c | |
parent | 6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff) | |
download | postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.tar.gz postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.zip |
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.
Diffstat (limited to 'src/backend/utils/cache/syscache.c')
-rw-r--r-- | src/backend/utils/cache/syscache.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index c9c7770f8cc..204f13ffab9 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.35 1999/09/04 22:00:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.36 1999/09/18 19:07:55 tgl Exp $ * * NOTES * These routines allow the parser/planner/executor to perform @@ -575,11 +575,19 @@ SearchSysCacheGetAttribute(int cacheId, Datum attributeValue; void *returnValue; - tp = SearchSysCacheTuple(cacheId, key1, key2, key3, key4); + /* + * Open the relation first, to ensure we are in sync with SI inval + * events --- we don't want the tuple found in the cache to be + * invalidated out from under us. + */ cacheName = cacheinfo[cacheId].name; + relation = heap_openr(cacheName, AccessShareLock); + + tp = SearchSysCacheTuple(cacheId, key1, key2, key3, key4); if (!HeapTupleIsValid(tp)) { + heap_close(relation, AccessShareLock); #ifdef CACHEDEBUG elog(DEBUG, "SearchSysCacheGetAttribute: Lookup in %s(%d) failed", @@ -588,8 +596,6 @@ SearchSysCacheGetAttribute(int cacheId, return NULL; } - relation = heap_openr(cacheName); - if (attributeNumber < 0 && attributeNumber > FirstLowInvalidHeapAttributeNumber) { @@ -604,6 +610,7 @@ SearchSysCacheGetAttribute(int cacheId, } else { + heap_close(relation, AccessShareLock); elog(ERROR, "SearchSysCacheGetAttribute: Bad attr # %d in %s(%d)", attributeNumber, cacheName, cacheId); @@ -617,11 +624,11 @@ SearchSysCacheGetAttribute(int cacheId, if (isNull) { - /* * Used to be an elog(DEBUG, ...) here and a claim that it should * be a FATAL error, I don't think either is warranted -mer 6/9/92 */ + heap_close(relation, AccessShareLock); return NULL; } @@ -639,6 +646,6 @@ SearchSysCacheGetAttribute(int cacheId, returnValue = (void *) tmp; } - heap_close(relation); + heap_close(relation, AccessShareLock); return returnValue; } |