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

Function ExecAppendAsyncEventWait

src/backend/executor/nodeAppend.c:1059–1138  ·  view source on GitHub ↗

---------------------------------------------------------------- * ExecAppendAsyncEventWait * * Wait or poll for file descriptor events and fire callbacks. * ---------------------------------------------------------------- */

Source from the content-addressed store, hash-verified

1057 * ----------------------------------------------------------------
1058 */
1059static void
1060ExecAppendAsyncEventWait(AppendState *node)
1061{
1062 int nevents = node->as_nasyncplans + 1;
1063 long timeout = node->as_syncdone ? -1 : 0;
1064 WaitEvent occurred_event[EVENT_BUFFER_SIZE];
1065 int noccurred;
1066 int i;
1067
1068 /* We should never be called when there are no valid async subplans. */
1069 Assert(node->as_nasyncremain > 0);
1070
1071 node->as_eventset = CreateWaitEventSet(CurrentMemoryContext, nevents);
1072 AddWaitEventToSet(node->as_eventset, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET,
1073 NULL, NULL);
1074
1075 /* Give each waiting subplan a chance to add an event. */
1076 i = -1;
1077 while ((i = bms_next_member(node->as_asyncplans, i)) >= 0)
1078 {
1079 AsyncRequest *areq = node->as_asyncrequests[i];
1080
1081 if (areq->callback_pending)
1082 ExecAsyncConfigureWait(areq);
1083 }
1084
1085 /*
1086 * No need for further processing if there are no configured events other
1087 * than the postmaster death event.
1088 */
1089 if (GetNumRegisteredWaitEvents(node->as_eventset) == 1)
1090 {
1091 FreeWaitEventSet(node->as_eventset);
1092 node->as_eventset = NULL;
1093 return;
1094 }
1095
1096 /* We wait on at most EVENT_BUFFER_SIZE events. */
1097 if (nevents > EVENT_BUFFER_SIZE)
1098 nevents = EVENT_BUFFER_SIZE;
1099
1100 /*
1101 * If the timeout is -1, wait until at least one event occurs. If the
1102 * timeout is 0, poll for events, but do not wait at all.
1103 */
1104 noccurred = WaitEventSetWait(node->as_eventset, timeout, occurred_event,
1105 nevents, WAIT_EVENT_APPEND_READY);
1106 FreeWaitEventSet(node->as_eventset);
1107 node->as_eventset = NULL;
1108 if (noccurred == 0)
1109 return;
1110
1111 /* Deliver notifications. */
1112 for (i = 0; i < noccurred; i++)
1113 {
1114 WaitEvent *w = &occurred_event[i];
1115
1116 /*

Callers 2

ExecAppendFunction · 0.85
ExecAppendAsyncGetNextFunction · 0.85

Calls 8

CreateWaitEventSetFunction · 0.85
AddWaitEventToSetFunction · 0.85
bms_next_memberFunction · 0.85
ExecAsyncConfigureWaitFunction · 0.85
FreeWaitEventSetFunction · 0.85
WaitEventSetWaitFunction · 0.85
ExecAsyncNotifyFunction · 0.85

Tested by

no test coverage detected