* 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. */
| 922 | * received by the leader backend whereas this ensures the complete shutdown. |
| 923 | */ |
| 924 | static void |
| 925 | WaitForParallelWorkersToExit(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. |
no test coverage detected