* Logic that builds the currentOp responses (only runs on query coordinator) */
| 346 | * Logic that builds the currentOp responses (only runs on query coordinator) |
| 347 | */ |
| 348 | static void |
| 349 | MergeWorkerBsons(List *workerBsons, TupleDesc descriptor, Tuplestorestate *tupleStore) |
| 350 | { |
| 351 | ListCell *workerCell; |
| 352 | foreach(workerCell, workerBsons) |
| 353 | { |
| 354 | pgbson *workerBson = lfirst(workerCell); |
| 355 | bson_iter_t workerIter; |
| 356 | PgbsonInitIterator(workerBson, &workerIter); |
| 357 | |
| 358 | int errorCode = 0; |
| 359 | const char *errorMessage = NULL; |
| 360 | while (bson_iter_next(&workerIter)) |
| 361 | { |
| 362 | const char *key = bson_iter_key(&workerIter); |
| 363 | if (strcmp(key, ErrCodeKey) == 0) |
| 364 | { |
| 365 | errorCode = BsonValueAsInt32(bson_iter_value(&workerIter)); |
| 366 | } |
| 367 | else if (strcmp(key, ErrMsgKey) == 0) |
| 368 | { |
| 369 | const char *string = bson_iter_utf8(&workerIter, NULL); |
| 370 | errorMessage = pstrdup(string); |
| 371 | } |
| 372 | else if (strcmp(key, "activities") == 0) |
| 373 | { |
| 374 | bson_iter_t activityIter; |
| 375 | if (bson_iter_recurse(&workerIter, &activityIter)) |
| 376 | { |
| 377 | while (bson_iter_next(&activityIter)) |
| 378 | { |
| 379 | pgbson *docBson = PgbsonInitFromDocumentBsonValue(bson_iter_value( |
| 380 | & |
| 381 | activityIter)); |
| 382 | |
| 383 | Datum tupleValue[1] = { PointerGetDatum(docBson) }; |
| 384 | bool nulls[1] = { false }; |
| 385 | tuplestore_putvalues(tupleStore, descriptor, tupleValue, nulls); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | ereport(ERROR, (errmsg("unknown field received from currentOp worker %s", |
| 392 | key))); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | if (errorMessage != NULL) |
| 397 | { |
| 398 | errorCode = errorCode == 0 ? ERRCODE_DOCUMENTDB_INTERNALERROR : errorCode; |
| 399 | ereport(ERROR, (errcode(errorCode), errmsg("Error running currentOp: %s", |
| 400 | errorMessage))); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 |
no test coverage detected