* As part of the worker merge, each worker sends back a list of index sizes. * Here we need to merge all the index sizes into a common document * that is ordered by index name from the collection_indexes table (for stability). */
| 577 | * that is ordered by index name from the collection_indexes table (for stability). |
| 578 | */ |
| 579 | static pgbson * |
| 580 | MergeWorkerIndexDocs(MongoCollection *collection, List *workerIndexDocs, int32 scale, |
| 581 | int *indexCount) |
| 582 | { |
| 583 | *indexCount = 0; |
| 584 | HTAB *bsonElementHash = CreatePgbsonElementHashSet(); |
| 585 | |
| 586 | /* First run through the worker index docs - |
| 587 | * For each doc, add the { "indexName": (int64)indexSize } |
| 588 | * into the bsonElement hash. If the entry for that indexName |
| 589 | * already exists, add to the existing size. |
| 590 | */ |
| 591 | ListCell *indexCell; |
| 592 | foreach(indexCell, workerIndexDocs) |
| 593 | { |
| 594 | bson_value_t *value = lfirst(indexCell); |
| 595 | bson_iter_t indexDocIter; |
| 596 | BsonValueInitIterator(value, &indexDocIter); |
| 597 | |
| 598 | while (bson_iter_next(&indexDocIter)) |
| 599 | { |
| 600 | pgbsonelement element = { 0 }; |
| 601 | element.path = bson_iter_key(&indexDocIter); |
| 602 | element.pathLength = bson_iter_key_len(&indexDocIter); |
| 603 | element.bsonValue = *bson_iter_value(&indexDocIter); |
| 604 | |
| 605 | bool found = false; |
| 606 | pgbsonelement *foundVal = hash_search(bsonElementHash, &element, HASH_ENTER, |
| 607 | &found); |
| 608 | if (found) |
| 609 | { |
| 610 | bool overflowedIgnore = false; |
| 611 | AddNumberToBsonValue(&foundVal->bsonValue, &element.bsonValue, |
| 612 | &overflowedIgnore); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | * Get the existing set of names (ordered) from the collection_indexes |
| 619 | * table. |
| 620 | */ |
| 621 | bool excludeIdIndex = false; |
| 622 | bool inProgressOnly = false; |
| 623 | List *indexNames = CollectionIdGetIndexNames(collection->collectionId, excludeIdIndex, |
| 624 | inProgressOnly); |
| 625 | *indexCount = list_length(indexNames); |
| 626 | |
| 627 | pgbson_writer writer; |
| 628 | PgbsonWriterInit(&writer); |
| 629 | ListCell *cell; |
| 630 | |
| 631 | /* |
| 632 | * Now write out the aggregate sizes of the indexes in the order in which the indexes |
| 633 | * are returned from the collection_indexes table. |
| 634 | */ |
| 635 | foreach(cell, indexNames) |
| 636 | { |
no test coverage detected