MCPcopy Create free account
hub / github.com/apache/cloudberry / InitCatCache

Function InitCatCache

src/backend/utils/cache/catcache.c:763–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

761#endif
762
763CatCache *
764InitCatCache(int id,
765 Oid reloid,
766 Oid indexoid,
767 int nkeys,
768 const int *key,
769 int nbuckets)
770{
771 CatCache *cp;
772 MemoryContext oldcxt;
773 size_t sz;
774 int i;
775
776 /*
777 * nbuckets is the initial number of hash buckets to use in this catcache.
778 * It will be enlarged later if it becomes too full.
779 *
780 * nbuckets must be a power of two. We check this via Assert rather than
781 * a full runtime check because the values will be coming from constant
782 * tables.
783 *
784 * If you're confused by the power-of-two check, see comments in
785 * bitmapset.c for an explanation.
786 */
787 Assert(nbuckets > 0 && (nbuckets & -nbuckets) == nbuckets);
788
789 /*
790 * first switch to the cache context so our allocations do not vanish at
791 * the end of a transaction
792 */
793 if (!CacheMemoryContext)
794 CreateCacheMemoryContext();
795
796 oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
797
798 /*
799 * if first time through, initialize the cache group header
800 */
801 if (CacheHdr == NULL)
802 {
803 CacheHdr = (CatCacheHeader *) palloc(sizeof(CatCacheHeader));
804 slist_init(&CacheHdr->ch_caches);
805 CacheHdr->ch_ntup = 0;
806#ifdef CATCACHE_STATS
807 /* set up to dump stats at backend exit */
808 on_proc_exit(CatCachePrintStats, 0);
809#endif
810 }
811
812 /*
813 * Allocate a new cache structure, aligning to a cacheline boundary
814 *
815 * Note: we rely on zeroing to initialize all the dlist headers correctly
816 */
817 sz = sizeof(CatCache) + PG_CACHE_LINE_SIZE;
818 cp = (CatCache *) CACHELINEALIGN(palloc0(sz));
819 cp->cc_bucket = palloc0(nbuckets * sizeof(dlist_head));
820

Callers 1

InitCatalogCacheFunction · 0.85

Calls 7

CreateCacheMemoryContextFunction · 0.85
MemoryContextSwitchToFunction · 0.85
slist_initFunction · 0.85
on_proc_exitFunction · 0.85
slist_push_headFunction · 0.85
pallocFunction · 0.50
palloc0Function · 0.50

Tested by

no test coverage detected