postgresql/src
Thomas Munro 65e388d418 Fix race in SERIALIZABLE READ ONLY.
Commit bdaabb9b started skipping doomed transactions when building the
list of possible conflicts for SERIALIZABLE READ ONLY.  That makes
sense, because doomed transactions won't commit, but a couple of subtle
things broke:

1.  If all uncommitted r/w transactions are doomed, a READ ONLY
transaction would arbitrarily not benefit from the safe snapshot
optimization.  It would not be taken immediately, and yet no other
transaction would set SXACT_FLAG_RO_SAFE later.

2.  In the same circumstances but with DEFERRABLE, GetSafeSnapshot()
would correctly exit its wait loop without sleeping and then take the
optimization in non-assert builds, but assert builds would fail a sanity
check that SXACT_FLAG_RO_SAFE had been set by another transaction.

This is similar to the case for PredXact->WritableSxactCount == 0.  We
should opt out immediately if our possibleUnsafeConflicts list is empty
after filtering.

The code to maintain the serializable global xmin is moved down below
the new opt out site, because otherwise we'd have to reverse its effects
before returning.

Back-patch to all supported releases.  Bug #17368.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/17116-d6ca217acc180e30%40postgresql.org
Discussion: https://postgr.es/m/20110707212159.GF76634%40csail.mit.edu
2023-03-09 16:33:24 +13:00
..
backend Fix race in SERIALIZABLE READ ONLY. 2023-03-09 16:33:24 +13:00
bin meson: tests: Adjust with_icu/ZSTD env vars for pg_dump, pg_basebackup 2023-03-08 17:04:15 -08:00
common meson: don't require 'touch' binary, make use of 'cp' optional 2023-03-07 18:44:42 -08:00
fe_utils Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
include Allow tailoring of ICU locales with custom rules 2023-03-08 16:56:37 +01:00
interfaces Break up long GETTEXT_FILES lists 2023-03-08 15:05:43 +01:00
makefiles meson: Add equivalent of configure --disable-rpath option 2023-03-01 08:05:42 +01:00
pl Break up long GETTEXT_FILES lists 2023-03-08 15:05:43 +01:00
port Remove gratuitous references to postmaster program 2023-01-26 10:48:32 +01:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test 001_libpq_pipeline.pl: use Test::Differences if available 2023-03-08 18:31:55 +01:00
timezone Fix outdated references to guc.c 2023-03-02 13:49:39 +01:00
tools meson: Add target for installing test files & improve install_test_files 2023-03-08 11:12:10 -08:00
tutorial Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
.gitignore
DEVELOPERS
Makefile Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
Makefile.global.in autoconf: Move export_dynamic determination to configure 2022-12-06 18:55:28 -08:00
Makefile.shlib autoconf: Rely on ar supporting index creation 2022-10-07 11:53:39 -07:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00