aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-02-02 18:26:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-02-02 18:26:07 -0500
commit957ff087c822c95f63df956e1a91c15614ecb2b4 (patch)
treee42fe5db4dc63ad2dd21ab00e4720611b641160c
parentbf641d3376018c40860f26167a60febff5bc1f51 (diff)
downloadpostgresql-957ff087c822c95f63df956e1a91c15614ecb2b4.tar.gz
postgresql-957ff087c822c95f63df956e1a91c15614ecb2b4.zip
Be more wary about shm_toc_lookup failure.
Commit 445dbd82a basically missed the point of commit d46633506, which was that we shouldn't allow shm_toc_lookup() failure to lead to a core dump or assertion crash, because the odds of such a failure should never be considered negligible. It's correct that we can't expect the PARALLEL_KEY_ERROR_QUEUE TOC entry to be there if we have no workers. But if we have no workers, we're not going to do anything in this function with the lookup result anyway, so let's just skip it. That lets the code use the easy-to-prove-safe noError=false case, rather than anything requiring effort to review. Back-patch to v10, like the previous commit. Discussion: https://postgr.es/m/3647.1517601675@sss.pgh.pa.us
-rw-r--r--src/backend/access/transam/parallel.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index a325933940d..9d4efc0f8fc 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -434,8 +434,6 @@ void
ReinitializeParallelDSM(ParallelContext *pcxt)
{
FixedParallelState *fps;
- char *error_queue_space;
- int i;
/* Wait for any old workers to exit. */
if (pcxt->nworkers_launched > 0)
@@ -456,18 +454,23 @@ ReinitializeParallelDSM(ParallelContext *pcxt)
fps->last_xlog_end = 0;
/* Recreate error queues (if they exist). */
- error_queue_space =
- shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, true);
- Assert(pcxt->nworkers == 0 || error_queue_space != NULL);
- for (i = 0; i < pcxt->nworkers; ++i)
+ if (pcxt->nworkers > 0)
{
- char *start;
- shm_mq *mq;
+ char *error_queue_space;
+ int i;
- start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
- mq = shm_mq_create(start, PARALLEL_ERROR_QUEUE_SIZE);
- shm_mq_set_receiver(mq, MyProc);
- pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
+ error_queue_space =
+ shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, false);
+ for (i = 0; i < pcxt->nworkers; ++i)
+ {
+ char *start;
+ shm_mq *mq;
+
+ start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
+ mq = shm_mq_create(start, PARALLEL_ERROR_QUEUE_SIZE);
+ shm_mq_set_receiver(mq, MyProc);
+ pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
+ }
}
}