postgresql/src/include
Thomas Munro 8d578b9b2e Fix race in parallel hash join batch cleanup, take II.
With unlucky timing and parallel_leader_participation=off (not the
default), PHJ could attempt to access per-batch shared state just as it
was being freed.  There was code intended to prevent that by checking
for a cleared pointer, but it was racy.  Fix, by introducing an extra
barrier phase.  The new phase PHJ_BUILD_RUNNING means that it's safe to
access the per-batch state to find a batch to help with, and
PHJ_BUILD_DONE means that it is too late.  The last to detach will free
the array of per-batch state as before, but now it will also atomically
advance the phase, so that late attachers can avoid the hazard.  This
mirrors the way per-batch hash tables are freed (see phases
PHJ_BATCH_PROBING and PHJ_BATCH_DONE).

An earlier attempt to fix this (commit 3b8981b6, later reverted) missed
one special case.  When the inner side is empty (the "empty inner
optimization), the build barrier would only make it to
PHJ_BUILD_HASHING_INNER phase before workers attempted to detach from
the hashtable.  In that case, fast-forward the build barrier to
PHJ_BUILD_RUNNING before proceeding, so that our later assertions hold
and we can still negotiate who is cleaning up.

Revealed by build farm failures, where BarrierAttach() failed a sanity
check assertion, because the memory had been clobbered by dsa_free().
In non-assert builds, the result could be a segmentation fault.

Back-patch to all supported releases.

Author: Thomas Munro <thomas.munro@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reported-by: David Geier <geidav.pg@gmail.com>
Tested-by: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/20200929061142.GA29096%40paquier.xyz
2023-03-21 14:29:34 +13:00
..
access Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Update copyright for 2023 2023-01-02 15:00:37 -05:00
bootstrap Update copyright for 2023 2023-01-02 15:00:37 -05:00
catalog Add functions to do timestamptz arithmetic in a non-default timezone. 2023-03-18 14:12:16 -04:00
commands Add a DEFAULT option to COPY FROM 2023-03-13 10:01:56 -04:00
common Revise pg_pwrite_zeros() 2023-03-06 13:21:33 +09:00
datatype Code review for commit 05a7be935. 2023-01-26 12:51:00 -05:00
executor Fix race in parallel hash join batch cleanup, take II. 2023-03-21 14:29:34 +13:00
fe_utils Update copyright for 2023 2023-01-02 15:00:37 -05:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit Update copyright for 2023 2023-01-02 15:00:37 -05:00
lib Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
libpq libpq: Remove code for SCM credential authentication 2023-03-17 10:52:26 +09:00
mb Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodes Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
optimizer Fix mis-handling of outer join quals generated by EquivalenceClasses. 2023-02-23 11:05:58 -05:00
parser Support [NO] INDENT option in XMLSERIALIZE(). 2023-03-15 16:59:09 -04:00
partitioning Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
pch Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Don't leak descriptors into subprograms. 2023-03-03 10:43:33 +13:00
portability instr_time: Represent time as an int64 on all platforms 2023-01-20 21:16:47 -08:00
postmaster Redesign archive modules 2023-02-17 14:26:42 +09:00
regex Update copyright for 2023 2023-01-02 15:00:37 -05:00
replication Add macros for ReorderBufferTXN toptxn. 2023-03-17 08:29:41 +05:30
rewrite Make Vars be outer-join-aware. 2023-01-30 13:16:20 -05:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Update copyright for 2023 2023-01-02 15:00:37 -05:00
storage Update types in smgr API 2023-02-27 07:47:46 +01:00
tcop Update copyright for 2023 2023-01-02 15:00:37 -05:00
tsearch Fix ts_headline() to handle ORs and phrase queries more honestly. 2023-01-19 16:21:44 -05:00
utils Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
Makefile Include headers of archive/ in installation 2023-03-10 20:08:10 +09:00
c.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
fmgr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
funcapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
getopt_long.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
meson.build Include headers of archive/ in installation 2023-03-10 20:08:10 +09:00
miscadmin.h Fix outdated references to guc.c 2023-03-02 13:49:39 +01:00
pg_config.h.in libpq: Remove code for SCM credential authentication 2023-03-17 10:52:26 +09: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.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_getopt.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_trace.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgstat.h Remove PgStat_BackendFunctionEntry 2023-03-16 14:22:34 +09:00
pgtar.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgtime.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
port.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
postgres.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
varatt.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
windowapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00