PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sinval.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * sinval.h
4 * POSTGRES shared cache invalidation communication definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2025, 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 <signal.h>
18
20
21/*
22 * We support several types of shared-invalidation messages:
23 * * invalidate a specific tuple in a specific catcache
24 * * invalidate all catcache entries from a given system catalog
25 * * invalidate a relcache entry for a specific logical relation
26 * * invalidate all relcache entries
27 * * invalidate an smgr cache entry for a specific physical relation
28 * * invalidate the mapped-relation mapping for a given database
29 * * invalidate any saved snapshot that might be used to scan a given relation
30 * * invalidate a RelationSyncCache entry for a specific relation
31 * More types could be added if needed. The message type is identified by
32 * the first "int8" field of the message struct. Zero or positive means a
33 * specific-catcache inval message (and also serves as the catcache ID field).
34 * Negative values identify the other message types, as per codes below.
35 *
36 * Catcache inval events are initially driven by detecting tuple inserts,
37 * updates and deletions in system catalogs (see CacheInvalidateHeapTuple).
38 * An update can generate two inval events, one for the old tuple and one for
39 * the new, but this is reduced to one event if the tuple's hash key doesn't
40 * change. Note that the inval events themselves don't actually say whether
41 * the tuple is being inserted or deleted. Also, since we transmit only a
42 * hash key, there is a small risk of unnecessary invalidations due to chance
43 * matches of hash keys.
44 *
45 * Note that some system catalogs have multiple caches on them (with different
46 * indexes). On detecting a tuple invalidation in such a catalog, separate
47 * catcache inval messages must be generated for each of its caches, since
48 * the hash keys will generally be different.
49 *
50 * Catcache, relcache, relsynccache, and snapshot invalidations are
51 * transactional, and so are sent to other backends upon commit. Internally
52 * to the generating backend, they are also processed at
53 * CommandCounterIncrement so that later commands in the same transaction see
54 * the new state. The generating backend also has to process them at abort,
55 * to flush out any cache state it's loaded from no-longer-valid entries.
56 *
57 * smgr and relation mapping invalidations are non-transactional: they are
58 * sent immediately when the underlying file change is made.
59 */
60
61typedef struct
62{
63 int8 id; /* cache ID --- must be first */
64 Oid dbId; /* database ID, or 0 if a shared relation */
65 uint32 hashValue; /* hash value of key for this catcache */
67
68#define SHAREDINVALCATALOG_ID (-1)
69
70typedef struct
71{
72 int8 id; /* type field --- must be first */
73 Oid dbId; /* database ID, or 0 if a shared catalog */
74 Oid catId; /* ID of catalog whose contents are invalid */
76
77#define SHAREDINVALRELCACHE_ID (-2)
78
79typedef struct
80{
81 int8 id; /* type field --- must be first */
82 Oid dbId; /* database ID, or 0 if a shared relation */
83 Oid relId; /* relation ID, or 0 if whole relcache */
85
86#define SHAREDINVALSMGR_ID (-3)
87
88typedef struct
89{
90 /* note: field layout chosen to pack into 16 bytes */
91 int8 id; /* type field --- must be first */
92 int8 backend_hi; /* high bits of backend procno, if temprel */
93 uint16 backend_lo; /* low bits of backend procno, if temprel */
94 RelFileLocator rlocator; /* spcOid, dbOid, relNumber */
96
97#define SHAREDINVALRELMAP_ID (-4)
98
99typedef struct
100{
101 int8 id; /* type field --- must be first */
102 Oid dbId; /* database ID, or 0 for shared catalogs */
104
105#define SHAREDINVALSNAPSHOT_ID (-5)
106
107typedef struct
108{
109 int8 id; /* type field --- must be first */
110 Oid dbId; /* database ID, or 0 if a shared relation */
111 Oid relId; /* relation ID */
113
114#define SHAREDINVALRELSYNC_ID (-6)
115
116typedef struct
117{
118 int8 id; /* type field --- must be first */
119 Oid dbId; /* database ID */
120 Oid relid; /* relation ID, or 0 if whole
121 * RelationSyncCache */
123
124typedef union
125{
126 int8 id; /* type field --- must be first */
135
136
137/* Counter of messages processed; don't worry about overflow. */
139
140extern PGDLLIMPORT volatile sig_atomic_t catchupInterruptPending;
141
143 int n);
144extern void ReceiveSharedInvalidMessages(void (*invalFunction) (SharedInvalidationMessage *msg),
145 void (*resetFunction) (void));
146
147/* signal handler for catchup events (PROCSIG_CATCHUP_INTERRUPT) */
148extern void HandleCatchupInterrupt(void);
149
150/*
151 * enable/disable processing of catchup events directly from signal handler.
152 * The enable routine first performs processing of any catchup events that
153 * have occurred since the last disable.
154 */
155extern void ProcessCatchupInterrupt(void);
156
158 bool *RelcacheInitFileInval);
160 bool *RelcacheInitFileInval);
162 int nmsgs, bool RelcacheInitFileInval,
163 Oid dbid, Oid tsid);
164
166
167#endif /* SINVAL_H */
#define PGDLLIMPORT
Definition: c.h:1291
int8_t int8
Definition: c.h:496
uint64_t uint64
Definition: c.h:503
uint16_t uint16
Definition: c.h:501
uint32_t uint32
Definition: c.h:502
unsigned int Oid
Definition: postgres_ext.h:30
void HandleCatchupInterrupt(void)
Definition: sinval.c:154
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:823
void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs, int n)
Definition: sinval.c:47
int xactGetCommittedInvalidationMessages(SharedInvalidationMessage **msgs, bool *RelcacheInitFileInval)
Definition: inval.c:1012
PGDLLIMPORT volatile sig_atomic_t catchupInterruptPending
Definition: sinval.c:39
PGDLLIMPORT uint64 SharedInvalidMessageCounter
Definition: sinval.c:24
int inplaceGetInvalidationMessages(SharedInvalidationMessage **msgs, bool *RelcacheInitFileInval)
Definition: inval.c:1088
void ReceiveSharedInvalidMessages(void(*invalFunction)(SharedInvalidationMessage *msg), void(*resetFunction)(void))
Definition: sinval.c:69
void ProcessCatchupInterrupt(void)
Definition: sinval.c:174
void ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs, int nmsgs, bool RelcacheInitFileInval, Oid dbid, Oid tsid)
Definition: inval.c:1135
uint16 backend_lo
Definition: sinval.h:93
RelFileLocator rlocator
Definition: sinval.h:94
SharedInvalCatcacheMsg cc
Definition: sinval.h:127
SharedInvalRelcacheMsg rc
Definition: sinval.h:129
SharedInvalCatalogMsg cat
Definition: sinval.h:128
SharedInvalRelSyncMsg rs
Definition: sinval.h:133
SharedInvalSmgrMsg sm
Definition: sinval.h:130
SharedInvalSnapshotMsg sn
Definition: sinval.h:132
SharedInvalRelmapMsg rm
Definition: sinval.h:131