Refactor CreateTenantStatsHashKey() to FillTenantStatsHashKey

pull/6868/head
Gokhan Gulbiz 2023-05-10 13:00:57 +03:00
parent f53b4cb1f8
commit 0466b8196a
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
1 changed files with 7 additions and 14 deletions

View File

@ -65,7 +65,7 @@ static MultiTenantMonitor * GetMultiTenantMonitor(void);
static void MultiTenantMonitorSMInit(void); static void MultiTenantMonitorSMInit(void);
static TenantStats * CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz static TenantStats * CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz
queryTime); queryTime);
static TenantStatsHashKey * CreateTenantStatsHashKey(char *tenantAttribute, uint32 static void FillTenantStatsHashKey(TenantStatsHashKey *key, char *tenantAttribute, uint32
colocationGroupId); colocationGroupId);
static TenantStats * FindTenantStats(MultiTenantMonitor *monitor); static TenantStats * FindTenantStats(MultiTenantMonitor *monitor);
static size_t MultiTenantMonitorshmemSize(void); static size_t MultiTenantMonitorshmemSize(void);
@ -706,14 +706,12 @@ CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz queryTime)
*/ */
EvictTenantsIfNecessary(queryTime); EvictTenantsIfNecessary(queryTime);
TenantStatsHashKey *key = CreateTenantStatsHashKey(AttributeToTenant, TenantStatsHashKey *key = (TenantStatsHashKey *) palloc(sizeof(TenantStatsHashKey));
AttributeToColocationGroupId); FillTenantStatsHashKey(key, AttributeToTenant, AttributeToColocationGroupId);
TenantStats *stats = (TenantStats *) hash_search(monitor->tenants, key, TenantStats *stats = (TenantStats *) hash_search(monitor->tenants, key,
HASH_ENTER, NULL); HASH_ENTER, NULL);
pfree(key);
stats->writesInLastPeriod = 0; stats->writesInLastPeriod = 0;
stats->writesInThisPeriod = 0; stats->writesInThisPeriod = 0;
stats->readsInLastPeriod = 0; stats->readsInLastPeriod = 0;
@ -735,27 +733,22 @@ CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz queryTime)
static TenantStats * static TenantStats *
FindTenantStats(MultiTenantMonitor *monitor) FindTenantStats(MultiTenantMonitor *monitor)
{ {
TenantStatsHashKey *key = CreateTenantStatsHashKey(AttributeToTenant, TenantStatsHashKey *key = (TenantStatsHashKey *) palloc(sizeof(TenantStatsHashKey));
AttributeToColocationGroupId); FillTenantStatsHashKey(key, AttributeToTenant, AttributeToColocationGroupId);
TenantStats *stats = (TenantStats *) hash_search(monitor->tenants, key, TenantStats *stats = (TenantStats *) hash_search(monitor->tenants, key,
HASH_FIND, NULL); HASH_FIND, NULL);
pfree(key);
return stats; return stats;
} }
static TenantStatsHashKey * static void
CreateTenantStatsHashKey(char *tenantAttribute, uint32 colocationGroupId) FillTenantStatsHashKey(TenantStatsHashKey *key, char *tenantAttribute, uint32 colocationGroupId)
{ {
TenantStatsHashKey *key = (TenantStatsHashKey *) palloc(sizeof(TenantStatsHashKey));
memset(key->tenantAttribute, 0, MAX_TENANT_ATTRIBUTE_LENGTH); memset(key->tenantAttribute, 0, MAX_TENANT_ATTRIBUTE_LENGTH);
strlcpy(key->tenantAttribute, tenantAttribute, MAX_TENANT_ATTRIBUTE_LENGTH); strlcpy(key->tenantAttribute, tenantAttribute, MAX_TENANT_ATTRIBUTE_LENGTH);
key->colocationGroupId = colocationGroupId; key->colocationGroupId = colocationGroupId;
return key;
} }