PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define MAXINVALMSGS   32

Function Documentation

void HandleCatchupInterrupt ( void  )

Definition at line 157 of file sinval.c.

References catchupInterruptPending, MyLatch, and SetLatch().

Referenced by procsignal_sigusr1_handler().

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

Definition at line 177 of file sinval.c.

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

Referenced by AutoVacLauncherMain(), and ProcessClientReadInterrupt().

178 {
180  {
181  /*
182  * What we need to do here is cause ReceiveSharedInvalidMessages() to
183  * run, which will do the necessary work and also reset the
184  * catchupInterruptPending flag. If we are inside a transaction we
185  * can just call AcceptInvalidationMessages() to do this. If we
186  * aren't, we start and immediately end a transaction; the call to
187  * AcceptInvalidationMessages() happens down inside transaction start.
188  *
189  * It is awfully tempting to just call AcceptInvalidationMessages()
190  * without the rest of the xact start/stop overhead, and I think that
191  * would actually work in the normal case; but I am not sure that
192  * things would clean up nicely if we got an error partway through.
193  */
195  {
196  elog(DEBUG4, "ProcessCatchupEvent inside transaction");
198  }
199  else
200  {
201  elog(DEBUG4, "ProcessCatchupEvent outside transaction");
204  }
205  }
206 }
void AcceptInvalidationMessages(void)
Definition: inval.c:679
void CommitTransactionCommand(void)
Definition: xact.c:2748
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4323
#define DEBUG4
Definition: elog.h:22
void StartTransactionCommand(void)
Definition: xact.c:2678
volatile sig_atomic_t catchupInterruptPending
Definition: sinval.c:41
#define elog
Definition: elog.h:219
void ReceiveSharedInvalidMessages ( void(*)(SharedInvalidationMessage *msg)  invalFunction,
void(*)(void)  resetFunction 
)

Definition at line 71 of file sinval.c.

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

Referenced by AcceptInvalidationMessages().

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

Definition at line 49 of file sinval.c.

References SIInsertDataEntries().

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

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

Variable Documentation

volatile sig_atomic_t catchupInterruptPending = false
uint64 SharedInvalidMessageCounter