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

Function CollStatsCoordinator

pg_documentdb/src/commands/coll_stats.c:319–359  ·  view source on GitHub ↗

* The core logic for coll stats on the entry point function * i.e. the Coordinator of the coll stats. * This function simply calls the "worker" collstats against * all available nodes, and then aggregates/merges the results into * the necessary wire protocol format. */

Source from the content-addressed store, hash-verified

317 * the necessary wire protocol format.
318 */
319static pgbson *
320CollStatsCoordinator(Datum databaseName, Datum collectionName, int scale)
321{
322 if (scale < 1)
323 {
324 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION51024), errmsg(
325 "The BSON field 'scale' must have a value of at least 1, but the provided value is '%d'.",
326 scale)));
327 }
328
329 StringInfo namespaceString = makeStringInfo();
330
331 appendStringInfo(namespaceString, "%.*s.%.*s",
332 (int) VARSIZE_ANY_EXHDR(databaseName),
333 (char *) VARDATA_ANY(databaseName),
334 (int) VARSIZE_ANY_EXHDR(collectionName),
335 (char *) VARDATA_ANY(collectionName));
336
337 CollStatsResult result = { 0 };
338 result.ns = namespaceString->data;
339 result.scaleFactor = scale;
340 result.ok = 1;
341
342 pgbson *response;
343 MongoCollection *collection =
344 GetMongoCollectionByNameDatum(databaseName,
345 collectionName,
346 AccessShareLock);
347 if (collection == NULL)
348 {
349 response = BuildEmptyResponseMessage(&result);
350 }
351 else
352 {
353 BuildResultData(databaseName, collectionName, &result, collection, scale,
354 CollStatsAggMode_CountAndStorage);
355 response = BuildResponseMessage(&result);
356 }
357
358 return response;
359}
360
361
362/*

Callers 1

command_coll_statsFunction · 0.85

Calls 4

BuildResultDataFunction · 0.70
BuildResponseMessageFunction · 0.70

Tested by

no test coverage detected