1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* inval.c--
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES cache invalidation dispatcher code.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1997-11-17 17:59:36 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.9 1997/11/17 16:59:22 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note - this code is real crufty...
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
1996-11-06 11:32:10 +01:00
|
|
|
|
|
|
|
#include <miscadmin.h>
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#include "access/heapam.h" /* XXX to support hacks below */
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "access/htup.h"
|
|
|
|
#include "catalog/catalog.h"
|
|
|
|
#include "storage/bufpage.h"
|
1997-09-07 07:04:48 +02:00
|
|
|
#include "storage/buf.h" /* XXX for InvalidBuffer */
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "storage/ipc.h"
|
|
|
|
#include "storage/sinval.h"
|
|
|
|
#include "utils/catcache.h"
|
|
|
|
#include "utils/inval.h"
|
|
|
|
#include "utils/rel.h"
|
|
|
|
#include "utils/relcache.h"
|
|
|
|
#include "catalog/catname.h" /* XXX to support hacks below */
|
1997-09-07 07:04:48 +02:00
|
|
|
#include "utils/syscache.h" /* XXX to support the hacks below */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-08-19 23:40:56 +02:00
|
|
|
static InvalidationEntry InvalidationEntryAllocate(uint16 size);
|
1997-09-08 04:41:22 +02:00
|
|
|
static void LocalInvalidInvalidate(LocalInvalid invalid, void (*function) ());
|
1997-09-07 07:04:48 +02:00
|
|
|
static LocalInvalid
|
|
|
|
LocalInvalidRegister(LocalInvalid invalid,
|
1997-08-19 23:40:56 +02:00
|
|
|
InvalidationEntry entry);
|
1997-09-08 04:41:22 +02:00
|
|
|
static void getmyrelids(void);
|
1997-08-19 23:40:56 +02:00
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* private invalidation structures
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct CatalogInvalidationData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Index cacheId;
|
|
|
|
Index hashIndex;
|
1997-09-07 07:04:48 +02:00
|
|
|
ItemPointerData pointerData;
|
1997-09-08 23:56:23 +02:00
|
|
|
} CatalogInvalidationData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct RelationInvalidationData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid relationId;
|
|
|
|
Oid objectId;
|
1997-09-08 23:56:23 +02:00
|
|
|
} RelationInvalidationData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef union AnyInvalidation
|
|
|
|
{
|
|
|
|
CatalogInvalidationData catalog;
|
|
|
|
RelationInvalidationData relation;
|
1997-09-08 22:59:27 +02:00
|
|
|
} AnyInvalidation;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct InvalidationMessageData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char kind;
|
1997-09-07 07:04:48 +02:00
|
|
|
AnyInvalidation any;
|
1997-09-08 23:56:23 +02:00
|
|
|
} InvalidationMessageData;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef InvalidationMessageData *InvalidationMessage;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* variables and macros
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
static LocalInvalid Invalid = EmptyLocalInvalid; /* XXX global */
|
1997-09-08 04:41:22 +02:00
|
|
|
static bool RefreshWhenInvalidate = false;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid MyRelationRelationId = InvalidOid;
|
|
|
|
Oid MyAttributeRelationId = InvalidOid;
|
|
|
|
Oid MyAMRelationId = InvalidOid;
|
|
|
|
Oid MyAMOPRelationId = InvalidOid;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
#define ValidateHacks() \
|
1997-09-07 07:04:48 +02:00
|
|
|
if (!OidIsValid(MyRelationRelationId)) getmyrelids()
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* "local" invalidation support functions
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* InvalidationEntryAllocate--
|
|
|
|
* Allocates an invalidation entry.
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static InvalidationEntry
|
1996-07-09 08:22:35 +02:00
|
|
|
InvalidationEntryAllocate(uint16 size)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationEntryData *entryDataP;
|
|
|
|
|
|
|
|
entryDataP = (InvalidationEntryData *)
|
|
|
|
malloc(sizeof(char *) + size); /* XXX alignment */
|
|
|
|
entryDataP->nextP = NULL;
|
1997-09-08 23:56:23 +02:00
|
|
|
return ((Pointer) &entryDataP->userData);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* LocalInvalidRegister --
|
|
|
|
* Returns a new local cache invalidation state containing a new entry.
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static LocalInvalid
|
1996-07-09 08:22:35 +02:00
|
|
|
LocalInvalidRegister(LocalInvalid invalid,
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationEntry entry)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Assert(PointerIsValid(entry));
|
|
|
|
|
|
|
|
((InvalidationUserData *) entry)->dataP[-1] =
|
|
|
|
(InvalidationUserData *) invalid;
|
|
|
|
|
|
|
|
return (entry);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* LocalInvalidInvalidate--
|
|
|
|
* Processes, then frees all entries in a local cache
|
|
|
|
* invalidation state.
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
static void
|
1997-09-07 07:04:48 +02:00
|
|
|
LocalInvalidInvalidate(LocalInvalid invalid, void (*function) ())
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationEntryData *entryDataP;
|
|
|
|
|
|
|
|
while (PointerIsValid(invalid))
|
|
|
|
{
|
|
|
|
entryDataP = (InvalidationEntryData *)
|
1997-09-08 23:56:23 +02:00
|
|
|
&((InvalidationUserData *) invalid)->dataP[-1];
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (PointerIsValid(function))
|
|
|
|
{
|
1997-09-08 23:56:23 +02:00
|
|
|
(*function) ((Pointer) &entryDataP->userData);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
invalid = (Pointer) entryDataP->nextP;
|
|
|
|
|
|
|
|
/* help catch errors */
|
|
|
|
entryDataP->nextP = (InvalidationUserData *) NULL;
|
|
|
|
|
|
|
|
free((Pointer) entryDataP);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* private support functions
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* CacheIdRegisterLocalInvalid
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
#define CacheIdRegisterLocalInvalid_DEBUG1 \
|
|
|
|
elog(DEBUG, "CacheIdRegisterLocalInvalid(%d, %d, [%d, %d])", \
|
1997-09-07 07:04:48 +02:00
|
|
|
cacheId, hashIndex, ItemPointerGetBlockNumber(pointer), \
|
|
|
|
ItemPointerGetOffsetNumber(pointer))
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
|
|
|
#define CacheIdRegisterLocalInvalid_DEBUG1
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* INVALIDDEBUG */
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
|
|
|
CacheIdRegisterLocalInvalid(Index cacheId,
|
1997-09-07 07:04:48 +02:00
|
|
|
Index hashIndex,
|
|
|
|
ItemPointer pointer)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationMessage message;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
CacheIdRegisterLocalInvalid_DEBUG1;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* create a message describing the system catalog tuple
|
|
|
|
* we wish to invalidate.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
message = (InvalidationMessage)
|
|
|
|
InvalidationEntryAllocate(sizeof(InvalidationMessageData));
|
|
|
|
|
|
|
|
message->kind = 'c';
|
|
|
|
message->any.catalog.cacheId = cacheId;
|
|
|
|
message->any.catalog.hashIndex = hashIndex;
|
|
|
|
|
|
|
|
ItemPointerCopy(pointer, &message->any.catalog.pointerData);
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Note: Invalid is a global variable
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
Invalid = LocalInvalidRegister(Invalid, (InvalidationEntry) message);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* RelationIdRegisterLocalInvalid
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationMessage message;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef INVALIDDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG, "RelationRegisterLocalInvalid(%d, %d)", relationId,
|
|
|
|
objectId);
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* create a message describing the relation descriptor
|
|
|
|
* we wish to invalidate.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
message = (InvalidationMessage)
|
|
|
|
InvalidationEntryAllocate(sizeof(InvalidationMessageData));
|
|
|
|
|
|
|
|
message->kind = 'r';
|
|
|
|
message->any.relation.relationId = relationId;
|
|
|
|
message->any.relation.objectId = objectId;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Note: Invalid is a global variable
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
Invalid = LocalInvalidRegister(Invalid, (InvalidationEntry) message);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* getmyrelids
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
static void
|
1996-07-09 08:22:35 +02:00
|
|
|
getmyrelids()
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple tuple;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
tuple = SearchSysCacheTuple(RELNAME,
|
|
|
|
PointerGetDatum(RelationRelationName),
|
|
|
|
0, 0, 0);
|
|
|
|
Assert(HeapTupleIsValid(tuple));
|
|
|
|
MyRelationRelationId = tuple->t_oid;
|
|
|
|
|
|
|
|
tuple = SearchSysCacheTuple(RELNAME,
|
|
|
|
PointerGetDatum(AttributeRelationName),
|
|
|
|
0, 0, 0);
|
|
|
|
Assert(HeapTupleIsValid(tuple));
|
|
|
|
MyAttributeRelationId = tuple->t_oid;
|
|
|
|
|
|
|
|
tuple = SearchSysCacheTuple(RELNAME,
|
|
|
|
PointerGetDatum(AccessMethodRelationName),
|
|
|
|
0, 0, 0);
|
|
|
|
Assert(HeapTupleIsValid(tuple));
|
|
|
|
MyAMRelationId = tuple->t_oid;
|
|
|
|
|
|
|
|
tuple = SearchSysCacheTuple(RELNAME,
|
|
|
|
PointerGetDatum(AccessMethodOperatorRelationName),
|
|
|
|
0, 0, 0);
|
|
|
|
Assert(HeapTupleIsValid(tuple));
|
|
|
|
MyAMOPRelationId = tuple->t_oid;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* CacheIdInvalidate
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* This routine can invalidate an tuple in a system catalog cache
|
|
|
|
* or a cached relation descriptor. You pay your money and you
|
|
|
|
* take your chances...
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
#define CacheIdInvalidate_DEBUG1 \
|
|
|
|
elog(DEBUG, "CacheIdInvalidate(%d, %d, 0x%x[%d])", cacheId, hashIndex,\
|
1997-09-07 07:04:48 +02:00
|
|
|
pointer, ItemPointerIsValid(pointer))
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
|
|
|
#define CacheIdInvalidate_DEBUG1
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
|
|
|
CacheIdInvalidate(Index cacheId,
|
1997-09-07 07:04:48 +02:00
|
|
|
Index hashIndex,
|
|
|
|
ItemPointer pointer)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
/* ----------------
|
|
|
|
* assume that if the item pointer is valid, then we are
|
|
|
|
* invalidating an item in the specified system catalog cache.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
if (ItemPointerIsValid(pointer))
|
|
|
|
{
|
|
|
|
CatalogCacheIdInvalidate(cacheId, hashIndex, pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheIdInvalidate_DEBUG1;
|
|
|
|
|
|
|
|
ValidateHacks(); /* XXX */
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* if the cacheId is the oid of any of the tuples in the
|
|
|
|
* following system relations, then assume we are invalidating
|
|
|
|
* a relation descriptor
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
if (cacheId == MyRelationRelationId)
|
|
|
|
{
|
|
|
|
RelationIdInvalidateRelationCacheByRelationId(hashIndex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cacheId == MyAttributeRelationId)
|
|
|
|
{
|
|
|
|
RelationIdInvalidateRelationCacheByRelationId(hashIndex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cacheId == MyAMRelationId)
|
|
|
|
{
|
|
|
|
RelationIdInvalidateRelationCacheByAccessMethodId(hashIndex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cacheId == MyAMOPRelationId)
|
|
|
|
{
|
|
|
|
RelationIdInvalidateRelationCacheByAccessMethodId(InvalidOid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Yow! the caller asked us to invalidate something else.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
elog(FATAL, "CacheIdInvalidate: cacheId=%d relation id?", cacheId);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ResetSystemCaches
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* this blows away all tuples in the system catalog caches and
|
|
|
|
* all the cached relation descriptors (and closes the files too).
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ResetSystemCaches()
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
ResetSystemCache();
|
|
|
|
RelationCacheInvalidate(false);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* InvalidationMessageRegisterSharedInvalid
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
#define InvalidationMessageRegisterSharedInvalid_DEBUG1 \
|
|
|
|
elog(DEBUG,\
|
1997-09-07 07:04:48 +02:00
|
|
|
"InvalidationMessageRegisterSharedInvalid(c, %d, %d, [%d, %d])",\
|
|
|
|
message->any.catalog.cacheId,\
|
|
|
|
message->any.catalog.hashIndex,\
|
|
|
|
ItemPointerGetBlockNumber(&message->any.catalog.pointerData),\
|
|
|
|
ItemPointerGetOffsetNumber(&message->any.catalog.pointerData))
|
1996-07-09 08:22:35 +02:00
|
|
|
#define InvalidationMessageRegisterSharedInvalid_DEBUG2 \
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG, \
|
|
|
|
"InvalidationMessageRegisterSharedInvalid(r, %d, %d)", \
|
|
|
|
message->any.relation.relationId, \
|
|
|
|
message->any.relation.objectId)
|
|
|
|
#else
|
1996-07-09 08:22:35 +02:00
|
|
|
#define InvalidationMessageRegisterSharedInvalid_DEBUG1
|
|
|
|
#define InvalidationMessageRegisterSharedInvalid_DEBUG2
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* INVALIDDEBUG */
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
|
|
|
InvalidationMessageRegisterSharedInvalid(InvalidationMessage message)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Assert(PointerIsValid(message));
|
|
|
|
|
|
|
|
switch (message->kind)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case 'c': /* cached system catalog tuple */
|
|
|
|
InvalidationMessageRegisterSharedInvalid_DEBUG1;
|
|
|
|
|
|
|
|
RegisterSharedInvalid(message->any.catalog.cacheId,
|
|
|
|
message->any.catalog.hashIndex,
|
|
|
|
&message->any.catalog.pointerData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r': /* cached relation descriptor */
|
|
|
|
InvalidationMessageRegisterSharedInvalid_DEBUG2;
|
|
|
|
|
|
|
|
RegisterSharedInvalid(message->any.relation.relationId,
|
|
|
|
message->any.relation.objectId,
|
|
|
|
(ItemPointer) NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elog(FATAL,
|
|
|
|
"InvalidationMessageRegisterSharedInvalid: `%c' kind",
|
|
|
|
message->kind);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* InvalidationMessageCacheInvalidate
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
#define InvalidationMessageCacheInvalidate_DEBUG1 \
|
|
|
|
elog(DEBUG, "InvalidationMessageCacheInvalidate(c, %d, %d, [%d, %d])",\
|
1997-09-07 07:04:48 +02:00
|
|
|
message->any.catalog.cacheId,\
|
|
|
|
message->any.catalog.hashIndex,\
|
|
|
|
ItemPointerGetBlockNumber(&message->any.catalog.pointerData),\
|
|
|
|
ItemPointerGetOffsetNumber(&message->any.catalog.pointerData))
|
1996-07-09 08:22:35 +02:00
|
|
|
#define InvalidationMessageCacheInvalidate_DEBUG2 \
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG, "InvalidationMessageCacheInvalidate(r, %d, %d)", \
|
|
|
|
message->any.relation.relationId, \
|
|
|
|
message->any.relation.objectId)
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
|
|
|
#define InvalidationMessageCacheInvalidate_DEBUG1
|
|
|
|
#define InvalidationMessageCacheInvalidate_DEBUG2
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
|
|
|
InvalidationMessageCacheInvalidate(InvalidationMessage message)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Assert(PointerIsValid(message));
|
|
|
|
|
|
|
|
switch (message->kind)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case 'c': /* cached system catalog tuple */
|
|
|
|
InvalidationMessageCacheInvalidate_DEBUG1;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
CatalogCacheIdInvalidate(message->any.catalog.cacheId,
|
|
|
|
message->any.catalog.hashIndex,
|
|
|
|
&message->any.catalog.pointerData);
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case 'r': /* cached relation descriptor */
|
|
|
|
InvalidationMessageCacheInvalidate_DEBUG2;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/* XXX ignore this--is this correct ??? */
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
default:
|
|
|
|
elog(FATAL, "InvalidationMessageCacheInvalidate: `%c' kind",
|
|
|
|
message->kind);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* RelationInvalidateRelationCache
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
RelationInvalidateRelationCache(Relation relation,
|
1997-09-07 07:04:48 +02:00
|
|
|
HeapTuple tuple,
|
|
|
|
void (*function) ())
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid relationId;
|
|
|
|
Oid objectId = (Oid) 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* get the relation object id
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
ValidateHacks(); /* XXX */
|
|
|
|
relationId = RelationGetRelationId(relation);
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
*
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
if (relationId == MyRelationRelationId)
|
|
|
|
{
|
|
|
|
objectId = tuple->t_oid;
|
|
|
|
}
|
|
|
|
else if (relationId == MyAttributeRelationId)
|
|
|
|
{
|
|
|
|
objectId = ((AttributeTupleForm) GETSTRUCT(tuple))->attrelid;
|
|
|
|
}
|
|
|
|
else if (relationId == MyAMRelationId)
|
|
|
|
{
|
|
|
|
objectId = tuple->t_oid;
|
|
|
|
}
|
|
|
|
else if (relationId == MyAMOPRelationId)
|
|
|
|
{
|
|
|
|
; /* objectId is unused */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* can't handle immediate relation descriptor invalidation
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
Assert(PointerIsValid(function));
|
|
|
|
|
|
|
|
(*function) (relationId, objectId);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DiscardInvalid --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Causes the invalidated cache state to be discarded.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* This should be called as the first step in processing a transaction.
|
|
|
|
* This should be called while waiting for a query from the front end
|
|
|
|
* when other backends are active.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
DiscardInvalid()
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef INVALIDDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG, "DiscardInvalid called");
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
InvalidateSharedInvalid(CacheIdInvalidate, ResetSystemCaches);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RegisterInvalid --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Causes registration of invalidated state with other backends iff true.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* This should be called as the last step in processing a transaction.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
RegisterInvalid(bool send)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef INVALIDDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG, "RegisterInvalid(%d) called", send);
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Note: Invalid is a global variable
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
if (send)
|
|
|
|
LocalInvalidInvalidate(Invalid,
|
|
|
|
InvalidationMessageRegisterSharedInvalid);
|
|
|
|
else
|
|
|
|
LocalInvalidInvalidate(Invalid,
|
|
|
|
InvalidationMessageCacheInvalidate);
|
|
|
|
|
|
|
|
Invalid = EmptyLocalInvalid;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SetRefreshWhenInvalidate --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Causes the local caches to be immediately refreshed iff true.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
SetRefreshWhenInvalidate(bool on)
|
|
|
|
{
|
|
|
|
#ifdef INVALIDDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
elog(DEBUG, "RefreshWhenInvalidate(%d) called", on);
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
RefreshWhenInvalidate = on;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RelationIdInvalidateHeapTuple --
|
1997-09-07 07:04:48 +02:00
|
|
|
* Causes the given tuple in a relation to be invalidated.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumes object id is valid.
|
|
|
|
* Assumes tuple is valid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
#define RelationInvalidateHeapTuple_DEBUG1 \
|
1997-11-17 17:59:36 +01:00
|
|
|
elog(DEBUG, "RelationInvalidateHeapTuple(%s, [%d,%d])", \
|
1997-09-07 07:04:48 +02:00
|
|
|
RelationGetRelationName(relation), \
|
|
|
|
ItemPointerGetBlockNumber(&tuple->t_ctid), \
|
|
|
|
ItemPointerGetOffsetNumber(&tuple->t_ctid))
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
|
|
|
#define RelationInvalidateHeapTuple_DEBUG1
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
void
|
|
|
|
RelationInvalidateHeapTuple(Relation relation, HeapTuple tuple)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
/* ----------------
|
|
|
|
* sanity checks
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
Assert(RelationIsValid(relation));
|
|
|
|
Assert(HeapTupleIsValid(tuple));
|
|
|
|
|
|
|
|
if (IsBootstrapProcessingMode())
|
|
|
|
return;
|
|
|
|
/* ----------------
|
|
|
|
* this only works for system relations now
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
if (!IsSystemRelationName(RelationGetRelationTupleForm(relation)->relname.data))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
RelationInvalidateHeapTuple_DEBUG1;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
*
|
|
|
|
* ----------------
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
RelationInvalidateCatalogCacheTuple(relation,
|
1997-09-07 07:04:48 +02:00
|
|
|
tuple,
|
|
|
|
CacheIdRegisterLocalInvalid);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
RelationInvalidateRelationCache(relation,
|
|
|
|
tuple,
|
|
|
|
RelationIdRegisterLocalInvalid);
|
|
|
|
|
|
|
|
if (RefreshWhenInvalidate)
|
|
|
|
RelationInvalidateCatalogCacheTuple(relation,
|
|
|
|
tuple,
|
|
|
|
(void (*) ()) NULL);
|
|
|
|
}
|