PostgreSQL Source Code  git master
sinval.c File Reference
#include "postgres.h"
#include "access/xact.h"
#include "commands/async.h"
#include "miscadmin.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "storage/sinvaladt.h"
#include "utils/inval.h"
Include dependency graph for sinval.c:

Go to the source code of this file.

Macros

#define MAXINVALMSGS   32
 

Functions

void SendSharedInvalidMessages (const SharedInvalidationMessage *msgs, int n)
 
void ReceiveSharedInvalidMessages (void(*invalFunction)(SharedInvalidationMessage *msg), void(*resetFunction)(void))
 
void HandleCatchupInterrupt (void)
 
void ProcessCatchupInterrupt (void)
 

Variables

uint64 SharedInvalidMessageCounter
 
volatile sig_atomic_t catchupInterruptPending = false
 

Macro Definition Documentation

◆ MAXINVALMSGS

#define MAXINVALMSGS   32

Function Documentation

◆ HandleCatchupInterrupt()

void HandleCatchupInterrupt ( void  )

Definition at line 156 of file sinval.c.

157 {
158  /*
159  * Note: this is called by a SIGNAL HANDLER. You must be very wary what
160  * you do here.
161  */
162 
164 
165  /* make sure the event is processed in due course */
166  SetLatch(MyLatch);
167 }
struct Latch * MyLatch
Definition: globals.c:58
void SetLatch(Latch *latch)
Definition: latch.c:605
volatile sig_atomic_t catchupInterruptPending
Definition: sinval.c:41

References catchupInterruptPending, MyLatch, and SetLatch().

Referenced by procsignal_sigusr1_handler().

◆ ProcessCatchupInterrupt()

void ProcessCatchupInterrupt ( void  )

Definition at line 176 of file sinval.c.

177 {
179  {
180  /*
181  * What we need to do here is cause ReceiveSharedInvalidMessages() to
182  * run, which will do the necessary work and also reset the
183  * catchupInterruptPending flag. If we are inside a transaction we
184  * can just call AcceptInvalidationMessages() to do this. If we
185  * aren't, we start and immediately end a transaction; the call to
186  * AcceptInvalidationMessages() happens down inside transaction start.
187  *
188  * It is awfully tempting to just call AcceptInvalidationMessages()
189  * without the rest of the xact start/stop overhead, and I think that
190  * would actually work in the normal case; but I am not sure that
191  * things would clean up nicely if we got an error partway through.
192  */
194  {
195  elog(DEBUG4, "ProcessCatchupEvent inside transaction");
197  }
198  else
199  {
200  elog(DEBUG4, "ProcessCatchupEvent outside transaction");
203  }
204  }
205 }
#define DEBUG4
Definition: elog.h:27
void AcceptInvalidationMessages(void)
Definition: inval.c:746
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4834
void StartTransactionCommand(void)
Definition: xact.c:2937
void CommitTransactionCommand(void)
Definition: xact.c:3034

References AcceptInvalidationMessages(), catchupInterruptPending, CommitTransactionCommand(), DEBUG4, elog(), IsTransactionOrTransactionBlock(), and StartTransactionCommand().

Referenced by HandleAutoVacLauncherInterrupts(), and ProcessClientReadInterrupt().

◆ ReceiveSharedInvalidMessages()

void ReceiveSharedInvalidMessages ( void(*)(SharedInvalidationMessage *msg)  invalFunction,
void(*)(void)  resetFunction 
)

Definition at line 71 of file sinval.c.

73 {
74 #define MAXINVALMSGS 32
75  static SharedInvalidationMessage messages[MAXINVALMSGS];
76 
77  /*
78  * We use volatile here to prevent bugs if a compiler doesn't realize that
79  * recursion is a possibility ...
80  */
81  static volatile int nextmsg = 0;
82  static volatile int nummsgs = 0;
83 
84  /* Deal with any messages still pending from an outer recursion */
85  while (nextmsg < nummsgs)
86  {
87  SharedInvalidationMessage msg = messages[nextmsg++];
88 
90  invalFunction(&msg);
91  }
92 
93  do
94  {
95  int getResult;
96 
97  nextmsg = nummsgs = 0;
98 
99  /* Try to get some more messages */
100  getResult = SIGetDataEntries(messages, MAXINVALMSGS);
101 
102  if (getResult < 0)
103  {
104  /* got a reset message */
105  elog(DEBUG4, "cache state reset");
107  resetFunction();
108  break; /* nothing more to do */
109  }
110 
111  /* Process them, being wary that a recursive call might eat some */
112  nextmsg = 0;
113  nummsgs = getResult;
114 
115  while (nextmsg < nummsgs)
116  {
117  SharedInvalidationMessage msg = messages[nextmsg++];
118 
120  invalFunction(&msg);
121  }
122 
123  /*
124  * We only need to loop if the last SIGetDataEntries call (which might
125  * have been within a recursive call) returned a full buffer.
126  */
127  } while (nummsgs == MAXINVALMSGS);
128 
129  /*
130  * We are now caught up. If we received a catchup signal, reset that
131  * flag, and call SICleanupQueue(). This is not so much because we need
132  * to flush dead messages right now, as that we want to pass on the
133  * catchup signal to the next slowest backend. "Daisy chaining" the
134  * catchup signal this way avoids creating spikes in system load for what
135  * should be just a background maintenance activity.
136  */
138  {
139  catchupInterruptPending = false;
140  elog(DEBUG4, "sinval catchup complete, cleaning queue");
141  SICleanupQueue(false, 0);
142  }
143 }
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
#define MAXINVALMSGS
void SICleanupQueue(bool callerHasWriteLock, int minFree)
Definition: sinvaladt.c:654
int SIGetDataEntries(SharedInvalidationMessage *data, int datasize)
Definition: sinvaladt.c:550

References catchupInterruptPending, DEBUG4, elog(), MAXINVALMSGS, SharedInvalidMessageCounter, SICleanupQueue(), and SIGetDataEntries().

Referenced by AcceptInvalidationMessages().

◆ SendSharedInvalidMessages()

void SendSharedInvalidMessages ( const SharedInvalidationMessage msgs,
int  n 
)

Definition at line 49 of file sinval.c.

50 {
51  SIInsertDataEntries(msgs, n);
52 }
void SIInsertDataEntries(const SharedInvalidationMessage *data, int n)
Definition: sinvaladt.c:447

References SIInsertDataEntries().

Referenced by AtEOXact_Inval(), CacheInvalidateRelmap(), CacheInvalidateSmgr(), FinishPreparedTransaction(), and ProcessCommittedInvalidationMessages().

Variable Documentation

◆ catchupInterruptPending

volatile sig_atomic_t catchupInterruptPending = false

◆ SharedInvalidMessageCounter

uint64 SharedInvalidMessageCounter