/* * Initialize the anchor hashtable component of the cache. Allocates * or attaches to an existing hashtable in shared memory. */ static void Cache_InitHashtable(CacheCtl *cacheCtl, Cache *cache) { Assert(NULL != cache); Assert(NULL != cacheCtl); Assert(NULL != cacheCtl->cacheName); SyncHTCtl syncHTCtl; MemSet(&syncHTCtl, 0, sizeof(syncHTCtl)); /* Initialize fields for the anchor hashtable */ /* Storing only hash codes in hashtable */ syncHTCtl.keySize = sizeof(uint32); syncHTCtl.hash = int32_hash; syncHTCtl.keyCopy = memcpy; syncHTCtl.match = memcmp; /* Entries in the hashtable are CacheAnchors */ syncHTCtl.entrySize = sizeof(CacheAnchor); /* Partitions and associated locks */ syncHTCtl.numPartitions = cacheCtl->numPartitions; syncHTCtl.baseLWLockId = cacheCtl->baseLWLockId; /* Name of the hashtable is the name of the cache + CACHE_HASHTABLE_SUFFIX */ uint32 nameLength = strlen(cacheCtl->cacheName) + strlen(CACHE_HASHTABLE_SUFFIX) + 1; char *hashName = (char *) palloc(nameLength); snprintf(hashName, nameLength, "%s%s", cacheCtl->cacheName, CACHE_HASHTABLE_SUFFIX); syncHTCtl.tabName = hashName; /* Create anchor hashtable with the same number of elements as the cache */ syncHTCtl.numElements = cacheCtl->maxSize; /* Offsets to fields in the entry required by the SyncHashtable */ syncHTCtl.keyOffset = GPDB_OFFSET(CacheAnchor, hashvalue); syncHTCtl.pinCountOffset = GPDB_OFFSET(CacheAnchor, pinCount); /* Callbacks for SyncHashtable to manipulate anchor entries */ syncHTCtl.isEmptyEntry = Cache_IsAnchorEmpty; syncHTCtl.initEntry = Cache_InitAnchor; /* Create or attach to the anchor hashtable */ cache->syncHashtable = SyncHTCreate(&syncHTCtl); Assert(cache->syncHashtable != NULL); pfree(hashName); }
/* * Initialize the cache in shared memory, or attach to an existing one * */ void workfile_mgr_cache_init(void) { CacheCtl cacheCtl; MemSet(&cacheCtl, 0, sizeof(CacheCtl)); cacheCtl.maxSize = gp_workfile_max_entries; cacheCtl.cacheName = "Workfile Manager Cache"; cacheCtl.entrySize = sizeof(workfile_set); cacheCtl.keySize = sizeof(((workfile_set *)0)->key); cacheCtl.keyOffset = GPDB_OFFSET(workfile_set, key); cacheCtl.hash = int32_hash; cacheCtl.keyCopy = (HashCopyFunc) memcpy; cacheCtl.match = (HashCompareFunc) memcmp; cacheCtl.cleanupEntry = workfile_mgr_cleanup_set; cacheCtl.populateEntry = workfile_mgr_populate_set; cacheCtl.baseLWLockId = FirstWorkfileMgrLock; cacheCtl.numPartitions = NUM_WORKFILEMGR_PARTITIONS; workfile_mgr_cache = Cache_Create(&cacheCtl); Assert(NULL != workfile_mgr_cache); /* * Initialize the WorkfileDiskspace and WorkfileQueryspace APIs * to track disk space usage */ WorkfileDiskspace_Init(); }
/* * Initialize the shared memory data structures needed for MD Versioning * */ void mdver_shmem_init(void) { CacheCtl cacheCtl; MemSet(&cacheCtl, 0, sizeof(CacheCtl)); cacheCtl.maxSize = gp_mdver_max_entries; cacheCtl.cacheName = MDVER_GLOB_MDVN_SHMEM_NAME; cacheCtl.entrySize = sizeof(mdver_entry); cacheCtl.keySize = sizeof(((mdver_entry *)0)->key); cacheCtl.keyOffset = GPDB_OFFSET(mdver_entry, key); cacheCtl.hash = int32_hash; cacheCtl.keyCopy = (HashCopyFunc) memcpy; cacheCtl.match = (HashCompareFunc) memcmp; cacheCtl.equivalentEntries = mdver_entry_equivalent; cacheCtl.cleanupEntry = NULL; /* No cleanup necessary */ cacheCtl.populateEntry = mdver_entry_populate; cacheCtl.baseLWLockId = FirstMDVersioningLock; cacheCtl.numPartitions = NUM_MDVERSIONING_PARTITIONS; mdver_glob_mdvsn = Cache_Create(&cacheCtl); Assert(NULL != mdver_glob_mdvsn); bool attach = false; /* Allocate or attach to shared memory area */ void *shmem_base = ShmemInitStruct(MDVER_GLOBAL_VER_SHMEM_NAME, sizeof(*mdver_global_version_counter), &attach); mdver_global_version_counter = (int64 *)shmem_base; Assert(0 == *mdver_global_version_counter); }