PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pmsignal.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct PMSignalData PMSignalData
 

Enumerations

enum  PMSignalReason {
  PMSIGNAL_RECOVERY_STARTED, PMSIGNAL_BEGIN_HOT_STANDBY, PMSIGNAL_WAKEN_ARCHIVER, PMSIGNAL_ROTATE_LOGFILE,
  PMSIGNAL_START_AUTOVAC_LAUNCHER, PMSIGNAL_START_AUTOVAC_WORKER, PMSIGNAL_BACKGROUND_WORKER_CHANGE, PMSIGNAL_START_WALRECEIVER,
  PMSIGNAL_ADVANCE_STATE_MACHINE, NUM_PMSIGNALS
}
 

Functions

Size PMSignalShmemSize (void)
 
void PMSignalShmemInit (void)
 
void SendPostmasterSignal (PMSignalReason reason)
 
bool CheckPostmasterSignal (PMSignalReason reason)
 
int AssignPostmasterChildSlot (void)
 
bool ReleasePostmasterChildSlot (int slot)
 
bool IsPostmasterChildWalSender (int slot)
 
void MarkPostmasterChildActive (void)
 
void MarkPostmasterChildInactive (void)
 
void MarkPostmasterChildWalSender (void)
 
bool PostmasterIsAlive (void)
 

Typedef Documentation

Definition at line 39 of file pmsignal.h.

Enumeration Type Documentation

Enumerator
PMSIGNAL_RECOVERY_STARTED 
PMSIGNAL_BEGIN_HOT_STANDBY 
PMSIGNAL_WAKEN_ARCHIVER 
PMSIGNAL_ROTATE_LOGFILE 
PMSIGNAL_START_AUTOVAC_LAUNCHER 
PMSIGNAL_START_AUTOVAC_WORKER 
PMSIGNAL_BACKGROUND_WORKER_CHANGE 
PMSIGNAL_START_WALRECEIVER 
PMSIGNAL_ADVANCE_STATE_MACHINE 
NUM_PMSIGNALS 

Definition at line 23 of file pmsignal.h.

24 {
25  PMSIGNAL_RECOVERY_STARTED, /* recovery has started */
26  PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */
27  PMSIGNAL_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */
28  PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */
29  PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */
30  PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */
31  PMSIGNAL_BACKGROUND_WORKER_CHANGE, /* background worker state change */
32  PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
33  PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
34 
35  NUM_PMSIGNALS /* Must be last value of enum! */
PMSignalReason
Definition: pmsignal.h:23

Function Documentation

int AssignPostmasterChildSlot ( void  )

Definition at line 151 of file pmsignal.c.

References elog, FATAL, PMSignalData::next_child_flag, PMSignalData::num_child_flags, PM_CHILD_ASSIGNED, PM_CHILD_UNUSED, PMSignalData::PMChildFlags, and PMSignalState.

Referenced by assign_backendlist_entry(), BackendStartup(), and StartAutovacuumWorker().

152 {
153  int slot = PMSignalState->next_child_flag;
154  int n;
155 
156  /*
157  * Scan for a free slot. We track the last slot assigned so as not to
158  * waste time repeatedly rescanning low-numbered slots.
159  */
160  for (n = PMSignalState->num_child_flags; n > 0; n--)
161  {
162  if (--slot < 0)
163  slot = PMSignalState->num_child_flags - 1;
165  {
168  return slot + 1;
169  }
170  }
171 
172  /* Out of slots ... should never happen, else postmaster.c messed up */
173  elog(FATAL, "no free slots in PMChildFlags array");
174  return 0; /* keep compiler quiet */
175 }
int next_child_flag
Definition: pmsignal.c:68
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define PM_CHILD_ASSIGNED
Definition: pmsignal.c:57
int num_child_flags
Definition: pmsignal.c:67
#define FATAL
Definition: elog.h:52
#define PM_CHILD_UNUSED
Definition: pmsignal.c:56
#define elog
Definition: elog.h:219
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER]
Definition: pmsignal.c:69
bool CheckPostmasterSignal ( PMSignalReason  reason)

Definition at line 130 of file pmsignal.c.

References PMSignalData::PMSignalFlags, and PMSignalState.

Referenced by sigusr1_handler().

131 {
132  /* Careful here --- don't clear flag if we haven't seen it set */
133  if (PMSignalState->PMSignalFlags[reason])
134  {
135  PMSignalState->PMSignalFlags[reason] = false;
136  return true;
137  }
138  return false;
139 }
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
sig_atomic_t PMSignalFlags[NUM_PMSIGNALS]
Definition: pmsignal.c:65
bool IsPostmasterChildWalSender ( int  slot)

Definition at line 207 of file pmsignal.c.

References Assert, PM_CHILD_WALSENDER, PMSignalData::PMChildFlags, and PMSignalState.

Referenced by CountChildren(), and SignalSomeChildren().

208 {
209  Assert(slot > 0 && slot <= PMSignalState->num_child_flags);
210  slot--;
211 
213  return true;
214  else
215  return false;
216 }
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define Assert(condition)
Definition: c.h:675
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER]
Definition: pmsignal.c:69
#define PM_CHILD_WALSENDER
Definition: pmsignal.c:59
void MarkPostmasterChildActive ( void  )

Definition at line 223 of file pmsignal.c.

References Assert, MyPMChildSlot, PM_CHILD_ACTIVE, PM_CHILD_ASSIGNED, PMSignalData::PMChildFlags, and PMSignalState.

Referenced by InitProcess().

224 {
225  int slot = MyPMChildSlot;
226 
227  Assert(slot > 0 && slot <= PMSignalState->num_child_flags);
228  slot--;
231 }
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define PM_CHILD_ACTIVE
Definition: pmsignal.c:58
#define PM_CHILD_ASSIGNED
Definition: pmsignal.c:57
#define Assert(condition)
Definition: c.h:675
int MyPMChildSlot
Definition: globals.c:42
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER]
Definition: pmsignal.c:69
void MarkPostmasterChildInactive ( void  )

Definition at line 256 of file pmsignal.c.

References Assert, MyPMChildSlot, PM_CHILD_ACTIVE, PM_CHILD_ASSIGNED, PM_CHILD_WALSENDER, PMSignalData::PMChildFlags, and PMSignalState.

Referenced by ProcKill().

257 {
258  int slot = MyPMChildSlot;
259 
260  Assert(slot > 0 && slot <= PMSignalState->num_child_flags);
261  slot--;
265 }
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define PM_CHILD_ACTIVE
Definition: pmsignal.c:58
#define PM_CHILD_ASSIGNED
Definition: pmsignal.c:57
#define Assert(condition)
Definition: c.h:675
int MyPMChildSlot
Definition: globals.c:42
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER]
Definition: pmsignal.c:69
#define PM_CHILD_WALSENDER
Definition: pmsignal.c:59
void MarkPostmasterChildWalSender ( void  )

Definition at line 239 of file pmsignal.c.

References am_walsender, Assert, MyPMChildSlot, PM_CHILD_ACTIVE, PM_CHILD_WALSENDER, PMSignalData::PMChildFlags, and PMSignalState.

Referenced by WalSndShutdown().

240 {
241  int slot = MyPMChildSlot;
242 
244 
245  Assert(slot > 0 && slot <= PMSignalState->num_child_flags);
246  slot--;
249 }
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define PM_CHILD_ACTIVE
Definition: pmsignal.c:58
bool am_walsender
Definition: walsender.c:111
#define Assert(condition)
Definition: c.h:675
int MyPMChildSlot
Definition: globals.c:42
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER]
Definition: pmsignal.c:69
#define PM_CHILD_WALSENDER
Definition: pmsignal.c:59
void PMSignalShmemInit ( void  )

Definition at line 95 of file pmsignal.c.

References MaxLivePostmasterChildren(), MemSet, PMSignalData::num_child_flags, PMSignalShmemSize(), PMSignalState, and ShmemInitStruct().

Referenced by CreateSharedMemoryAndSemaphores().

96 {
97  bool found;
98 
100  ShmemInitStruct("PMSignalState", PMSignalShmemSize(), &found);
101 
102  if (!found)
103  {
106  }
107 }
Size PMSignalShmemSize(void)
Definition: pmsignal.c:80
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define MemSet(start, val, len)
Definition: c.h:857
int num_child_flags
Definition: pmsignal.c:67
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
int MaxLivePostmasterChildren(void)
Definition: postmaster.c:5460
Size PMSignalShmemSize ( void  )

Definition at line 80 of file pmsignal.c.

References add_size(), MaxLivePostmasterChildren(), mul_size(), and offsetof.

Referenced by CreateSharedMemoryAndSemaphores(), and PMSignalShmemInit().

81 {
82  Size size;
83 
84  size = offsetof(PMSignalData, PMChildFlags);
86  sizeof(sig_atomic_t)));
87 
88  return size;
89 }
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
int MaxLivePostmasterChildren(void)
Definition: postmaster.c:5460
size_t Size
Definition: c.h:356
#define offsetof(type, field)
Definition: c.h:555
bool PostmasterIsAlive ( void  )

Definition at line 272 of file pmsignal.c.

References EAGAIN, elog, EWOULDBLOCK, FATAL, postmaster_alive_fds, POSTMASTER_FD_WATCH, and read.

Referenced by HandleStartupProcInterrupts(), pgarch_ArchiverCopyLoop(), pgarch_MainLoop(), SyncRepWaitForLSN(), WalRcvWaitForStartPosition(), WalSndLoop(), WalSndWaitForWal(), and WalSndWriteData().

273 {
274 #ifndef WIN32
275  char c;
276  ssize_t rc;
277 
279  if (rc < 0)
280  {
281  if (errno == EAGAIN || errno == EWOULDBLOCK)
282  return true;
283  else
284  elog(FATAL, "read on postmaster death monitoring pipe failed: %m");
285  }
286  else if (rc > 0)
287  elog(FATAL, "unexpected data in postmaster death monitoring pipe");
288 
289  return false;
290 #else /* WIN32 */
291  return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT);
292 #endif /* WIN32 */
293 }
#define EWOULDBLOCK
Definition: win32.h:291
#define EAGAIN
Definition: win32.h:283
#define FATAL
Definition: elog.h:52
char * c
int postmaster_alive_fds[2]
Definition: postmaster.c:557
#define elog
Definition: elog.h:219
#define POSTMASTER_FD_WATCH
Definition: postmaster.h:42
#define read(a, b, c)
Definition: win32.h:13
bool ReleasePostmasterChildSlot ( int  slot)

Definition at line 185 of file pmsignal.c.

References Assert, PM_CHILD_ASSIGNED, PM_CHILD_UNUSED, PMSignalData::PMChildFlags, PMSignalState, and result.

Referenced by BackendStartup(), CleanupBackend(), CleanupBackgroundWorker(), do_start_bgworker(), HandleChildCrash(), and StartAutovacuumWorker().

186 {
187  bool result;
188 
189  Assert(slot > 0 && slot <= PMSignalState->num_child_flags);
190  slot--;
191 
192  /*
193  * Note: the slot state might already be unused, because the logic in
194  * postmaster.c is such that this might get called twice when a child
195  * crashes. So we don't try to Assert anything about the state.
196  */
197  result = (PMSignalState->PMChildFlags[slot] == PM_CHILD_ASSIGNED);
199  return result;
200 }
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
#define PM_CHILD_ASSIGNED
Definition: pmsignal.c:57
return result
Definition: formatting.c:1632
#define Assert(condition)
Definition: c.h:675
#define PM_CHILD_UNUSED
Definition: pmsignal.c:56
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER]
Definition: pmsignal.c:69
void SendPostmasterSignal ( PMSignalReason  reason)

Definition at line 113 of file pmsignal.c.

References IsUnderPostmaster, PMSignalData::PMSignalFlags, PMSignalState, PostmasterPid, and SIGUSR1.

Referenced by AutoVacLauncherMain(), CheckRecoveryConsistency(), do_start_worker(), GetNewMultiXactId(), GetNewTransactionId(), pg_rotate_logfile(), RegisterDynamicBackgroundWorker(), RequestXLogStreaming(), SetMultiXactIdLimit(), SetTransactionIdLimit(), StartupXLOG(), TerminateBackgroundWorker(), WalSndShutdown(), and XLogArchiveNotify().

114 {
115  /* If called in a standalone backend, do nothing */
116  if (!IsUnderPostmaster)
117  return;
118  /* Atomically set the proper flag */
119  PMSignalState->PMSignalFlags[reason] = true;
120  /* Send signal to postmaster */
121  kill(PostmasterPid, SIGUSR1);
122 }
#define SIGUSR1
Definition: win32.h:202
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:72
bool IsUnderPostmaster
Definition: globals.c:100
pid_t PostmasterPid
Definition: globals.c:86
sig_atomic_t PMSignalFlags[NUM_PMSIGNALS]
Definition: pmsignal.c:65