Use HASH_BLOB flag for tenants

pull/6868/head
Gokhan Gulbiz 2023-05-09 17:05:31 +03:00
parent 301c258849
commit 9c4c40217b
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
2 changed files with 4 additions and 39 deletions

View File

@ -68,8 +68,6 @@ static TenantStats * CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz
static TenantStatsHashKey * CreateTenantStatsHashKey(char *tenantAttribute, uint32 static TenantStatsHashKey * CreateTenantStatsHashKey(char *tenantAttribute, uint32
colocationGroupId); colocationGroupId);
static TenantStats * FindTenantStats(MultiTenantMonitor *monitor); 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 size_t MultiTenantMonitorshmemSize(void);
static char * ExtractTopComment(const char *inputString); static char * ExtractTopComment(const char *inputString);
static char * EscapeCommentChars(const char *str); static char * EscapeCommentChars(const char *str);
@ -636,13 +634,11 @@ CreateSharedMemoryForMultiTenantMonitor()
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.keysize = sizeof(TenantStatsHashKey); info.keysize = sizeof(TenantStatsHashKey);
info.entrysize = sizeof(TenantStats); info.entrysize = sizeof(TenantStats);
info.hash = TenantStatsHashFn;
info.match = TenantStatsMatchFn;
monitor->tenants = ShmemInitHash("citus_stats_tenants hash", monitor->tenants = ShmemInitHash("citus_stats_tenants hash",
StatTenantsLimit * 3, StatTenantsLimit * 3, StatTenantsLimit * 3, StatTenantsLimit * 3,
&info, HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | &info, HASH_ELEM |
HASH_SHARED_MEM); HASH_SHARED_MEM | HASH_BLOBS);
return monitor; 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 * MultiTenantMonitorshmemSize calculates the size of the multi tenant monitor using
* StatTenantsLimit parameter. * StatTenantsLimit parameter.

View File

@ -11,6 +11,7 @@
#ifndef CITUS_ATTRIBUTE_H #ifndef CITUS_ATTRIBUTE_H
#define CITUS_ATTRIBUTE_H #define CITUS_ATTRIBUTE_H
#include "distributed/hash_helpers.h"
#include "executor/execdesc.h" #include "executor/execdesc.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "storage/lwlock.h" #include "storage/lwlock.h"
@ -28,6 +29,7 @@ typedef struct TenantStatsHashKey
char tenantAttribute[MAX_TENANT_ATTRIBUTE_LENGTH]; char tenantAttribute[MAX_TENANT_ATTRIBUTE_LENGTH];
int colocationGroupId; int colocationGroupId;
} TenantStatsHashKey; } TenantStatsHashKey;
assert_valid_hash_key2(TenantStatsHashKey, tenantAttribute, colocationGroupId);
/* /*
* TenantStats is the struct that keeps statistics about one tenant. * TenantStats is the struct that keeps statistics about one tenant.