postgresql/src/include
Thomas Munro 0da096d78e Fix recovery conflict SIGUSR1 handling.
We shouldn't be doing non-trivial work in signal handlers in general,
and in this case the handler could reach unsafe code and corrupt state.
It also clobbered its own "reason" code.

Move all recovery conflict decision logic into the next
CHECK_FOR_INTERRUPTS(), and have the signal handler just set flags and
the latch, following the standard pattern.  Since there are several
different "reasons", use a separate flag for each.

With this refactoring, the recovery conflict system no longer
piggy-backs on top of the regular query cancelation mechanism, but
instead raises an error directly if it decides that is necessary.  It
still needs to respect QueryCancelHoldoffCount, because otherwise the
FEBE protocol might get out of sync (see commit 2b3a8b20c2).

This fixes one class of intermittent failure in the new
031_recovery_conflict.pl test added by commit 9f8a050f, though the buggy
coding is much older.  Failures outside contrived testing seem to be
very rare (or perhaps incorrectly attributed) in the field, based on
lack of reports.

No back-patch for now due to complexity and release schedule.  We have
the option to back-patch into 16 later, as 16 has prerequisite commit
bea3d7e.

Reviewed-by: Andres Freund <andres@anarazel.de> (earlier version)
Reviewed-by: Michael Paquier <michael@paquier.xyz> (earlier version)
Reviewed-by: Robert Haas <robertmhaas@gmail.com> (earlier version)
Tested-by: Christoph Berg <myon@debian.org>
Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com
Discussion: https://postgr.es/m/CALj2ACVr8au2J_9D88UfRCi0JdWhyQDDxAcSVav0B0irx9nXEg%40mail.gmail.com
2023-09-07 12:39:24 +12:00
..
access Remove the "snapshot too old" feature. 2023-09-05 19:53:43 +12:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Fix some typos and some incorrectly duplicated words 2023-04-18 14:03:49 +12:00
bootstrap Add const decorations 2023-08-23 06:39:39 +02:00
catalog Restructure DECLARE_INDEX arguments 2023-08-31 08:14:57 +02:00
commands Rename some function arguments for better clarity 2023-08-23 06:39:39 +02:00
common Add support for syncfs() in frontend support functions. 2023-09-06 16:27:00 -07:00
datatype Code review for commit 05a7be935. 2023-01-26 12:51:00 -05:00
executor Allow the use of a hash index on the subscriber during replication. 2023-07-14 08:21:54 +05:30
fe_utils Allow using syncfs() in frontend utilities. 2023-09-06 16:27:16 -07:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit Update copyright for 2023 2023-01-02 15:00:37 -05:00
lib Fix type of iterator variable in SH_START_ITERATE 2023-07-06 09:57:28 -07:00
libpq Introduce macros for protocol characters. 2023-08-22 19:16:12 -07:00
mb Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodes Show names of DEALLOCATE as constants in pg_stat_statements 2023-08-27 17:27:44 +09:00
optimizer Re-allow FDWs and custom scan providers to replace joins with pseudoconstant quals. 2023-08-15 16:45:00 +09:00
parser Avoid unnecessary plancache revalidation of utility statements. 2023-08-24 12:02:46 -04:00
partitioning Revert "Move PartitionPruneInfo out of plan nodes into PlannedStmt" 2023-05-04 12:09:59 +02:00
pch Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Use native CRC instructions on 64-bit LoongArch 2023-08-10 11:36:15 +07:00
portability instr_time: Represent time as an int64 on all platforms 2023-01-20 21:16:47 -08:00
postmaster Increase size of bgw_library_name. 2023-07-03 15:02:16 -07:00
regex Fix various typos 2023-04-18 13:23:23 +12:00
replication Rename logical_replication_mode to debug_logical_replication_streaming 2023-08-29 15:19:56 +02:00
rewrite Make Vars be outer-join-aware. 2023-01-30 13:16:20 -05:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Add macro for maximum statistics target 2023-07-03 07:18:57 +02:00
storage Fix recovery conflict SIGUSR1 handling. 2023-09-07 12:39:24 +12:00
tcop Fix recovery conflict SIGUSR1 handling. 2023-09-07 12:39:24 +12:00
tsearch Update tsearch regex memory management. 2023-04-08 22:09:17 +12:00
utils Remove the "snapshot too old" feature. 2023-09-05 19:53:43 +12:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Improve const use in zlib-using code 2023-08-07 09:34:38 +02:00
fmgr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
funcapi.h Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
getopt_long.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
Makefile Introduce macros for protocol characters. 2023-08-22 19:16:12 -07:00
meson.build Introduce macros for protocol characters. 2023-08-22 19:16:12 -07:00
miscadmin.h Fix privilege check for SET SESSION AUTHORIZATION. 2023-07-13 21:13:45 -07:00
pg_config.h.in Use native CRC instructions on 64-bit LoongArch 2023-08-10 11:36:15 +07:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Update PG_CACHE_LINE_SIZE description. 2023-07-03 11:56:30 +03:00
pg_getopt.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_trace.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgstat.h Add writeback to pg_stat_io 2023-05-17 11:18:35 -07:00
pgtar.h Add and use symbolic constants for tar header offsets and file types. 2023-08-01 13:50:42 -04:00
pgtime.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
port.h Rename port/thread.c to port/user.c. 2023-07-09 18:17:09 +12:00
postgres.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
varatt.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
windowapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00