MCPcopy Create free account
hub / github.com/documentdb/documentdb / BuildResultData

Function BuildResultData

pg_documentdb/src/commands/db_stats.c:272–324  ·  view source on GitHub ↗

* Helper method on the coordinator that populates the * DbStatsResult with the merged worker statistics (along with any * additional statistics that may be needed from the coordinator). */

Source from the content-addressed store, hash-verified

270 * additional statistics that may be needed from the coordinator).
271 */
272static void
273BuildResultData(Datum databaseName, DbStatsResult *result, int32 scale)
274{
275 int64 numViews = 0;
276 List *collectionIdsList = GetAllCollectionIdsInDb(databaseName, &numViews);
277 int64 numCollections = list_length(collectionIdsList);
278
279 result->collections = numCollections;
280 result->views = numViews;
281
282 if (numCollections == 0)
283 {
284 /* When no collections, skip gathering data from workers */
285 return;
286 }
287
288 Datum *collectionIdDatums = palloc0(sizeof(Datum) * numCollections);
289
290 int64 i = 0;
291 uint64 collectionId;
292 ListCell *cell;
293 foreach(cell, collectionIdsList)
294 {
295 CHECK_FOR_INTERRUPTS();
296 collectionId = *(uint64 *) lfirst(cell);
297 collectionIdDatums[i] = Int64GetDatum(collectionId);
298 i++;
299 }
300
301 ArrayType *collectionIdArray = construct_array(collectionIdDatums, numCollections,
302 INT8OID,
303 sizeof(uint64), true,
304 TYPALIGN_INT);
305
306 List *workerBsons;
307 int numValues = 1;
308 Datum values[1] = { PointerGetDatum(collectionIdArray) };
309 Oid types[1] = { INT8ARRAYOID };
310
311 workerBsons = RunQueryOnAllServerNodes("DbStats", values, types, numValues,
312 command_db_stats_worker,
313 ApiInternalSchemaName,
314 "db_stats_worker");
315
316 /* Now that we have the worker BSON results, merge them to the final one */
317 MergeWorkerResults(result, workerBsons, scale);
318
319 /* Get the count of Indexes for all the collections in array.
320 * Querying index metadata needs to happen on the coordinator since
321 * the index metadata is only present at coordinator
322 */
323 result->indexes = CollectionIdsGetIndexCount(collectionIdArray);
324}
325
326
327/*

Callers 1

DbStatsCoordinatorFunction · 0.70

Calls 5

GetAllCollectionIdsInDbFunction · 0.85
RunQueryOnAllServerNodesFunction · 0.85
MergeWorkerResultsFunction · 0.70
foreachFunction · 0.50

Tested by

no test coverage detected