* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.42 2001/03/22 03:59:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.43 2001/06/01 20:23:06 tgl Exp $
*
* Note - this code is real crufty... badly needs a rewrite to improve
* readability and portability. (Shouldn't assume Oid == Index, for example)
/*
* private invalidation structures
- *
*/
typedef struct InvalidationUserData
/*
* variables and macros
- *
*/
/*
/*
* InvalidationEntryAllocate
* Allocates an invalidation entry.
- *
*/
static InvalidationEntry
InvalidationEntryAllocate(uint16 size)
entryDataP = (InvalidationEntryData *)
malloc(sizeof(char *) + size); /* XXX alignment */
+ if (entryDataP == NULL)
+ elog(ERROR, "Memory exhausted in InvalidationEntryAllocate");
entryDataP->nextP = NULL;
return (Pointer) &entryDataP->userData;
}
* LocalInvalidRegister
* Link an invalidation entry into a chain of them. Really ugly
* coding here.
- *
*/
static LocalInvalid
LocalInvalidRegister(LocalInvalid invalid,
* LocalInvalidInvalidate
* Processes, then frees all entries in a local cache
* invalidation list unless freemember parameter is false.
- *
*/
static void
LocalInvalidInvalidate(LocalInvalid invalid,
/*
* CacheIdRegisterSpecifiedLocalInvalid
- *
*/
static LocalInvalid
CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
/*
* debugging stuff
- *
*/
CacheIdRegisterSpecifiedLocalInvalid_DEBUG1;
/*
* create a message describing the system catalog tuple we wish to
* invalidate.
- *
*/
message = (InvalidationMessage)
InvalidationEntryAllocate(sizeof(InvalidationMessageData));
/*
* Add message to linked list of unprocessed messages.
- *
*/
invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message);
return invalid;
/*
* CacheIdRegisterLocalInvalid
- *
*/
static void
CacheIdRegisterLocalInvalid(int cacheId,
/*
* debugging stuff
- *
*/
CacheIdRegisterLocalInvalid_DEBUG1;
/*
* Add message to InvalidForall linked list.
- *
*/
InvalidForall = CacheIdRegisterSpecifiedLocalInvalid(InvalidForall,
cacheId, hashIndex, pointer);
/*
* Add message to InvalidLocal linked list.
- *
*/
InvalidLocal = CacheIdRegisterSpecifiedLocalInvalid(InvalidLocal,
cacheId, hashIndex, pointer);
/*
* CacheIdRegisterLocalRollback
- *
*/
static void
CacheIdRegisterLocalRollback(int cacheId,
/*
* debugging stuff
- *
*/
CacheIdRegisterLocalRollback_DEBUG1;
/*
* Add message to RollbackStack linked list.
- *
*/
RollbackStack = CacheIdRegisterSpecifiedLocalInvalid(
RollbackStack, cacheId, hashIndex, pointer);
/*
* RelationIdRegisterSpecifiedLocalInvalid
- *
*/
static LocalInvalid
RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
/*
* debugging stuff
- *
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "RelationRegisterSpecifiedLocalInvalid(%u, %u)", relationId,
/*
* create a message describing the relation descriptor we wish to
* invalidate.
- *
*/
message = (InvalidationMessage)
InvalidationEntryAllocate(sizeof(InvalidationMessageData));
/*
* Add message to linked list of unprocessed messages.
- *
*/
invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message);
return invalid;
/*
* RelationIdRegisterLocalInvalid
- *
*/
static void
RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
/*
* debugging stuff
- *
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "RelationRegisterLocalInvalid(%u, %u)", relationId,
/*
* Add message to InvalidForall linked list.
- *
*/
InvalidForall = RelationIdRegisterSpecifiedLocalInvalid(InvalidForall,
relationId, objectId);
/*
* Add message to InvalidLocal linked list.
- *
*/
InvalidLocal = RelationIdRegisterSpecifiedLocalInvalid(InvalidLocal,
relationId, objectId);
/*
* RelationIdRegisterLocalRollback
- *
*/
static void
RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
/*
* debugging stuff
- *
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "RelationRegisterLocalRollback(%u, %u)", relationId,
/*
* Add message to RollbackStack linked list.
- *
*/
RollbackStack = RelationIdRegisterSpecifiedLocalInvalid(
RollbackStack, relationId, objectId);
* This routine can invalidate a tuple in a system catalog cache
* or a cached relation descriptor. You pay your money and you
* take your chances...
- *
*/
#ifdef INVALIDDEBUG
#define CacheIdInvalidate_DEBUG1 \
/*
* assume that if the item pointer is valid, then we are invalidating
* an item in the specified system catalog cache.
- *
*/
if (ItemPointerIsValid(pointer))
{
/*
* if the cacheId is the oid of any of the following system relations,
* then assume we are invalidating a relation descriptor
- *
*/
if (cacheId == RelOid_pg_class)
{
/*
* Yow! the caller asked us to invalidate something else.
- *
*/
elog(FATAL, "CacheIdInvalidate: cacheId=%d relation id?", cacheId);
}
* This blows away all tuples in the system catalog caches and
* all the cached relation descriptors (and closes their files too).
* Relation descriptors that have positive refcounts are then rebuilt.
- *
*/
static void
ResetSystemCaches(void)
/*
* InvalidationMessageRegisterSharedInvalid
- *
*/
#ifdef INVALIDDEBUG
#define InvalidationMessageRegisterSharedInvalid_DEBUG1 \
/*
* InvalidationMessageCacheInvalidate
- *
*/
#ifdef INVALIDDEBUG
#define InvalidationMessageCacheInvalidate_DEBUG1 \
/*
* PrepareToInvalidateRelationCache
- *
*/
static void
PrepareToInvalidateRelationCache(Relation relation,
/*
* get the relation object id
- *
*/
relationId = RelationGetRelid(relation);
/*
* is it one of the ones we need to send an SI message for?
- *
*/
if (relationId == RelOid_pg_class)
objectId = tuple->t_data->t_oid;
/*
* register the relcache-invalidation action in the appropriate list
- *
*/
Assert(PointerIsValid(function));
/*
* debugging stuff
- *
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "DiscardInvalid called");
/*
* debugging stuff
- *
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "RegisterInvalid(%d) called", send);
/*
* Process and free the current list of inval messages.
- *
*/
DiscardInvalidStack(&InvalidLocal);
/*
* debugging stuff
- *
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "ImmediateLocalInvalidation(%d) called", send);
/*
* Process and free the local list of inval messages.
- *
*/
if (send)
/*
* sanity checks
- *
*/
Assert(RelationIsValid(relation));
Assert(HeapTupleIsValid(tuple));
* We only need to worry about invalidation for tuples that are in
* system relations; user-relation tuples are never in catcaches and
* can't affect the relcache either.
- *
*/
if (!IsSystemRelationName(NameStr(RelationGetForm(relation)->relname)))
return;
/*
* debugging stuff
- *
*/
PrepareForTupleInvalidation_DEBUG1;