Header And Logo

PostgreSQL
| The world's most advanced open source database.

sinval.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * sinval.h
00004  *    POSTGRES shared cache invalidation communication definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/sinval.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef SINVAL_H
00015 #define SINVAL_H
00016 
00017 #include "storage/relfilenode.h"
00018 
00019 
00020 /*
00021  * We support several types of shared-invalidation messages:
00022  *  * invalidate a specific tuple in a specific catcache
00023  *  * invalidate all catcache entries from a given system catalog
00024  *  * invalidate a relcache entry for a specific logical relation
00025  *  * invalidate an smgr cache entry for a specific physical relation
00026  *  * invalidate the mapped-relation mapping for a given database
00027  * More types could be added if needed.  The message type is identified by
00028  * the first "int8" field of the message struct.  Zero or positive means a
00029  * specific-catcache inval message (and also serves as the catcache ID field).
00030  * Negative values identify the other message types, as per codes below.
00031  *
00032  * Catcache inval events are initially driven by detecting tuple inserts,
00033  * updates and deletions in system catalogs (see CacheInvalidateHeapTuple).
00034  * An update can generate two inval events, one for the old tuple and one for
00035  * the new, but this is reduced to one event if the tuple's hash key doesn't
00036  * change.  Note that the inval events themselves don't actually say whether
00037  * the tuple is being inserted or deleted.  Also, since we transmit only a
00038  * hash key, there is a small risk of unnecessary invalidations due to chance
00039  * matches of hash keys.
00040  *
00041  * Note that some system catalogs have multiple caches on them (with different
00042  * indexes).  On detecting a tuple invalidation in such a catalog, separate
00043  * catcache inval messages must be generated for each of its caches, since
00044  * the hash keys will generally be different.
00045  *
00046  * Catcache and relcache invalidations are transactional, and so are sent
00047  * to other backends upon commit.  Internally to the generating backend,
00048  * they are also processed at CommandCounterIncrement so that later commands
00049  * in the same transaction see the new state.  The generating backend also
00050  * has to process them at abort, to flush out any cache state it's loaded
00051  * from no-longer-valid entries.
00052  *
00053  * smgr and relation mapping invalidations are non-transactional: they are
00054  * sent immediately when the underlying file change is made.
00055  */
00056 
00057 typedef struct
00058 {
00059     int8        id;             /* cache ID --- must be first */
00060     Oid         dbId;           /* database ID, or 0 if a shared relation */
00061     uint32      hashValue;      /* hash value of key for this catcache */
00062 } SharedInvalCatcacheMsg;
00063 
00064 #define SHAREDINVALCATALOG_ID   (-1)
00065 
00066 typedef struct
00067 {
00068     int8        id;             /* type field --- must be first */
00069     Oid         dbId;           /* database ID, or 0 if a shared catalog */
00070     Oid         catId;          /* ID of catalog whose contents are invalid */
00071 } SharedInvalCatalogMsg;
00072 
00073 #define SHAREDINVALRELCACHE_ID  (-2)
00074 
00075 typedef struct
00076 {
00077     int8        id;             /* type field --- must be first */
00078     Oid         dbId;           /* database ID, or 0 if a shared relation */
00079     Oid         relId;          /* relation ID */
00080 } SharedInvalRelcacheMsg;
00081 
00082 #define SHAREDINVALSMGR_ID      (-3)
00083 
00084 typedef struct
00085 {
00086     /* note: field layout chosen to pack into 16 bytes */
00087     int8        id;             /* type field --- must be first */
00088     int8        backend_hi;     /* high bits of backend ID, if temprel */
00089     uint16      backend_lo;     /* low bits of backend ID, if temprel */
00090     RelFileNode rnode;          /* spcNode, dbNode, relNode */
00091 } SharedInvalSmgrMsg;
00092 
00093 #define SHAREDINVALRELMAP_ID    (-4)
00094 
00095 typedef struct
00096 {
00097     int8        id;             /* type field --- must be first */
00098     Oid         dbId;           /* database ID, or 0 for shared catalogs */
00099 } SharedInvalRelmapMsg;
00100 
00101 typedef union
00102 {
00103     int8        id;             /* type field --- must be first */
00104     SharedInvalCatcacheMsg cc;
00105     SharedInvalCatalogMsg cat;
00106     SharedInvalRelcacheMsg rc;
00107     SharedInvalSmgrMsg sm;
00108     SharedInvalRelmapMsg rm;
00109 } SharedInvalidationMessage;
00110 
00111 
00112 /* Counter of messages processed; don't worry about overflow. */
00113 extern uint64 SharedInvalidMessageCounter;
00114 
00115 
00116 extern void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs,
00117                           int n);
00118 extern void ReceiveSharedInvalidMessages(
00119                       void (*invalFunction) (SharedInvalidationMessage *msg),
00120                              void (*resetFunction) (void));
00121 
00122 /* signal handler for catchup events (PROCSIG_CATCHUP_INTERRUPT) */
00123 extern void HandleCatchupInterrupt(void);
00124 
00125 /*
00126  * enable/disable processing of catchup events directly from signal handler.
00127  * The enable routine first performs processing of any catchup events that
00128  * have occurred since the last disable.
00129  */
00130 extern void EnableCatchupInterrupt(void);
00131 extern bool DisableCatchupInterrupt(void);
00132 
00133 extern int xactGetCommittedInvalidationMessages(SharedInvalidationMessage **msgs,
00134                                      bool *RelcacheInitFileInval);
00135 extern void ProcessCommittedInvalidationMessages(SharedInvalidationMessage *msgs,
00136                                      int nmsgs, bool RelcacheInitFileInval,
00137                                      Oid dbid, Oid tsid);
00138 
00139 #endif   /* SINVAL_H */