MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecParallelSetupTupleQueues

Function ExecParallelSetupTupleQueues

src/backend/executor/execParallel.c:538–584  ·  view source on GitHub ↗

* It sets up the response queues for backend workers to return tuples * to the main backend and start the workers. */

Source from the content-addressed store, hash-verified

536 * to the main backend and start the workers.
537 */
538static shm_mq_handle **
539ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize)
540{
541 shm_mq_handle **responseq;
542 char *tqueuespace;
543 int i;
544
545 /* Skip this if no workers. */
546 if (pcxt->nworkers == 0)
547 return NULL;
548
549 /* Allocate memory for shared memory queue handles. */
550 responseq = (shm_mq_handle **)
551 palloc(pcxt->nworkers * sizeof(shm_mq_handle *));
552
553 /*
554 * If not reinitializing, allocate space from the DSM for the queues;
555 * otherwise, find the already allocated space.
556 */
557 if (!reinitialize)
558 tqueuespace =
559 shm_toc_allocate(pcxt->toc,
560 mul_size(PARALLEL_TUPLE_QUEUE_SIZE,
561 pcxt->nworkers));
562 else
563 tqueuespace = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, false);
564
565 /* Create the queues, and become the receiver for each. */
566 for (i = 0; i < pcxt->nworkers; ++i)
567 {
568 shm_mq *mq;
569
570 mq = shm_mq_create(tqueuespace +
571 ((Size) i) * PARALLEL_TUPLE_QUEUE_SIZE,
572 (Size) PARALLEL_TUPLE_QUEUE_SIZE);
573
574 shm_mq_set_receiver(mq, MyProc);
575 responseq[i] = shm_mq_attach(mq, pcxt->seg, NULL);
576 }
577
578 /* Add array of queues to shm_toc, so others can find it. */
579 if (!reinitialize)
580 shm_toc_insert(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, tqueuespace);
581
582 /* Return array of handles. */
583 return responseq;
584}
585
586/*
587 * Sets up the required infrastructure for backend workers to perform

Callers 2

ExecInitParallelPlanFunction · 0.85
ExecParallelReinitializeFunction · 0.85

Calls 8

shm_toc_allocateFunction · 0.85
mul_sizeFunction · 0.85
shm_toc_lookupFunction · 0.85
shm_mq_createFunction · 0.85
shm_mq_set_receiverFunction · 0.85
shm_mq_attachFunction · 0.85
shm_toc_insertFunction · 0.85
pallocFunction · 0.50

Tested by

no test coverage detected