OSDN Git Service

1188c68c95add98786b8fbb79b2433e468fe3c19
[pg-rex/syncrep.git] / src / include / storage / sinval.h
1 /*-------------------------------------------------------------------------
2  *
3  * sinval.h
4  *        POSTGRES shared cache invalidation communication definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: sinval.h,v 1.29 2002/08/29 21:02:12 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef SINVAL_H
15 #define SINVAL_H
16
17 #include "storage/backendid.h"
18 #include "storage/itemptr.h"
19
20
21 /*
22  * We currently support two types of shared-invalidation messages: one that
23  * invalidates an entry in a catcache, and one that invalidates a relcache
24  * entry.  More types could be added if needed.  The message type is
25  * identified by the first "int16" field of the message struct.  Zero or
26  * positive means a catcache inval message (and also serves as the catcache
27  * ID field).  -1 means a relcache inval message.  Other negative values
28  * are available to identify other inval message types.
29  *
30  * Shared-inval events are initially driven by detecting tuple inserts,
31  * updates and deletions in system catalogs (see CacheInvalidateHeapTuple).
32  * An update generates two inval events, one for the old tuple and one for
33  * the new --- this is needed to get rid of both positive entries for the
34  * old tuple, and negative cache entries associated with the new tuple's
35  * cache key.  (This could perhaps be optimized down to one event when the
36  * cache key is not changing, but for now we don't bother to try.)  Note that
37  * the inval events themselves don't actually say whether the tuple is being
38  * inserted or deleted.
39  *
40  * Note that some system catalogs have multiple caches on them (with different
41  * indexes).  On detecting a tuple invalidation in such a catalog, separate
42  * catcache inval messages must be generated for each of its caches.  The
43  * catcache inval messages carry the hash value for the target tuple, so
44  * that the catcache only needs to search one hash chain not all its chains,
45  * and so that negative cache entries can be recognized with good accuracy.
46  * (Of course this assumes that all the backends are using identical hashing
47  * code, but that should be OK.)
48  */
49
50 typedef struct
51 {
52         /* note: field layout chosen with an eye to alignment concerns */
53         int16           id;                             /* cache ID --- must be first */
54         ItemPointerData tuplePtr;       /* tuple identifier in cached relation */
55         Oid                     dbId;                   /* database ID, or 0 if a shared relation */
56         uint32          hashValue;              /* hash value of key for this catcache */
57 } SharedInvalCatcacheMsg;
58
59 #define SHAREDINVALRELCACHE_ID  (-1)
60
61 typedef struct
62 {
63         int16           id;                             /* type field --- must be first */
64         Oid                     dbId;                   /* database ID, or 0 if a shared relation */
65         Oid                     relId;                  /* relation ID */
66 } SharedInvalRelcacheMsg;
67
68 typedef union
69 {
70         int16           id;                             /* type field --- must be first */
71         SharedInvalCatcacheMsg cc;
72         SharedInvalRelcacheMsg rc;
73 } SharedInvalidationMessage;
74
75
76 extern int      SInvalShmemSize(int maxBackends);
77 extern void CreateSharedInvalidationState(int maxBackends);
78 extern void InitBackendSharedInvalidationState(void);
79 extern void SendSharedInvalidMessage(SharedInvalidationMessage *msg);
80 extern void ReceiveSharedInvalidMessages(
81                                   void (*invalFunction) (SharedInvalidationMessage *msg),
82                                                          void (*resetFunction) (void));
83
84 extern bool DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself);
85 extern bool TransactionIdIsInProgress(TransactionId xid);
86 extern TransactionId GetOldestXmin(bool allDbs);
87 extern int      CountActiveBackends(void);
88
89 /* Use "struct PGPROC", not PGPROC, to avoid including proc.h here */
90 extern struct PGPROC *BackendIdGetProc(BackendId procId);
91
92 extern int CountEmptyBackendSlots(void);
93
94 #endif   /* SINVAL_H */