diff --git a/src/diskquota.c b/src/diskquota.c index 834656da..2d9116b8 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -78,7 +78,7 @@ int diskquota_max_workers = 10; int diskquota_max_table_segments = 0; int diskquota_max_monitored_databases = 0; int diskquota_max_quota_probes = 0; -time_t diskquota_hashmap_overflow_report_timeout = 0; +int diskquota_hashmap_overflow_report_timeout = 0; DiskQuotaLocks diskquota_locks; ExtensionDDLMessage *extension_ddl_message = NULL; @@ -417,7 +417,8 @@ define_guc_variables(void) PGC_POSTMASTER, 0, NULL, NULL, NULL); DefineCustomIntVariable("diskquota.hashmap_overflow_report_timeout", "Time interval in seconds between shared hash map overflow report.", NULL, - &diskquota_hashmap_overflow_report_timeout, 60, 0, INT_MAX, PGC_SUSET, 0, NULL, NULL, NULL); + &diskquota_hashmap_overflow_report_timeout, 60, 0, INT_MAX / 1000, PGC_SUSET, 0, NULL, NULL, + NULL); } /* ---- Functions for disk quota worker process ---- */ diff --git a/src/diskquota.h b/src/diskquota.h index 006c62ab..28a6c469 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -286,7 +286,7 @@ extern Datum diskquota_fetch_table_stat(PG_FUNCTION_ARGS); extern int diskquota_naptime; extern int diskquota_max_active_tables; extern bool diskquota_hardlimit; -extern time_t diskquota_hashmap_overflow_report_timeout; +extern int diskquota_hashmap_overflow_report_timeout; extern int SEGCOUNT; extern int worker_spi_get_extension_version(int *major, int *minor); @@ -317,6 +317,6 @@ extern HTAB *diskquota_hash_create(const char *tabname, long nelem, HASHC extern HTAB *DiskquotaShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags, DiskquotaHashFunction hash_function); extern void refresh_monitored_dbid_cache(void); -extern void *shm_hash_enter(HTAB *hashp, void *keyPtr, bool *foundPtr, uint max_size, const char *warning_message, - time_t *last_overflow_report); +extern void *shm_hash_enter(HTAB *hashp, const void *keyPtr, bool *foundPtr, int max_size, const char *warning_message, + TimestampTz *last_overflow_report); #endif diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 2cfc28d3..14c192f2 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1678,9 +1678,9 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo infoP->hash = oid_hash; else infoP->hash = string_hash; - return ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_FUNCTION); + return ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_FUNCTION | HASH_FIXED_SIZE); #else - return ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_BLOBS); + return ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_BLOBS | HASH_FIXED_SIZE); #endif /* GP_VERSION_NUM */ } @@ -1688,22 +1688,16 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo // When overflowing, the warning warning_message will be report. But not more often than specified in // diskquota_hashmap_overflow_report_timeout. The time of the last warning is passed in last_overflow_report. void * -shm_hash_enter(HTAB *hashp, void *keyPtr, bool *foundPtr, uint max_size, const char *warning_message, - time_t *last_overflow_report) +shm_hash_enter(HTAB *hashp, const void *keyPtr, bool *foundPtr, int max_size, const char *warning_message, + TimestampTz *last_overflow_report) { - if (hash_get_num_entries(hashp) >= max_size) + void *result = hash_search(hashp, keyPtr, HASH_ENTER_NULL, foundPtr); + if (hash_get_num_entries(hashp) >= max_size && + TimestampDifferenceExceeds(*last_overflow_report, GetCurrentTimestamp(), + diskquota_hashmap_overflow_report_timeout * 1000)) { - return hash_search(hashp, keyPtr, HASH_FIND, foundPtr); - } - else - { - void *result = hash_search(hashp, keyPtr, HASH_ENTER, foundPtr); - if (hash_get_num_entries(hashp) >= max_size && - (time(NULL) - *last_overflow_report) >= diskquota_hashmap_overflow_report_timeout) - { - ereport(WARNING, (errmsg(warning_message, max_size))); - *last_overflow_report = time(NULL); - } - return result; + ereport(WARNING, (errmsg(warning_message, max_size))); + *last_overflow_report = GetCurrentTimestamp(); } + return result; } diff --git a/src/gp_activetable.c b/src/gp_activetable.c index 549a1c5f..4f6039f9 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -52,7 +52,7 @@ typedef struct DiskQuotaSetOFCache } DiskQuotaSetOFCache; HTAB *active_tables_map = NULL; // Set -time_t active_tables_last_overflow_report = 0; +TimestampTz active_tables_last_overflow_report = 0; #define ACTIVE_TABLE_ENTER(keyPtr, foundPtr) \ shm_hash_enter(active_tables_map, keyPtr, foundPtr, diskquota_max_active_tables, \ @@ -69,7 +69,7 @@ time_t active_tables_last_overflow_report = 0; * dbid will be removed from it when droping diskquota extension */ HTAB *altered_reloid_cache = NULL; // Set -time_t altered_reloid_cache_last_overflow_report = 0; +TimestampTz altered_reloid_cache_last_overflow_report = 0; #define ALTERED_RELOID_CACHE_ENTER(keyPtr, foundPtr) \ shm_hash_enter(altered_reloid_cache, keyPtr, foundPtr, diskquota_max_active_tables, \ diff --git a/src/quotamodel.c b/src/quotamodel.c index ed3f6b16..cb73de8d 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -473,7 +473,7 @@ disk_quota_shmem_startup(void) hash_ctl.keysize = sizeof(RejectMapEntry); hash_ctl.entrysize = sizeof(GlobalRejectMapEntry); disk_quota_reject_map = - DiskquotaShmemInitHash("rejectmap whose quota limitation is reached", INIT_DISK_QUOTA_REJECT_ENTRIES, + DiskquotaShmemInitHash("rejectmap whose quota limitation is reached", MAX_DISK_QUOTA_REJECT_ENTRIES, MAX_DISK_QUOTA_REJECT_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); init_shm_worker_active_tables(); @@ -582,8 +582,8 @@ init_disk_quota_model(uint32 id) memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(TableSizeEntryKey); hash_ctl.entrysize = sizeof(TableSizeEntry); - table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, - &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); + table_size_map = DiskquotaShmemInitHash(str.data, MAX_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, + HASH_ELEM, DISKQUOTA_TAG_HASH); /* for localrejectmap */ /* WARNNING: The max length of name of the map is 48 */ @@ -600,7 +600,7 @@ init_disk_quota_model(uint32 id) memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.entrysize = sizeof(QuotaInfoEntry); hash_ctl.keysize = sizeof(QuotaInfoEntryKey); - quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, + quota_info_map = DiskquotaShmemInitHash(str.data, MAX_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); pfree(str.data); @@ -635,8 +635,8 @@ vacuum_disk_quota_model(uint32 id) memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(TableSizeEntryKey); hash_ctl.entrysize = sizeof(TableSizeEntry); - table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, - &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); + table_size_map = DiskquotaShmemInitHash(str.data, MAX_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, + HASH_ELEM, DISKQUOTA_TAG_HASH); hash_seq_init(&iter, table_size_map); while ((tsentry = hash_seq_search(&iter)) != NULL) { @@ -663,7 +663,7 @@ vacuum_disk_quota_model(uint32 id) memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.entrysize = sizeof(QuotaInfoEntry); hash_ctl.keysize = sizeof(QuotaInfoEntryKey); - quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, + quota_info_map = DiskquotaShmemInitHash(str.data, MAX_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); hash_seq_init(&iter, quota_info_map); while ((qentry = hash_seq_search(&iter)) != NULL)