* Given a List of bsons that were dispatched by the query workers, * and a given collection & scale, merges the results into the target * DbStatsResult struct. */
| 420 | * DbStatsResult struct. |
| 421 | */ |
| 422 | static void |
| 423 | MergeWorkerResults(DbStatsResult *result, |
| 424 | List *workerResults, int32 scale) |
| 425 | { |
| 426 | /* To merge the results, we apply each shard's results consecutively until we have everything |
| 427 | * each field is processed by its intent |
| 428 | */ |
| 429 | |
| 430 | ListCell *workerCell; |
| 431 | |
| 432 | int64 totalDocCount = 0; |
| 433 | int64 totalAllDocsSize = 0; |
| 434 | int64 totalStorageSize = 0; |
| 435 | int64 totalIndexSize = 0; |
| 436 | int64 totalTotalSize = 0; |
| 437 | |
| 438 | foreach(workerCell, workerResults) |
| 439 | { |
| 440 | pgbson *workerBson = lfirst(workerCell); |
| 441 | bson_iter_t workerIter; |
| 442 | PgbsonInitIterator(workerBson, &workerIter); |
| 443 | |
| 444 | int64 workerDocCount = 0; |
| 445 | int32 workerAvgDocSize = 0; |
| 446 | int64 workerStorageSize = 0; |
| 447 | int64 workerIndexSize = 0; |
| 448 | int64 workerTotalSize = 0; |
| 449 | |
| 450 | int errorCode = 0; |
| 451 | const char *errorMessage = NULL; |
| 452 | |
| 453 | while (bson_iter_next(&workerIter)) |
| 454 | { |
| 455 | const char *key = bson_iter_key(&workerIter); |
| 456 | if (strcmp(key, ErrCodeKey) == 0) |
| 457 | { |
| 458 | errorCode = BsonValueAsInt32(bson_iter_value(&workerIter)); |
| 459 | } |
| 460 | else if (strcmp(key, ErrMsgKey) == 0) |
| 461 | { |
| 462 | const char *string = bson_iter_utf8(&workerIter, NULL); |
| 463 | errorMessage = pstrdup(string); |
| 464 | } |
| 465 | else if (strcmp(key, "total_rel_size") == 0) |
| 466 | { |
| 467 | /* associative - sum up across nodes */ |
| 468 | workerTotalSize = BsonValueAsInt64(bson_iter_value(&workerIter)); |
| 469 | } |
| 470 | else if (strcmp(key, "total_tbl_size") == 0) |
| 471 | { |
| 472 | /* associative - sum up across nodes */ |
| 473 | workerStorageSize = BsonValueAsInt64(bson_iter_value(&workerIter)); |
| 474 | } |
| 475 | else if (strcmp(key, "total_doc_count") == 0) |
| 476 | { |
| 477 | /* associative - sum up across nodes */ |
| 478 | workerDocCount = BsonValueAsInt64(bson_iter_value(&workerIter)); |
| 479 | } |
no test coverage detected