* 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. */
| 317 | * the necessary wire protocol format. |
| 318 | */ |
| 319 | static pgbson * |
| 320 | CollStatsCoordinator(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 | /* |
no test coverage detected