postgresql/src/backend/storage
Michael Paquier effe7d9552 Make release of 2PC identifier and locks consistent in COMMIT PREPARED
When preparing a transaction in two-phase commit, a dummy PGPROC entry
holding the GID used for the transaction is registered, which gets
released once COMMIT PREPARED is run.  Prior releasing its shared memory
state, all the locks taken in the prepared transaction are released
using a dedicated set of callbacks (pgstat and multixact having similar
callbacks), which may cause the locks to be released before the GID is
set free.

Hence, there is a small window where lock conflicts could happen, for
example:
- Transaction A releases its locks, still holding its GID in shared
memory.
- Transaction B held a lock which conflicted with locks of transaction
A.
- Transaction B continues its processing, reusing the same GID as
transaction A.
- Transaction B fails because of a conflicting GID, already in use by
transaction A.

This commit changes the shared memory state release so as post-commit
callbacks and predicate lock cleanup happen consistently with the shared
memory state cleanup for the dummy PGPROC entry.  The race window is
small and 2PC had this issue from the start, so no backpatch is done.
On top if that fixes discussed involved ABI breakages, which are not
welcome in stable branches.

Reported-by: Oleksii Kliukin, Ildar Musin
Diagnosed-by: Oleksii Kliukin, Ildar Musin
Author: Michael Paquier
Reviewed-by: Masahiko Sawada, Oleksii Kliukin
Discussion: https://postgr.es/m/BF9B38A4-2BFF-46E8-BA87-A2D00A8047A6@hintbits.com
2019-02-25 14:19:34 +09:00
..
buffer Update copyright for 2019 2019-01-02 12:44:25 -05:00
file Tolerate EINVAL when calling fsync() on a directory. 2019-02-24 23:50:20 +13:00
freespace Avoid creation of the free space map for small heap relations, take 2. 2019-02-04 07:49:15 +05:30
ipc Fix race in dsm_unpin_segment() when handles are reused. 2019-02-18 09:58:29 +13:00
large_object Remove superfluous tqual.h includes. 2019-01-21 12:15:02 -08:00
lmgr Make release of 2PC identifier and locks consistent in COMMIT PREPARED 2019-02-25 14:19:34 +09:00
page Update copyright for 2019 2019-01-02 12:44:25 -05:00
smgr In bootstrap mode, don't allow the creation of files if they don't already 2019-01-28 07:52:51 +05:30
Makefile Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00