* Handle a single protocol message received from a single parallel worker. */
| 1149 | * Handle a single protocol message received from a single parallel worker. |
| 1150 | */ |
| 1151 | static void |
| 1152 | HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg) |
| 1153 | { |
| 1154 | char msgtype; |
| 1155 | |
| 1156 | if (pcxt->known_attached_workers != NULL && |
| 1157 | !pcxt->known_attached_workers[i]) |
| 1158 | { |
| 1159 | pcxt->known_attached_workers[i] = true; |
| 1160 | pcxt->nknown_attached_workers++; |
| 1161 | } |
| 1162 | |
| 1163 | msgtype = pq_getmsgbyte(msg); |
| 1164 | |
| 1165 | switch (msgtype) |
| 1166 | { |
| 1167 | case 'K': /* BackendKeyData */ |
| 1168 | { |
| 1169 | int32 pid = pq_getmsgint(msg, 4); |
| 1170 | |
| 1171 | (void) pq_getmsgint(msg, 4); /* discard cancel key */ |
| 1172 | (void) pq_getmsgend(msg); |
| 1173 | pcxt->worker[i].pid = pid; |
| 1174 | break; |
| 1175 | } |
| 1176 | |
| 1177 | case 'E': /* ErrorResponse */ |
| 1178 | case 'N': /* NoticeResponse */ |
| 1179 | { |
| 1180 | ErrorData edata; |
| 1181 | ErrorContextCallback *save_error_context_stack; |
| 1182 | |
| 1183 | /* Parse ErrorResponse or NoticeResponse. */ |
| 1184 | pq_parse_errornotice(msg, &edata); |
| 1185 | |
| 1186 | /* Death of a worker isn't enough justification for suicide. */ |
| 1187 | edata.elevel = Min(edata.elevel, ERROR); |
| 1188 | |
| 1189 | /* |
| 1190 | * If desired, add a context line to show that this is a |
| 1191 | * message propagated from a parallel worker. Otherwise, it |
| 1192 | * can sometimes be confusing to understand what actually |
| 1193 | * happened. (We don't do this in FORCE_PARALLEL_REGRESS mode |
| 1194 | * because it causes test-result instability depending on |
| 1195 | * whether a parallel worker is actually used or not.) |
| 1196 | */ |
| 1197 | if (force_parallel_mode != FORCE_PARALLEL_REGRESS) |
| 1198 | { |
| 1199 | if (edata.context) |
| 1200 | edata.context = psprintf("%s\n%s", edata.context, |
| 1201 | _("parallel worker")); |
| 1202 | else |
| 1203 | edata.context = pstrdup(_("parallel worker")); |
| 1204 | } |
| 1205 | |
| 1206 | /* |
| 1207 | * Context beyond that should use the error context callbacks |
| 1208 | * that were in effect when the ParallelContext was created, |
no test coverage detected