* Parses the per node worker results and returns a post-processed * set of index documents that can be merged. */
| 281 | * set of index documents that can be merged. |
| 282 | */ |
| 283 | static List * |
| 284 | ParseWorkerResults(List *workerResults) |
| 285 | { |
| 286 | ListCell *workerCell; |
| 287 | |
| 288 | List *indexDocs = NIL; |
| 289 | foreach(workerCell, workerResults) |
| 290 | { |
| 291 | pgbson *workerBson = lfirst(workerCell); |
| 292 | bson_iter_t workerIter; |
| 293 | PgbsonInitIterator(workerBson, &workerIter); |
| 294 | |
| 295 | int errorCode = 0; |
| 296 | const char *errorMessage = NULL; |
| 297 | |
| 298 | while (bson_iter_next(&workerIter)) |
| 299 | { |
| 300 | const char *key = bson_iter_key(&workerIter); |
| 301 | if (strcmp(key, ErrCodeKey) == 0) |
| 302 | { |
| 303 | errorCode = BsonValueAsInt32(bson_iter_value(&workerIter)); |
| 304 | } |
| 305 | else if (strcmp(key, ErrMsgKey) == 0) |
| 306 | { |
| 307 | const char *string = bson_iter_utf8(&workerIter, NULL); |
| 308 | errorMessage = pstrdup(string); |
| 309 | } |
| 310 | else if (strcmp(key, IndexUsageKey) == 0) |
| 311 | { |
| 312 | bson_value_t *value = palloc(sizeof(bson_value_t)); |
| 313 | *value = *bson_iter_value(&workerIter); |
| 314 | indexDocs = lappend(indexDocs, value); |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | ereport(ERROR, (errmsg("unknown field received from indexStats worker %s", |
| 319 | key))); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | if (errorMessage != NULL) |
| 324 | { |
| 325 | errorCode = errorCode == 0 ? ERRCODE_DOCUMENTDB_INTERNALERROR : errorCode; |
| 326 | ereport(ERROR, (errcode(errorCode), errmsg("Error running indexStats %s", |
| 327 | errorMessage))); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | return indexDocs; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | /* |
no test coverage detected