OSDN Git Service

rebuid:
[eos/hostdependX86MAC64.git] / util / X86MAC64 / include / postgresql / server / storage / sinval.h
1 /*-------------------------------------------------------------------------
2  *
3  * sinval.h
4  *        POSTGRES shared cache invalidation communication definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/sinval.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef SINVAL_H
15 #define SINVAL_H
16
17 #include "storage/relfilenode.h"
18
19
20 /*
21  * We support several types of shared-invalidation messages:
22  *      * invalidate a specific tuple in a specific catcache
23  *      * invalidate all catcache entries from a given system catalog
24  *      * invalidate a relcache entry for a specific logical relation
25  *      * invalidate an smgr cache entry for a specific physical relation
26  *      * invalidate the mapped-relation mapping for a given database
27  *      * invalidate any saved snapshot that might be used to scan a given relation
28  * More types could be added if needed.  The message type is identified by
29  * the first "int8" field of the message struct.  Zero or positive means a
30  * specific-catcache inval message (and also serves as the catcache ID field).
31  * Negative values identify the other message types, as per codes below.
32  *
33  * Catcache inval events are initially driven by detecting tuple inserts,
34  * updates and deletions in system catalogs (see CacheInvalidateHeapTuple).
35  * An update can generate two inval events, one for the old tuple and one for
36  * the new, but this is reduced to one event if the tuple's hash key doesn't
37  * change.  Note that the inval events themselves don't actually say whether
38  * the tuple is being inserted or deleted.  Also, since we transmit only a
39  * hash key, there is a small risk of unnecessary invalidations due to chance
40  * matches of hash keys.
41  *
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, since
45  * the hash keys will generally be different.
46  *
47  * Catcache, relcache, and snapshot invalidations are transactional, and so
48  * are sent to other backends upon commit.  Internally to the generating
49  * backend, they are also processed at CommandCounterIncrement so that later
50  * commands in the same transaction see the new state.  The generating backend
51  * also has to process them at abort, to flush out any cache state it's loaded
52  * from no-longer-valid entries.
53  *
54  * smgr and relation mapping invalidations are non-transactional: they are
55  * sent immediately when the underlying file change is made.
56  */
57
58 typedef struct
59 {
60         int8            id;                             /* cache ID --- must be first */
61         Oid                     dbId;                   /* database ID, or 0 if a shared relation */
62         uint32          hashValue;              /* hash value of key for this catcache */
63 } SharedInvalCatcacheMsg;
64
65 #define SHAREDINVALCATALOG_ID   (-1)
66
67 typedef struct
68 {
69         int8            id;                             /* type field --- must be first */
70         Oid                     dbId;                   /* database ID, or 0 if a shared catalog */
71         Oid                     catId;                  /* ID of catalog whose contents are invalid */
72 } SharedInvalCatalogMsg;
73
74 #define SHAREDINVALRELCACHE_ID  (-2)
75
76 typedef struct
77 {
78         int8            id;                             /* type field --- must be first */
79         Oid                     dbId;                   /* database ID, or 0 if a shared relation */
80         Oid                     relId;                  /* relation ID */
81 } SharedInvalRelcacheMsg;
82
83 #define SHAREDINVALSMGR_ID              (-3)
84
85 typedef struct
86 {
87         /* note: field layout chosen to pack into 16 bytes */
88         int8            id;                             /* type field --- must be first */
89         int8            backend_hi;             /* high bits of backend ID, if temprel */
90         uint16          backend_lo;             /* low bits of backend ID, if temprel */
91         RelFileNode rnode;                      /* spcNode, dbNode, relNode */
92 } SharedInvalSmgrMsg;
93
94 #define SHAREDINVALRELMAP_ID    (-4)
95
96 typedef struct
97 {
98         int8            id;                             /* type field --- must be first */
99         Oid                     dbId;                   /* database ID, or 0 for shared catalogs */
100 } SharedInvalRelmapMsg;
101
102 #define SHAREDINVALSNAPSHOT_ID  (-5)
103
104 typedef struct
105 {
106         int8            id;                             /* type field --- must be first */
107         Oid                     dbId;                   /* database ID, or 0 if a shared relation */
108         Oid                     relId;                  /* relation ID */
109 } SharedInvalSnapshotMsg;
110
111 typedef union
112 {
113         int8            id;                             /* type field --- must be first */
114         SharedInvalCatcacheMsg cc;
115         SharedInvalCatalogMsg cat;
116         SharedInvalRelcacheMsg rc;
117         SharedInvalSmgrMsg sm;
118         SharedInvalRelmapMsg rm;
119         SharedInvalSnapshotMsg sn;
120 } SharedInvalidationMessage;
121
122
123 /* Counter of messages processed; don't worry about overflow. */
124 extern uint64 SharedInvalidMessageCounter;
125
126
127 extern void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs,
128                                                   int n);
129 extern void ReceiveSharedInvalidMessages(
130                                           void (*invalFunction) (SharedInvalidationMessage *msg),
131                                                          void (*resetFunction) (void));
132
133 /* signal handler for catchup events (PROCSIG_CATCHUP_INTERRUPT) */
134 extern void HandleCatchupInterrupt(void);
135
136 /*
137  * enable/disable processing of catchup events directly from signal handler.
138  * The enable routine first performs processing of any catchup events that
139  * have occurred since the last disable.
140  */
141 extern void EnableCatchupInterrupt(void);
142 extern bool DisableCatchupInterrupt(void);
143
144 extern int xactGetCommittedInvalidationMessages(SharedInvalidationMessage **msgs,
145                                                                          bool *RelcacheInitFileInval);
146 extern void ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs,
147                                                                          int nmsgs, bool RelcacheInitFileInval,
148                                                                          Oid dbid, Oid tsid);
149
150 extern void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg);
151
152 #endif   /* SINVAL_H */