1 /*-------------------------------------------------------------------------
4 * POSTGRES shared cache invalidation communication definitions.
7 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/sinval.h
12 *-------------------------------------------------------------------------
17 #include "storage/relfilenode.h"
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.
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.
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.
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.
54 * smgr and relation mapping invalidations are non-transactional: they are
55 * sent immediately when the underlying file change is made.
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;
65 #define SHAREDINVALCATALOG_ID (-1)
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;
74 #define SHAREDINVALRELCACHE_ID (-2)
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;
83 #define SHAREDINVALSMGR_ID (-3)
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 */
94 #define SHAREDINVALRELMAP_ID (-4)
98 int8 id; /* type field --- must be first */
99 Oid dbId; /* database ID, or 0 for shared catalogs */
100 } SharedInvalRelmapMsg;
102 #define SHAREDINVALSNAPSHOT_ID (-5)
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;
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;
123 /* Counter of messages processed; don't worry about overflow. */
124 extern uint64 SharedInvalidMessageCounter;
127 extern void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs,
129 extern void ReceiveSharedInvalidMessages(
130 void (*invalFunction) (SharedInvalidationMessage *msg),
131 void (*resetFunction) (void));
133 /* signal handler for catchup events (PROCSIG_CATCHUP_INTERRUPT) */
134 extern void HandleCatchupInterrupt(void);
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.
141 extern void EnableCatchupInterrupt(void);
142 extern bool DisableCatchupInterrupt(void);
144 extern int xactGetCommittedInvalidationMessages(SharedInvalidationMessage **msgs,
145 bool *RelcacheInitFileInval);
146 extern void ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs,
147 int nmsgs, bool RelcacheInitFileInval,
150 extern void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg);
152 #endif /* SINVAL_H */