mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +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:
19
src/backend/utils/cache/syscache.c
vendored
19
src/backend/utils/cache/syscache.c
vendored
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user