From 9c4c40217b4615f003ed3460d3e73b38459791a2 Mon Sep 17 00:00:00 2001 From: Gokhan Gulbiz Date: Tue, 9 May 2023 17:05:31 +0300 Subject: [PATCH] Use HASH_BLOB flag for tenants --- .../distributed/utils/citus_stat_tenants.c | 41 +------------------ .../distributed/utils/citus_stat_tenants.h | 2 + 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/backend/distributed/utils/citus_stat_tenants.c b/src/backend/distributed/utils/citus_stat_tenants.c index eff70839b..3f28e215c 100644 --- a/src/backend/distributed/utils/citus_stat_tenants.c +++ b/src/backend/distributed/utils/citus_stat_tenants.c @@ -68,8 +68,6 @@ static TenantStats * CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz static TenantStatsHashKey * CreateTenantStatsHashKey(char *tenantAttribute, uint32 colocationGroupId); static TenantStats * FindTenantStats(MultiTenantMonitor *monitor); -static uint32 TenantStatsHashFn(const void *key, Size keysize); -static int TenantStatsMatchFn(const void *key1, const void *key2, Size keysize); static size_t MultiTenantMonitorshmemSize(void); static char * ExtractTopComment(const char *inputString); static char * EscapeCommentChars(const char *str); @@ -636,13 +634,11 @@ CreateSharedMemoryForMultiTenantMonitor() memset(&info, 0, sizeof(info)); info.keysize = sizeof(TenantStatsHashKey); info.entrysize = sizeof(TenantStats); - info.hash = TenantStatsHashFn; - info.match = TenantStatsMatchFn; monitor->tenants = ShmemInitHash("citus_stats_tenants hash", StatTenantsLimit * 3, StatTenantsLimit * 3, - &info, HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | - HASH_SHARED_MEM); + &info, HASH_ELEM | + HASH_SHARED_MEM | HASH_BLOBS); return monitor; } @@ -768,39 +764,6 @@ CreateTenantStatsHashKey(char *tenantAttribute, uint32 colocationGroupId) } -/* - * CitusQuerysStatsHashFn calculates and returns hash value for a key - */ -static uint32 -TenantStatsHashFn(const void *key, Size keysize) -{ - const TenantStatsHashKey *k = (const TenantStatsHashKey *) key; - - return hash_any((const unsigned char *) (k->tenantAttribute), strlen( - k->tenantAttribute)) ^ - hash_uint32((uint32) k->colocationGroupId); -} - - -/* - * TenantStatsMatchFn compares two keys - zero means match. - * See definition of HashCompareFunc in hsearch.h for more info. - */ -static int -TenantStatsMatchFn(const void *key1, const void *key2, Size keysize) -{ - const TenantStatsHashKey *k1 = (const TenantStatsHashKey *) key1; - const TenantStatsHashKey *k2 = (const TenantStatsHashKey *) key2; - - if (strcmp(k1->tenantAttribute, k2->tenantAttribute) == 0 && - k1->colocationGroupId == k2->colocationGroupId) - { - return 0; - } - return 1; -} - - /* * MultiTenantMonitorshmemSize calculates the size of the multi tenant monitor using * StatTenantsLimit parameter. diff --git a/src/include/distributed/utils/citus_stat_tenants.h b/src/include/distributed/utils/citus_stat_tenants.h index bbea85d3e..6acbd5de7 100644 --- a/src/include/distributed/utils/citus_stat_tenants.h +++ b/src/include/distributed/utils/citus_stat_tenants.h @@ -11,6 +11,7 @@ #ifndef CITUS_ATTRIBUTE_H #define CITUS_ATTRIBUTE_H +#include "distributed/hash_helpers.h" #include "executor/execdesc.h" #include "executor/executor.h" #include "storage/lwlock.h" @@ -28,6 +29,7 @@ typedef struct TenantStatsHashKey char tenantAttribute[MAX_TENANT_ATTRIBUTE_LENGTH]; int colocationGroupId; } TenantStatsHashKey; +assert_valid_hash_key2(TenantStatsHashKey, tenantAttribute, colocationGroupId); /* * TenantStats is the struct that keeps statistics about one tenant.