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

Function GetMongoCollectionByColId

pg_documentdb/src/metadata/collection.c:315–428  ·  view source on GitHub ↗

* GetMongoCollectionByColId() gets the MongoCollection metadata by collectionId. */

Source from the content-addressed store, hash-verified

313 * GetMongoCollectionByColId() gets the MongoCollection metadata by collectionId.
314 */
315MongoCollection *
316GetMongoCollectionByColId(uint64 collectionId, LOCKMODE lockMode)
317{
318 /* make sure hashes exist */
319 InitializeCollectionsHash();
320
321 Oid documentsTableOid = GetRelationIdForCollectionId(collectionId, lockMode);
322
323 if (!OidIsValid(documentsTableOid))
324 {
325 /* table was dropped */
326 return NULL;
327 }
328
329 bool foundInCache = false;
330
331 RelationIdToCollectionCacheEntry *entryByRelId =
332 hash_search(RelationIdToCollectionHash, &documentsTableOid, HASH_FIND,
333 &foundInCache);
334
335 if (foundInCache)
336 {
337 /* now that we have a lock, check for invalidations */
338 AcceptInvalidationMessages();
339
340 /*
341 * After acquiring the lock on the table, we may have received an invalidation
342 * that could indicate a rename. In that case, CollectionCacheIsValid or
343 * entry->isValid is set to false and we treat this as a cache miss by
344 * continuing below.
345 */
346 if (!CollectionCacheIsValid)
347 {
348 InitializeCollectionsHash();
349 }
350 else if (entryByRelId->isValid)
351 {
352 return CopyMongoCollection(&(entryByRelId->collection));
353 }
354 }
355
356 MongoCollection collection;
357 memset(&collection, 0, sizeof(collection));
358
359 /*
360 * Temporarily disable unimportant logs related to collection catalog lookup
361 * so that regression test outputs don't become flaky (e.g.: due to commands
362 * being executed by Citus locally).
363 */
364 int savedGUCLevel = NewGUCNestLevel();
365 SetGUCLocally("client_min_messages", "WARNING");
366
367 /* Read the collection metadata from ApiCatalogSchemaName.collections */
368 bool collectionExists =
369 GetMongoCollectionFromCatalogById(collectionId, documentsTableOid,
370 &collection);
371
372 /* rollback the GUC change that we made for client_min_messages */

Tested by

no test coverage detected