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

Function MergeBloatStatsBsons

pg_documentdb/src/utils/storage_utils.c:185–217  ·  view source on GitHub ↗

* Merges the bloat stats from all the workers into a single * CollectionBloatStats object. */

Source from the content-addressed store, hash-verified

183 * CollectionBloatStats object.
184 */
185static CollectionBloatStats
186MergeBloatStatsBsons(List *workerBsons)
187{
188 CollectionBloatStats bloatStats;
189 memset(&bloatStats, 0, sizeof(CollectionBloatStats));
190 bloatStats.nullStats = true;
191
192 ListCell *workerCell;
193 foreach(workerCell, workerBsons)
194 {
195 pgbson *workerBson = lfirst(workerCell);
196 bson_iter_t iter;
197 PgbsonInitIterator(workerBson, &iter);
198 while (bson_iter_next(&iter))
199 {
200 /* Non-Empty stats, reset nullStats */
201 bloatStats.nullStats = false;
202
203 const char *key = bson_iter_key(&iter);
204 const bson_value_t *value = bson_iter_value(&iter);
205 if (key[0] == 'b')
206 {
207 bloatStats.estimatedBloatStorage += BsonValueAsInt64(value);
208 }
209 else if (key[0] == 't')
210 {
211 bloatStats.estimatedTableStorage += BsonValueAsInt64(value);
212 }
213 }
214 }
215
216 return bloatStats;
217}

Callers 1

Calls 3

PgbsonInitIteratorFunction · 0.85
BsonValueAsInt64Function · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected