PostgreSQL Source Code  git master
procsignal.h File Reference
Include dependency graph for procsignal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ProcSignalReason {
  PROCSIG_CATCHUP_INTERRUPT , PROCSIG_NOTIFY_INTERRUPT , PROCSIG_PARALLEL_MESSAGE , PROCSIG_WALSND_INIT_STOPPING ,
  PROCSIG_BARRIER , PROCSIG_LOG_MEMORY_CONTEXT , PROCSIG_PARALLEL_APPLY_MESSAGE , PROCSIG_RECOVERY_CONFLICT_FIRST ,
  PROCSIG_RECOVERY_CONFLICT_DATABASE = PROCSIG_RECOVERY_CONFLICT_FIRST , PROCSIG_RECOVERY_CONFLICT_TABLESPACE , PROCSIG_RECOVERY_CONFLICT_LOCK , PROCSIG_RECOVERY_CONFLICT_SNAPSHOT ,
  PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT , PROCSIG_RECOVERY_CONFLICT_BUFFERPIN , PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK , PROCSIG_RECOVERY_CONFLICT_LAST = PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK ,
  NUM_PROCSIGNALS
}
 
enum  ProcSignalBarrierType { PROCSIGNAL_BARRIER_SMGRRELEASE }
 

Functions

Size ProcSignalShmemSize (void)
 
void ProcSignalShmemInit (void)
 
void ProcSignalInit (int pss_idx)
 
int SendProcSignal (pid_t pid, ProcSignalReason reason, BackendId backendId)
 
uint64 EmitProcSignalBarrier (ProcSignalBarrierType type)
 
void WaitForProcSignalBarrier (uint64 generation)
 
void ProcessProcSignalBarrier (void)
 
void procsignal_sigusr1_handler (SIGNAL_ARGS)
 

Enumeration Type Documentation

◆ ProcSignalBarrierType

Enumerator
PROCSIGNAL_BARRIER_SMGRRELEASE 

Definition at line 54 of file procsignal.h.

55 {
56  PROCSIGNAL_BARRIER_SMGRRELEASE, /* ask smgr to close files */
ProcSignalBarrierType
Definition: procsignal.h:55
@ PROCSIGNAL_BARRIER_SMGRRELEASE
Definition: procsignal.h:56

◆ ProcSignalReason

Enumerator
PROCSIG_CATCHUP_INTERRUPT 
PROCSIG_NOTIFY_INTERRUPT 
PROCSIG_PARALLEL_MESSAGE 
PROCSIG_WALSND_INIT_STOPPING 
PROCSIG_BARRIER 
PROCSIG_LOG_MEMORY_CONTEXT 
PROCSIG_PARALLEL_APPLY_MESSAGE 
PROCSIG_RECOVERY_CONFLICT_FIRST 
PROCSIG_RECOVERY_CONFLICT_DATABASE 
PROCSIG_RECOVERY_CONFLICT_TABLESPACE 
PROCSIG_RECOVERY_CONFLICT_LOCK 
PROCSIG_RECOVERY_CONFLICT_SNAPSHOT 
PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT 
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN 
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK 
PROCSIG_RECOVERY_CONFLICT_LAST 
NUM_PROCSIGNALS 

Definition at line 30 of file procsignal.h.

31 {
32  PROCSIG_CATCHUP_INTERRUPT, /* sinval catchup interrupt */
33  PROCSIG_NOTIFY_INTERRUPT, /* listen/notify interrupt */
34  PROCSIG_PARALLEL_MESSAGE, /* message from cooperating parallel backend */
35  PROCSIG_WALSND_INIT_STOPPING, /* ask walsenders to prepare for shutdown */
36  PROCSIG_BARRIER, /* global barrier interrupt */
37  PROCSIG_LOG_MEMORY_CONTEXT, /* ask backend to log the memory contexts */
38  PROCSIG_PARALLEL_APPLY_MESSAGE, /* Message from parallel apply workers */
39 
40  /* Recovery conflict reasons */
50 
51  NUM_PROCSIGNALS /* Must be last! */
ProcSignalReason
Definition: procsignal.h:31
@ PROCSIG_PARALLEL_MESSAGE
Definition: procsignal.h:34
@ PROCSIG_RECOVERY_CONFLICT_BUFFERPIN
Definition: procsignal.h:47
@ PROCSIG_CATCHUP_INTERRUPT
Definition: procsignal.h:32
@ PROCSIG_RECOVERY_CONFLICT_LOCK
Definition: procsignal.h:44
@ PROCSIG_LOG_MEMORY_CONTEXT
Definition: procsignal.h:37
@ PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT
Definition: procsignal.h:46
@ PROCSIG_BARRIER
Definition: procsignal.h:36
@ PROCSIG_RECOVERY_CONFLICT_DATABASE
Definition: procsignal.h:42
@ PROCSIG_WALSND_INIT_STOPPING
Definition: procsignal.h:35
@ PROCSIG_PARALLEL_APPLY_MESSAGE
Definition: procsignal.h:38
@ PROCSIG_RECOVERY_CONFLICT_SNAPSHOT
Definition: procsignal.h:45
@ PROCSIG_RECOVERY_CONFLICT_LAST
Definition: procsignal.h:49
@ PROCSIG_RECOVERY_CONFLICT_FIRST
Definition: procsignal.h:41
@ PROCSIG_NOTIFY_INTERRUPT
Definition: procsignal.h:33
@ PROCSIG_RECOVERY_CONFLICT_TABLESPACE
Definition: procsignal.h:43
@ NUM_PROCSIGNALS
Definition: procsignal.h:51
@ PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK
Definition: procsignal.h:48

Function Documentation

◆ EmitProcSignalBarrier()

uint64 EmitProcSignalBarrier ( ProcSignalBarrierType  type)

Definition at line 333 of file procsignal.c.

334 {
335  uint32 flagbit = 1 << (uint32) type;
336  uint64 generation;
337 
338  /*
339  * Set all the flags.
340  *
341  * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
342  * totally ordered with respect to anything the caller did before, and
343  * anything that we do afterwards. (This is also true of the later call to
344  * pg_atomic_add_fetch_u64.)
345  */
346  for (int i = 0; i < NumProcSignalSlots; i++)
347  {
348  volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
349 
351  }
352 
353  /*
354  * Increment the generation counter.
355  */
356  generation =
358 
359  /*
360  * Signal all the processes, so that they update their advertised barrier
361  * generation.
362  *
363  * Concurrency is not a problem here. Backends that have exited don't
364  * matter, and new backends that have joined since we entered this
365  * function must already have current state, since the caller is
366  * responsible for making sure that the relevant state is entirely visible
367  * before calling this function in the first place. We still have to wake
368  * them up - because we can't distinguish between such backends and older
369  * backends that need to update state - but they won't actually need to
370  * change any state.
371  */
372  for (int i = NumProcSignalSlots - 1; i >= 0; i--)
373  {
374  volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
375  pid_t pid = slot->pss_pid;
376 
377  if (pid != 0)
378  {
379  /* see SendProcSignal for details */
380  slot->pss_signalFlags[PROCSIG_BARRIER] = true;
381  kill(pid, SIGUSR1);
382  }
383  }
384 
385  return generation;
386 }
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:367
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:499
unsigned int uint32
Definition: c.h:495
int i
Definition: isn.c:73
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:100
#define NumProcSignalSlots
Definition: procsignal.c:90
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:82
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:81
volatile pid_t pss_pid
Definition: procsignal.c:66
volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition: procsignal.c:67
pg_atomic_uint32 pss_barrierCheckMask
Definition: procsignal.c:69
const char * type
#define kill(pid, sig)
Definition: win32_port.h:485
#define SIGUSR1
Definition: win32_port.h:180

References i, kill, NumProcSignalSlots, pg_atomic_add_fetch_u64(), pg_atomic_fetch_or_u32(), PROCSIG_BARRIER, ProcSignal, ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, SIGUSR1, and type.

Referenced by dbase_redo(), dropdb(), DropTableSpace(), movedb(), and tblspc_redo().

◆ ProcessProcSignalBarrier()

void ProcessProcSignalBarrier ( void  )

Definition at line 468 of file procsignal.c.

469 {
470  uint64 local_gen;
471  uint64 shared_gen;
472  volatile uint32 flags;
473 
475 
476  /* Exit quickly if there's no work to do. */
478  return;
479  ProcSignalBarrierPending = false;
480 
481  /*
482  * It's not unlikely to process multiple barriers at once, before the
483  * signals for all the barriers have arrived. To avoid unnecessary work in
484  * response to subsequent signals, exit early if we already have processed
485  * all of them.
486  */
489 
490  Assert(local_gen <= shared_gen);
491 
492  if (local_gen == shared_gen)
493  return;
494 
495  /*
496  * Get and clear the flags that are set for this backend. Note that
497  * pg_atomic_exchange_u32 is a full barrier, so we're guaranteed that the
498  * read of the barrier generation above happens before we atomically
499  * extract the flags, and that any subsequent state changes happen
500  * afterward.
501  *
502  * NB: In order to avoid race conditions, we must zero
503  * pss_barrierCheckMask first and only afterwards try to do barrier
504  * processing. If we did it in the other order, someone could send us
505  * another barrier of some type right after we called the
506  * barrier-processing function but before we cleared the bit. We would
507  * have no way of knowing that the bit needs to stay set in that case, so
508  * the need to call the barrier-processing function again would just get
509  * forgotten. So instead, we tentatively clear all the bits and then put
510  * back any for which we don't manage to successfully absorb the barrier.
511  */
513 
514  /*
515  * If there are no flags set, then we can skip doing any real work.
516  * Otherwise, establish a PG_TRY block, so that we don't lose track of
517  * which types of barrier processing are needed if an ERROR occurs.
518  */
519  if (flags != 0)
520  {
521  bool success = true;
522 
523  PG_TRY();
524  {
525  /*
526  * Process each type of barrier. The barrier-processing functions
527  * should normally return true, but may return false if the
528  * barrier can't be absorbed at the current time. This should be
529  * rare, because it's pretty expensive. Every single
530  * CHECK_FOR_INTERRUPTS() will return here until we manage to
531  * absorb the barrier, and that cost will add up in a hurry.
532  *
533  * NB: It ought to be OK to call the barrier-processing functions
534  * unconditionally, but it's more efficient to call only the ones
535  * that might need us to do something based on the flags.
536  */
537  while (flags != 0)
538  {
540  bool processed = true;
541 
543  switch (type)
544  {
546  processed = ProcessBarrierSmgrRelease();
547  break;
548  }
549 
550  /*
551  * To avoid an infinite loop, we must always unset the bit in
552  * flags.
553  */
554  BARRIER_CLEAR_BIT(flags, type);
555 
556  /*
557  * If we failed to process the barrier, reset the shared bit
558  * so we try again later, and set a flag so that we don't bump
559  * our generation.
560  */
561  if (!processed)
562  {
564  success = false;
565  }
566  }
567  }
568  PG_CATCH();
569  {
570  /*
571  * If an ERROR occurred, we'll need to try again later to handle
572  * that barrier type and any others that haven't been handled yet
573  * or weren't successfully absorbed.
574  */
576  PG_RE_THROW();
577  }
578  PG_END_TRY();
579 
580  /*
581  * If some barrier types were not successfully absorbed, we will have
582  * to try again later.
583  */
584  if (!success)
585  return;
586  }
587 
588  /*
589  * State changes related to all types of barriers that might have been
590  * emitted have now been handled, so we can update our notion of the
591  * generation to the one we observed before beginning the updates. If
592  * things have changed further, it'll get fixed up when this function is
593  * next called.
594  */
597 }
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:433
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:287
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:424
void ConditionVariableBroadcast(ConditionVariable *cv)
#define PG_RE_THROW()
Definition: elog.h:411
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define PG_CATCH(...)
Definition: elog.h:380
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:38
static bool success
Definition: initdb.c:184
Assert(fmt[strlen(fmt) - 1] !='\n')
static int pg_rightmost_one_pos32(uint32 word)
Definition: pg_bitutils.h:111
static void ResetProcSignalBarrierBits(uint32 flags)
Definition: procsignal.c:605
static ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:101
#define BARRIER_CLEAR_BIT(flags, type)
Definition: procsignal.c:97
bool ProcessBarrierSmgrRelease(void)
Definition: smgr.c:819
ConditionVariable pss_barrierCV
Definition: procsignal.c:70
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:68

References Assert(), BARRIER_CLEAR_BIT, ConditionVariableBroadcast(), MyProcSignalSlot, pg_atomic_exchange_u32(), pg_atomic_read_u64(), pg_atomic_write_u64(), PG_CATCH, PG_END_TRY, PG_RE_THROW, pg_rightmost_one_pos32(), PG_TRY, ProcessBarrierSmgrRelease(), ProcSignal, PROCSIGNAL_BARRIER_SMGRRELEASE, ProcSignalBarrierPending, ProcSignalHeader::psh_barrierGeneration, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierCV, ProcSignalSlot::pss_barrierGeneration, ResetProcSignalBarrierBits(), success, and type.

Referenced by BufferSync(), CheckpointWriteDelay(), HandleAutoVacLauncherInterrupts(), HandleCheckpointerInterrupts(), HandleMainLoopInterrupts(), HandlePgArchInterrupts(), HandleStartupProcInterrupts(), HandleWalSummarizerInterrupts(), and ProcessInterrupts().

◆ procsignal_sigusr1_handler()

void procsignal_sigusr1_handler ( SIGNAL_ARGS  )

Definition at line 639 of file procsignal.c.

640 {
643 
646 
649 
652 
655 
658 
661 
664 
667 
670 
673 
676 
679 
682 
683  SetLatch(MyLatch);
684 }
void HandleParallelApplyMessageInterrupt(void)
void HandleNotifyInterrupt(void)
Definition: async.c:1796
void HandleParallelMessageInterrupt(void)
Definition: parallel.c:1019
struct Latch * MyLatch
Definition: globals.c:59
void SetLatch(Latch *latch)
Definition: latch.c:633
void HandleLogMemoryContextInterrupt(void)
Definition: mcxt.c:1157
void HandleRecoveryConflictInterrupt(ProcSignalReason reason)
Definition: postgres.c:3034
static bool CheckProcSignal(ProcSignalReason reason)
Definition: procsignal.c:618
static void HandleProcSignalBarrierInterrupt(void)
Definition: procsignal.c:452
void HandleCatchupInterrupt(void)
Definition: sinval.c:156
void HandleWalSndInitStopping(void)
Definition: walsender.c:3455

References CheckProcSignal(), HandleCatchupInterrupt(), HandleLogMemoryContextInterrupt(), HandleNotifyInterrupt(), HandleParallelApplyMessageInterrupt(), HandleParallelMessageInterrupt(), HandleProcSignalBarrierInterrupt(), HandleRecoveryConflictInterrupt(), HandleWalSndInitStopping(), MyLatch, PROCSIG_BARRIER, PROCSIG_CATCHUP_INTERRUPT, PROCSIG_LOG_MEMORY_CONTEXT, PROCSIG_NOTIFY_INTERRUPT, PROCSIG_PARALLEL_APPLY_MESSAGE, PROCSIG_PARALLEL_MESSAGE, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, PROCSIG_RECOVERY_CONFLICT_TABLESPACE, PROCSIG_WALSND_INIT_STOPPING, and SetLatch().

Referenced by autoprewarm_main(), AutoVacLauncherMain(), AutoVacWorkerMain(), BackgroundWorkerMain(), BackgroundWriterMain(), CheckpointerMain(), PgArchiverMain(), PostgresMain(), ReplSlotSyncWorkerMain(), StartupProcessMain(), WalReceiverMain(), WalSndSignals(), WalSummarizerMain(), and WalWriterMain().

◆ ProcSignalInit()

void ProcSignalInit ( int  pss_idx)

Definition at line 162 of file procsignal.c.

163 {
164  ProcSignalSlot *slot;
165  uint64 barrier_generation;
166 
167  Assert(pss_idx >= 1 && pss_idx <= NumProcSignalSlots);
168 
169  slot = &ProcSignal->psh_slot[pss_idx - 1];
170 
171  /* sanity check */
172  if (slot->pss_pid != 0)
173  elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
174  MyProcPid, pss_idx);
175 
176  /* Clear out any leftover signal reasons */
177  MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
178 
179  /*
180  * Initialize barrier state. Since we're a brand-new process, there
181  * shouldn't be any leftover backend-private state that needs to be
182  * updated. Therefore, we can broadcast the latest barrier generation and
183  * disregard any previously-set check bits.
184  *
185  * NB: This only works if this initialization happens early enough in the
186  * startup sequence that we haven't yet cached any state that might need
187  * to be invalidated. That's also why we have a memory barrier here, to be
188  * sure that any later reads of memory happen strictly after this.
189  */
191  barrier_generation =
193  pg_atomic_write_u64(&slot->pss_barrierGeneration, barrier_generation);
195 
196  /* Mark slot with my PID */
197  slot->pss_pid = MyProcPid;
198 
199  /* Remember slot location for CheckProcSignal */
200  MyProcSignalSlot = slot;
201 
202  /* Set up to release the slot on process exit */
204 }
#define pg_memory_barrier()
Definition: atomics.h:140
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:253
#define MemSet(start, val, len)
Definition: c.h:1009
#define LOG
Definition: elog.h:31
int MyProcPid
Definition: globals.c:45
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static void CleanupProcSignalState(int status, Datum arg)
Definition: procsignal.c:213

References Assert(), CleanupProcSignalState(), elog(), Int32GetDatum(), LOG, MemSet, MyProcPid, MyProcSignalSlot, NUM_PROCSIGNALS, NumProcSignalSlots, on_shmem_exit(), pg_atomic_read_u64(), pg_atomic_write_u32(), pg_atomic_write_u64(), pg_memory_barrier, ProcSignal, ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_pid, and ProcSignalSlot::pss_signalFlags.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

◆ ProcSignalShmemInit()

void ProcSignalShmemInit ( void  )

Definition at line 126 of file procsignal.c.

127 {
128  Size size = ProcSignalShmemSize();
129  bool found;
130 
132  ShmemInitStruct("ProcSignal", size, &found);
133 
134  /* If we're first, initialize. */
135  if (!found)
136  {
137  int i;
138 
140 
141  for (i = 0; i < NumProcSignalSlots; ++i)
142  {
143  ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
144 
145  slot->pss_pid = 0;
146  MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
150  }
151  }
152 }
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:218
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:410
#define PG_UINT64_MAX
Definition: c.h:582
size_t Size
Definition: c.h:594
void ConditionVariableInit(ConditionVariable *cv)
Size ProcSignalShmemSize(void)
Definition: procsignal.c:112
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:388

References ConditionVariableInit(), i, MemSet, NumProcSignalSlots, pg_atomic_init_u32(), pg_atomic_init_u64(), PG_UINT64_MAX, ProcSignal, ProcSignalShmemSize(), ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierCV, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, and ShmemInitStruct().

Referenced by CreateOrAttachShmemStructs().

◆ ProcSignalShmemSize()

Size ProcSignalShmemSize ( void  )

Definition at line 112 of file procsignal.c.

113 {
114  Size size;
115 
116  size = mul_size(NumProcSignalSlots, sizeof(ProcSignalSlot));
117  size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
118  return size;
119 }
Size add_size(Size s1, Size s2)
Definition: shmem.c:494
Size mul_size(Size s1, Size s2)
Definition: shmem.c:511

References add_size(), mul_size(), and NumProcSignalSlots.

Referenced by CalculateShmemSize(), and ProcSignalShmemInit().

◆ SendProcSignal()

int SendProcSignal ( pid_t  pid,
ProcSignalReason  reason,
BackendId  backendId 
)

Definition at line 262 of file procsignal.c.

263 {
264  volatile ProcSignalSlot *slot;
265 
266  if (backendId != InvalidBackendId)
267  {
268  slot = &ProcSignal->psh_slot[backendId - 1];
269 
270  /*
271  * Note: Since there's no locking, it's possible that the target
272  * process detaches from shared memory and exits right after this
273  * test, before we set the flag and send signal. And the signal slot
274  * might even be recycled by a new process, so it's remotely possible
275  * that we set a flag for a wrong process. That's OK, all the signals
276  * are such that no harm is done if they're mistakenly fired.
277  */
278  if (slot->pss_pid == pid)
279  {
280  /* Atomically set the proper flag */
281  slot->pss_signalFlags[reason] = true;
282  /* Send signal */
283  return kill(pid, SIGUSR1);
284  }
285  }
286  else
287  {
288  /*
289  * BackendId not provided, so search the array using pid. We search
290  * the array back to front so as to reduce search overhead. Passing
291  * InvalidBackendId means that the target is most likely an auxiliary
292  * process, which will have a slot near the end of the array.
293  */
294  int i;
295 
296  for (i = NumProcSignalSlots - 1; i >= 0; i--)
297  {
298  slot = &ProcSignal->psh_slot[i];
299 
300  if (slot->pss_pid == pid)
301  {
302  /* the above note about race conditions applies here too */
303 
304  /* Atomically set the proper flag */
305  slot->pss_signalFlags[reason] = true;
306  /* Send signal */
307  return kill(pid, SIGUSR1);
308  }
309  }
310  }
311 
312  errno = ESRCH;
313  return -1;
314 }
#define InvalidBackendId
Definition: backendid.h:23

References i, InvalidBackendId, kill, NumProcSignalSlots, ProcSignal, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, and SIGUSR1.

Referenced by CancelDBBackends(), InvalidatePossiblyObsoleteSlot(), mq_putmessage(), pa_shutdown(), ParallelWorkerShutdown(), pg_log_backend_memory_contexts(), SICleanupQueue(), SignalBackends(), SignalVirtualTransaction(), and WalSndInitStopping().

◆ WaitForProcSignalBarrier()

void WaitForProcSignalBarrier ( uint64  generation)

Definition at line 393 of file procsignal.c.

394 {
396 
397  elog(DEBUG1,
398  "waiting for all backends to process ProcSignalBarrier generation "
400  generation);
401 
402  for (int i = NumProcSignalSlots - 1; i >= 0; i--)
403  {
404  ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
405  uint64 oldval;
406 
407  /*
408  * It's important that we check only pss_barrierGeneration here and
409  * not pss_barrierCheckMask. Bits in pss_barrierCheckMask get cleared
410  * before the barrier is actually absorbed, but pss_barrierGeneration
411  * is updated only afterward.
412  */
413  oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
414  while (oldval < generation)
415  {
417  5000,
418  WAIT_EVENT_PROC_SIGNAL_BARRIER))
419  ereport(LOG,
420  (errmsg("still waiting for backend with PID %d to accept ProcSignalBarrier",
421  (int) slot->pss_pid)));
422  oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
423  }
425  }
426 
427  elog(DEBUG1,
428  "finished waiting for all backends to process ProcSignalBarrier generation "
430  generation);
431 
432  /*
433  * The caller is probably calling this function because it wants to read
434  * the shared state or perform further writes to shared state once all
435  * backends are known to have absorbed the barrier. However, the read of
436  * pss_barrierGeneration was performed unlocked; insert a memory barrier
437  * to separate it from whatever follows.
438  */
440 }
#define UINT64_FORMAT
Definition: c.h:538
bool ConditionVariableCancelSleep(void)
bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info)
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#define DEBUG1
Definition: elog.h:30
#define ereport(elevel,...)
Definition: elog.h:149

References Assert(), ConditionVariableCancelSleep(), ConditionVariableTimedSleep(), DEBUG1, elog(), ereport, errmsg(), i, LOG, NumProcSignalSlots, pg_atomic_read_u64(), pg_memory_barrier, ProcSignal, ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCV, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_pid, and UINT64_FORMAT.

Referenced by dbase_redo(), dropdb(), DropTableSpace(), movedb(), and tblspc_redo().