PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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.

Macros

#define NUM_PROCSIGNALS   (PROCSIG_RECOVERY_CONFLICT + 1)
 
#define MAX_CANCEL_KEY_LENGTH   32
 

Typedefs

typedef struct ProcSignalHeader ProcSignalHeader
 

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
}
 
enum  ProcSignalBarrierType { PROCSIGNAL_BARRIER_SMGRRELEASE , PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO }
 

Functions

Size ProcSignalShmemSize (void)
 
void ProcSignalShmemInit (void)
 
void ProcSignalInit (const uint8 *cancel_key, int cancel_key_len)
 
int SendProcSignal (pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
 
void SendCancelRequest (int backendPID, const uint8 *cancel_key, int cancel_key_len)
 
uint64 EmitProcSignalBarrier (ProcSignalBarrierType type)
 
void WaitForProcSignalBarrier (uint64 generation)
 
void ProcessProcSignalBarrier (void)
 
void procsignal_sigusr1_handler (SIGNAL_ARGS)
 

Macro Definition Documentation

◆ MAX_CANCEL_KEY_LENGTH

#define MAX_CANCEL_KEY_LENGTH   32

Definition at line 61 of file procsignal.h.

◆ NUM_PROCSIGNALS

#define NUM_PROCSIGNALS   (PROCSIG_RECOVERY_CONFLICT + 1)

Definition at line 44 of file procsignal.h.

Typedef Documentation

◆ ProcSignalHeader

Definition at line 81 of file procsignal.h.

Enumeration Type Documentation

◆ ProcSignalBarrierType

Enumerator
PROCSIGNAL_BARRIER_SMGRRELEASE 
PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO 

Definition at line 46 of file procsignal.h.

47{
48 PROCSIGNAL_BARRIER_SMGRRELEASE, /* ask smgr to close files */
50 * XLogLogicalInfo */
ProcSignalBarrierType
Definition procsignal.h:47
@ PROCSIGNAL_BARRIER_SMGRRELEASE
Definition procsignal.h:48
@ PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO
Definition procsignal.h:49

◆ 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 

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 PROCSIG_RECOVERY_CONFLICT, /* backend is blocking recovery, check
40 * PGPROC->pendingRecoveryConflicts for the
41 * reason */
ProcSignalReason
Definition procsignal.h:31
@ PROCSIG_RECOVERY_CONFLICT
Definition procsignal.h:39
@ PROCSIG_PARALLEL_MESSAGE
Definition procsignal.h:34
@ PROCSIG_CATCHUP_INTERRUPT
Definition procsignal.h:32
@ PROCSIG_LOG_MEMORY_CONTEXT
Definition procsignal.h:37
@ PROCSIG_BARRIER
Definition procsignal.h:36
@ PROCSIG_WALSND_INIT_STOPPING
Definition procsignal.h:35
@ PROCSIG_PARALLEL_APPLY_MESSAGE
Definition procsignal.h:38
@ PROCSIG_NOTIFY_INTERRUPT
Definition procsignal.h:33

Function Documentation

◆ EmitProcSignalBarrier()

uint64 EmitProcSignalBarrier ( ProcSignalBarrierType  type)
extern

Definition at line 359 of file procsignal.c.

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}
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition atomics.h:410
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
uint64_t uint64
Definition c.h:589
uint32_t uint32
Definition c.h:588
int i
Definition isn.c:77
static int fb(int x)
#define NumProcSignalSlots
Definition procsignal.c:98
NON_EXEC_STATIC ProcSignalHeader * ProcSignal
Definition procsignal.c:108
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition procsignal.c:89
pg_atomic_uint64 psh_barrierGeneration
Definition procsignal.c:88
volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition procsignal.c:71
slock_t pss_mutex
Definition procsignal.c:72
pg_atomic_uint32 pss_pid
Definition procsignal.c:68
pg_atomic_uint32 pss_barrierCheckMask
Definition procsignal.c:76
const char * type
#define kill(pid, sig)
Definition win32_port.h:490
#define SIGUSR1
Definition win32_port.h:170

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(), EnableLogicalDecoding(), movedb(), tblspc_redo(), and UpdateLogicalDecodingStatusEndOfRecovery().

◆ ProcessProcSignalBarrier()

void ProcessProcSignalBarrier ( void  )
extern

Definition at line 502 of file procsignal.c.

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 }
586
587 /*
588 * To avoid an infinite loop, we must always unset the bit in
589 * flags.
590 */
591 BARRIER_CLEAR_BIT(flags, type);
592
593 /*
594 * If we failed to process the barrier, reset the shared bit
595 * so we try again later, and set a flag so that we don't bump
596 * our generation.
597 */
598 if (!processed)
599 {
601 success = false;
602 }
603 }
604 }
605 PG_CATCH();
606 {
607 /*
608 * If an ERROR occurred, we'll need to try again later to handle
609 * that barrier type and any others that haven't been handled yet
610 * or weren't successfully absorbed.
611 */
613 PG_RE_THROW();
614 }
615 PG_END_TRY();
616
617 /*
618 * If some barrier types were not successfully absorbed, we will have
619 * to try again later.
620 */
621 if (!success)
622 return;
623 }
624
625 /*
626 * State changes related to all types of barriers that might have been
627 * emitted have now been handled, so we can update our notion of the
628 * generation to the one we observed before beginning the updates. If
629 * things have changed further, it'll get fixed up when this function is
630 * next called.
631 */
634}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:485
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition atomics.h:330
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition atomics.h:467
#define Assert(condition)
Definition c.h:915
void ConditionVariableBroadcast(ConditionVariable *cv)
#define PG_RE_THROW()
Definition elog.h:405
#define PG_TRY(...)
Definition elog.h:372
#define PG_END_TRY(...)
Definition elog.h:397
#define PG_CATCH(...)
Definition elog.h:382
volatile sig_atomic_t ProcSignalBarrierPending
Definition globals.c:40
static bool success
Definition initdb.c:187
bool ProcessBarrierUpdateXLogLogicalInfo(void)
Definition logicalctl.c:187
static int pg_rightmost_one_pos32(uint32 word)
static void ResetProcSignalBarrierBits(uint32 flags)
Definition procsignal.c:642
static ProcSignalSlot * MyProcSignalSlot
Definition procsignal.c:109
#define BARRIER_CLEAR_BIT(flags, type)
Definition procsignal.c:105
bool ProcessBarrierSmgrRelease(void)
Definition smgr.c:1027
ConditionVariable pss_barrierCV
Definition procsignal.c:77
pg_atomic_uint64 pss_barrierGeneration
Definition procsignal.c:75

References 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_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  )
extern

Definition at line 680 of file procsignal.c.

681{
684
687
690
693
696
699
702
705
707}
void HandleParallelApplyMessageInterrupt(void)
void HandleNotifyInterrupt(void)
Definition async.c:2543
void HandleParallelMessageInterrupt(void)
Definition parallel.c:1046
struct Latch * MyLatch
Definition globals.c:63
void SetLatch(Latch *latch)
Definition latch.c:290
void HandleLogMemoryContextInterrupt(void)
Definition mcxt.c:1323
void HandleRecoveryConflictInterrupt(void)
Definition postgres.c:3074
static bool CheckProcSignal(ProcSignalReason reason)
Definition procsignal.c:655
static void HandleProcSignalBarrierInterrupt(void)
Definition procsignal.c:486
void HandleCatchupInterrupt(void)
Definition sinval.c:154
void HandleWalSndInitStopping(void)
Definition walsender.c:3705

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, PROCSIG_WALSND_INIT_STOPPING, and SetLatch().

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

◆ ProcSignalInit()

void ProcSignalInit ( const uint8 cancel_key,
int  cancel_key_len 
)
extern

Definition at line 169 of file procsignal.c.

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}
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:274
#define MemSet(start, val, len)
Definition c.h:1079
#define LOG
Definition elog.h:31
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
int MyProcPid
Definition globals.c:47
ProcNumber MyProcNumber
Definition globals.c:90
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:372
uint64_t Datum
Definition postgres.h:70
static void CleanupProcSignalState(int status, Datum arg)
Definition procsignal.c:232
#define NUM_PROCSIGNALS
Definition procsignal.h:44
#define MAX_CANCEL_KEY_LENGTH
Definition procsignal.h:61
uint8 pss_cancel_key[MAX_CANCEL_KEY_LENGTH]
Definition procsignal.c:70
int pss_cancel_key_len
Definition procsignal.c:69

References Assert, CleanupProcSignalState(), elog, ERROR, fb(), LOG, MAX_CANCEL_KEY_LENGTH, 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()

void ProcSignalShmemInit ( void  )
extern

Definition at line 134 of file procsignal.c.

135{
136 Size size = ProcSignalShmemSize();
137 bool found;
138
140 ShmemInitStruct("ProcSignal", size, &found);
141
142 /* If we're first, initialize. */
143 if (!found)
144 {
145 int i;
146
148
149 for (i = 0; i < NumProcSignalSlots; ++i)
150 {
152
153 SpinLockInit(&slot->pss_mutex);
154 pg_atomic_init_u32(&slot->pss_pid, 0);
155 slot->pss_cancel_key_len = 0;
156 MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
160 }
161 }
162}
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:219
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:453
#define PG_UINT64_MAX
Definition c.h:649
size_t Size
Definition c.h:661
void ConditionVariableInit(ConditionVariable *cv)
Size ProcSignalShmemSize(void)
Definition procsignal.c:120
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:378
static void SpinLockInit(volatile slock_t *lock)
Definition spin.h:50

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_cancel_key_len, ProcSignalSlot::pss_mutex, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, ShmemInitStruct(), and SpinLockInit().

Referenced by CreateOrAttachShmemStructs().

◆ ProcSignalShmemSize()

Size ProcSignalShmemSize ( void  )
extern

Definition at line 120 of file procsignal.c.

121{
122 Size size;
123
125 size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
126 return size;
127}
Size add_size(Size s1, Size s2)
Definition shmem.c:482
Size mul_size(Size s1, Size s2)
Definition shmem.c:497

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

Referenced by CalculateShmemSize(), and ProcSignalShmemInit().

◆ SendCancelRequest()

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

Definition at line 717 of file procsignal.c.

718{
719 if (backendPID == 0)
720 {
721 ereport(LOG, (errmsg("invalid cancel request with PID 0")));
722 return;
723 }
724
725 /*
726 * See if we have a matching backend. Reading the pss_pid and
727 * pss_cancel_key fields is racy, a backend might die and remove itself
728 * from the array at any time. The probability of the cancellation key
729 * matching wrong process is miniscule, however, so we can live with that.
730 * PIDs are reused too, so sending the signal based on PID is inherently
731 * racy anyway, although OS's avoid reusing PIDs too soon.
732 */
733 for (int i = 0; i < NumProcSignalSlots; i++)
734 {
736 bool match;
737
738 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
739 continue;
740
741 /* Acquire the spinlock and re-check */
743 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
744 {
746 continue;
747 }
748 else
749 {
750 match = slot->pss_cancel_key_len == cancel_key_len &&
752
754
755 if (match)
756 {
757 /* Found a match; signal that backend to cancel current op */
759 (errmsg_internal("processing cancel request: sending SIGINT to process %d",
760 backendPID)));
761
762 /*
763 * If we have setsid(), signal the backend's whole process
764 * group
765 */
766#ifdef HAVE_SETSID
767 kill(-backendPID, SIGINT);
768#else
769 kill(backendPID, SIGINT);
770#endif
771 }
772 else
773 {
774 /* Right PID, wrong key: no way, Jose */
775 ereport(LOG,
776 (errmsg("wrong key in cancel request for process %d",
777 backendPID)));
778 }
779 return;
780 }
781 }
782
783 /* No matching backend */
784 ereport(LOG,
785 (errmsg("PID %d in cancel request did not match any process",
786 backendPID)));
787}
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define DEBUG2
Definition elog.h:29
#define ereport(elevel,...)
Definition elog.h:150
static char * errmsg
int timingsafe_bcmp(const void *b1, const void *b2, size_t n)

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 
)
extern

Definition at line 287 of file procsignal.c.

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}
#define INVALID_PROC_NUMBER
Definition procnumber.h:26

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(), SICleanupQueue(), SignalBackends(), SignalRecoveryConflict(), SignalRecoveryConflictWithDatabase(), SignalRecoveryConflictWithVirtualXID(), and WalSndInitStopping().

◆ WaitForProcSignalBarrier()

void WaitForProcSignalBarrier ( uint64  generation)
extern

Definition at line 427 of file procsignal.c.

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}
#define pg_memory_barrier()
Definition atomics.h:141
#define UINT64_FORMAT
Definition c.h:607
bool ConditionVariableCancelSleep(void)
bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info)
#define DEBUG1
Definition elog.h:30

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(), EnableLogicalDecoding(), movedb(), tblspc_redo(), and UpdateLogicalDecodingStatusEndOfRecovery().