Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * procsignal.c
4 : * Routines for interprocess signaling
5 : *
6 : *
7 : * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8 : * Portions Copyright (c) 1994, Regents of the University of California
9 : *
10 : * IDENTIFICATION
11 : * src/backend/storage/ipc/procsignal.c
12 : *
13 : *-------------------------------------------------------------------------
14 : */
15 : #include "postgres.h"
16 :
17 : #include <signal.h>
18 : #include <unistd.h>
19 :
20 : #include "access/parallel.h"
21 : #include "port/pg_bitutils.h"
22 : #include "commands/async.h"
23 : #include "miscadmin.h"
24 : #include "pgstat.h"
25 : #include "replication/walsender.h"
26 : #include "storage/ipc.h"
27 : #include "storage/latch.h"
28 : #include "storage/proc.h"
29 : #include "storage/shmem.h"
30 : #include "storage/sinval.h"
31 : #include "tcop/tcopprot.h"
32 :
33 : /*
34 : * The SIGUSR1 signal is multiplexed to support signaling multiple event
35 : * types. The specific reason is communicated via flags in shared memory.
36 : * We keep a boolean flag for each possible "reason", so that different
37 : * reasons can be signaled to a process concurrently. (However, if the same
38 : * reason is signaled more than once nearly simultaneously, the process may
39 : * observe it only once.)
40 : *
41 : * Each process that wants to receive signals registers its process ID
42 : * in the ProcSignalSlots array. The array is indexed by backend ID to make
43 : * slot allocation simple, and to avoid having to search the array when you
44 : * know the backend ID of the process you're signaling. (We do support
45 : * signaling without backend ID, but it's a bit less efficient.)
46 : *
47 : * The flags are actually declared as "volatile sig_atomic_t" for maximum
48 : * portability. This should ensure that loads and stores of the flag
49 : * values are atomic, allowing us to dispense with any explicit locking.
50 : *
51 : * pss_signalFlags are intended to be set in cases where we don't need to
52 : * keep track of whether or not the target process has handled the signal,
53 : * but sometimes we need confirmation, as when making a global state change
54 : * that cannot be considered complete until all backends have taken notice
55 : * of it. For such use cases, we set a bit in pss_barrierCheckMask and then
56 : * increment the current "barrier generation"; when the new barrier generation
57 : * (or greater) appears in the pss_barrierGeneration flag of every process,
58 : * we know that the message has been received everywhere.
59 : */
60 : typedef struct
61 : {
62 : pid_t pss_pid;
63 : sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS];
64 : pg_atomic_uint64 pss_barrierGeneration;
65 : pg_atomic_uint32 pss_barrierCheckMask;
66 : } ProcSignalSlot;
67 :
68 : /*
69 : * Information that is global to the entire ProcSignal system can be stored
70 : * here.
71 : *
72 : * psh_barrierGeneration is the highest barrier generation in existence.
73 : */
74 : typedef struct
75 : {
76 : pg_atomic_uint64 psh_barrierGeneration;
77 : ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER];
78 : } ProcSignalHeader;
79 :
80 : /*
81 : * We reserve a slot for each possible BackendId, plus one for each
82 : * possible auxiliary process type. (This scheme assumes there is not
83 : * more than one of any auxiliary process type at a time.)
84 : */
85 : #define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
86 :
87 : /* Check whether the relevant type bit is set in the flags. */
88 : #define BARRIER_SHOULD_CHECK(flags, type) \
89 : (((flags) & (((uint32) 1) << (uint32) (type))) != 0)
90 :
91 : /* Clear the relevant type bit from the flags. */
92 : #define BARRIER_CLEAR_BIT(flags, type) \
93 : ((flags) &= ~(((uint32) 1) << (uint32) (type)))
94 :
95 : static ProcSignalHeader *ProcSignal = NULL;
96 : static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
97 :
98 : static bool CheckProcSignal(ProcSignalReason reason);
99 : static void CleanupProcSignalState(int status, Datum arg);
100 : static void ResetProcSignalBarrierBits(uint32 flags);
101 : static bool ProcessBarrierPlaceholder(void);
102 :
103 : /*
104 : * ProcSignalShmemSize
105 : * Compute space needed for procsignal's shared memory
106 : */
107 : Size
108 4856 : ProcSignalShmemSize(void)
109 : {
110 : Size size;
111 :
112 4856 : size = mul_size(NumProcSignalSlots, sizeof(ProcSignalSlot));
113 4856 : size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
114 4856 : return size;
115 : }
116 :
117 : /*
118 : * ProcSignalShmemInit
119 : * Allocate and initialize procsignal's shared memory
120 : */
121 : void
122 2426 : ProcSignalShmemInit(void)
123 : {
124 2426 : Size size = ProcSignalShmemSize();
125 : bool found;
126 :
127 2426 : ProcSignal = (ProcSignalHeader *)
128 2426 : ShmemInitStruct("ProcSignal", size, &found);
129 :
130 : /* If we're first, initialize. */
131 2426 : if (!found)
132 : {
133 : int i;
134 :
135 2426 : pg_atomic_init_u64(&ProcSignal->psh_barrierGeneration, 0);
136 :
137 275406 : for (i = 0; i < NumProcSignalSlots; ++i)
138 : {
139 272980 : ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
140 :
141 272980 : slot->pss_pid = 0;
142 272980 : MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
143 272980 : pg_atomic_init_u64(&slot->pss_barrierGeneration, PG_UINT64_MAX);
144 272980 : pg_atomic_init_u32(&slot->pss_barrierCheckMask, 0);
145 : }
146 : }
147 2426 : }
148 :
149 : /*
150 : * ProcSignalInit
151 : * Register the current process in the procsignal array
152 : *
153 : * The passed index should be my BackendId if the process has one,
154 : * or MaxBackends + aux process type if not.
155 : */
156 : void
157 14708 : ProcSignalInit(int pss_idx)
158 : {
159 : volatile ProcSignalSlot *slot;
160 : uint64 barrier_generation;
161 :
162 : Assert(pss_idx >= 1 && pss_idx <= NumProcSignalSlots);
163 :
164 14708 : slot = &ProcSignal->psh_slot[pss_idx - 1];
165 :
166 : /* sanity check */
167 14708 : if (slot->pss_pid != 0)
168 0 : elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
169 : MyProcPid, pss_idx);
170 :
171 : /* Clear out any leftover signal reasons */
172 14708 : MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
173 :
174 : /*
175 : * Initialize barrier state. Since we're a brand-new process, there
176 : * shouldn't be any leftover backend-private state that needs to be
177 : * updated. Therefore, we can broadcast the latest barrier generation and
178 : * disregard any previously-set check bits.
179 : *
180 : * NB: This only works if this initialization happens early enough in the
181 : * startup sequence that we haven't yet cached any state that might need
182 : * to be invalidated. That's also why we have a memory barrier here, to be
183 : * sure that any later reads of memory happen strictly after this.
184 : */
185 14708 : pg_atomic_write_u32(&slot->pss_barrierCheckMask, 0);
186 : barrier_generation =
187 14708 : pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration);
188 14708 : pg_atomic_write_u64(&slot->pss_barrierGeneration, barrier_generation);
189 14708 : pg_memory_barrier();
190 :
191 : /* Mark slot with my PID */
192 14708 : slot->pss_pid = MyProcPid;
193 :
194 : /* Remember slot location for CheckProcSignal */
195 14708 : MyProcSignalSlot = slot;
196 :
197 : /* Set up to release the slot on process exit */
198 14708 : on_shmem_exit(CleanupProcSignalState, Int32GetDatum(pss_idx));
199 14708 : }
200 :
201 : /*
202 : * CleanupProcSignalState
203 : * Remove current process from ProcSignal mechanism
204 : *
205 : * This function is called via on_shmem_exit() during backend shutdown.
206 : */
207 : static void
208 14708 : CleanupProcSignalState(int status, Datum arg)
209 : {
210 14708 : int pss_idx = DatumGetInt32(arg);
211 : volatile ProcSignalSlot *slot;
212 :
213 14708 : slot = &ProcSignal->psh_slot[pss_idx - 1];
214 : Assert(slot == MyProcSignalSlot);
215 :
216 : /*
217 : * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
218 : * won't try to access it after it's no longer ours (and perhaps even
219 : * after we've unmapped the shared memory segment).
220 : */
221 14708 : MyProcSignalSlot = NULL;
222 :
223 : /* sanity check */
224 14708 : if (slot->pss_pid != MyProcPid)
225 : {
226 : /*
227 : * don't ERROR here. We're exiting anyway, and don't want to get into
228 : * infinite loop trying to exit
229 : */
230 0 : elog(LOG, "process %d releasing ProcSignal slot %d, but it contains %d",
231 : MyProcPid, pss_idx, (int) slot->pss_pid);
232 0 : return; /* XXX better to zero the slot anyway? */
233 : }
234 :
235 : /*
236 : * Make this slot look like it's absorbed all possible barriers, so that
237 : * no barrier waits block on it.
238 : */
239 14708 : pg_atomic_write_u64(&slot->pss_barrierGeneration, PG_UINT64_MAX);
240 :
241 14708 : slot->pss_pid = 0;
242 : }
243 :
244 : /*
245 : * SendProcSignal
246 : * Send a signal to a Postgres process
247 : *
248 : * Providing backendId is optional, but it will speed up the operation.
249 : *
250 : * On success (a signal was sent), zero is returned.
251 : * On error, -1 is returned, and errno is set (typically to ESRCH or EPERM).
252 : *
253 : * Not to be confused with ProcSendSignal
254 : */
255 : int
256 8138 : SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
257 : {
258 : volatile ProcSignalSlot *slot;
259 :
260 8138 : if (backendId != InvalidBackendId)
261 : {
262 8098 : slot = &ProcSignal->psh_slot[backendId - 1];
263 :
264 : /*
265 : * Note: Since there's no locking, it's possible that the target
266 : * process detaches from shared memory and exits right after this
267 : * test, before we set the flag and send signal. And the signal slot
268 : * might even be recycled by a new process, so it's remotely possible
269 : * that we set a flag for a wrong process. That's OK, all the signals
270 : * are such that no harm is done if they're mistakenly fired.
271 : */
272 8098 : if (slot->pss_pid == pid)
273 : {
274 : /* Atomically set the proper flag */
275 8098 : slot->pss_signalFlags[reason] = true;
276 : /* Send signal */
277 8098 : return kill(pid, SIGUSR1);
278 : }
279 : }
280 : else
281 : {
282 : /*
283 : * BackendId not provided, so search the array using pid. We search
284 : * the array back to front so as to reduce search overhead. Passing
285 : * InvalidBackendId means that the target is most likely an auxiliary
286 : * process, which will have a slot near the end of the array.
287 : */
288 : int i;
289 :
290 1444 : for (i = NumProcSignalSlots - 1; i >= 0; i--)
291 : {
292 1444 : slot = &ProcSignal->psh_slot[i];
293 :
294 1444 : if (slot->pss_pid == pid)
295 : {
296 : /* the above note about race conditions applies here too */
297 :
298 : /* Atomically set the proper flag */
299 40 : slot->pss_signalFlags[reason] = true;
300 : /* Send signal */
301 40 : return kill(pid, SIGUSR1);
302 : }
303 : }
304 : }
305 :
306 0 : errno = ESRCH;
307 0 : return -1;
308 : }
309 :
310 : /*
311 : * EmitProcSignalBarrier
312 : * Send a signal to every Postgres process
313 : *
314 : * The return value of this function is the barrier "generation" created
315 : * by this operation. This value can be passed to WaitForProcSignalBarrier
316 : * to wait until it is known that every participant in the ProcSignal
317 : * mechanism has absorbed the signal (or started afterwards).
318 : *
319 : * Note that it would be a bad idea to use this for anything that happens
320 : * frequently, as interrupting every backend could cause a noticeable
321 : * performance hit.
322 : *
323 : * Callers are entitled to assume that this function will not throw ERROR
324 : * or FATAL.
325 : */
326 : uint64
327 0 : EmitProcSignalBarrier(ProcSignalBarrierType type)
328 : {
329 0 : uint32 flagbit = 1 << (uint32) type;
330 : uint64 generation;
331 :
332 : /*
333 : * Set all the flags.
334 : *
335 : * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
336 : * totally ordered with respect to anything the caller did before, and
337 : * anything that we do afterwards. (This is also true of the later call to
338 : * pg_atomic_add_fetch_u64.)
339 : */
340 0 : for (int i = 0; i < NumProcSignalSlots; i++)
341 : {
342 0 : volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
343 :
344 0 : pg_atomic_fetch_or_u32(&slot->pss_barrierCheckMask, flagbit);
345 : }
346 :
347 : /*
348 : * Increment the generation counter.
349 : */
350 : generation =
351 0 : pg_atomic_add_fetch_u64(&ProcSignal->psh_barrierGeneration, 1);
352 :
353 : /*
354 : * Signal all the processes, so that they update their advertised barrier
355 : * generation.
356 : *
357 : * Concurrency is not a problem here. Backends that have exited don't
358 : * matter, and new backends that have joined since we entered this
359 : * function must already have current state, since the caller is
360 : * responsible for making sure that the relevant state is entirely visible
361 : * before calling this function in the first place. We still have to wake
362 : * them up - because we can't distinguish between such backends and older
363 : * backends that need to update state - but they won't actually need to
364 : * change any state.
365 : */
366 0 : for (int i = NumProcSignalSlots - 1; i >= 0; i--)
367 : {
368 0 : volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
369 0 : pid_t pid = slot->pss_pid;
370 :
371 0 : if (pid != 0)
372 : {
373 : /* see SendProcSignal for details */
374 0 : slot->pss_signalFlags[PROCSIG_BARRIER] = true;
375 0 : kill(pid, SIGUSR1);
376 : }
377 : }
378 :
379 0 : return generation;
380 : }
381 :
382 : /*
383 : * WaitForProcSignalBarrier - wait until it is guaranteed that all changes
384 : * requested by a specific call to EmitProcSignalBarrier() have taken effect.
385 : *
386 : * We expect that the barrier will normally be absorbed very quickly by other
387 : * backends, so we start by waiting just 1/8 of a second and then back off
388 : * by a factor of two every time we time out, to a maximum wait time of
389 : * 1 second.
390 : */
391 : void
392 0 : WaitForProcSignalBarrier(uint64 generation)
393 : {
394 0 : long timeout = 125L;
395 :
396 : Assert(generation <= pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration));
397 :
398 0 : for (int i = NumProcSignalSlots - 1; i >= 0; i--)
399 : {
400 0 : volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
401 : uint64 oldval;
402 :
403 : /*
404 : * It's important that we check only pss_barrierGeneration here and
405 : * not pss_barrierCheckMask. Bits in pss_barrierCheckMask get cleared
406 : * before the barrier is actually absorbed, but pss_barrierGeneration
407 : * is updated only afterward.
408 : */
409 0 : oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
410 0 : while (oldval < generation)
411 : {
412 : int events;
413 :
414 0 : CHECK_FOR_INTERRUPTS();
415 :
416 : events =
417 0 : WaitLatch(MyLatch,
418 : WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
419 : timeout, WAIT_EVENT_PROC_SIGNAL_BARRIER);
420 0 : ResetLatch(MyLatch);
421 :
422 0 : oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
423 0 : if (events & WL_TIMEOUT)
424 0 : timeout = Min(timeout * 2, 1000L);
425 : }
426 : }
427 :
428 : /*
429 : * The caller is probably calling this function because it wants to read
430 : * the shared state or perform further writes to shared state once all
431 : * backends are known to have absorbed the barrier. However, the read of
432 : * pss_barrierGeneration was performed unlocked; insert a memory barrier
433 : * to separate it from whatever follows.
434 : */
435 0 : pg_memory_barrier();
436 0 : }
437 :
438 : /*
439 : * Handle receipt of an interrupt indicating a global barrier event.
440 : *
441 : * All the actual work is deferred to ProcessProcSignalBarrier(), because we
442 : * cannot safely access the barrier generation inside the signal handler as
443 : * 64bit atomics might use spinlock based emulation, even for reads. As this
444 : * routine only gets called when PROCSIG_BARRIER is sent that won't cause a
445 : * lot of unnecessary work.
446 : */
447 : static void
448 0 : HandleProcSignalBarrierInterrupt(void)
449 : {
450 0 : InterruptPending = true;
451 0 : ProcSignalBarrierPending = true;
452 : /* latch will be set by procsignal_sigusr1_handler */
453 0 : }
454 :
455 : /*
456 : * Perform global barrier related interrupt checking.
457 : *
458 : * Any backend that participates in ProcSignal signaling must arrange to
459 : * call this function periodically. It is called from CHECK_FOR_INTERRUPTS(),
460 : * which is enough for normal backends, but not necessarily for all types of
461 : * background processes.
462 : */
463 : void
464 0 : ProcessProcSignalBarrier(void)
465 : {
466 : uint64 local_gen;
467 : uint64 shared_gen;
468 : volatile uint32 flags;
469 :
470 : Assert(MyProcSignalSlot);
471 :
472 : /* Exit quickly if there's no work to do. */
473 0 : if (!ProcSignalBarrierPending)
474 0 : return;
475 0 : ProcSignalBarrierPending = false;
476 :
477 : /*
478 : * It's not unlikely to process multiple barriers at once, before the
479 : * signals for all the barriers have arrived. To avoid unnecessary work in
480 : * response to subsequent signals, exit early if we already have processed
481 : * all of them.
482 : */
483 0 : local_gen = pg_atomic_read_u64(&MyProcSignalSlot->pss_barrierGeneration);
484 0 : shared_gen = pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration);
485 :
486 : Assert(local_gen <= shared_gen);
487 :
488 0 : if (local_gen == shared_gen)
489 0 : return;
490 :
491 : /*
492 : * Get and clear the flags that are set for this backend. Note that
493 : * pg_atomic_exchange_u32 is a full barrier, so we're guaranteed that the
494 : * read of the barrier generation above happens before we atomically
495 : * extract the flags, and that any subsequent state changes happen
496 : * afterward.
497 : *
498 : * NB: In order to avoid race conditions, we must zero pss_barrierCheckMask
499 : * first and only afterwards try to do barrier processing. If we did it
500 : * in the other order, someone could send us another barrier of some
501 : * type right after we called the barrier-processing function but before
502 : * we cleared the bit. We would have no way of knowing that the bit needs
503 : * to stay set in that case, so the need to call the barrier-processing
504 : * function again would just get forgotten. So instead, we tentatively
505 : * clear all the bits and then put back any for which we don't manage
506 : * to successfully absorb the barrier.
507 : */
508 0 : flags = pg_atomic_exchange_u32(&MyProcSignalSlot->pss_barrierCheckMask, 0);
509 :
510 : /*
511 : * If there are no flags set, then we can skip doing any real work.
512 : * Otherwise, establish a PG_TRY block, so that we don't lose track of
513 : * which types of barrier processing are needed if an ERROR occurs.
514 : */
515 0 : if (flags != 0)
516 : {
517 0 : bool success = true;
518 :
519 0 : PG_TRY();
520 : {
521 : /*
522 : * Process each type of barrier. The barrier-processing functions
523 : * should normally return true, but may return false if the barrier
524 : * can't be absorbed at the current time. This should be rare,
525 : * because it's pretty expensive. Every single
526 : * CHECK_FOR_INTERRUPTS() will return here until we manage to
527 : * absorb the barrier, and that cost will add up in a hurry.
528 : *
529 : * NB: It ought to be OK to call the barrier-processing functions
530 : * unconditionally, but it's more efficient to call only the ones
531 : * that might need us to do something based on the flags.
532 : */
533 0 : while (flags != 0)
534 : {
535 : ProcSignalBarrierType type;
536 0 : bool processed = true;
537 :
538 0 : type = (ProcSignalBarrierType) pg_rightmost_one_pos32(flags);
539 0 : switch (type)
540 : {
541 0 : case PROCSIGNAL_BARRIER_PLACEHOLDER:
542 0 : processed = ProcessBarrierPlaceholder();
543 0 : break;
544 : }
545 :
546 : /*
547 : * To avoid an infinite loop, we must always unset the bit
548 : * in flags.
549 : */
550 0 : BARRIER_CLEAR_BIT(flags, type);
551 :
552 : /*
553 : * If we failed to process the barrier, reset the shared bit
554 : * so we try again later, and set a flag so that we don't bump
555 : * our generation.
556 : */
557 0 : if (!processed)
558 : {
559 0 : ResetProcSignalBarrierBits(((uint32) 1) << type);
560 0 : success = false;
561 : }
562 : }
563 : }
564 0 : PG_CATCH();
565 : {
566 : /*
567 : * If an ERROR occurred, we'll need to try again later to handle
568 : * that barrier type and any others that haven't been handled yet
569 : * or weren't successfully absorbed.
570 : */
571 0 : ResetProcSignalBarrierBits(flags);
572 0 : PG_RE_THROW();
573 : }
574 0 : PG_END_TRY();
575 :
576 : /*
577 : * If some barrier types were not successfully absorbed, we will have
578 : * to try again later.
579 : */
580 0 : if (!success)
581 0 : return;
582 : }
583 :
584 : /*
585 : * State changes related to all types of barriers that might have been
586 : * emitted have now been handled, so we can update our notion of the
587 : * generation to the one we observed before beginning the updates. If
588 : * things have changed further, it'll get fixed up when this function is
589 : * next called.
590 : */
591 0 : pg_atomic_write_u64(&MyProcSignalSlot->pss_barrierGeneration, shared_gen);
592 : }
593 :
594 : /*
595 : * If it turns out that we couldn't absorb one or more barrier types, either
596 : * because the barrier-processing functions returned false or due to an error,
597 : * arrange for processing to be retried later.
598 : */
599 : static void
600 0 : ResetProcSignalBarrierBits(uint32 flags)
601 : {
602 0 : pg_atomic_fetch_or_u32(&MyProcSignalSlot->pss_barrierCheckMask, flags);
603 0 : ProcSignalBarrierPending = true;
604 0 : InterruptPending = true;
605 0 : }
606 :
607 : static bool
608 0 : ProcessBarrierPlaceholder(void)
609 : {
610 : /*
611 : * XXX. This is just a placeholder until the first real user of this
612 : * machinery gets committed. Rename PROCSIGNAL_BARRIER_PLACEHOLDER to
613 : * PROCSIGNAL_BARRIER_SOMETHING_ELSE where SOMETHING_ELSE is something
614 : * appropriately descriptive. Get rid of this function and instead have
615 : * ProcessBarrierSomethingElse. Most likely, that function should live in
616 : * the file pertaining to that subsystem, rather than here.
617 : *
618 : * The return value should be 'true' if the barrier was successfully
619 : * absorbed and 'false' if not. Note that returning 'false' can lead to
620 : * very frequent retries, so try hard to make that an uncommon case.
621 : */
622 0 : return true;
623 : }
624 :
625 : /*
626 : * CheckProcSignal - check to see if a particular reason has been
627 : * signaled, and clear the signal flag. Should be called after receiving
628 : * SIGUSR1.
629 : */
630 : static bool
631 5594952 : CheckProcSignal(ProcSignalReason reason)
632 : {
633 5594952 : volatile ProcSignalSlot *slot = MyProcSignalSlot;
634 :
635 5594952 : if (slot != NULL)
636 : {
637 : /* Careful here --- don't clear flag if we haven't seen it set */
638 5594644 : if (slot->pss_signalFlags[reason])
639 : {
640 7888 : slot->pss_signalFlags[reason] = false;
641 7888 : return true;
642 : }
643 : }
644 :
645 5587064 : return false;
646 : }
647 :
648 : /*
649 : * procsignal_sigusr1_handler - handle SIGUSR1 signal.
650 : */
651 : void
652 508632 : procsignal_sigusr1_handler(SIGNAL_ARGS)
653 : {
654 508632 : int save_errno = errno;
655 :
656 508632 : if (CheckProcSignal(PROCSIG_CATCHUP_INTERRUPT))
657 3236 : HandleCatchupInterrupt();
658 :
659 508632 : if (CheckProcSignal(PROCSIG_NOTIFY_INTERRUPT))
660 20 : HandleNotifyInterrupt();
661 :
662 508632 : if (CheckProcSignal(PROCSIG_PARALLEL_MESSAGE))
663 4592 : HandleParallelMessageInterrupt();
664 :
665 508632 : if (CheckProcSignal(PROCSIG_WALSND_INIT_STOPPING))
666 40 : HandleWalSndInitStopping();
667 :
668 508632 : if (CheckProcSignal(PROCSIG_BARRIER))
669 0 : HandleProcSignalBarrierInterrupt();
670 :
671 508632 : if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_DATABASE))
672 0 : RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_DATABASE);
673 :
674 508632 : if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_TABLESPACE))
675 0 : RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_TABLESPACE);
676 :
677 508632 : if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_LOCK))
678 0 : RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_LOCK);
679 :
680 508632 : if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_SNAPSHOT))
681 0 : RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_SNAPSHOT);
682 :
683 508632 : if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK))
684 0 : RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK);
685 :
686 508632 : if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
687 0 : RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
688 :
689 508632 : SetLatch(MyLatch);
690 :
691 508632 : latch_sigusr1_handler();
692 :
693 508632 : errno = save_errno;
694 508632 : }
|