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

Function DestroyParallelContext

src/backend/access/transam/parallel.c:964–1033  ·  view source on GitHub ↗

* Destroy a parallel context. * * If expecting a clean exit, you should use WaitForParallelWorkersToFinish() * first, before calling this function. When this function is invoked, any * remaining workers are forcibly killed; the dynamic shared memory segment * is unmapped; and we then wait (uninterruptibly) for the workers to exit. */

Source from the content-addressed store, hash-verified

962 * is unmapped; and we then wait (uninterruptibly) for the workers to exit.
963 */
964void
965DestroyParallelContext(ParallelContext *pcxt)
966{
967 int i;
968
969 /*
970 * Be careful about order of operations here! We remove the parallel
971 * context from the list before we do anything else; otherwise, if an
972 * error occurs during a subsequent step, we might try to nuke it again
973 * from AtEOXact_Parallel or AtEOSubXact_Parallel.
974 */
975 dlist_delete(&pcxt->node);
976
977 /* Kill each worker in turn, and forget their error queues. */
978 if (pcxt->worker != NULL)
979 {
980 for (i = 0; i < pcxt->nworkers_launched; ++i)
981 {
982 if (pcxt->worker[i].error_mqh != NULL)
983 {
984 TerminateBackgroundWorker(pcxt->worker[i].bgwhandle);
985
986 shm_mq_detach(pcxt->worker[i].error_mqh);
987 pcxt->worker[i].error_mqh = NULL;
988 }
989 }
990 }
991
992 /*
993 * If we have allocated a shared memory segment, detach it. This will
994 * implicitly detach the error queues, and any other shared memory queues,
995 * stored there.
996 */
997 if (pcxt->seg != NULL)
998 {
999 dsm_detach(pcxt->seg);
1000 pcxt->seg = NULL;
1001 }
1002
1003 /*
1004 * If this parallel context is actually in backend-private memory rather
1005 * than shared memory, free that memory instead.
1006 */
1007 if (pcxt->private_memory != NULL)
1008 {
1009 pfree(pcxt->private_memory);
1010 pcxt->private_memory = NULL;
1011 }
1012
1013 /*
1014 * We can't finish transaction commit or abort until all of the workers
1015 * have exited. This means, in particular, that we can't respond to
1016 * interrupts at this stage.
1017 */
1018 HOLD_INTERRUPTS();
1019 WaitForParallelWorkersToExit(pcxt);
1020 RESUME_INTERRUPTS();
1021

Callers 6

AtEOSubXact_ParallelFunction · 0.85
AtEOXact_ParallelFunction · 0.85
end_parallel_vacuumFunction · 0.85
_bt_begin_parallelFunction · 0.85
_bt_end_parallelFunction · 0.85
ExecParallelCleanupFunction · 0.85

Calls 6

dlist_deleteFunction · 0.85
shm_mq_detachFunction · 0.85
dsm_detachFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected