forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitc03c6e8
committed
Fix race in parallel hash join batch cleanup, take II.
With unlucky timing and parallel_leader_participation=off (not thedefault), PHJ could attempt to access per-batch shared state just as itwas being freed. There was code intended to prevent that by checkingfor a cleared pointer, but it was racy. Fix, by introducing an extrabarrier phase. The new phase PHJ_BUILD_RUNNING means that it's safe toaccess the per-batch state to find a batch to help with, andPHJ_BUILD_DONE means that it is too late. The last to detach will freethe array of per-batch state as before, but now it will also atomicallyadvance the phase, so that late attachers can avoid the hazard. Thismirrors the way per-batch hash tables are freed (see phasesPHJ_BATCH_PROBING and PHJ_BATCH_DONE).An earlier attempt to fix this (commit3b8981b, later reverted) missedone special case. When the inner side is empty (the "empty inneroptimization), the build barrier would only make it toPHJ_BUILD_HASHING_INNER phase before workers attempted to detach fromthe hashtable. In that case, fast-forward the build barrier toPHJ_BUILD_RUNNING before proceeding, so that our later assertions holdand we can still negotiate who is cleaning up.Revealed by build farm failures, where BarrierAttach() failed a sanitycheck 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.xyz1 parent0c7726c commitc03c6e8
File tree
3 files changed
+74
-33
lines changed- src
- backend/executor
- include/executor
3 files changed
+74
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
337 | 343 | | |
338 | 344 | | |
339 | 345 | | |
340 | | - | |
341 | | - | |
| 346 | + | |
| 347 | + | |
342 | 348 | | |
343 | 349 | | |
| 350 | + | |
344 | 351 | | |
345 | 352 | | |
346 | 353 | | |
| |||
624 | 631 | | |
625 | 632 | | |
626 | 633 | | |
627 | | - | |
| 634 | + | |
628 | 635 | | |
629 | 636 | | |
630 | 637 | | |
| |||
3068 | 3075 | | |
3069 | 3076 | | |
3070 | 3077 | | |
3071 | | - | |
3072 | | - | |
3073 | | - | |
3074 | | - | |
3075 | | - | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
3076 | 3081 | | |
3077 | | - | |
3078 | | - | |
| 3082 | + | |
3079 | 3083 | | |
3080 | 3084 | | |
3081 | 3085 | | |
| |||
3195 | 3199 | | |
3196 | 3200 | | |
3197 | 3201 | | |
3198 | | - | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
3199 | 3213 | | |
3200 | | - | |
3201 | 3214 | | |
3202 | 3215 | | |
3203 | 3216 | | |
| |||
3213 | 3226 | | |
3214 | 3227 | | |
3215 | 3228 | | |
3216 | | - | |
| 3229 | + | |
3217 | 3230 | | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
3218 | 3237 | | |
3219 | 3238 | | |
3220 | 3239 | | |
3221 | 3240 | | |
3222 | 3241 | | |
3223 | 3242 | | |
3224 | | - | |
3225 | | - | |
3226 | 3243 | | |
| 3244 | + | |
3227 | 3245 | | |
3228 | 3246 | | |
3229 | 3247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
296 | 302 | | |
297 | 303 | | |
298 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
299 | 318 | | |
| 319 | + | |
300 | 320 | | |
301 | 321 | | |
302 | 322 | | |
| |||
317 | 337 | | |
318 | 338 | | |
319 | 339 | | |
| 340 | + | |
320 | 341 | | |
321 | 342 | | |
322 | 343 | | |
| |||
329 | 350 | | |
330 | 351 | | |
331 | 352 | | |
332 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
333 | 362 | | |
334 | 363 | | |
| 364 | + | |
335 | 365 | | |
336 | 366 | | |
337 | 367 | | |
| |||
1090 | 1120 | | |
1091 | 1121 | | |
1092 | 1122 | | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | 1123 | | |
1102 | 1124 | | |
1103 | 1125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
| 262 | + | |
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
| |||
0 commit comments
Comments
(0)