forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8d578b9
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 parentef719e7 commit8d578b9
File tree
3 files changed
+74
-33
lines changed- src
- backend/executor
- include/executor
3 files changed
+74
-33
lines changedLines changed: 34 additions & 16 deletions
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 |
| |
| |||
620 | 627 |
| |
621 | 628 |
| |
622 | 629 |
| |
623 |
| - | |
| 630 | + | |
624 | 631 |
| |
625 | 632 |
| |
626 | 633 |
| |
| |||
3054 | 3061 |
| |
3055 | 3062 |
| |
3056 | 3063 |
| |
3057 |
| - | |
3058 |
| - | |
3059 |
| - | |
3060 |
| - | |
3061 |
| - | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
3062 | 3067 |
| |
3063 |
| - | |
3064 |
| - | |
| 3068 | + | |
3065 | 3069 |
| |
3066 | 3070 |
| |
3067 | 3071 |
| |
| |||
3181 | 3185 |
| |
3182 | 3186 |
| |
3183 | 3187 |
| |
3184 |
| - | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
3185 | 3199 |
| |
3186 |
| - | |
3187 | 3200 |
| |
3188 | 3201 |
| |
3189 | 3202 |
| |
| |||
3199 | 3212 |
| |
3200 | 3213 |
| |
3201 | 3214 |
| |
3202 |
| - | |
| 3215 | + | |
3203 | 3216 |
| |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
3204 | 3223 |
| |
3205 | 3224 |
| |
3206 | 3225 |
| |
3207 | 3226 |
| |
3208 | 3227 |
| |
3209 | 3228 |
| |
3210 |
| - | |
3211 |
| - | |
3212 | 3229 |
| |
| 3230 | + | |
3213 | 3231 |
| |
3214 | 3232 |
| |
3215 | 3233 |
| |
|
Lines changed: 38 additions & 16 deletions
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 |
| |
|
Lines changed: 2 additions & 1 deletion
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)