* This is the core logic for db_stats that executes on * every node in the cluster. */
| 542 | * every node in the cluster. |
| 543 | */ |
| 544 | static pgbson * |
| 545 | DbStatsWorker(void *fcinfoPointer) |
| 546 | { |
| 547 | PG_FUNCTION_ARGS = fcinfoPointer; |
| 548 | ArrayType *collectionIdArray = PG_GETARG_ARRAYTYPE_P(0); |
| 549 | |
| 550 | /* First step, get the relevant shards on this node (We're already in the query worker) */ |
| 551 | ArrayType *shardNames = NULL; |
| 552 | ArrayType *shardOids = NULL; |
| 553 | |
| 554 | /* Next get the relation and table size */ |
| 555 | pgbson_writer writer; |
| 556 | PgbsonWriterInit(&writer); |
| 557 | |
| 558 | /* Only do work if there are shards */ |
| 559 | if (GetAllMongoCollectionShardOidsAndNamesInDB(collectionIdArray, &shardOids, |
| 560 | &shardNames)) |
| 561 | { |
| 562 | Assert(shardNames != NULL); |
| 563 | |
| 564 | /* |
| 565 | * Given the relevant shard tables, get the total size of the overall table |
| 566 | * that is relevant to this node (sum up the table sizes across the shards |
| 567 | * located in this node). |
| 568 | */ |
| 569 | int64 totalRelationSize, totalTableSize; |
| 570 | GetPostgresRelationSizes(shardOids, &totalRelationSize, &totalTableSize); |
| 571 | |
| 572 | /* Write it out to the target writer */ |
| 573 | PgbsonWriterAppendInt64(&writer, "total_rel_size", 14, totalRelationSize); |
| 574 | PgbsonWriterAppendInt64(&writer, "total_tbl_size", 14, totalTableSize); |
| 575 | |
| 576 | /* |
| 577 | * Next get statistics details: Fetch document count from statistics |
| 578 | * We don't do runtime counts here - instead we do it in the coordinator |
| 579 | * if it's needed. |
| 580 | */ |
| 581 | int64 documentCount = GetPostgresDocumentCountStats(shardOids); |
| 582 | |
| 583 | PgbsonWriterAppendInt64(&writer, "total_doc_count", 15, documentCount); |
| 584 | |
| 585 | /* |
| 586 | * Look at statistics for document sizes. |
| 587 | */ |
| 588 | int32 workerAvgDocSize = GetAverageDocumentSizeFromStats(shardNames); |
| 589 | PgbsonWriterAppendInt32(&writer, "avg_doc_size", 12, workerAvgDocSize); |
| 590 | |
| 591 | /* |
| 592 | * Get cumulative size of all indexes for given relationIds. |
| 593 | */ |
| 594 | int64 indexesSize = GetIndexSizesWorker(shardOids); |
| 595 | PgbsonWriterAppendInt64(&writer, "indexes_size", 12, indexesSize); |
| 596 | } |
| 597 | |
| 598 | return PgbsonWriterGetPgbson(&writer); |
| 599 | } |
| 600 | |
| 601 |
nothing calls this directly
no test coverage detected