PostgreSQL Source Code  git master
inval.h File Reference
#include "access/htup.h"
#include "storage/relfilenode.h"
#include "utils/relcache.h"
Include dependency graph for inval.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* SyscacheCallbackFunction) (Datum arg, int cacheid, uint32 hashvalue)
 
typedef void(* RelcacheCallbackFunction) (Datum arg, Oid relid)
 

Functions

void AcceptInvalidationMessages (void)
 
void AtEOXact_Inval (bool isCommit)
 
void AtEOSubXact_Inval (bool isCommit)
 
void PostPrepare_Inval (void)
 
void CommandEndInvalidationMessages (void)
 
void CacheInvalidateHeapTuple (Relation relation, HeapTuple tuple, HeapTuple newtuple)
 
void CacheInvalidateCatalog (Oid catalogId)
 
void CacheInvalidateRelcache (Relation relation)
 
void CacheInvalidateRelcacheAll (void)
 
void CacheInvalidateRelcacheByTuple (HeapTuple classTuple)
 
void CacheInvalidateRelcacheByRelid (Oid relid)
 
void CacheInvalidateSmgr (RelFileNodeBackend rnode)
 
void CacheInvalidateRelmap (Oid databaseId)
 
void CacheRegisterSyscacheCallback (int cacheid, SyscacheCallbackFunction func, Datum arg)
 
void CacheRegisterRelcacheCallback (RelcacheCallbackFunction func, Datum arg)
 
void CallSyscacheCallbacks (int cacheid, uint32 hashvalue)
 
void InvalidateSystemCaches (void)
 
void LogLogicalInvalidations (void)
 

Typedef Documentation

◆ RelcacheCallbackFunction

typedef void(* RelcacheCallbackFunction) (Datum arg, Oid relid)

Definition at line 23 of file inval.h.

◆ SyscacheCallbackFunction

typedef void(* SyscacheCallbackFunction) (Datum arg, int cacheid, uint32 hashvalue)

Definition at line 22 of file inval.h.

Function Documentation

◆ AcceptInvalidationMessages()

void AcceptInvalidationMessages ( void  )

Definition at line 684 of file inval.c.

References InvalidateSystemCaches(), LocalExecuteInvalidationMessage(), ReceiveSharedInvalidMessages(), and recursion_depth.

Referenced by apply_handle_commit_internal(), AtStart_Cache(), ConditionalLockRelation(), ConditionalLockRelationOid(), delay_execution_planner(), InitializeSessionUserId(), LockDatabaseObject(), LockRelation(), LockRelationOid(), LockSharedObject(), LogicalRepApplyLoop(), ProcessCatchupInterrupt(), RangeVarGetRelidExtended(), relation_openrv(), relation_openrv_extended(), RemoveRelations(), and write_relcache_init_file().

685 {
688 
689  /*
690  * Test code to force cache flushes anytime a flush could happen.
691  *
692  * If used with CLOBBER_FREED_MEMORY, CLOBBER_CACHE_ALWAYS provides a
693  * fairly thorough test that the system contains no cache-flush hazards.
694  * However, it also makes the system unbelievably slow --- the regression
695  * tests take about 100 times longer than normal.
696  *
697  * If you're a glutton for punishment, try CLOBBER_CACHE_RECURSIVELY. This
698  * slows things by at least a factor of 10000, so I wouldn't suggest
699  * trying to run the entire regression tests that way. It's useful to try
700  * a few simple tests, to make sure that cache reload isn't subject to
701  * internal cache-flush hazards, but after you've done a few thousand
702  * recursive reloads it's unlikely you'll learn more.
703  */
704 #if defined(CLOBBER_CACHE_ALWAYS)
705  {
706  static bool in_recursion = false;
707 
708  if (!in_recursion)
709  {
710  in_recursion = true;
712  in_recursion = false;
713  }
714  }
715 #elif defined(CLOBBER_CACHE_RECURSIVELY)
716  {
717  static int recursion_depth = 0;
718 
719  /* Maximum depth is arbitrary depending on your threshold of pain */
720  if (recursion_depth < 3)
721  {
722  recursion_depth++;
724  recursion_depth--;
725  }
726  }
727 #endif
728 }
static int recursion_depth
Definition: elog.c:148
void InvalidateSystemCaches(void)
Definition: inval.c:646
void ReceiveSharedInvalidMessages(void(*invalFunction)(SharedInvalidationMessage *msg), void(*resetFunction)(void))
Definition: sinval.c:71
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:559

◆ AtEOSubXact_Inval()

void AtEOSubXact_Inval ( bool  isCommit)

Definition at line 1011 of file inval.c.

References AppendInvalidationMessages(), Assert, CommandEndInvalidationMessages(), GetCurrentTransactionNestLevel(), LocalExecuteInvalidationMessage(), TransInvalidationInfo::my_level, TransInvalidationInfo::parent, pfree(), TransInvalidationInfo::PriorCmdInvalidMsgs, ProcessInvalidationMessages(), TransInvalidationInfo::RelcacheInitFileInval, and transInvalInfo.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

1012 {
1013  int my_level;
1015 
1016  /* Quick exit if no messages. */
1017  if (myInfo == NULL)
1018  return;
1019 
1020  /* Also bail out quickly if messages are not for this level. */
1021  my_level = GetCurrentTransactionNestLevel();
1022  if (myInfo->my_level != my_level)
1023  {
1024  Assert(myInfo->my_level < my_level);
1025  return;
1026  }
1027 
1028  if (isCommit)
1029  {
1030  /* If CurrentCmdInvalidMsgs still has anything, fix it */
1032 
1033  /*
1034  * We create invalidation stack entries lazily, so the parent might
1035  * not have one. Instead of creating one, moving all the data over,
1036  * and then freeing our own, we can just adjust the level of our own
1037  * entry.
1038  */
1039  if (myInfo->parent == NULL || myInfo->parent->my_level < my_level - 1)
1040  {
1041  myInfo->my_level--;
1042  return;
1043  }
1044 
1045  /* Pass up my inval messages to parent */
1047  &myInfo->PriorCmdInvalidMsgs);
1048 
1049  /* Pending relcache inval becomes parent's problem too */
1050  if (myInfo->RelcacheInitFileInval)
1051  myInfo->parent->RelcacheInitFileInval = true;
1052 
1053  /* Pop the transaction state stack */
1054  transInvalInfo = myInfo->parent;
1055 
1056  /* Need not free anything else explicitly */
1057  pfree(myInfo);
1058  }
1059  else
1060  {
1063 
1064  /* Pop the transaction state stack */
1065  transInvalInfo = myInfo->parent;
1066 
1067  /* Need not free anything else explicitly */
1068  pfree(myInfo);
1069  }
1070 }
static void AppendInvalidationMessages(InvalidationListHeader *dest, InvalidationListHeader *src)
Definition: inval.c:445
InvalidationListHeader PriorCmdInvalidMsgs
Definition: inval.c:170
void CommandEndInvalidationMessages(void)
Definition: inval.c:1088
struct TransInvalidationInfo * parent
Definition: inval.c:161
static TransInvalidationInfo * transInvalInfo
Definition: inval.c:176
void pfree(void *pointer)
Definition: mcxt.c:1057
bool RelcacheInitFileInval
Definition: inval.c:173
static void ProcessInvalidationMessages(InvalidationListHeader *hdr, void(*func)(SharedInvalidationMessage *msg))
Definition: inval.c:459
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:857
#define Assert(condition)
Definition: c.h:800
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:559

◆ AtEOXact_Inval()

void AtEOXact_Inval ( bool  isCommit)

Definition at line 952 of file inval.c.

References AppendInvalidationMessages(), Assert, TransInvalidationInfo::CurrentCmdInvalidMsgs, LocalExecuteInvalidationMessage(), TransInvalidationInfo::my_level, numSharedInvalidMessagesArray, TransInvalidationInfo::parent, TransInvalidationInfo::PriorCmdInvalidMsgs, ProcessInvalidationMessages(), ProcessInvalidationMessagesMulti(), RelationCacheInitFilePostInvalidate(), RelationCacheInitFilePreInvalidate(), TransInvalidationInfo::RelcacheInitFileInval, and SendSharedInvalidMessages().

Referenced by AbortTransaction(), CommitTransaction(), and PostPrepare_Inval().

953 {
954  /* Quick exit if no messages */
955  if (transInvalInfo == NULL)
956  return;
957 
958  /* Must be at top of stack */
960 
961  if (isCommit)
962  {
963  /*
964  * Relcache init file invalidation requires processing both before and
965  * after we send the SI messages. However, we need not do anything
966  * unless we committed.
967  */
970 
973 
976 
979  }
980  else
981  {
984  }
985 
986  /* Need not free anything explicitly */
987  transInvalInfo = NULL;
990 }
static void AppendInvalidationMessages(InvalidationListHeader *dest, InvalidationListHeader *src)
Definition: inval.c:445
static SharedInvalidationMessage * SharedInvalidMessagesArray
Definition: inval.c:178
InvalidationListHeader PriorCmdInvalidMsgs
Definition: inval.c:170
struct TransInvalidationInfo * parent
Definition: inval.c:161
static TransInvalidationInfo * transInvalInfo
Definition: inval.c:176
InvalidationListHeader CurrentCmdInvalidMsgs
Definition: inval.c:167
static int numSharedInvalidMessagesArray
Definition: inval.c:179
static void ProcessInvalidationMessagesMulti(InvalidationListHeader *hdr, void(*func)(const SharedInvalidationMessage *msgs, int n))
Definition: inval.c:471
bool RelcacheInitFileInval
Definition: inval.c:173
static void ProcessInvalidationMessages(InvalidationListHeader *hdr, void(*func)(SharedInvalidationMessage *msg))
Definition: inval.c:459
void RelationCacheInitFilePostInvalidate(void)
Definition: relcache.c:6325
void RelationCacheInitFilePreInvalidate(void)
Definition: relcache.c:6300
#define Assert(condition)
Definition: c.h:800
void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs, int n)
Definition: sinval.c:49
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:559

◆ CacheInvalidateCatalog()

void CacheInvalidateCatalog ( Oid  catalogId)

Definition at line 1254 of file inval.c.

References InvalidOid, IsSharedRelation(), MyDatabaseId, PrepareInvalidationState(), and RegisterCatalogInvalidation().

Referenced by finish_heap_swap().

1255 {
1256  Oid databaseId;
1257 
1259 
1260  if (IsSharedRelation(catalogId))
1261  databaseId = InvalidOid;
1262  else
1263  databaseId = MyDatabaseId;
1264 
1265  RegisterCatalogInvalidation(databaseId, catalogId);
1266 }
unsigned int Oid
Definition: postgres_ext.h:31
static void PrepareInvalidationState(void)
Definition: inval.c:735
Oid MyDatabaseId
Definition: globals.c:85
static void RegisterCatalogInvalidation(Oid dbId, Oid catId)
Definition: inval.c:503
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:236
#define InvalidOid
Definition: postgres_ext.h:36

◆ CacheInvalidateHeapTuple()

void CacheInvalidateHeapTuple ( Relation  relation,
HeapTuple  tuple,
HeapTuple  newtuple 
)

Definition at line 1122 of file inval.c.

References GETSTRUCT, InvalidOid, IsBootstrapProcessingMode, IsCatalogRelation(), IsSharedRelation(), IsToastRelation(), MyDatabaseId, OidIsValid, PrepareInvalidationState(), PrepareToInvalidateCacheTuple(), RegisterCatcacheInvalidation(), RegisterRelcacheInvalidation(), RegisterSnapshotInvalidation(), RelationGetRelid, and RelationInvalidatesSnapshotsOnly().

Referenced by AlterDomainAddConstraint(), AlterDomainDropConstraint(), heap_delete(), heap_inplace_update(), heap_insert(), heap_multi_insert(), and heap_update().

1125 {
1126  Oid tupleRelId;
1127  Oid databaseId;
1128  Oid relationId;
1129 
1130  /* Do nothing during bootstrap */
1132  return;
1133 
1134  /*
1135  * We only need to worry about invalidation for tuples that are in system
1136  * catalogs; user-relation tuples are never in catcaches and can't affect
1137  * the relcache either.
1138  */
1139  if (!IsCatalogRelation(relation))
1140  return;
1141 
1142  /*
1143  * IsCatalogRelation() will return true for TOAST tables of system
1144  * catalogs, but we don't care about those, either.
1145  */
1146  if (IsToastRelation(relation))
1147  return;
1148 
1149  /*
1150  * If we're not prepared to queue invalidation messages for this
1151  * subtransaction level, get ready now.
1152  */
1154 
1155  /*
1156  * First let the catcache do its thing
1157  */
1158  tupleRelId = RelationGetRelid(relation);
1159  if (RelationInvalidatesSnapshotsOnly(tupleRelId))
1160  {
1161  databaseId = IsSharedRelation(tupleRelId) ? InvalidOid : MyDatabaseId;
1162  RegisterSnapshotInvalidation(databaseId, tupleRelId);
1163  }
1164  else
1165  PrepareToInvalidateCacheTuple(relation, tuple, newtuple,
1167 
1168  /*
1169  * Now, is this tuple one of the primary definers of a relcache entry? See
1170  * comments in file header for deeper explanation.
1171  *
1172  * Note we ignore newtuple here; we assume an update cannot move a tuple
1173  * from being part of one relcache entry to being part of another.
1174  */
1175  if (tupleRelId == RelationRelationId)
1176  {
1177  Form_pg_class classtup = (Form_pg_class) GETSTRUCT(tuple);
1178 
1179  relationId = classtup->oid;
1180  if (classtup->relisshared)
1181  databaseId = InvalidOid;
1182  else
1183  databaseId = MyDatabaseId;
1184  }
1185  else if (tupleRelId == AttributeRelationId)
1186  {
1187  Form_pg_attribute atttup = (Form_pg_attribute) GETSTRUCT(tuple);
1188 
1189  relationId = atttup->attrelid;
1190 
1191  /*
1192  * KLUGE ALERT: we always send the relcache event with MyDatabaseId,
1193  * even if the rel in question is shared (which we can't easily tell).
1194  * This essentially means that only backends in this same database
1195  * will react to the relcache flush request. This is in fact
1196  * appropriate, since only those backends could see our pg_attribute
1197  * change anyway. It looks a bit ugly though. (In practice, shared
1198  * relations can't have schema changes after bootstrap, so we should
1199  * never come here for a shared rel anyway.)
1200  */
1201  databaseId = MyDatabaseId;
1202  }
1203  else if (tupleRelId == IndexRelationId)
1204  {
1205  Form_pg_index indextup = (Form_pg_index) GETSTRUCT(tuple);
1206 
1207  /*
1208  * When a pg_index row is updated, we should send out a relcache inval
1209  * for the index relation. As above, we don't know the shared status
1210  * of the index, but in practice it doesn't matter since indexes of
1211  * shared catalogs can't have such updates.
1212  */
1213  relationId = indextup->indexrelid;
1214  databaseId = MyDatabaseId;
1215  }
1216  else if (tupleRelId == ConstraintRelationId)
1217  {
1218  Form_pg_constraint constrtup = (Form_pg_constraint) GETSTRUCT(tuple);
1219 
1220  /*
1221  * Foreign keys are part of relcache entries, too, so send out an
1222  * inval for the table that the FK applies to.
1223  */
1224  if (constrtup->contype == CONSTRAINT_FOREIGN &&
1225  OidIsValid(constrtup->conrelid))
1226  {
1227  relationId = constrtup->conrelid;
1228  databaseId = MyDatabaseId;
1229  }
1230  else
1231  return;
1232  }
1233  else
1234  return;
1235 
1236  /*
1237  * Yes. We need to register a relcache invalidation event.
1238  */
1239  RegisterRelcacheInvalidation(databaseId, relationId);
1240 }
bool IsToastRelation(Relation relation)
Definition: catalog.c:138
bool IsCatalogRelation(Relation relation)
Definition: catalog.c:96
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
void PrepareToInvalidateCacheTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple, void(*function)(int, uint32, Oid))
Definition: catcache.c:2007
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:706
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
static void PrepareInvalidationState(void)
Definition: inval.c:735
FormData_pg_index * Form_pg_index
Definition: pg_index.h:68
Oid MyDatabaseId
Definition: globals.c:85
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:236
#define InvalidOid
Definition: postgres_ext.h:36
static void RegisterRelcacheInvalidation(Oid dbId, Oid relId)
Definition: inval.c:515
FormData_pg_constraint * Form_pg_constraint
static void RegisterCatcacheInvalidation(int cacheId, uint32 hashValue, Oid dbId)
Definition: inval.c:489
bool RelationInvalidatesSnapshotsOnly(Oid relid)
Definition: syscache.c:1472
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:393
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
#define RelationGetRelid(relation)
Definition: rel.h:457
static void RegisterSnapshotInvalidation(Oid dbId, Oid relId)
Definition: inval.c:545

◆ CacheInvalidateRelcache()

void CacheInvalidateRelcache ( Relation  relation)

Definition at line 1278 of file inval.c.

References InvalidOid, MyDatabaseId, PrepareInvalidationState(), RelationData::rd_rel, RegisterRelcacheInvalidation(), and RelationGetRelid.

Referenced by AlterPolicy(), ATExecAlterCollationRefreshVersion(), ATExecAlterConstraint(), ATExecDetachPartition(), ATExecGenericOptions(), ATExecValidateConstraint(), CreatePolicy(), CreateStatistics(), EnableDisableRule(), EnableDisableTrigger(), index_concurrently_set_dead(), index_create(), index_drop(), publication_add_relation(), reindex_index(), RelationSetNewRelfilenode(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectPolicy(), RemoveTriggerById(), rename_constraint_internal(), rename_policy(), RenameRewriteRule(), renametrig(), SetRelationNumChecks(), StorePartitionBound(), and StorePartitionKey().

1279 {
1280  Oid databaseId;
1281  Oid relationId;
1282 
1284 
1285  relationId = RelationGetRelid(relation);
1286  if (relation->rd_rel->relisshared)
1287  databaseId = InvalidOid;
1288  else
1289  databaseId = MyDatabaseId;
1290 
1291  RegisterRelcacheInvalidation(databaseId, relationId);
1292 }
Form_pg_class rd_rel
Definition: rel.h:110
unsigned int Oid
Definition: postgres_ext.h:31
static void PrepareInvalidationState(void)
Definition: inval.c:735
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static void RegisterRelcacheInvalidation(Oid dbId, Oid relId)
Definition: inval.c:515
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ CacheInvalidateRelcacheAll()

void CacheInvalidateRelcacheAll ( void  )

Definition at line 1302 of file inval.c.

References InvalidOid, PrepareInvalidationState(), and RegisterRelcacheInvalidation().

Referenced by AlterPublicationOptions().

1303 {
1305 
1307 }
static void PrepareInvalidationState(void)
Definition: inval.c:735
#define InvalidOid
Definition: postgres_ext.h:36
static void RegisterRelcacheInvalidation(Oid dbId, Oid relId)
Definition: inval.c:515

◆ CacheInvalidateRelcacheByRelid()

void CacheInvalidateRelcacheByRelid ( Oid  relid)

Definition at line 1337 of file inval.c.

References CacheInvalidateRelcacheByTuple(), elog, ERROR, HeapTupleIsValid, ObjectIdGetDatum, PrepareInvalidationState(), ReleaseSysCache(), RELOID, and SearchSysCache1().

Referenced by AlterPublicationOptions(), ATExecAlterConstraint(), ATExecDetachPartition(), DefineIndex(), heap_drop_with_catalog(), ReindexRelationConcurrently(), RemovePublicationRelById(), RemoveStatisticsById(), and StorePartitionBound().

1338 {
1339  HeapTuple tup;
1340 
1342 
1343  tup = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
1344  if (!HeapTupleIsValid(tup))
1345  elog(ERROR, "cache lookup failed for relation %u", relid);
1347  ReleaseSysCache(tup);
1348 }
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static void PrepareInvalidationState(void)
Definition: inval.c:735
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1115
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1163
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:228
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
Definition: inval.c:1314

◆ CacheInvalidateRelcacheByTuple()

void CacheInvalidateRelcacheByTuple ( HeapTuple  classTuple)

Definition at line 1314 of file inval.c.

References GETSTRUCT, InvalidOid, MyDatabaseId, PrepareInvalidationState(), and RegisterRelcacheInvalidation().

Referenced by CacheInvalidateRelcacheByRelid(), copy_table_data(), CreateTrigger(), index_update_stats(), SetRelationHasSubclass(), SetRelationRuleStatus(), and swap_relation_files().

1315 {
1316  Form_pg_class classtup = (Form_pg_class) GETSTRUCT(classTuple);
1317  Oid databaseId;
1318  Oid relationId;
1319 
1321 
1322  relationId = classtup->oid;
1323  if (classtup->relisshared)
1324  databaseId = InvalidOid;
1325  else
1326  databaseId = MyDatabaseId;
1327  RegisterRelcacheInvalidation(databaseId, relationId);
1328 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
unsigned int Oid
Definition: postgres_ext.h:31
static void PrepareInvalidationState(void)
Definition: inval.c:735
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
static void RegisterRelcacheInvalidation(Oid dbId, Oid relId)
Definition: inval.c:515
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153

◆ CacheInvalidateRelmap()

void CacheInvalidateRelmap ( Oid  databaseId)

Definition at line 1407 of file inval.c.

References SharedInvalRelmapMsg::dbId, SharedInvalRelmapMsg::id, SharedInvalidationMessage::rm, SendSharedInvalidMessages(), SHAREDINVALRELMAP_ID, and VALGRIND_MAKE_MEM_DEFINED.

Referenced by write_relmap_file().

1408 {
1410 
1411  msg.rm.id = SHAREDINVALRELMAP_ID;
1412  msg.rm.dbId = databaseId;
1413  /* check AddCatcacheInvalidationMessage() for an explanation */
1414  VALGRIND_MAKE_MEM_DEFINED(&msg, sizeof(msg));
1415 
1416  SendSharedInvalidMessages(&msg, 1);
1417 }
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
Definition: memdebug.h:26
SharedInvalRelmapMsg rm
Definition: sinval.h:120
#define SHAREDINVALRELMAP_ID
Definition: sinval.h:96
void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs, int n)
Definition: sinval.c:49

◆ CacheInvalidateSmgr()

void CacheInvalidateSmgr ( RelFileNodeBackend  rnode)

Definition at line 1377 of file inval.c.

References RelFileNodeBackend::backend, SharedInvalSmgrMsg::backend_hi, SharedInvalSmgrMsg::backend_lo, SharedInvalSmgrMsg::id, RelFileNodeBackend::node, SharedInvalSmgrMsg::rnode, SendSharedInvalidMessages(), SHAREDINVALSMGR_ID, SharedInvalidationMessage::sm, and VALGRIND_MAKE_MEM_DEFINED.

Referenced by smgrdounlinkall(), smgrtruncate(), and vm_extend().

1378 {
1380 
1381  msg.sm.id = SHAREDINVALSMGR_ID;
1382  msg.sm.backend_hi = rnode.backend >> 16;
1383  msg.sm.backend_lo = rnode.backend & 0xffff;
1384  msg.sm.rnode = rnode.node;
1385  /* check AddCatcacheInvalidationMessage() for an explanation */
1386  VALGRIND_MAKE_MEM_DEFINED(&msg, sizeof(msg));
1387 
1388  SendSharedInvalidMessages(&msg, 1);
1389 }
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
Definition: memdebug.h:26
RelFileNode node
Definition: relfilenode.h:74
SharedInvalSmgrMsg sm
Definition: sinval.h:119
BackendId backend
Definition: relfilenode.h:75
void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs, int n)
Definition: sinval.c:49
uint16 backend_lo
Definition: sinval.h:92
RelFileNode rnode
Definition: sinval.h:93
#define SHAREDINVALSMGR_ID
Definition: sinval.h:85

◆ CacheRegisterRelcacheCallback()

void CacheRegisterRelcacheCallback ( RelcacheCallbackFunction  func,
Datum  arg 
)

Definition at line 1476 of file inval.c.

References arg, RELCACHECALLBACK::arg, elog, FATAL, RELCACHECALLBACK::function, MAX_RELCACHE_CALLBACKS, relcache_callback_count, and relcache_callback_list.

Referenced by init_rel_sync_cache(), InitializeRelfilenodeMap(), InitPlanCache(), logicalrep_partmap_init(), logicalrep_relmap_init(), and lookup_type_cache().

1478 {
1480  elog(FATAL, "out of relcache_callback_list slots");
1481 
1484 
1486 }
static struct RELCACHECALLBACK relcache_callback_list[MAX_RELCACHE_CALLBACKS]
#define MAX_RELCACHE_CALLBACKS
Definition: inval.c:194
static int relcache_callback_count
Definition: inval.c:214
RelcacheCallbackFunction function
Definition: inval.c:210
#define FATAL
Definition: elog.h:52
#define elog(elevel,...)
Definition: elog.h:228
void * arg

◆ CacheRegisterSyscacheCallback()

void CacheRegisterSyscacheCallback ( int  cacheid,
SyscacheCallbackFunction  func,
Datum  arg 
)

Definition at line 1434 of file inval.c.

References arg, SYSCACHECALLBACK::arg, elog, FATAL, SYSCACHECALLBACK::function, i, SYSCACHECALLBACK::id, SYSCACHECALLBACK::link, MAX_SYSCACHE_CALLBACKS, syscache_callback_count, syscache_callback_links, syscache_callback_list, and SysCacheSize.

Referenced by ApplyWorkerMain(), BuildEventTriggerCache(), find_oper_cache_entry(), GetConnection(), init_rel_sync_cache(), init_ts_config_cache(), initialize_acl(), InitializeAttoptCache(), InitializeSearchPath(), InitializeShippableCache(), InitializeTableSpaceCache(), InitPlanCache(), lookup_proof_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), pgoutput_startup(), ri_InitHashTables(), and superuser_arg().

1437 {
1438  if (cacheid < 0 || cacheid >= SysCacheSize)
1439  elog(FATAL, "invalid cache ID: %d", cacheid);
1441  elog(FATAL, "out of syscache_callback_list slots");
1442 
1443  if (syscache_callback_links[cacheid] == 0)
1444  {
1445  /* first callback for this cache */
1447  }
1448  else
1449  {
1450  /* add to end of chain, so that older callbacks are called first */
1451  int i = syscache_callback_links[cacheid] - 1;
1452 
1453  while (syscache_callback_list[i].link > 0)
1454  i = syscache_callback_list[i].link - 1;
1456  }
1457 
1462 
1464 }
int16 link
Definition: inval.c:199
#define SysCacheSize
Definition: syscache.h:113
#define FATAL
Definition: elog.h:52
#define MAX_SYSCACHE_CALLBACKS
Definition: inval.c:193
static struct SYSCACHECALLBACK syscache_callback_list[MAX_SYSCACHE_CALLBACKS]
static int syscache_callback_count
Definition: inval.c:206
static int16 syscache_callback_links[SysCacheSize]
Definition: inval.c:204
#define elog(elevel,...)
Definition: elog.h:228
int i
void * arg
SyscacheCallbackFunction function
Definition: inval.c:200

◆ CallSyscacheCallbacks()

void CallSyscacheCallbacks ( int  cacheid,
uint32  hashvalue 
)

Definition at line 1495 of file inval.c.

References SYSCACHECALLBACK::arg, Assert, elog, ERROR, SYSCACHECALLBACK::function, i, SYSCACHECALLBACK::id, SYSCACHECALLBACK::link, syscache_callback_links, syscache_callback_list, and SysCacheSize.

Referenced by CatalogCacheFlushCatalog(), and LocalExecuteInvalidationMessage().

1496 {
1497  int i;
1498 
1499  if (cacheid < 0 || cacheid >= SysCacheSize)
1500  elog(ERROR, "invalid cache ID: %d", cacheid);
1501 
1502  i = syscache_callback_links[cacheid] - 1;
1503  while (i >= 0)
1504  {
1505  struct SYSCACHECALLBACK *ccitem = syscache_callback_list + i;
1506 
1507  Assert(ccitem->id == cacheid);
1508  ccitem->function(ccitem->arg, cacheid, hashvalue);
1509  i = ccitem->link - 1;
1510  }
1511 }
int16 link
Definition: inval.c:199
#define SysCacheSize
Definition: syscache.h:113
#define ERROR
Definition: elog.h:43
static struct SYSCACHECALLBACK syscache_callback_list[MAX_SYSCACHE_CALLBACKS]
#define Assert(condition)
Definition: c.h:800
static int16 syscache_callback_links[SysCacheSize]
Definition: inval.c:204
#define elog(elevel,...)
Definition: elog.h:228
int i
SyscacheCallbackFunction function
Definition: inval.c:200

◆ CommandEndInvalidationMessages()

void CommandEndInvalidationMessages ( void  )

Definition at line 1088 of file inval.c.

References AppendInvalidationMessages(), TransInvalidationInfo::CurrentCmdInvalidMsgs, LocalExecuteInvalidationMessage(), LogLogicalInvalidations(), TransInvalidationInfo::PriorCmdInvalidMsgs, ProcessInvalidationMessages(), and XLogLogicalInfoActive.

Referenced by AtCCI_LocalCache(), and AtEOSubXact_Inval().

1089 {
1090  /*
1091  * You might think this shouldn't be called outside any transaction, but
1092  * bootstrap does it, and also ABORT issued when not in a transaction. So
1093  * just quietly return if no state to work on.
1094  */
1095  if (transInvalInfo == NULL)
1096  return;
1097 
1100 
1101  /* WAL Log per-command invalidation messages for wal_level=logical */
1102  if (XLogLogicalInfoActive())
1104 
1107 }
static void AppendInvalidationMessages(InvalidationListHeader *dest, InvalidationListHeader *src)
Definition: inval.c:445
InvalidationListHeader PriorCmdInvalidMsgs
Definition: inval.c:170
static TransInvalidationInfo * transInvalInfo
Definition: inval.c:176
InvalidationListHeader CurrentCmdInvalidMsgs
Definition: inval.c:167
#define XLogLogicalInfoActive()
Definition: xlog.h:208
void LogLogicalInvalidations()
Definition: inval.c:1521
static void ProcessInvalidationMessages(InvalidationListHeader *hdr, void(*func)(SharedInvalidationMessage *msg))
Definition: inval.c:459
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:559

◆ InvalidateSystemCaches()

void InvalidateSystemCaches ( void  )

Definition at line 646 of file inval.c.

References SYSCACHECALLBACK::arg, RELCACHECALLBACK::arg, SYSCACHECALLBACK::function, RELCACHECALLBACK::function, i, SYSCACHECALLBACK::id, InvalidateCatalogSnapshot(), InvalidOid, RelationCacheInvalidate(), relcache_callback_count, relcache_callback_list, ResetCatalogCaches(), syscache_callback_count, and syscache_callback_list.

Referenced by AcceptInvalidationMessages(), ParallelWorkerMain(), pg_logical_replication_slot_advance(), and pg_logical_slot_get_changes_guts().

647 {
648  int i;
649 
652  RelationCacheInvalidate(); /* gets smgr and relmap too */
653 
654  for (i = 0; i < syscache_callback_count; i++)
655  {
656  struct SYSCACHECALLBACK *ccitem = syscache_callback_list + i;
657 
658  ccitem->function(ccitem->arg, ccitem->id, 0);
659  }
660 
661  for (i = 0; i < relcache_callback_count; i++)
662  {
663  struct RELCACHECALLBACK *ccitem = relcache_callback_list + i;
664 
665  ccitem->function(ccitem->arg, InvalidOid);
666  }
667 }
static struct RELCACHECALLBACK relcache_callback_list[MAX_RELCACHE_CALLBACKS]
static int relcache_callback_count
Definition: inval.c:214
RelcacheCallbackFunction function
Definition: inval.c:210
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:456
static struct SYSCACHECALLBACK syscache_callback_list[MAX_SYSCACHE_CALLBACKS]
static int syscache_callback_count
Definition: inval.c:206
#define InvalidOid
Definition: postgres_ext.h:36
void ResetCatalogCaches(void)
Definition: catcache.c:689
void RelationCacheInvalidate(void)
Definition: relcache.c:2832
int i
SyscacheCallbackFunction function
Definition: inval.c:200

◆ LogLogicalInvalidations()

void LogLogicalInvalidations ( void  )

Definition at line 1521 of file inval.c.

References Assert, TransInvalidationInfo::CurrentCmdInvalidMsgs, MakeSharedInvalidMessagesArray(), MinSizeOfXactInvals, xl_xact_invals::nmsgs, numSharedInvalidMessagesArray, pfree(), ProcessInvalidationMessagesMulti(), SharedInvalidMessagesArray, XLOG_XACT_INVALIDATIONS, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().

Referenced by CommandEndInvalidationMessages(), and RecordTransactionCommit().

1522 {
1523  xl_xact_invals xlrec;
1524  SharedInvalidationMessage *invalMessages;
1525  int nmsgs = 0;
1526 
1527  /* Quick exit if we haven't done anything with invalidation messages. */
1528  if (transInvalInfo == NULL)
1529  return;
1530 
1533 
1535  SharedInvalidMessagesArray == NULL));
1536 
1537  invalMessages = SharedInvalidMessagesArray;
1541 
1542  if (nmsgs > 0)
1543  {
1544  /* prepare record */
1545  memset(&xlrec, 0, MinSizeOfXactInvals);
1546  xlrec.nmsgs = nmsgs;
1547 
1548  /* perform insertion */
1549  XLogBeginInsert();
1550  XLogRegisterData((char *) (&xlrec), MinSizeOfXactInvals);
1551  XLogRegisterData((char *) invalMessages,
1552  nmsgs * sizeof(SharedInvalidationMessage));
1553  XLogInsert(RM_XACT_ID, XLOG_XACT_INVALIDATIONS);
1554 
1555  pfree(invalMessages);
1556  }
1557 }
static SharedInvalidationMessage * SharedInvalidMessagesArray
Definition: inval.c:178
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:154
static TransInvalidationInfo * transInvalInfo
Definition: inval.c:176
InvalidationListHeader CurrentCmdInvalidMsgs
Definition: inval.c:167
void pfree(void *pointer)
Definition: mcxt.c:1057
static void MakeSharedInvalidMessagesArray(const SharedInvalidationMessage *msgs, int n)
Definition: inval.c:781
static int numSharedInvalidMessagesArray
Definition: inval.c:179
#define MinSizeOfXactInvals
Definition: xact.h:257
static void ProcessInvalidationMessagesMulti(InvalidationListHeader *hdr, void(*func)(const SharedInvalidationMessage *msgs, int n))
Definition: inval.c:471
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:330
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:422
#define Assert(condition)
Definition: c.h:800
void XLogBeginInsert(void)
Definition: xloginsert.c:123
int nmsgs
Definition: xact.h:254

◆ PostPrepare_Inval()

void PostPrepare_Inval ( void  )

Definition at line 772 of file inval.c.

References AtEOXact_Inval().

Referenced by PrepareTransaction().

773 {
774  AtEOXact_Inval(false);
775 }
void AtEOXact_Inval(bool isCommit)
Definition: inval.c:952