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

Function InitializeCollectionsHash

pg_documentdb/src/metadata/collection.c:172–219  ·  view source on GitHub ↗

* InitializeCollectionsHash (re)creates the collections hashes if they are * not valid. * * At the end of this function, either CollectionCacheIsValid is true or * an OOM was thrown. In the latter case, we will try again on the next * call. */

Source from the content-addressed store, hash-verified

170 * call.
171 */
172static void
173InitializeCollectionsHash(void)
174{
175 /* make sure the metadata cache is initalized */
176 InitializeDocumentDBApiExtensionCache();
177
178 /* should not call this function if extension does not exist */
179 Assert(IsDocumentDBApiExtensionActive());
180
181 if (CollectionCacheIsValid)
182 {
183 /* already built the hashes */
184 return;
185 }
186
187 if (CollectionsCacheContext == NULL)
188 {
189 CollectionsCacheContext = AllocSetContextCreate(CacheMemoryContext,
190 "Cache context for collection",
191 ALLOCSET_DEFAULT_SIZES);
192 }
193
194 /* reset any previously allocated memory */
195 MemoryContextReset(CollectionsCacheContext);
196
197 int hashFlags = HASH_ELEM | HASH_BLOBS | HASH_CONTEXT;
198
199 /* create the (database name, collection name) -> collection hash */
200 HASHCTL info;
201 memset(&info, 0, sizeof(info));
202 info.keysize = sizeof(MongoCollectionName);
203 info.entrysize = sizeof(NameToCollectionCacheEntry);
204 info.hcxt = CollectionsCacheContext;
205
206 NameToCollectionHash = hash_create("Name to Collection ID Hash", 32,
207 &info, hashFlags);
208
209 /* create the (relation OID) -> collection hash */
210 memset(&info, 0, sizeof(info));
211 info.keysize = sizeof(Oid);
212 info.entrysize = sizeof(RelationIdToCollectionCacheEntry);
213 info.hcxt = CollectionsCacheContext;
214
215 RelationIdToCollectionHash = hash_create("Relation ID to Collection ID Hash", 32,
216 &info, hashFlags);
217
218 CollectionCacheIsValid = true;
219}
220
221
222/*

Callers 2

Tested by

no test coverage detected