]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix broken snapshot handling in parallel workers.
authorRobert Haas <rhaas@postgresql.org>
Wed, 25 Aug 2021 12:32:04 +0000 (08:32 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 25 Aug 2021 12:55:52 +0000 (08:55 -0400)
commit96f6ef9fe451aa07d0b9b744f41482e52bdd1b8a
tree91d4057576666fca22c4a8c1c0a37867f9e53099
parentedc6d3a9806fc330e6c8fd603b0455c1693b10eb
Fix broken snapshot handling in parallel workers.

Pengchengliu reported an assertion failure in a parallel woker while
performing a parallel scan using an overflowed snapshot. The proximate
cause is that TransactionXmin was set to an incorrect value.  The
underlying cause is incorrect snapshot handling in parallel.c.

In particular, InitializeParallelDSM() was unconditionally calling
GetTransactionSnapshot(), because I (rhaas) mistakenly thought that
was always retrieving an existing snapshot whereas, at isolation
levels less than REPEATABLE READ, it's actually taking a new one. So
instead do this only at higher isolation levels where there actually
is a single snapshot for the whole transaction.

By itself, this is not a sufficient fix, because we still need to
guarantee that TransactionXmin gets set properly in the workers. The
easiest way to do that seems to be to install the leader's active
snapshot as the transaction snapshot if the leader did not serialize a
transaction snapshot. This doesn't affect the results of future
GetTrasnactionSnapshot() calls since those have to take a new snapshot
anyway; what we care about is the side effect of setting TransactionXmin.

Report by Pengchengliu. Patch by Greg Nancarrow, except for some comment
text which I supplied.

Discussion: https://postgr.es/m/002f01d748ac$eaa781a0$bff684e0$@tju.edu.cn
src/backend/access/transam/parallel.c