postgresql/src/include
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
..
access Make release of 2PC identifier and locks consistent in COMMIT PREPARED 2019-02-25 14:19:34 +09:00
bootstrap Update copyright for 2019 2019-01-02 12:44:25 -05:00
catalog Move code for managing PartitionDescs into a new file, partdesc.c 2019-02-21 11:45:02 -05:00
commands Move vacuumlazy.c into access/heap. 2019-01-15 12:06:19 -08:00
common Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
datatype Update copyright for 2019 2019-01-02 12:44:25 -05:00
executor Allow to reset execGrouping.c style tuple hashtables. 2019-02-09 01:05:49 -08:00
fe_utils pgbench: add \cset and \gset commands 2019-01-10 13:42:20 -03:00
foreign Rename nodes/relation.h to nodes/pathnodes.h. 2019-01-29 16:49:25 -05:00
jit Renaming for new subscripting mechanism 2019-02-01 12:50:32 -03:00
lib simplehash: Add support for resetting a hashtable's contents. 2019-02-09 01:05:49 -08:00
libpq Get rid of another unconstify through API changes 2019-02-14 20:44:47 +01:00
mb Update copyright for 2019 2019-01-02 12:44:25 -05:00
nodes Allow user control of CTE materialization, and change the default behavior. 2019-02-16 16:11:12 -05:00
optimizer Allow extensions to generate lossy index conditions. 2019-02-11 21:26:14 -05:00
parser Create the infrastructure for planner support functions. 2019-02-09 18:08:48 -05:00
partitioning Move code for managing PartitionDescs into a new file, partdesc.c 2019-02-21 11:45:02 -05:00
port Fix previous MinGW fix. 2019-02-16 15:23:02 +00:00
portability Update copyright for 2019 2019-01-02 12:44:25 -05:00
postmaster Update copyright for 2019 2019-01-02 12:44:25 -05:00
regex Update copyright for 2019 2019-01-02 12:44:25 -05:00
replication Update copyright for 2019 2019-01-02 12:44:25 -05:00
rewrite Update copyright for 2019 2019-01-02 12:44:25 -05:00
snowball Update copyright for 2019 2019-01-02 12:44:25 -05:00
statistics Rename nodes/relation.h to nodes/pathnodes.h. 2019-01-29 16:49:25 -05:00
storage Move max_wal_senders out of max_connections for connection slot handling 2019-02-12 10:07:56 +09:00
tcop Update copyright for 2019 2019-01-02 12:44:25 -05:00
tsearch Update copyright for 2019 2019-01-02 12:44:25 -05:00
utils Move estimate_hashagg_tablesize to selfuncs.c, and widen result to double. 2019-02-21 14:59:12 -05:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
Makefile Install JIT related headers. 2019-01-28 13:51:12 -08:00
c.h Use an unsigned char for bool if we don't use the native bool. 2019-02-20 21:31:02 +00:00
fmgr.h Change function call information to be variable length. 2019-01-26 14:17:52 -08:00
funcapi.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
getaddrinfo.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
getopt_long.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
miscadmin.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
pg_config.h.in Make use of compiler builtins and/or assembly for CLZ, CTZ, POPCNT. 2019-02-15 23:22:33 -05:00
pg_config.h.win32 Make use of compiler builtins and/or assembly for CLZ, CTZ, POPCNT. 2019-02-15 23:22:33 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
pg_getopt.h Use our own getopt() on OpenBSD. 2019-01-18 15:06:26 -05:00
pg_trace.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
pgstat.h Add more columns to pg_stat_ssl 2019-02-01 00:33:47 +01:00
pgtar.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
pgtime.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
port.h Cygwin and Mingw floating-point fixes. 2019-02-16 01:50:16 +00:00
postgres.h Change function call information to be variable length. 2019-01-26 14:17:52 -08:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
rusagestub.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
windowapi.h Update copyright for 2019 2019-01-02 12:44:25 -05:00