forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit44d44aa
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 parent9286568 commit44d44aa
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 | | |
| |||
3019 | 3026 | | |
3020 | 3027 | | |
3021 | 3028 | | |
3022 | | - | |
3023 | | - | |
3024 | | - | |
3025 | | - | |
3026 | | - | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
3027 | 3032 | | |
3028 | | - | |
3029 | | - | |
| 3033 | + | |
3030 | 3034 | | |
3031 | 3035 | | |
3032 | 3036 | | |
| |||
3146 | 3150 | | |
3147 | 3151 | | |
3148 | 3152 | | |
3149 | | - | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
3150 | 3164 | | |
3151 | | - | |
3152 | 3165 | | |
3153 | 3166 | | |
3154 | 3167 | | |
| |||
3164 | 3177 | | |
3165 | 3178 | | |
3166 | 3179 | | |
3167 | | - | |
| 3180 | + | |
3168 | 3181 | | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
3169 | 3188 | | |
3170 | 3189 | | |
3171 | 3190 | | |
3172 | 3191 | | |
3173 | 3192 | | |
3174 | 3193 | | |
3175 | | - | |
3176 | | - | |
3177 | 3194 | | |
| 3195 | + | |
3178 | 3196 | | |
3179 | 3197 | | |
3180 | 3198 | | |
| |||
| 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)