1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* inval.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES cache invalidation dispatcher code.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-01-26 06:58:53 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.32 2000/01/26 05:57:17 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
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/catalog.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "catalog/catname.h"
|
1999-02-02 04:45:56 +01:00
|
|
|
#include "catalog/heap.h"
|
1999-11-21 02:58:22 +01:00
|
|
|
#include "catalog/pg_class.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "miscadmin.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "storage/sinval.h"
|
|
|
|
#include "utils/catcache.h"
|
|
|
|
#include "utils/inval.h"
|
|
|
|
#include "utils/relcache.h"
|
|
|
|
|
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
|
|
|
* ----------------
|
|
|
|
*/
|
1999-11-21 02:58:22 +01:00
|
|
|
|
|
|
|
typedef struct InvalidationUserData
|
|
|
|
{
|
|
|
|
struct InvalidationUserData *dataP[1]; /* VARIABLE LENGTH */
|
|
|
|
} InvalidationUserData; /* VARIABLE LENGTH STRUCTURE */
|
|
|
|
|
|
|
|
typedef struct InvalidationEntryData
|
|
|
|
{
|
|
|
|
InvalidationUserData *nextP;
|
|
|
|
InvalidationUserData userData; /* VARIABLE LENGTH ARRAY */
|
|
|
|
} InvalidationEntryData; /* VARIABLE LENGTH STRUCTURE */
|
|
|
|
|
|
|
|
typedef Pointer InvalidationEntry;
|
|
|
|
|
|
|
|
typedef InvalidationEntry LocalInvalid;
|
|
|
|
|
|
|
|
#define EmptyLocalInvalid NULL
|
|
|
|
|
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
|
|
|
* ----------------
|
|
|
|
*/
|
2000-01-10 07:30:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ----------------
|
|
|
|
* Invalidation info was devided into three parts.
|
|
|
|
* 1) shared invalidation to be registerd for all backends
|
|
|
|
* 2) local invalidation for the transaction itself
|
|
|
|
* 3) rollback information for the transaction itself
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* head of invalidation linked list for all backends
|
|
|
|
* eaten by AtCommit_Cache() in CommitTransaction()
|
|
|
|
*/
|
|
|
|
static LocalInvalid InvalidForall = EmptyLocalInvalid;
|
|
|
|
/*
|
|
|
|
* head of invalidation linked list for the backend itself
|
|
|
|
* eaten by AtCommit_LocalCache() in CommandCounterIncrement()
|
|
|
|
*/
|
|
|
|
static LocalInvalid InvalidLocal = EmptyLocalInvalid;
|
|
|
|
/*
|
|
|
|
* head of rollback linked list for the backend itself
|
|
|
|
* eaten by AtAbort_Cache() in AbortTransaction()
|
|
|
|
*/
|
|
|
|
static LocalInvalid RollbackStack = EmptyLocalInvalid;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
1999-11-21 02:58:22 +01:00
|
|
|
static InvalidationEntry InvalidationEntryAllocate(uint16 size);
|
2000-01-10 07:30:56 +01:00
|
|
|
static void LocalInvalidInvalidate(LocalInvalid invalid, void (*function) (), bool freemember);
|
1999-11-21 02:58:22 +01:00
|
|
|
static LocalInvalid LocalInvalidRegister(LocalInvalid invalid,
|
|
|
|
InvalidationEntry entry);
|
2000-01-10 07:30:56 +01:00
|
|
|
static void DiscardInvalidStack(LocalInvalid *invalid);
|
|
|
|
static void InvalidationMessageRegisterSharedInvalid(InvalidationMessage message);
|
1999-11-21 02:58:22 +01:00
|
|
|
|
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
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* --------------------------------
|
1999-02-14 00:22:53 +01:00
|
|
|
* InvalidationEntryAllocate
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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;
|
1998-09-01 05:29:17 +02:00
|
|
|
return (Pointer) &entryDataP->userData;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1999-05-25 18:15:34 +02:00
|
|
|
* LocalInvalidRegister
|
1999-11-21 02:58:22 +01:00
|
|
|
* Link an invalidation entry into a chain of them. Really ugly
|
|
|
|
* coding here.
|
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] =
|
1999-05-25 18:15:34 +02:00
|
|
|
(InvalidationUserData *) invalid;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return entry;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
1999-02-14 00:22:53 +01:00
|
|
|
* LocalInvalidInvalidate
|
1997-09-07 07:04:48 +02:00
|
|
|
* Processes, then frees all entries in a local cache
|
2000-01-10 07:30:56 +01:00
|
|
|
* invalidation list unless freemember parameter is false.
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
static void
|
2000-01-10 07:30:56 +01:00
|
|
|
LocalInvalidInvalidate(LocalInvalid invalid, void (*function) (), bool freemember)
|
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;
|
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
if (!freemember)
|
|
|
|
continue;
|
1997-09-07 07:04:48 +02:00
|
|
|
/* help catch errors */
|
|
|
|
entryDataP->nextP = (InvalidationUserData *) NULL;
|
|
|
|
|
|
|
|
free((Pointer) entryDataP);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
static void
|
|
|
|
DiscardInvalidStack(LocalInvalid *invalid)
|
|
|
|
{
|
|
|
|
LocalInvalid locinv;
|
|
|
|
|
|
|
|
locinv = *invalid;
|
|
|
|
*invalid = EmptyLocalInvalid;
|
|
|
|
if (locinv)
|
|
|
|
LocalInvalidInvalidate(locinv, (void (*)()) NULL, true);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/* --------------------------------
|
2000-01-10 07:30:56 +01:00
|
|
|
* CacheIdRegister.......
|
|
|
|
* RelationIdRegister....
|
1996-07-09 08:22:35 +02:00
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
2000-01-10 07:30:56 +01:00
|
|
|
#define CacheIdRegisterSpecifiedLocalInvalid_DEBUG1 \
|
|
|
|
elog(DEBUG, "CacheIdRegisterSpecifiedLocalInvalid(%d, %d, [%d, %d])", \
|
|
|
|
cacheId, hashIndex, ItemPointerGetBlockNumber(pointer), \
|
|
|
|
ItemPointerGetOffsetNumber(pointer))
|
1996-07-09 08:22:35 +02:00
|
|
|
#define CacheIdRegisterLocalInvalid_DEBUG1 \
|
|
|
|
elog(DEBUG, "CacheIdRegisterLocalInvalid(%d, %d, [%d, %d])", \
|
1997-09-07 07:04:48 +02:00
|
|
|
cacheId, hashIndex, ItemPointerGetBlockNumber(pointer), \
|
|
|
|
ItemPointerGetOffsetNumber(pointer))
|
2000-01-10 07:30:56 +01:00
|
|
|
#define CacheIdRegisterLocalRollback_DEBUG1 \
|
|
|
|
elog(DEBUG, "CacheIdRegisterLocalRollback(%d, %d, [%d, %d])", \
|
|
|
|
cacheId, hashIndex, ItemPointerGetBlockNumber(pointer), \
|
|
|
|
ItemPointerGetOffsetNumber(pointer))
|
|
|
|
#define CacheIdImmediateRegisterSharedInvalid_DEBUG1 \
|
|
|
|
elog(DEBUG, "CacheIdImmediateRegisterSharedInvalid(%d, %d, [%d, %d])", \
|
|
|
|
cacheId, hashIndex, ItemPointerGetBlockNumber(pointer), \
|
|
|
|
ItemPointerGetOffsetNumber(pointer))
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
2000-01-10 07:30:56 +01:00
|
|
|
#define CacheIdRegisterSpecifiedLocalInvalid_DEBUG1
|
1996-07-09 08:22:35 +02:00
|
|
|
#define CacheIdRegisterLocalInvalid_DEBUG1
|
2000-01-10 07:30:56 +01:00
|
|
|
#define CacheIdRegisterLocalRollback_DEBUG1
|
|
|
|
#define CacheIdImmediateRegisterSharedInvalid_DEBUG1
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* INVALIDDEBUG */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
/* --------------------------------
|
|
|
|
* CacheIdRegisterSpecifiedLocalInvalid
|
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static LocalInvalid
|
|
|
|
CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
|
|
|
|
Index cacheId, Index hashIndex, ItemPointer pointer)
|
|
|
|
{
|
|
|
|
InvalidationMessage message;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
CacheIdRegisterSpecifiedLocalInvalid_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);
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Add message to linked list of unprocessed messages.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message);
|
|
|
|
return invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
|
|
|
* CacheIdRegisterLocalInvalid
|
|
|
|
* --------------------------------
|
|
|
|
*/
|
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)
|
2000-01-10 07:30:56 +01:00
|
|
|
{
|
|
|
|
/* ----------------
|
|
|
|
* 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(Index cacheId, Index hashIndex,
|
|
|
|
ItemPointer pointer)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
CacheIdRegisterLocalRollback_DEBUG1;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Add message to RollbackStack linked list.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
RollbackStack = CacheIdRegisterSpecifiedLocalInvalid(
|
|
|
|
RollbackStack, cacheId, hashIndex, pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
|
|
|
* CacheIdImmediateRegisterSharedInvalid
|
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
CacheIdImmediateRegisterSharedInvalid(Index cacheId, Index hashIndex,
|
|
|
|
ItemPointer pointer)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationMessage message;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
2000-01-10 07:30:56 +01:00
|
|
|
CacheIdImmediateRegisterSharedInvalid_DEBUG1;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* 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);
|
2000-01-10 07:30:56 +01:00
|
|
|
/* ----------------
|
|
|
|
* Register a shared catalog cache invalidation.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
InvalidationMessageRegisterSharedInvalid(message);
|
|
|
|
free((Pointer) &((InvalidationUserData *) message)->dataP[-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
|
|
|
* RelationIdRegisterSpecifiedLocalInvalid
|
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static LocalInvalid
|
|
|
|
RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
|
|
|
|
Oid relationId, Oid objectId)
|
|
|
|
{
|
|
|
|
InvalidationMessage message;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
elog(DEBUG, "RelationRegisterSpecifiedLocalInvalid(%u, %u)", 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;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1999-11-21 02:58:22 +01:00
|
|
|
* Add message to linked list of unprocessed messages.
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2000-01-10 07:30:56 +01:00
|
|
|
invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message);
|
|
|
|
return invalid;
|
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)
|
2000-01-10 07:30:56 +01:00
|
|
|
{
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
elog(DEBUG, "RelationRegisterLocalInvalid(%u, %u)", relationId,
|
|
|
|
objectId);
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* 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,
|
|
|
|
objectId);
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Add message to RollbackStack linked list.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
RollbackStack = RelationIdRegisterSpecifiedLocalInvalid(
|
|
|
|
RollbackStack, relationId, objectId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------
|
|
|
|
* RelationIdImmediateRegisterSharedInvalid
|
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
RelationIdImmediateRegisterSharedInvalid(Oid relationId, Oid objectId)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
InvalidationMessage message;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef INVALIDDEBUG
|
2000-01-10 07:30:56 +01:00
|
|
|
elog(DEBUG, "RelationImmediateRegisterSharedInvalid(%u, %u)", relationId,
|
1997-09-07 07:04:48 +02:00
|
|
|
objectId);
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/* ----------------
|
2000-01-10 07:30:56 +01:00
|
|
|
* Register a shared catalog cache invalidation.
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2000-01-10 07:30:56 +01:00
|
|
|
InvalidationMessageRegisterSharedInvalid(message);
|
|
|
|
free((Pointer) &((InvalidationUserData *) message)->dataP[-1]);
|
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
|
|
|
*
|
1998-08-19 16:51:31 +02:00
|
|
|
* This routine can invalidate a tuple in a system catalog cache
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* ----------------
|
1999-11-21 02:58:22 +01:00
|
|
|
* if the cacheId is the oid of any of the following system relations,
|
|
|
|
* then assume we are invalidating a relation descriptor
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1999-11-21 02:58:22 +01:00
|
|
|
if (cacheId == RelOid_pg_class)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
RelationIdInvalidateRelationCacheByRelationId(hashIndex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-11-21 02:58:22 +01:00
|
|
|
if (cacheId == RelOid_pg_attribute)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
RelationIdInvalidateRelationCacheByRelationId(hashIndex);
|
|
|
|
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, \
|
1999-05-10 02:46:32 +02:00
|
|
|
"InvalidationMessageRegisterSharedInvalid(r, %u, %u)", \
|
1997-09-07 07:04:48 +02:00
|
|
|
message->any.relation.relationId, \
|
|
|
|
message->any.relation.objectId)
|
|
|
|
#else
|
1996-07-09 08:22:35 +02:00
|
|
|
#define InvalidationMessageRegisterSharedInvalid_DEBUG1
|
|
|
|
#define InvalidationMessageRegisterSharedInvalid_DEBUG2
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* INVALIDDEBUG */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
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 \
|
1999-05-10 02:46:32 +02:00
|
|
|
elog(DEBUG, "InvalidationMessageCacheInvalidate(r, %u, %u)", \
|
1997-09-07 07:04:48 +02:00
|
|
|
message->any.relation.relationId, \
|
|
|
|
message->any.relation.objectId)
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
|
|
|
#define InvalidationMessageCacheInvalidate_DEBUG1
|
|
|
|
#define InvalidationMessageCacheInvalidate_DEBUG2
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
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
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
CacheIdInvalidate(message->any.catalog.cacheId,
|
1997-09-08 04:41:22 +02:00
|
|
|
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
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
CacheIdInvalidate(message->any.relation.relationId,
|
|
|
|
message->any.relation.objectId,
|
|
|
|
(ItemPointer) NULL);
|
1997-09-08 04:41:22 +02:00
|
|
|
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;
|
1999-11-21 02:58:22 +01:00
|
|
|
Oid objectId;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* get the relation object id
|
|
|
|
* ----------------
|
|
|
|
*/
|
1998-08-19 04:04:17 +02:00
|
|
|
relationId = RelationGetRelid(relation);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1999-11-21 02:58:22 +01:00
|
|
|
* is it one of the ones we need to send an SI message for?
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1999-11-21 02:58:22 +01:00
|
|
|
if (relationId == RelOid_pg_class)
|
1998-11-27 20:52:36 +01:00
|
|
|
objectId = tuple->t_data->t_oid;
|
1999-11-21 02:58:22 +01:00
|
|
|
else if (relationId == RelOid_pg_attribute)
|
1998-09-01 05:29:17 +02:00
|
|
|
objectId = ((Form_pg_attribute) GETSTRUCT(tuple))->attrelid;
|
1997-09-07 07:04:48 +02:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* can't handle immediate relation descriptor invalidation
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
Assert(PointerIsValid(function));
|
|
|
|
|
|
|
|
(*function) (relationId, objectId);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1998-02-23 18:44:24 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-05-25 18:15:34 +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");
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
InvalidateSharedInvalid(CacheIdInvalidate, ResetSystemCaches);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +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)
|
|
|
|
{
|
1999-11-21 02:58:22 +01:00
|
|
|
LocalInvalid invalid;
|
|
|
|
|
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);
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1999-11-21 02:58:22 +01:00
|
|
|
* Process and free the current list of inval messages.
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1999-11-21 02:58:22 +01:00
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
DiscardInvalidStack(&InvalidLocal);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (send)
|
2000-01-10 07:30:56 +01:00
|
|
|
{
|
|
|
|
DiscardInvalidStack(&RollbackStack);
|
|
|
|
invalid = InvalidForall;
|
|
|
|
InvalidForall = EmptyLocalInvalid; /* clear InvalidForall */
|
|
|
|
LocalInvalidInvalidate(invalid, InvalidationMessageRegisterSharedInvalid, true);
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
else
|
2000-01-10 07:30:56 +01:00
|
|
|
{
|
|
|
|
DiscardInvalidStack(&InvalidForall);
|
|
|
|
invalid = RollbackStack;
|
|
|
|
RollbackStack = EmptyLocalInvalid; /* clear RollbackStack */
|
|
|
|
LocalInvalidInvalidate(invalid, InvalidationMessageCacheInvalidate, true);
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-10 07:30:56 +01:00
|
|
|
* ImmediateLocalInvalidation
|
|
|
|
* Causes invalidation immediately for the next command of the transaction.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Note:
|
2000-01-10 07:30:56 +01:00
|
|
|
* This should be called in time of CommandCounterIncrement().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ImmediateLocalInvalidation(bool send)
|
|
|
|
{
|
|
|
|
LocalInvalid invalid;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
elog(DEBUG, "ImmediateLocalInvalidation(%d) called", send);
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Process and free the local list of inval messages.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (send)
|
|
|
|
{
|
|
|
|
invalid = InvalidLocal;
|
|
|
|
InvalidLocal = EmptyLocalInvalid; /* clear InvalidLocal */
|
|
|
|
LocalInvalidInvalidate(invalid, InvalidationMessageCacheInvalidate, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This may be used for rollback to a savepoint.
|
|
|
|
* Don't clear InvalidForall and RollbackStack here.
|
|
|
|
*/
|
|
|
|
DiscardInvalidStack(&InvalidLocal);
|
|
|
|
invalid = RollbackStack;
|
|
|
|
LocalInvalidInvalidate(invalid, InvalidationMessageCacheInvalidate, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* InvokeHeapTupleInvalidation
|
|
|
|
* Invoke functions for the tuple which register invalidation
|
|
|
|
* of catalog/relation cache.
|
|
|
|
* 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
|
2000-01-10 07:30:56 +01:00
|
|
|
#define InvokeHeapTupleInvalidation_DEBUG1 \
|
|
|
|
elog(DEBUG, "%s(%s, [%d,%d])", \
|
|
|
|
funcname,\
|
1999-11-18 00:51:21 +01:00
|
|
|
RelationGetPhysicalRelationName(relation), \
|
2000-01-10 07:30:56 +01:00
|
|
|
ItemPointerGetBlockNumber(&tuple->t_self), \
|
|
|
|
ItemPointerGetOffsetNumber(&tuple->t_self))
|
1996-07-09 08:22:35 +02:00
|
|
|
#else
|
2000-01-10 07:30:56 +01:00
|
|
|
#define InvokeHeapTupleInvalidation_DEBUG1
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
static void
|
|
|
|
InvokeHeapTupleInvalidation(Relation relation, HeapTuple tuple,
|
|
|
|
void (*CacheIdRegisterFunc)(),
|
|
|
|
void (*RelationIdRegisterFunc)(),
|
|
|
|
const char *funcname)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
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
|
|
|
|
* ----------------
|
|
|
|
*/
|
1999-11-08 00:08:36 +01:00
|
|
|
if (!IsSystemRelationName(NameStr(RelationGetForm(relation)->relname)))
|
1997-09-07 07:04:48 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
2000-01-10 07:30:56 +01:00
|
|
|
InvokeHeapTupleInvalidation_DEBUG1;
|
|
|
|
|
|
|
|
RelationInvalidateCatalogCacheTuple(relation, tuple,
|
|
|
|
CacheIdRegisterFunc);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
RelationInvalidateRelationCache(relation, tuple,
|
|
|
|
RelationIdRegisterFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RelationInvalidateHeapTuple
|
|
|
|
* Causes the given tuple in a relation to be invalidated.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RelationInvalidateHeapTuple(Relation relation, HeapTuple tuple)
|
|
|
|
{
|
|
|
|
InvokeHeapTupleInvalidation(relation, tuple,
|
|
|
|
CacheIdRegisterLocalInvalid,
|
|
|
|
RelationIdRegisterLocalInvalid,
|
|
|
|
"RelationInvalidateHeapTuple");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RelationMark4RollbackHeapTuple
|
|
|
|
* keep the given tuple in a relation to be invalidated
|
|
|
|
* in case of abort.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RelationMark4RollbackHeapTuple(Relation relation, HeapTuple tuple)
|
|
|
|
{
|
|
|
|
InvokeHeapTupleInvalidation(relation, tuple,
|
|
|
|
CacheIdRegisterLocalRollback,
|
|
|
|
RelationIdRegisterLocalRollback,
|
|
|
|
"RelationMark4RollbackHeapTuple");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ImmediateInvalidateSharedHeapTuple
|
|
|
|
* Different from RelationInvalidateHeapTuple()
|
|
|
|
* this function queues shared invalidation info immediately.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ImmediateInvalidateSharedHeapTuple(Relation relation, HeapTuple tuple)
|
|
|
|
{
|
|
|
|
InvokeHeapTupleInvalidation(relation, tuple,
|
|
|
|
CacheIdImmediateRegisterSharedInvalid,
|
|
|
|
RelationIdImmediateRegisterSharedInvalid,
|
|
|
|
"ImmediateInvalidateSharedHeapTuple");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ImmediateSharedRelationCacheInvalidate
|
|
|
|
* Register shared relation cache invalidation immediately
|
|
|
|
*
|
|
|
|
* This is needed for smgrunlink()/smgrtruncate().
|
|
|
|
* Those functions unlink/truncate the base file immediately
|
|
|
|
* and couldn't be rollbacked in case of abort/crash.
|
|
|
|
* So relation cache invalidation must be registerd immediately.
|
|
|
|
* Note:
|
|
|
|
* Assumes Relation is valid.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ImmediateSharedRelationCacheInvalidate(Relation relation)
|
|
|
|
{
|
|
|
|
/* ----------------
|
|
|
|
* sanity checks
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
Assert(RelationIsValid(relation));
|
|
|
|
|
|
|
|
if (IsBootstrapProcessingMode())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* debugging stuff
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#ifdef INVALIDDEBUG
|
|
|
|
elog(DEBUG, "ImmediateSharedRelationCacheInvalidate(%s)", \
|
|
|
|
RelationGetPhysicalRelationName(relation));
|
|
|
|
#endif /* defined(INVALIDDEBUG) */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-01-10 07:30:56 +01:00
|
|
|
RelationIdImmediateRegisterSharedInvalid(
|
|
|
|
RelOid_pg_class, RelationGetRelid(relation));
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|