]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix race in SERIALIZABLE READ ONLY.
authorThomas Munro <tmunro@postgresql.org>
Thu, 9 Mar 2023 03:33:24 +0000 (16:33 +1300)
committerThomas Munro <tmunro@postgresql.org>
Thu, 9 Mar 2023 04:25:20 +0000 (17:25 +1300)
commite30fd0942493b1ba260b122c5ae4d8941926eb8f
treeae34ecaa037de8eacba63e0c8b4f947b1976bce5
parent3c92f7e9d851084bf51cb9231353c54474fe0438
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
src/backend/storage/lmgr/predicate.c