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

Function WaitForParallelWorkersToExit

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

* Wait for all workers to exit. * * This function ensures that workers have been completely shutdown. The * difference between WaitForParallelWorkersToFinish and this function is * that the former just ensures that last message sent by a worker backend is * received by the leader backend whereas this ensures the complete shutdown. */

Source from the content-addressed store, hash-verified

922 * received by the leader backend whereas this ensures the complete shutdown.
923 */
924static void
925WaitForParallelWorkersToExit(ParallelContext *pcxt)
926{
927 int i;
928
929 /* Wait until the workers actually die. */
930 for (i = 0; i < pcxt->nworkers_launched; ++i)
931 {
932 BgwHandleStatus status;
933
934 if (pcxt->worker == NULL || pcxt->worker[i].bgwhandle == NULL)
935 continue;
936
937 status = WaitForBackgroundWorkerShutdown(pcxt->worker[i].bgwhandle);
938
939 /*
940 * If the postmaster kicked the bucket, we have no chance of cleaning
941 * up safely -- we won't be able to tell when our workers are actually
942 * dead. This doesn't necessitate a PANIC since they will all abort
943 * eventually, but we can't safely continue this session.
944 */
945 if (status == BGWH_POSTMASTER_DIED)
946 ereport(FATAL,
947 (errcode(ERRCODE_ADMIN_SHUTDOWN),
948 errmsg("postmaster exited during a parallel transaction")));
949
950 /* Release memory. */
951 pfree(pcxt->worker[i].bgwhandle);
952 pcxt->worker[i].bgwhandle = NULL;
953 }
954}
955
956/*
957 * Destroy a parallel context.

Callers 2

ReinitializeParallelDSMFunction · 0.85
DestroyParallelContextFunction · 0.85

Calls 4

errcodeFunction · 0.50
errmsgFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected