postgresql/contrib/test_decoding/expected
Andres Freund 955a684e04 Fix race condition leading to hanging logical slot creation.
The snapshot assembly during the creation of logical slots relied
waiting for transactions in xl_running_xacts to end, by checking for
their commit/abort records.  Unfortunately, despite locking, it is
possible to see an xl_running_xact record listing transactions as
ready, that have already WAL-logged an commit/abort record, as the
locking just prevents the ProcArray to be adjusted, and the commit
record has to be logged first.

That lead to either delayed or hanging snapshot creation, because
snapbuild.c would wait "forever" to see commit/abort records for some
transactions.  That hang resolved only if a xl_running_xacts record
without any running transactions happened to be logged, far from
certain on a busy server.

It's impractical to prevent that via more heavyweight locking, the
likelihood of deadlocks and significantly increased contention would
be too big.

Instead change the initial snapshot creation to be solely based on
tracking the oldest running transaction via
xl_running_xacts->oldestRunningXid - that actually ends up
significantly simplifying the code.  That has two disadvantages:
1) Because we cannot fully "trust" the contents of xl_running_xacts,
   we cannot use it to build the initial snapshot.  Instead we have to
   wait twice for all running transactions to finish.
2) Previously a slot, unless the race occurred, could be created when
   the all transaction perceived as running based on commit/abort
   records, now we have to wait for the next xl_running_xacts record.
To address that, trigger logging new xl_running_xacts record from
within snapbuild.c exactly when necessary.

Unfortunately snabuild.c's SnapBuild is stored on disk, one of the
stupider ideas of a certain Mr Freund, so we can't change it in a
minor release.  As this is going to be backpatched, we have to hack
around a bit to keep on-disk compatibility.  A later commit will
rejigger that on master.

Author: Andres Freund, based on a quite different patch from Petr Jelinek
Analyzed-By: Petr Jelinek
Reviewed-By: Petr Jelinek
Discussion: https://postgr.es/m/f37e975c-908f-858e-707f-058d3b1eb214@2ndquadrant.com
Backpatch: 9.4-, where logical decoding has been introduced
2017-05-13 14:21:00 -07:00
..
binary.out Message style improvements 2015-10-28 20:38:36 -04:00
concurrent_ddl_dml.out Add skip-empty-xacts option to test_decoding for use in the regression tests. 2014-09-01 15:59:44 +02:00
ddl.out Rename WAL-related functions and views to use "lsn" not "location". 2017-05-11 11:49:59 -04:00
decoding_in_xact.out Collection of typo fixes. 2015-05-20 16:56:22 +03:00
decoding_into_rel.out Don't skip SQL backends in logical decoding for visibility computation. 2014-12-02 23:47:08 +01:00
delayed_startup.out Introduce logical decoding. 2014-03-03 16:32:18 -05:00
messages.out Add required database and origin filtering for logical messages. 2016-04-13 17:38:54 -07:00
mxact.out Introduce logical decoding. 2014-03-03 16:32:18 -05:00
ondisk_startup.out Fix race condition leading to hanging logical slot creation. 2017-05-13 14:21:00 -07:00
permissions.out Establish conventions about global object names used in regression tests. 2016-07-17 18:42:43 -04:00
prepared.out Add skip-empty-xacts option to test_decoding for use in the regression tests. 2014-09-01 15:59:44 +02:00
replorigin.out Add required database and origin filtering for logical messages. 2016-04-13 17:38:54 -07:00
rewrite.out Add skip-empty-xacts option to test_decoding for use in the regression tests. 2014-09-01 15:59:44 +02:00
slot.out Force synchronous commit in new-ish test_decoding test. 2017-04-04 14:38:00 -07:00
spill.out Make contrib/test_decoding regression tests safe for CZ locale. 2016-11-21 20:39:28 -05:00
time.out logical decoding: fix decoding of a commit's commit time. 2016-03-02 23:42:21 -08:00
toast.out logical decoding: Fix handling of large old tuples with replica identity full. 2016-03-05 18:02:20 -08:00
xact.out Don't propagate a null subtransaction snapshot up to parent transaction. 2016-08-07 13:15:55 -04:00