PostgreSQL Source Code git master
Loading...
Searching...
No Matches
procsignal.c File Reference
#include "postgres.h"
#include <signal.h>
#include <unistd.h>
#include "access/parallel.h"
#include "commands/async.h"
#include "commands/repack.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "port/pg_bitutils.h"
#include "postmaster/datachecksum_state.h"
#include "replication/logicalctl.h"
#include "replication/logicalworker.h"
#include "replication/slotsync.h"
#include "replication/walsender.h"
#include "storage/condition_variable.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/proc.h"
#include "storage/shmem.h"
#include "storage/sinval.h"
#include "storage/smgr.h"
#include "storage/subsystems.h"
#include "tcop/tcopprot.h"
#include "utils/memutils.h"
#include "utils/wait_event.h"
Include dependency graph for procsignal.c:

Go to the source code of this file.

Data Structures

struct  ProcSignalSlot
 
struct  ProcSignalHeader
 

Macros

#define NumProcSignalSlots   (MaxBackends + NUM_AUXILIARY_PROCS)
 
#define BARRIER_SHOULD_CHECK(flags, type)    (((flags) & (((uint32) 1) << (uint32) (type))) != 0)
 
#define BARRIER_CLEAR_BIT(flags, type)    ((flags) &= ~(((uint32) 1) << (uint32) (type)))
 

Functions

static void ProcSignalShmemRequest (void *arg)
 
static void ProcSignalShmemInit (void *arg)
 
static bool CheckProcSignal (ProcSignalReason reason)
 
static void CleanupProcSignalState (int status, Datum arg)
 
static void ResetProcSignalBarrierBits (uint32 flags)
 
void ProcSignalInit (const uint8 *cancel_key, int cancel_key_len)
 
int SendProcSignal (pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
 
uint64 EmitProcSignalBarrier (ProcSignalBarrierType type)
 
void WaitForProcSignalBarrier (uint64 generation)
 
static void HandleProcSignalBarrierInterrupt (void)
 
void ProcessProcSignalBarrier (void)
 
void procsignal_sigusr1_handler (SIGNAL_ARGS)
 
void SendCancelRequest (int backendPID, const uint8 *cancel_key, int cancel_key_len)
 

Variables

const ShmemCallbacks ProcSignalShmemCallbacks
 
NON_EXEC_STATIC ProcSignalHeaderProcSignal = NULL
 
static ProcSignalSlotMyProcSignalSlot = NULL
 

Macro Definition Documentation

◆ BARRIER_CLEAR_BIT

#define BARRIER_CLEAR_BIT (   flags,
  type 
)     ((flags) &= ~(((uint32) 1) << (uint32) (type)))

Definition at line 109 of file procsignal.c.

114 {
115 .request_fn = ProcSignalShmemRequest,
116 .init_fn = ProcSignalShmemInit,
117};
118
120
122
123static bool CheckProcSignal(ProcSignalReason reason);
124static void CleanupProcSignalState(int status, Datum arg);
125static void ResetProcSignalBarrierBits(uint32 flags);
126
127/*
128 * ProcSignalShmemRequest
129 * Register ProcSignal's shared memory needs at postmaster startup
130 */
131static void
133{
134 Size size;
135
137 size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
138
139 ShmemRequestStruct(.name = "ProcSignal",
140 .size = size,
141 .ptr = (void **) &ProcSignal,
142 );
143}
144
145static void
147{
149
150 for (int i = 0; i < NumProcSignalSlots; ++i)
151 {
153
154 SpinLockInit(&slot->pss_mutex);
155 pg_atomic_init_u32(&slot->pss_pid, 0);
156 slot->pss_cancel_key_len = 0;
157 MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
161 }
162}
163
164/*
165 * ProcSignalInit
166 * Register the current process in the ProcSignal array
167 */
168void
170{
171 ProcSignalSlot *slot;
174
176 if (MyProcNumber < 0)
177 elog(ERROR, "MyProcNumber not set");
179 elog(ERROR, "unexpected MyProcNumber %d in ProcSignalInit (max %d)", MyProcNumber, NumProcSignalSlots);
181
183
184 /* Value used for sanity check below */
186
187 /* Clear out any leftover signal reasons */
189
190 /*
191 * Initialize barrier state. Since we're a brand-new process, there
192 * shouldn't be any leftover backend-private state that needs to be
193 * updated. Therefore, we can broadcast the latest barrier generation and
194 * disregard any previously-set check bits.
195 *
196 * NB: This only works if this initialization happens early enough in the
197 * startup sequence that we haven't yet cached any state that might need
198 * to be invalidated. That's also why we have a memory barrier here, to be
199 * sure that any later reads of memory happen strictly after this.
200 */
205
206 if (cancel_key_len > 0)
210
212
213 /* Spinlock is released, do the check */
214 if (old_pss_pid != 0)
215 elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
217
218 /* Remember slot location for CheckProcSignal */
219 MyProcSignalSlot = slot;
220
221 /* Set up to release the slot on process exit */
223}
224
225/*
226 * CleanupProcSignalState
227 * Remove current process from ProcSignal mechanism
228 *
229 * This function is called via on_shmem_exit() during backend shutdown.
230 */
231static void
233{
236
237 /*
238 * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
239 * won't try to access it after it's no longer ours (and perhaps even
240 * after we've unmapped the shared memory segment).
241 */
244
245 /* sanity check */
248 if (old_pid != MyProcPid)
249 {
250 /*
251 * don't ERROR here. We're exiting anyway, and don't want to get into
252 * infinite loop trying to exit
253 */
255 elog(LOG, "process %d releasing ProcSignal slot %d, but it contains %d",
256 MyProcPid, (int) (slot - ProcSignal->psh_slot), (int) old_pid);
257 return; /* XXX better to zero the slot anyway? */
258 }
259
260 /* Mark the slot as unused */
261 pg_atomic_write_u32(&slot->pss_pid, 0);
262 slot->pss_cancel_key_len = 0;
263
264 /*
265 * Make this slot look like it's absorbed all possible barriers, so that
266 * no barrier waits block on it.
267 */
269
271
273}
274
275/*
276 * SendProcSignal
277 * Send a signal to a Postgres process
278 *
279 * Providing procNumber is optional, but it will speed up the operation.
280 *
281 * On success (a signal was sent), zero is returned.
282 * On error, -1 is returned, and errno is set (typically to ESRCH or EPERM).
283 *
284 * Not to be confused with ProcSendSignal
285 */
286int
287SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
288{
289 volatile ProcSignalSlot *slot;
290
291 if (procNumber != INVALID_PROC_NUMBER)
292 {
293 Assert(procNumber < NumProcSignalSlots);
294 slot = &ProcSignal->psh_slot[procNumber];
295
297 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
298 {
299 /* Atomically set the proper flag */
300 slot->pss_signalFlags[reason] = true;
302 /* Send signal */
303 return kill(pid, SIGUSR1);
304 }
306 }
307 else
308 {
309 /*
310 * procNumber not provided, so search the array using pid. We search
311 * the array back to front so as to reduce search overhead. Passing
312 * INVALID_PROC_NUMBER means that the target is most likely an
313 * auxiliary process, which will have a slot near the end of the
314 * array.
315 */
316 int i;
317
318 for (i = NumProcSignalSlots - 1; i >= 0; i--)
319 {
320 slot = &ProcSignal->psh_slot[i];
321
322 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
323 {
325 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
326 {
327 /* Atomically set the proper flag */
328 slot->pss_signalFlags[reason] = true;
330 /* Send signal */
331 return kill(pid, SIGUSR1);
332 }
334 }
335 }
336 }
337
338 errno = ESRCH;
339 return -1;
340}
341
342/*
343 * EmitProcSignalBarrier
344 * Send a signal to every Postgres process
345 *
346 * The return value of this function is the barrier "generation" created
347 * by this operation. This value can be passed to WaitForProcSignalBarrier
348 * to wait until it is known that every participant in the ProcSignal
349 * mechanism has absorbed the signal (or started afterwards).
350 *
351 * Note that it would be a bad idea to use this for anything that happens
352 * frequently, as interrupting every backend could cause a noticeable
353 * performance hit.
354 *
355 * Callers are entitled to assume that this function will not throw ERROR
356 * or FATAL.
357 */
358uint64
360{
361 uint32 flagbit = 1 << (uint32) type;
362 uint64 generation;
363
364 /*
365 * Set all the flags.
366 *
367 * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
368 * totally ordered with respect to anything the caller did before, and
369 * anything that we do afterwards. (This is also true of the later call to
370 * pg_atomic_add_fetch_u64.)
371 */
372 for (int i = 0; i < NumProcSignalSlots; i++)
373 {
374 volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
375
377 }
378
379 /*
380 * Increment the generation counter.
381 */
382 generation =
384
385 /*
386 * Signal all the processes, so that they update their advertised barrier
387 * generation.
388 *
389 * Concurrency is not a problem here. Backends that have exited don't
390 * matter, and new backends that have joined since we entered this
391 * function must already have current state, since the caller is
392 * responsible for making sure that the relevant state is entirely visible
393 * before calling this function in the first place. We still have to wake
394 * them up - because we can't distinguish between such backends and older
395 * backends that need to update state - but they won't actually need to
396 * change any state.
397 */
398 for (int i = NumProcSignalSlots - 1; i >= 0; i--)
399 {
400 volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
401 pid_t pid = pg_atomic_read_u32(&slot->pss_pid);
402
403 if (pid != 0)
404 {
406 pid = pg_atomic_read_u32(&slot->pss_pid);
407 if (pid != 0)
408 {
409 /* see SendProcSignal for details */
410 slot->pss_signalFlags[PROCSIG_BARRIER] = true;
412 kill(pid, SIGUSR1);
413 }
414 else
416 }
417 }
418
419 return generation;
420}
421
422/*
423 * WaitForProcSignalBarrier - wait until it is guaranteed that all changes
424 * requested by a specific call to EmitProcSignalBarrier() have taken effect.
425 */
426void
428{
430
431 elog(DEBUG1,
432 "waiting for all backends to process ProcSignalBarrier generation "
434 generation);
435
436 for (int i = NumProcSignalSlots - 1; i >= 0; i--)
437 {
440
441 /*
442 * It's important that we check only pss_barrierGeneration here and
443 * not pss_barrierCheckMask. Bits in pss_barrierCheckMask get cleared
444 * before the barrier is actually absorbed, but pss_barrierGeneration
445 * is updated only afterward.
446 */
448 while (oldval < generation)
449 {
451 5000,
453 ereport(LOG,
454 (errmsg("still waiting for backend with PID %d to accept ProcSignalBarrier",
455 (int) pg_atomic_read_u32(&slot->pss_pid))));
457 }
459 }
460
461 elog(DEBUG1,
462 "finished waiting for all backends to process ProcSignalBarrier generation "
464 generation);
465
466 /*
467 * The caller is probably calling this function because it wants to read
468 * the shared state or perform further writes to shared state once all
469 * backends are known to have absorbed the barrier. However, the read of
470 * pss_barrierGeneration was performed unlocked; insert a memory barrier
471 * to separate it from whatever follows.
472 */
474}
475
476/*
477 * Handle receipt of an interrupt indicating a global barrier event.
478 *
479 * All the actual work is deferred to ProcessProcSignalBarrier(), because we
480 * cannot safely access the barrier generation inside the signal handler as
481 * 64bit atomics might use spinlock based emulation, even for reads. As this
482 * routine only gets called when PROCSIG_BARRIER is sent that won't cause a
483 * lot of unnecessary work.
484 */
485static void
487{
488 InterruptPending = true;
490 /* latch will be set by procsignal_sigusr1_handler */
491}
492
493/*
494 * Perform global barrier related interrupt checking.
495 *
496 * Any backend that participates in ProcSignal signaling must arrange to
497 * call this function periodically. It is called from CHECK_FOR_INTERRUPTS(),
498 * which is enough for normal backends, but not necessarily for all types of
499 * background processes.
500 */
501void
503{
506 volatile uint32 flags;
507
509
510 /* Exit quickly if there's no work to do. */
512 return;
514
515 /*
516 * It's not unlikely to process multiple barriers at once, before the
517 * signals for all the barriers have arrived. To avoid unnecessary work in
518 * response to subsequent signals, exit early if we already have processed
519 * all of them.
520 */
523
525
526 if (local_gen == shared_gen)
527 return;
528
529 /*
530 * Get and clear the flags that are set for this backend. Note that
531 * pg_atomic_exchange_u32 is a full barrier, so we're guaranteed that the
532 * read of the barrier generation above happens before we atomically
533 * extract the flags, and that any subsequent state changes happen
534 * afterward.
535 *
536 * NB: In order to avoid race conditions, we must zero
537 * pss_barrierCheckMask first and only afterwards try to do barrier
538 * processing. If we did it in the other order, someone could send us
539 * another barrier of some type right after we called the
540 * barrier-processing function but before we cleared the bit. We would
541 * have no way of knowing that the bit needs to stay set in that case, so
542 * the need to call the barrier-processing function again would just get
543 * forgotten. So instead, we tentatively clear all the bits and then put
544 * back any for which we don't manage to successfully absorb the barrier.
545 */
547
548 /*
549 * If there are no flags set, then we can skip doing any real work.
550 * Otherwise, establish a PG_TRY block, so that we don't lose track of
551 * which types of barrier processing are needed if an ERROR occurs.
552 */
553 if (flags != 0)
554 {
555 bool success = true;
556
557 PG_TRY();
558 {
559 /*
560 * Process each type of barrier. The barrier-processing functions
561 * should normally return true, but may return false if the
562 * barrier can't be absorbed at the current time. This should be
563 * rare, because it's pretty expensive. Every single
564 * CHECK_FOR_INTERRUPTS() will return here until we manage to
565 * absorb the barrier, and that cost will add up in a hurry.
566 *
567 * NB: It ought to be OK to call the barrier-processing functions
568 * unconditionally, but it's more efficient to call only the ones
569 * that might need us to do something based on the flags.
570 */
571 while (flags != 0)
572 {
574 bool processed = true;
575
577 switch (type)
578 {
580 processed = ProcessBarrierSmgrRelease();
581 break;
584 break;
585
590 processed = AbsorbDataChecksumsBarrier(type);
591 break;
592 }
593
594 /*
595 * To avoid an infinite loop, we must always unset the bit in
596 * flags.
597 */
598 BARRIER_CLEAR_BIT(flags, type);
599
600 /*
601 * If we failed to process the barrier, reset the shared bit
602 * so we try again later, and set a flag so that we don't bump
603 * our generation.
604 */
605 if (!processed)
606 {
608 success = false;
609 }
610 }
611 }
612 PG_CATCH();
613 {
614 /*
615 * If an ERROR occurred, we'll need to try again later to handle
616 * that barrier type and any others that haven't been handled yet
617 * or weren't successfully absorbed.
618 */
620 PG_RE_THROW();
621 }
622 PG_END_TRY();
623
624 /*
625 * If some barrier types were not successfully absorbed, we will have
626 * to try again later.
627 */
628 if (!success)
629 return;
630 }
631
632 /*
633 * State changes related to all types of barriers that might have been
634 * emitted have now been handled, so we can update our notion of the
635 * generation to the one we observed before beginning the updates. If
636 * things have changed further, it'll get fixed up when this function is
637 * next called.
638 */
641}
642
643/*
644 * If it turns out that we couldn't absorb one or more barrier types, either
645 * because the barrier-processing functions returned false or due to an error,
646 * arrange for processing to be retried later.
647 */
648static void
650{
653 InterruptPending = true;
654}
655
656/*
657 * CheckProcSignal - check to see if a particular reason has been
658 * signaled, and clear the signal flag. Should be called after receiving
659 * SIGUSR1.
660 */
661static bool
663{
664 volatile ProcSignalSlot *slot = MyProcSignalSlot;
665
666 if (slot != NULL)
667 {
668 /*
669 * Careful here --- don't clear flag if we haven't seen it set.
670 * pss_signalFlags is of type "volatile sig_atomic_t" to allow us to
671 * read it here safely, without holding the spinlock.
672 */
673 if (slot->pss_signalFlags[reason])
674 {
675 slot->pss_signalFlags[reason] = false;
676 return true;
677 }
678 }
679
680 return false;
681}
682
683/*
684 * procsignal_sigusr1_handler - handle SIGUSR1 signal.
685 */
686void
688{
691
694
697
700
703
706
709
712
715
718
720}
721
722/*
723 * Send a query cancellation signal to backend.
724 *
725 * Note: This is called from a backend process before authentication. We
726 * cannot take LWLocks yet, but that's OK; we rely on atomic reads of the
727 * fields in the ProcSignal slots.
728 */
729void
730SendCancelRequest(int backendPID, const uint8 *cancel_key, int cancel_key_len)
731{
732 if (backendPID == 0)
733 {
734 ereport(LOG, (errmsg("invalid cancel request with PID 0")));
735 return;
736 }
737
738 /*
739 * See if we have a matching backend. Reading the pss_pid and
740 * pss_cancel_key fields is racy, a backend might die and remove itself
741 * from the array at any time. The probability of the cancellation key
742 * matching wrong process is miniscule, however, so we can live with that.
743 * PIDs are reused too, so sending the signal based on PID is inherently
744 * racy anyway, although OS's avoid reusing PIDs too soon.
745 */
746 for (int i = 0; i < NumProcSignalSlots; i++)
747 {
749 bool match;
750
751 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
752 continue;
753
754 /* Acquire the spinlock and re-check */
756 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
757 {
759 continue;
760 }
761 else
762 {
763 match = slot->pss_cancel_key_len == cancel_key_len &&
765
767
768 if (match)
769 {
770 /* Found a match; signal that backend to cancel current op */
772 (errmsg_internal("processing cancel request: sending SIGINT to process %d",
773 backendPID)));
774
775 /*
776 * If we have setsid(), signal the backend's whole process
777 * group
778 */
779#ifdef HAVE_SETSID
780 kill(-backendPID, SIGINT);
781#else
782 kill(backendPID, SIGINT);
783#endif
784 }
785 else
786 {
787 /* Right PID, wrong key: no way, Jose */
788 ereport(LOG,
789 (errmsg("wrong key in cancel request for process %d",
790 backendPID)));
791 }
792 return;
793 }
794 }
795
796 /* No matching backend */
797 ereport(LOG,
798 (errmsg("PID %d in cancel request did not match any process",
799 backendPID)));
800}
void HandleParallelApplyMessageInterrupt(void)
void HandleNotifyInterrupt(void)
Definition async.c:2550
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:485
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition atomics.h:410
#define pg_memory_barrier()
Definition atomics.h:141
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:219
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:274
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition atomics.h:237
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition atomics.h:569
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition atomics.h:330
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:453
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition atomics.h:467
void HandleParallelMessageInterrupt(void)
Definition parallel.c:1046
uint8_t uint8
Definition c.h:622
#define SIGNAL_ARGS
Definition c.h:1462
#define Assert(condition)
Definition c.h:943
#define UINT64_FORMAT
Definition c.h:635
uint64_t uint64
Definition c.h:625
uint32_t uint32
Definition c.h:624
#define PG_UINT64_MAX
Definition c.h:677
#define MemSet(start, val, len)
Definition c.h:1107
size_t Size
Definition c.h:689
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
bool ConditionVariableCancelSleep(void)
bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariableInit(ConditionVariable *cv)
bool AbsorbDataChecksumsBarrier(ProcSignalBarrierType barrier)
Datum arg
Definition elog.c:1323
#define LOG
Definition elog.h:32
#define PG_RE_THROW()
Definition elog.h:407
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define PG_TRY(...)
Definition elog.h:374
#define DEBUG2
Definition elog.h:30
#define PG_END_TRY(...)
Definition elog.h:399
#define DEBUG1
Definition elog.h:31
#define ERROR
Definition elog.h:40
#define PG_CATCH(...)
Definition elog.h:384
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
volatile sig_atomic_t ProcSignalBarrierPending
Definition globals.c:40
volatile sig_atomic_t InterruptPending
Definition globals.c:32
int MyProcPid
Definition globals.c:49
ProcNumber MyProcNumber
Definition globals.c:92
struct Latch * MyLatch
Definition globals.c:65
static bool success
Definition initdb.c:188
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:372
int i
Definition isn.c:77
void SetLatch(Latch *latch)
Definition latch.c:290
bool ProcessBarrierUpdateXLogLogicalInfo(void)
Definition logicalctl.c:184
void HandleLogMemoryContextInterrupt(void)
Definition mcxt.c:1323
static char * errmsg
static int pg_rightmost_one_pos32(uint32 word)
int timingsafe_bcmp(const void *b1, const void *b2, size_t n)
void HandleRecoveryConflictInterrupt(void)
Definition postgres.c:3097
uint64_t Datum
Definition postgres.h:70
#define NON_EXEC_STATIC
Definition postgres.h:573
static int fb(int x)
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
int ProcNumber
Definition procnumber.h:24
static void CleanupProcSignalState(int status, Datum arg)
Definition procsignal.c:233
int SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
Definition procsignal.c:288
void ProcSignalInit(const uint8 *cancel_key, int cancel_key_len)
Definition procsignal.c:170
static void ProcSignalShmemInit(void *arg)
Definition procsignal.c:147
#define NumProcSignalSlots
Definition procsignal.c:102
static bool CheckProcSignal(ProcSignalReason reason)
Definition procsignal.c:663
void ProcessProcSignalBarrier(void)
Definition procsignal.c:503
void WaitForProcSignalBarrier(uint64 generation)
Definition procsignal.c:428
NON_EXEC_STATIC ProcSignalHeader * ProcSignal
Definition procsignal.c:120
static void ResetProcSignalBarrierBits(uint32 flags)
Definition procsignal.c:650
void SendCancelRequest(int backendPID, const uint8 *cancel_key, int cancel_key_len)
Definition procsignal.c:731
uint64 EmitProcSignalBarrier(ProcSignalBarrierType type)
Definition procsignal.c:360
static void ProcSignalShmemRequest(void *arg)
Definition procsignal.c:133
static void HandleProcSignalBarrierInterrupt(void)
Definition procsignal.c:487
static ProcSignalSlot * MyProcSignalSlot
Definition procsignal.c:122
#define BARRIER_CLEAR_BIT(flags, type)
Definition procsignal.c:109
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition procsignal.c:688
#define NUM_PROCSIGNALS
Definition procsignal.h:46
ProcSignalReason
Definition procsignal.h:31
@ PROCSIG_RECOVERY_CONFLICT
Definition procsignal.h:41
@ PROCSIG_PARALLEL_MESSAGE
Definition procsignal.h:34
@ PROCSIG_CATCHUP_INTERRUPT
Definition procsignal.h:32
@ PROCSIG_SLOTSYNC_MESSAGE
Definition procsignal.h:39
@ PROCSIG_LOG_MEMORY_CONTEXT
Definition procsignal.h:37
@ PROCSIG_BARRIER
Definition procsignal.h:36
@ PROCSIG_REPACK_MESSAGE
Definition procsignal.h:40
@ PROCSIG_WALSND_INIT_STOPPING
Definition procsignal.h:35
@ PROCSIG_PARALLEL_APPLY_MESSAGE
Definition procsignal.h:38
@ PROCSIG_NOTIFY_INTERRUPT
Definition procsignal.h:33
ProcSignalBarrierType
Definition procsignal.h:49
@ PROCSIGNAL_BARRIER_CHECKSUM_INPROGRESS_OFF
Definition procsignal.h:55
@ PROCSIGNAL_BARRIER_SMGRRELEASE
Definition procsignal.h:50
@ PROCSIGNAL_BARRIER_CHECKSUM_INPROGRESS_ON
Definition procsignal.h:54
@ PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO
Definition procsignal.h:51
@ PROCSIGNAL_BARRIER_CHECKSUM_ON
Definition procsignal.h:56
@ PROCSIGNAL_BARRIER_CHECKSUM_OFF
Definition procsignal.h:53
#define MAX_CANCEL_KEY_LENGTH
Definition procsignal.h:67
void HandleRepackMessageInterrupt(void)
Definition repack.c:3505
Size add_size(Size s1, Size s2)
Definition shmem.c:1048
Size mul_size(Size s1, Size s2)
Definition shmem.c:1063
#define ShmemRequestStruct(...)
Definition shmem.h:176
void HandleCatchupInterrupt(void)
Definition sinval.c:154
void HandleSlotSyncMessageInterrupt(void)
Definition slotsync.c:1331
bool ProcessBarrierSmgrRelease(void)
Definition smgr.c:1027
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
static void SpinLockInit(volatile slock_t *lock)
Definition spin.h:50
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition procsignal.c:93
pg_atomic_uint64 psh_barrierGeneration
Definition procsignal.c:92
uint8 pss_cancel_key[MAX_CANCEL_KEY_LENGTH]
Definition procsignal.c:74
ConditionVariable pss_barrierCV
Definition procsignal.c:81
pg_atomic_uint64 pss_barrierGeneration
Definition procsignal.c:79
volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition procsignal.c:75
slock_t pss_mutex
Definition procsignal.c:76
pg_atomic_uint32 pss_pid
Definition procsignal.c:72
int pss_cancel_key_len
Definition procsignal.c:73
pg_atomic_uint32 pss_barrierCheckMask
Definition procsignal.c:80
const char * type
const char * name
void HandleWalSndInitStopping(void)
Definition walsender.c:3860
#define kill(pid, sig)
Definition win32_port.h:490
#define SIGUSR1
Definition win32_port.h:170

◆ BARRIER_SHOULD_CHECK

#define BARRIER_SHOULD_CHECK (   flags,
  type 
)     (((flags) & (((uint32) 1) << (uint32) (type))) != 0)

Definition at line 105 of file procsignal.c.

◆ NumProcSignalSlots

#define NumProcSignalSlots   (MaxBackends + NUM_AUXILIARY_PROCS)

Definition at line 102 of file procsignal.c.

Function Documentation

◆ CheckProcSignal()

static bool CheckProcSignal ( ProcSignalReason  reason)
static

Definition at line 663 of file procsignal.c.

664{
665 volatile ProcSignalSlot *slot = MyProcSignalSlot;
666
667 if (slot != NULL)
668 {
669 /*
670 * Careful here --- don't clear flag if we haven't seen it set.
671 * pss_signalFlags is of type "volatile sig_atomic_t" to allow us to
672 * read it here safely, without holding the spinlock.
673 */
674 if (slot->pss_signalFlags[reason])
675 {
676 slot->pss_signalFlags[reason] = false;
677 return true;
678 }
679 }
680
681 return false;
682}

References fb(), MyProcSignalSlot, and ProcSignalSlot::pss_signalFlags.

Referenced by procsignal_sigusr1_handler().

◆ CleanupProcSignalState()

static void CleanupProcSignalState ( int  status,
Datum  arg 
)
static

Definition at line 233 of file procsignal.c.

234{
237
238 /*
239 * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
240 * won't try to access it after it's no longer ours (and perhaps even
241 * after we've unmapped the shared memory segment).
242 */
245
246 /* sanity check */
249 if (old_pid != MyProcPid)
250 {
251 /*
252 * don't ERROR here. We're exiting anyway, and don't want to get into
253 * infinite loop trying to exit
254 */
256 elog(LOG, "process %d releasing ProcSignal slot %d, but it contains %d",
257 MyProcPid, (int) (slot - ProcSignal->psh_slot), (int) old_pid);
258 return; /* XXX better to zero the slot anyway? */
259 }
260
261 /* Mark the slot as unused */
262 pg_atomic_write_u32(&slot->pss_pid, 0);
263 slot->pss_cancel_key_len = 0;
264
265 /*
266 * Make this slot look like it's absorbed all possible barriers, so that
267 * no barrier waits block on it.
268 */
270
272
274}

References Assert, ConditionVariableBroadcast(), elog, fb(), LOG, MyProcPid, MyProcSignalSlot, pg_atomic_read_u32(), pg_atomic_write_u32(), pg_atomic_write_u64(), PG_UINT64_MAX, ProcSignal, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCV, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_cancel_key_len, ProcSignalSlot::pss_mutex, ProcSignalSlot::pss_pid, SpinLockAcquire(), and SpinLockRelease().

Referenced by ProcSignalInit().

◆ EmitProcSignalBarrier()

uint64 EmitProcSignalBarrier ( ProcSignalBarrierType  type)

Definition at line 360 of file procsignal.c.

361{
362 uint32 flagbit = 1 << (uint32) type;
363 uint64 generation;
364
365 /*
366 * Set all the flags.
367 *
368 * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
369 * totally ordered with respect to anything the caller did before, and
370 * anything that we do afterwards. (This is also true of the later call to
371 * pg_atomic_add_fetch_u64.)
372 */
373 for (int i = 0; i < NumProcSignalSlots; i++)
374 {
375 volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
376
378 }
379
380 /*
381 * Increment the generation counter.
382 */
383 generation =
385
386 /*
387 * Signal all the processes, so that they update their advertised barrier
388 * generation.
389 *
390 * Concurrency is not a problem here. Backends that have exited don't
391 * matter, and new backends that have joined since we entered this
392 * function must already have current state, since the caller is
393 * responsible for making sure that the relevant state is entirely visible
394 * before calling this function in the first place. We still have to wake
395 * them up - because we can't distinguish between such backends and older
396 * backends that need to update state - but they won't actually need to
397 * change any state.
398 */
399 for (int i = NumProcSignalSlots - 1; i >= 0; i--)
400 {
401 volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
402 pid_t pid = pg_atomic_read_u32(&slot->pss_pid);
403
404 if (pid != 0)
405 {
407 pid = pg_atomic_read_u32(&slot->pss_pid);
408 if (pid != 0)
409 {
410 /* see SendProcSignal for details */
411 slot->pss_signalFlags[PROCSIG_BARRIER] = true;
413 kill(pid, SIGUSR1);
414 }
415 else
417 }
418 }
419
420 return generation;
421}

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

Referenced by abort_logical_decoding_activation(), dbase_redo(), DisableLogicalDecoding(), dropdb(), DropTableSpace(), EmitAndWaitDataChecksumsBarrier(), EnableLogicalDecoding(), movedb(), SetDataChecksumsOff(), SetDataChecksumsOn(), SetDataChecksumsOnInProgress(), tblspc_redo(), and UpdateLogicalDecodingStatusEndOfRecovery().

◆ HandleProcSignalBarrierInterrupt()

static void HandleProcSignalBarrierInterrupt ( void  )
static

Definition at line 487 of file procsignal.c.

488{
489 InterruptPending = true;
491 /* latch will be set by procsignal_sigusr1_handler */
492}

References InterruptPending, and ProcSignalBarrierPending.

Referenced by procsignal_sigusr1_handler().

◆ ProcessProcSignalBarrier()

void ProcessProcSignalBarrier ( void  )

Definition at line 503 of file procsignal.c.

504{
507 volatile uint32 flags;
508
510
511 /* Exit quickly if there's no work to do. */
513 return;
515
516 /*
517 * It's not unlikely to process multiple barriers at once, before the
518 * signals for all the barriers have arrived. To avoid unnecessary work in
519 * response to subsequent signals, exit early if we already have processed
520 * all of them.
521 */
524
526
527 if (local_gen == shared_gen)
528 return;
529
530 /*
531 * Get and clear the flags that are set for this backend. Note that
532 * pg_atomic_exchange_u32 is a full barrier, so we're guaranteed that the
533 * read of the barrier generation above happens before we atomically
534 * extract the flags, and that any subsequent state changes happen
535 * afterward.
536 *
537 * NB: In order to avoid race conditions, we must zero
538 * pss_barrierCheckMask first and only afterwards try to do barrier
539 * processing. If we did it in the other order, someone could send us
540 * another barrier of some type right after we called the
541 * barrier-processing function but before we cleared the bit. We would
542 * have no way of knowing that the bit needs to stay set in that case, so
543 * the need to call the barrier-processing function again would just get
544 * forgotten. So instead, we tentatively clear all the bits and then put
545 * back any for which we don't manage to successfully absorb the barrier.
546 */
548
549 /*
550 * If there are no flags set, then we can skip doing any real work.
551 * Otherwise, establish a PG_TRY block, so that we don't lose track of
552 * which types of barrier processing are needed if an ERROR occurs.
553 */
554 if (flags != 0)
555 {
556 bool success = true;
557
558 PG_TRY();
559 {
560 /*
561 * Process each type of barrier. The barrier-processing functions
562 * should normally return true, but may return false if the
563 * barrier can't be absorbed at the current time. This should be
564 * rare, because it's pretty expensive. Every single
565 * CHECK_FOR_INTERRUPTS() will return here until we manage to
566 * absorb the barrier, and that cost will add up in a hurry.
567 *
568 * NB: It ought to be OK to call the barrier-processing functions
569 * unconditionally, but it's more efficient to call only the ones
570 * that might need us to do something based on the flags.
571 */
572 while (flags != 0)
573 {
575 bool processed = true;
576
578 switch (type)
579 {
581 processed = ProcessBarrierSmgrRelease();
582 break;
585 break;
586
591 processed = AbsorbDataChecksumsBarrier(type);
592 break;
593 }
594
595 /*
596 * To avoid an infinite loop, we must always unset the bit in
597 * flags.
598 */
599 BARRIER_CLEAR_BIT(flags, type);
600
601 /*
602 * If we failed to process the barrier, reset the shared bit
603 * so we try again later, and set a flag so that we don't bump
604 * our generation.
605 */
606 if (!processed)
607 {
609 success = false;
610 }
611 }
612 }
613 PG_CATCH();
614 {
615 /*
616 * If an ERROR occurred, we'll need to try again later to handle
617 * that barrier type and any others that haven't been handled yet
618 * or weren't successfully absorbed.
619 */
621 PG_RE_THROW();
622 }
623 PG_END_TRY();
624
625 /*
626 * If some barrier types were not successfully absorbed, we will have
627 * to try again later.
628 */
629 if (!success)
630 return;
631 }
632
633 /*
634 * State changes related to all types of barriers that might have been
635 * emitted have now been handled, so we can update our notion of the
636 * generation to the one we observed before beginning the updates. If
637 * things have changed further, it'll get fixed up when this function is
638 * next called.
639 */
642}

References AbsorbDataChecksumsBarrier(), Assert, BARRIER_CLEAR_BIT, ConditionVariableBroadcast(), fb(), 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(), ProcessBarrierUpdateXLogLogicalInfo(), ProcSignal, PROCSIGNAL_BARRIER_CHECKSUM_INPROGRESS_OFF, PROCSIGNAL_BARRIER_CHECKSUM_INPROGRESS_ON, PROCSIGNAL_BARRIER_CHECKSUM_OFF, PROCSIGNAL_BARRIER_CHECKSUM_ON, PROCSIGNAL_BARRIER_SMGRRELEASE, PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO, ProcSignalBarrierPending, ProcSignalHeader::psh_barrierGeneration, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierCV, ProcSignalSlot::pss_barrierGeneration, ResetProcSignalBarrierBits(), success, and type.

Referenced by BufferSync(), CheckpointWriteDelay(), ProcessAutoVacLauncherInterrupts(), ProcessCheckpointerInterrupts(), ProcessInterrupts(), ProcessMainLoopInterrupts(), ProcessPgArchInterrupts(), ProcessStartupProcInterrupts(), and ProcessWalSummarizerInterrupts().

◆ procsignal_sigusr1_handler()

void procsignal_sigusr1_handler ( SIGNAL_ARGS  )

Definition at line 688 of file procsignal.c.

References CheckProcSignal(), HandleCatchupInterrupt(), HandleLogMemoryContextInterrupt(), HandleNotifyInterrupt(), HandleParallelApplyMessageInterrupt(), HandleParallelMessageInterrupt(), HandleProcSignalBarrierInterrupt(), HandleRecoveryConflictInterrupt(), HandleRepackMessageInterrupt(), HandleSlotSyncMessageInterrupt(), HandleWalSndInitStopping(), MyLatch, PROCSIG_BARRIER, PROCSIG_CATCHUP_INTERRUPT, PROCSIG_LOG_MEMORY_CONTEXT, PROCSIG_NOTIFY_INTERRUPT, PROCSIG_PARALLEL_APPLY_MESSAGE, PROCSIG_PARALLEL_MESSAGE, PROCSIG_RECOVERY_CONFLICT, PROCSIG_REPACK_MESSAGE, PROCSIG_SLOTSYNC_MESSAGE, PROCSIG_WALSND_INIT_STOPPING, and SetLatch().

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

◆ ProcSignalInit()

void ProcSignalInit ( const uint8 cancel_key,
int  cancel_key_len 
)

Definition at line 170 of file procsignal.c.

171{
172 ProcSignalSlot *slot;
175
177 if (MyProcNumber < 0)
178 elog(ERROR, "MyProcNumber not set");
180 elog(ERROR, "unexpected MyProcNumber %d in ProcSignalInit (max %d)", MyProcNumber, NumProcSignalSlots);
182
184
185 /* Value used for sanity check below */
187
188 /* Clear out any leftover signal reasons */
190
191 /*
192 * Initialize barrier state. Since we're a brand-new process, there
193 * shouldn't be any leftover backend-private state that needs to be
194 * updated. Therefore, we can broadcast the latest barrier generation and
195 * disregard any previously-set check bits.
196 *
197 * NB: This only works if this initialization happens early enough in the
198 * startup sequence that we haven't yet cached any state that might need
199 * to be invalidated. That's also why we have a memory barrier here, to be
200 * sure that any later reads of memory happen strictly after this.
201 */
206
207 if (cancel_key_len > 0)
211
213
214 /* Spinlock is released, do the check */
215 if (old_pss_pid != 0)
216 elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
218
219 /* Remember slot location for CheckProcSignal */
220 MyProcSignalSlot = slot;
221
222 /* Set up to release the slot on process exit */
224}

References Assert, CleanupProcSignalState(), elog, ERROR, fb(), LOG, MAX_CANCEL_KEY_LENGTH, memcpy(), MemSet, MyProcNumber, MyProcPid, MyProcSignalSlot, NUM_PROCSIGNALS, NumProcSignalSlots, on_shmem_exit(), pg_atomic_read_u32(), pg_atomic_read_u64(), pg_atomic_write_u32(), pg_atomic_write_u64(), ProcSignal, ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_cancel_key, ProcSignalSlot::pss_cancel_key_len, ProcSignalSlot::pss_mutex, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, SpinLockAcquire(), and SpinLockRelease().

Referenced by AuxiliaryProcessMainCommon(), and InitPostgres().

◆ ProcSignalShmemInit()

◆ ProcSignalShmemRequest()

static void ProcSignalShmemRequest ( void arg)
static

Definition at line 133 of file procsignal.c.

134{
135 Size size;
136
138 size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
139
140 ShmemRequestStruct(.name = "ProcSignal",
141 .size = size,
142 .ptr = (void **) &ProcSignal,
143 );
144}

References add_size(), fb(), mul_size(), name, NumProcSignalSlots, ProcSignal, and ShmemRequestStruct.

◆ ResetProcSignalBarrierBits()

◆ SendCancelRequest()

void SendCancelRequest ( int  backendPID,
const uint8 cancel_key,
int  cancel_key_len 
)

Definition at line 731 of file procsignal.c.

732{
733 if (backendPID == 0)
734 {
735 ereport(LOG, (errmsg("invalid cancel request with PID 0")));
736 return;
737 }
738
739 /*
740 * See if we have a matching backend. Reading the pss_pid and
741 * pss_cancel_key fields is racy, a backend might die and remove itself
742 * from the array at any time. The probability of the cancellation key
743 * matching wrong process is miniscule, however, so we can live with that.
744 * PIDs are reused too, so sending the signal based on PID is inherently
745 * racy anyway, although OS's avoid reusing PIDs too soon.
746 */
747 for (int i = 0; i < NumProcSignalSlots; i++)
748 {
750 bool match;
751
752 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
753 continue;
754
755 /* Acquire the spinlock and re-check */
757 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
758 {
760 continue;
761 }
762 else
763 {
764 match = slot->pss_cancel_key_len == cancel_key_len &&
766
768
769 if (match)
770 {
771 /* Found a match; signal that backend to cancel current op */
773 (errmsg_internal("processing cancel request: sending SIGINT to process %d",
774 backendPID)));
775
776 /*
777 * If we have setsid(), signal the backend's whole process
778 * group
779 */
780#ifdef HAVE_SETSID
781 kill(-backendPID, SIGINT);
782#else
783 kill(backendPID, SIGINT);
784#endif
785 }
786 else
787 {
788 /* Right PID, wrong key: no way, Jose */
789 ereport(LOG,
790 (errmsg("wrong key in cancel request for process %d",
791 backendPID)));
792 }
793 return;
794 }
795 }
796
797 /* No matching backend */
798 ereport(LOG,
799 (errmsg("PID %d in cancel request did not match any process",
800 backendPID)));
801}

References DEBUG2, ereport, errmsg, errmsg_internal(), fb(), i, kill, LOG, NumProcSignalSlots, pg_atomic_read_u32(), ProcSignal, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_cancel_key, ProcSignalSlot::pss_cancel_key_len, ProcSignalSlot::pss_mutex, ProcSignalSlot::pss_pid, SpinLockAcquire(), SpinLockRelease(), and timingsafe_bcmp().

Referenced by ProcessCancelRequestPacket().

◆ SendProcSignal()

int SendProcSignal ( pid_t  pid,
ProcSignalReason  reason,
ProcNumber  procNumber 
)

Definition at line 288 of file procsignal.c.

289{
290 volatile ProcSignalSlot *slot;
291
292 if (procNumber != INVALID_PROC_NUMBER)
293 {
294 Assert(procNumber < NumProcSignalSlots);
295 slot = &ProcSignal->psh_slot[procNumber];
296
298 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
299 {
300 /* Atomically set the proper flag */
301 slot->pss_signalFlags[reason] = true;
303 /* Send signal */
304 return kill(pid, SIGUSR1);
305 }
307 }
308 else
309 {
310 /*
311 * procNumber not provided, so search the array using pid. We search
312 * the array back to front so as to reduce search overhead. Passing
313 * INVALID_PROC_NUMBER means that the target is most likely an
314 * auxiliary process, which will have a slot near the end of the
315 * array.
316 */
317 int i;
318
319 for (i = NumProcSignalSlots - 1; i >= 0; i--)
320 {
321 slot = &ProcSignal->psh_slot[i];
322
323 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
324 {
326 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
327 {
328 /* Atomically set the proper flag */
329 slot->pss_signalFlags[reason] = true;
331 /* Send signal */
332 return kill(pid, SIGUSR1);
333 }
335 }
336 }
337 }
338
339 errno = ESRCH;
340 return -1;
341}

References Assert, fb(), i, INVALID_PROC_NUMBER, kill, NumProcSignalSlots, pg_atomic_read_u32(), ProcSignal, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_mutex, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, SIGUSR1, SpinLockAcquire(), and SpinLockRelease().

Referenced by mq_putmessage(), pa_shutdown(), ParallelWorkerShutdown(), pg_log_backend_memory_contexts(), RepackWorkerShutdown(), ShutDownSlotSync(), SICleanupQueue(), SignalBackends(), SignalRecoveryConflict(), SignalRecoveryConflictWithDatabase(), SignalRecoveryConflictWithVirtualXID(), and WalSndInitStopping().

◆ WaitForProcSignalBarrier()

void WaitForProcSignalBarrier ( uint64  generation)

Definition at line 428 of file procsignal.c.

429{
431
432 elog(DEBUG1,
433 "waiting for all backends to process ProcSignalBarrier generation "
435 generation);
436
437 for (int i = NumProcSignalSlots - 1; i >= 0; i--)
438 {
441
442 /*
443 * It's important that we check only pss_barrierGeneration here and
444 * not pss_barrierCheckMask. Bits in pss_barrierCheckMask get cleared
445 * before the barrier is actually absorbed, but pss_barrierGeneration
446 * is updated only afterward.
447 */
449 while (oldval < generation)
450 {
452 5000,
454 ereport(LOG,
455 (errmsg("still waiting for backend with PID %d to accept ProcSignalBarrier",
456 (int) pg_atomic_read_u32(&slot->pss_pid))));
458 }
460 }
461
462 elog(DEBUG1,
463 "finished waiting for all backends to process ProcSignalBarrier generation "
465 generation);
466
467 /*
468 * The caller is probably calling this function because it wants to read
469 * the shared state or perform further writes to shared state once all
470 * backends are known to have absorbed the barrier. However, the read of
471 * pss_barrierGeneration was performed unlocked; insert a memory barrier
472 * to separate it from whatever follows.
473 */
475}

References Assert, ConditionVariableCancelSleep(), ConditionVariableTimedSleep(), DEBUG1, elog, ereport, errmsg, fb(), i, LOG, NumProcSignalSlots, pg_atomic_read_u32(), 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(), EmitAndWaitDataChecksumsBarrier(), EnableLogicalDecoding(), movedb(), SetDataChecksumsOff(), SetDataChecksumsOn(), SetDataChecksumsOnInProgress(), tblspc_redo(), and UpdateLogicalDecodingStatusEndOfRecovery().

Variable Documentation

◆ MyProcSignalSlot

◆ ProcSignal

◆ ProcSignalShmemCallbacks

const ShmemCallbacks ProcSignalShmemCallbacks
Initial value:
= {
.request_fn = ProcSignalShmemRequest,
.init_fn = ProcSignalShmemInit,
}

Definition at line 115 of file procsignal.c.

115 {
116 .request_fn = ProcSignalShmemRequest,
117 .init_fn = ProcSignalShmemInit,
118};