Skip to content

Commit bfb9374

Browse files
committed
Fix fuzzy thinking in ReinitializeParallelDSM().
The fact that no workers were successfully launched in the previous iteration does not excuse us from setting up properly to try again. This appears to explain crashes I saw in parallel regression testing due to error_mqh being NULL when it shouldn't be. Minor other cosmetic fixes too.
1 parent 75be664 commit bfb9374

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/backend/access/transam/parallel.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ CreateParallelContextForExternalFunction(char *library_name,
191191

192192
/*
193193
* Establish the dynamic shared memory segment for a parallel context and
194-
* copied state and other bookkeeping information that will need by parallel
195-
* workers into it.
194+
* copy state and other bookkeeping information that will be needed by
195+
* parallel workers into it.
196196
*/
197197
void
198198
InitializeParallelDSM(ParallelContext *pcxt)
@@ -271,7 +271,7 @@ InitializeParallelDSM(ParallelContext *pcxt)
271271
* parallelism than to fail outright.
272272
*/
273273
segsize = shm_toc_estimate(&pcxt->estimator);
274-
if (pcxt->nworkers != 0)
274+
if (pcxt->nworkers > 0)
275275
pcxt->seg = dsm_create(segsize, DSM_CREATE_NULL_IF_MAXSEGMENTS);
276276
if (pcxt->seg != NULL)
277277
pcxt->toc = shm_toc_create(PARALLEL_MAGIC,
@@ -397,11 +397,13 @@ ReinitializeParallelDSM(ParallelContext *pcxt)
397397
char *error_queue_space;
398398
int i;
399399

400-
if (pcxt->nworkers_launched == 0)
401-
return;
402-
403-
WaitForParallelWorkersToFinish(pcxt);
404-
WaitForParallelWorkersToExit(pcxt);
400+
/* Wait for any old workers to exit. */
401+
if (pcxt->nworkers_launched > 0)
402+
{
403+
WaitForParallelWorkersToFinish(pcxt);
404+
WaitForParallelWorkersToExit(pcxt);
405+
pcxt->nworkers_launched = 0;
406+
}
405407

406408
/* Reset a few bits of fixed parallel state to a clean state. */
407409
fps = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_FIXED);
@@ -420,9 +422,6 @@ ReinitializeParallelDSM(ParallelContext *pcxt)
420422
shm_mq_set_receiver(mq, MyProc);
421423
pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
422424
}
423-
424-
/* Reset number of workers launched. */
425-
pcxt->nworkers_launched = 0;
426425
}
427426

428427
/*
@@ -493,6 +492,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
493492
*/
494493
any_registrations_failed = true;
495494
pcxt->worker[i].bgwhandle = NULL;
495+
pfree(pcxt->worker[i].error_mqh);
496496
pcxt->worker[i].error_mqh = NULL;
497497
}
498498
}

0 commit comments

Comments
 (0)