1
/*-------------------------------------------------------------------------
4
* POSTGRES shared cache invalidation communication definitions.
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
10
* $PostgreSQL: pgsql/src/include/storage/sinval.h,v 1.40 2005-01-10 21:57:19 tgl Exp $
12
*-------------------------------------------------------------------------
17
#include "storage/backendid.h"
18
#include "storage/itemptr.h"
19
#include "storage/relfilenode.h"
23
* We currently support three types of shared-invalidation messages: one that
24
* invalidates an entry in a catcache, one that invalidates a relcache entry,
25
* and one that invalidates an smgr cache entry. More types could be added
26
* if needed. The message type is identified by the first "int16" field of
27
* the message struct. Zero or positive means a catcache inval message (and
28
* also serves as the catcache ID field). -1 means a relcache inval message.
29
* -2 means an smgr inval message. Other negative values are available to
30
* identify other inval message types.
32
* Catcache inval events are initially driven by detecting tuple inserts,
33
* updates and deletions in system catalogs (see CacheInvalidateHeapTuple).
34
* An update generates two inval events, one for the old tuple and one for
35
* the new --- this is needed to get rid of both positive entries for the
36
* old tuple, and negative cache entries associated with the new tuple's
37
* cache key. (This could perhaps be optimized down to one event when the
38
* cache key is not changing, but for now we don't bother to try.) Note that
39
* the inval events themselves don't actually say whether the tuple is being
40
* inserted or deleted.
42
* Note that some system catalogs have multiple caches on them (with different
43
* indexes). On detecting a tuple invalidation in such a catalog, separate
44
* catcache inval messages must be generated for each of its caches. The
45
* catcache inval messages carry the hash value for the target tuple, so
46
* that the catcache only needs to search one hash chain not all its chains,
47
* and so that negative cache entries can be recognized with good accuracy.
48
* (Of course this assumes that all the backends are using identical hashing
49
* code, but that should be OK.)
54
/* note: field layout chosen with an eye to alignment concerns */
55
int16 id; /* cache ID --- must be first */
56
ItemPointerData tuplePtr; /* tuple identifier in cached relation */
57
Oid dbId; /* database ID, or 0 if a shared relation */
58
uint32 hashValue; /* hash value of key for this catcache */
59
} SharedInvalCatcacheMsg;
61
#define SHAREDINVALRELCACHE_ID (-1)
65
int16 id; /* type field --- must be first */
66
Oid dbId; /* database ID, or 0 if a shared relation */
67
Oid relId; /* relation ID */
68
} SharedInvalRelcacheMsg;
70
#define SHAREDINVALSMGR_ID (-2)
74
int16 id; /* type field --- must be first */
75
RelFileNode rnode; /* physical file ID */
80
int16 id; /* type field --- must be first */
81
SharedInvalCatcacheMsg cc;
82
SharedInvalRelcacheMsg rc;
83
SharedInvalSmgrMsg sm;
84
} SharedInvalidationMessage;
87
extern int SInvalShmemSize(int maxBackends);
88
extern void CreateSharedInvalidationState(int maxBackends);
89
extern void InitBackendSharedInvalidationState(void);
90
extern void SendSharedInvalidMessage(SharedInvalidationMessage *msg);
91
extern void ReceiveSharedInvalidMessages(
92
void (*invalFunction) (SharedInvalidationMessage *msg),
93
void (*resetFunction) (void));
95
extern bool DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself);
96
extern bool TransactionIdIsInProgress(TransactionId xid);
97
extern bool IsBackendPid(int pid);
98
extern TransactionId GetOldestXmin(bool allDbs);
99
extern int CountActiveBackends(void);
100
extern int CountEmptyBackendSlots(void);
102
/* Use "struct PGPROC", not PGPROC, to avoid including proc.h here */
103
extern struct PGPROC *BackendIdGetProc(BackendId procId);
105
extern void XidCacheRemoveRunningXids(TransactionId xid,
106
int nxids, TransactionId *xids);
108
/* signal handler for catchup events (SIGUSR1) */
109
extern void CatchupInterruptHandler(SIGNAL_ARGS);
112
* enable/disable processing of catchup events directly from signal handler.
113
* The enable routine first performs processing of any catchup events that
114
* have occurred since the last disable.
116
extern void EnableCatchupInterrupt(void);
117
extern bool DisableCatchupInterrupt(void);
119
#endif /* SINVAL_H */