From 26d0a0e220cfc093cb149259f06818f7e4319e26 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Thu, 4 Dec 2025 15:59:48 +0500 Subject: [PATCH 01/37] Fix shared memory allocation and usage in diskquota --- src/diskquota.c | 10 ++++++ src/gp_activetable.c | 12 +++++++ src/quotamodel.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ src/relation_cache.c | 12 +++++++ 4 files changed, 113 insertions(+) diff --git a/src/diskquota.c b/src/diskquota.c index aa706f401..93ca525b3 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -105,6 +105,10 @@ static DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; */ BackgroundWorkerHandle **bgworker_handles; +#ifdef USE_ASSERT_CHECKING +extern pg_atomic_uint32 *diskquota_shmem_size; +#endif + typedef enum { SUCCESS, @@ -1734,6 +1738,12 @@ init_launcher_shmem() bool found; DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)ShmemInitStruct("Diskquota launcher Data", diskquota_launcher_shmem_size(), &found); + +#ifdef USE_ASSERT_CHECKING + if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, diskquota_launcher_shmem_size()); + if (found) elog(WARNING, "DiskquotaLauncherShmem found!"); +#endif + memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); if (!found) { diff --git a/src/gp_activetable.c b/src/gp_activetable.c index bf34e2ae0..629d1a16a 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -79,6 +79,10 @@ static file_truncate_hook_type prev_file_truncate_hook = NULL; static file_unlink_hook_type prev_file_unlink_hook = NULL; static object_access_hook_type prev_object_access_hook = NULL; +#ifdef USE_ASSERT_CHECKING +extern pg_atomic_uint32 *diskquota_shmem_size; +#endif + static void active_table_hook_smgrcreate(RelFileNodeBackend rnode); static void active_table_hook_smgrextend(RelFileNodeBackend rnode); static void active_table_hook_smgrtruncate(RelFileNodeBackend rnode); @@ -114,11 +118,19 @@ init_shm_worker_active_tables(void) active_tables_map = DiskquotaShmemInitHash("active_tables", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableFileEntry))); +#endif + memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); ctl.entrysize = sizeof(Oid); altered_reloid_cache = DiskquotaShmemInitHash("altered_reloid_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); + +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); +#endif } /* diff --git a/src/quotamodel.c b/src/quotamodel.c index ba0ab3ac2..181786b6d 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -210,6 +210,10 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; +#ifdef USE_ASSERT_CHECKING +pg_atomic_uint32 *diskquota_shmem_size; +#endif + /* functions to maintain the quota maps */ static void update_size_for_quota(int64 size, QuotaType type, Oid *keys, int16 segid); static void update_limit_for_quota(int64 limit, float segratio, QuotaType type, Oid *keys); @@ -439,8 +443,19 @@ disk_quota_shmem_startup(void) if (prev_shmem_startup_hook) (*prev_shmem_startup_hook)(); +#ifdef USE_ASSERT_CHECKING + elog(WARNING, "diskquota_shmem_size = %li", DiskQuotaShmemSize()); +#endif + LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); +#ifdef USE_ASSERT_CHECKING + diskquota_shmem_size = + ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint32), &found); + if (!found) pg_atomic_init_u32(diskquota_shmem_size, DiskQuotaShmemSize()); + if (found) elog(WARNING, "diskquota_shmem_size found!"); +#endif + init_lwlocks(); /* @@ -452,6 +467,11 @@ disk_quota_shmem_startup(void) extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); +#ifdef USE_ASSERT_CHECKING + if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); + if (found) elog(WARNING, "extension_ddl_message found!"); +#endif + memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); hash_ctl.entrysize = sizeof(GlobalRejectMapEntry); @@ -459,6 +479,10 @@ disk_quota_shmem_startup(void) DiskquotaShmemInitHash("rejectmap whose quota limitation is reached", diskquota_max_local_reject_entries, MAX_DISK_QUOTA_REJECT_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); +#endif + init_shm_worker_active_tables(); init_shm_worker_relation_cache(); @@ -470,8 +494,17 @@ disk_quota_shmem_startup(void) monitored_dbid_cache = DiskquotaShmemInitHash("table oid cache which shoud tracking", diskquota_max_monitored_databases, diskquota_max_monitored_databases, &hash_ctl, HASH_ELEM, DISKQUOTA_OID_HASH); + +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_monitored_databases, sizeof(MonitorDBEntry))); +#endif + init_launcher_shmem(); LWLockRelease(AddinShmemInitLock); + +#ifdef USE_ASSERT_CHECKING + elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); +#endif } /* @@ -534,6 +567,11 @@ DiskQuotaShmemSize(void) { Size size; size = sizeof(ExtensionDDLMessage); + +#ifdef USE_ASSERT_CHECKING + size = add_size(size, sizeof(pg_atomic_uint32)); +#endif + size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableEntry))); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); @@ -563,16 +601,32 @@ init_disk_quota_model(uint32 id) bool found; initStringInfo(&str); +#ifdef USE_ASSERT_CHECKING + elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); +#endif + + LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); + format_name("TableSizeEntrymap", id, &str); 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); + +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry))); +#endif + format_name("TableSizeEntrymap_last_overflow_report", id, &str); table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *table_size_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); + if (found) elog(WARNING, "table_size_map_last_overflow_report found!"); +#endif + /* for localrejectmap */ /* WARNNING: The max length of name of the map is 48 */ format_name("localrejectmap", id, &str); @@ -583,10 +637,19 @@ init_disk_quota_model(uint32 id) DiskquotaShmemInitHash(str.data, diskquota_max_local_reject_entries, diskquota_max_local_reject_entries, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); +#endif + format_name("localrejectmap_last_overflow_report", id, &str); local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); + if (found) elog(WARNING, "local_disk_quota_reject_map_last_overflow_report found!"); +#endif + /* for quota_info_map */ format_name("QuotaInfoMap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -594,11 +657,27 @@ init_disk_quota_model(uint32 id) hash_ctl.keysize = sizeof(QuotaInfoEntryKey); quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); + +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); +#endif + format_name("QuotaInfoMap_last_overflow_report", id, &str); quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *quota_info_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); + if (found) elog(WARNING, "quota_info_map_last_overflow_report found!"); +#endif + pfree(str.data); + + LWLockRelease(AddinShmemInitLock); + +#ifdef USE_ASSERT_CHECKING + elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); +#endif } /* diff --git a/src/relation_cache.c b/src/relation_cache.c index b5624c420..c0036ca50 100644 --- a/src/relation_cache.c +++ b/src/relation_cache.c @@ -42,6 +42,10 @@ static const char *relid_cache_warning = "the number of relid cache entries reached the limit, please increase " "the GUC value for diskquota.max_active_tables."; +#ifdef USE_ASSERT_CHECKING +extern pg_atomic_uint32 *diskquota_shmem_size; +#endif + static void update_relation_entry(Oid relid, DiskQuotaRelationCacheEntry *relation_entry, DiskQuotaRelidCacheEntry *relid_entry); @@ -58,11 +62,19 @@ init_shm_worker_relation_cache(void) relation_cache = DiskquotaShmemInitHash("relation_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); +#endif + memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); ctl.entrysize = sizeof(DiskQuotaRelidCacheEntry); relid_cache = DiskquotaShmemInitHash("relid_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); + +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); +#endif } Oid From 5a868315b138b4e0009c0f1011667d273836d3fd Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 5 Dec 2025 09:36:42 +0500 Subject: [PATCH 02/37] fix --- src/gp_activetable.c | 3 ++- src/quotamodel.c | 45 +++++++++++++++++++++++++------------------- src/relation_cache.c | 6 ++++-- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/gp_activetable.c b/src/gp_activetable.c index 629d1a16a..e041ae5d9 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -119,7 +119,8 @@ init_shm_worker_active_tables(void) diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableFileEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableFileEntry))); #endif memset(&ctl, 0, sizeof(ctl)); diff --git a/src/quotamodel.c b/src/quotamodel.c index 181786b6d..7efc49d66 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -450,8 +450,7 @@ disk_quota_shmem_startup(void) LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); #ifdef USE_ASSERT_CHECKING - diskquota_shmem_size = - ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint32), &found); + diskquota_shmem_size = ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint32), &found); if (!found) pg_atomic_init_u32(diskquota_shmem_size, DiskQuotaShmemSize()); if (found) elog(WARNING, "diskquota_shmem_size found!"); #endif @@ -480,7 +479,8 @@ disk_quota_shmem_startup(void) MAX_DISK_QUOTA_REJECT_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); #endif init_shm_worker_active_tables(); @@ -496,10 +496,11 @@ disk_quota_shmem_startup(void) diskquota_max_monitored_databases, &hash_ctl, HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_monitored_databases, sizeof(MonitorDBEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(diskquota_max_monitored_databases, sizeof(struct MonitorDBEntryStruct))); #endif - init_launcher_shmem(); + if (IS_QUERY_DISPATCHER()) init_launcher_shmem(); LWLockRelease(AddinShmemInitLock); #ifdef USE_ASSERT_CHECKING @@ -548,10 +549,10 @@ static Size diskquota_worker_shmem_size() { Size size; - size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES / diskquota_max_monitored_databases + 100, - sizeof(TableSizeEntry)); - size = add_size(size, hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); - size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); + size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry)); // table_size_map + size = add_size(size, hash_estimate_size(diskquota_max_local_reject_entries, + sizeof(LocalRejectMapEntry))); // local_disk_quota_reject_map + size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); // quota_info_map size = add_size(size, sizeof(TimestampTz)); // table_size_map_last_overflow_report size = add_size(size, sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report size = add_size(size, sizeof(TimestampTz)); // quota_info_map_last_overflow_report @@ -566,23 +567,27 @@ static Size DiskQuotaShmemSize(void) { Size size; - size = sizeof(ExtensionDDLMessage); + size = sizeof(ExtensionDDLMessage); // extension_ddl_message #ifdef USE_ASSERT_CHECKING - size = add_size(size, sizeof(pg_atomic_uint32)); + size = add_size(size, sizeof(pg_atomic_uint32)); // diskquota_shmem_size #endif - size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableEntry))); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); + size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, + sizeof(GlobalRejectMapEntry))); // disk_quota_reject_map + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, + sizeof(DiskQuotaActiveTableFileEntry))); // active_tables_map + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, + sizeof(DiskQuotaRelationCacheEntry))); // relation_cache + size = add_size(size, + hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); // relid_cache + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); // altered_reloid_cache size = add_size(size, hash_estimate_size(diskquota_max_monitored_databases, sizeof(struct MonitorDBEntryStruct))); // monitored_dbid_cache if (IS_QUERY_DISPATCHER()) { - size = add_size(size, diskquota_launcher_shmem_size()); + size = add_size(size, diskquota_launcher_shmem_size()); // DiskquotaLauncherShmem size = add_size(size, diskquota_worker_shmem_size() * diskquota_max_monitored_databases); } @@ -615,7 +620,8 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry))); #endif format_name("TableSizeEntrymap_last_overflow_report", id, &str); @@ -638,7 +644,8 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); #endif format_name("localrejectmap_last_overflow_report", id, &str); diff --git a/src/relation_cache.c b/src/relation_cache.c index c0036ca50..d5e81b4fc 100644 --- a/src/relation_cache.c +++ b/src/relation_cache.c @@ -63,7 +63,8 @@ init_shm_worker_relation_cache(void) &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); #endif memset(&ctl, 0, sizeof(ctl)); @@ -73,7 +74,8 @@ init_shm_worker_relation_cache(void) HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); + pg_atomic_sub_fetch_u32(diskquota_shmem_size, + hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); #endif } From 393f5ab12915710a81475bd5e805228240dbbfa3 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 5 Dec 2025 09:57:13 +0500 Subject: [PATCH 03/37] assert --- src/quotamodel.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 7efc49d66..59a2b26d8 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -243,6 +243,8 @@ static bool get_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag static void reset_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag flag); static void set_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag flag); +static Size diskquota_worker_shmem_size(); + typedef struct { ArrayBuildState *tableids; @@ -451,7 +453,7 @@ disk_quota_shmem_startup(void) #ifdef USE_ASSERT_CHECKING diskquota_shmem_size = ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint32), &found); - if (!found) pg_atomic_init_u32(diskquota_shmem_size, DiskQuotaShmemSize()); + if (!found) pg_atomic_init_u32(diskquota_shmem_size, DiskQuotaShmemSize() - sizeof(pg_atomic_uint32)); if (found) elog(WARNING, "diskquota_shmem_size found!"); #endif @@ -505,6 +507,11 @@ disk_quota_shmem_startup(void) #ifdef USE_ASSERT_CHECKING elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); + if (IS_QUERY_DISPATCHER()) + Assert(pg_atomic_read_u32(diskquota_shmem_size) == + diskquota_worker_shmem_size() * diskquota_max_monitored_databases); + else + Assert(pg_atomic_read_u32(diskquota_shmem_size) == 0); #endif } @@ -608,6 +615,7 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); + Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); #endif LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); @@ -684,6 +692,7 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); + Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); #endif } From 899e80904a05847288c0c52afde480f44712f52d Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 5 Dec 2025 09:59:57 +0500 Subject: [PATCH 04/37] rm warning --- src/diskquota.c | 1 - src/quotamodel.c | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 93ca525b3..5b48bf56e 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1741,7 +1741,6 @@ init_launcher_shmem() #ifdef USE_ASSERT_CHECKING if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, diskquota_launcher_shmem_size()); - if (found) elog(WARNING, "DiskquotaLauncherShmem found!"); #endif memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); diff --git a/src/quotamodel.c b/src/quotamodel.c index 59a2b26d8..73be8cd84 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -445,16 +445,11 @@ disk_quota_shmem_startup(void) if (prev_shmem_startup_hook) (*prev_shmem_startup_hook)(); -#ifdef USE_ASSERT_CHECKING - elog(WARNING, "diskquota_shmem_size = %li", DiskQuotaShmemSize()); -#endif - LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); #ifdef USE_ASSERT_CHECKING diskquota_shmem_size = ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint32), &found); if (!found) pg_atomic_init_u32(diskquota_shmem_size, DiskQuotaShmemSize() - sizeof(pg_atomic_uint32)); - if (found) elog(WARNING, "diskquota_shmem_size found!"); #endif init_lwlocks(); @@ -470,7 +465,6 @@ disk_quota_shmem_startup(void) #ifdef USE_ASSERT_CHECKING if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); - if (found) elog(WARNING, "extension_ddl_message found!"); #endif memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -506,7 +500,6 @@ disk_quota_shmem_startup(void) LWLockRelease(AddinShmemInitLock); #ifdef USE_ASSERT_CHECKING - elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); if (IS_QUERY_DISPATCHER()) Assert(pg_atomic_read_u32(diskquota_shmem_size) == diskquota_worker_shmem_size() * diskquota_max_monitored_databases); @@ -614,7 +607,6 @@ init_disk_quota_model(uint32 id) initStringInfo(&str); #ifdef USE_ASSERT_CHECKING - elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); #endif @@ -638,7 +630,6 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); - if (found) elog(WARNING, "table_size_map_last_overflow_report found!"); #endif /* for localrejectmap */ @@ -662,7 +653,6 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); - if (found) elog(WARNING, "local_disk_quota_reject_map_last_overflow_report found!"); #endif /* for quota_info_map */ @@ -683,7 +673,6 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); - if (found) elog(WARNING, "quota_info_map_last_overflow_report found!"); #endif pfree(str.data); @@ -691,7 +680,6 @@ init_disk_quota_model(uint32 id) LWLockRelease(AddinShmemInitLock); #ifdef USE_ASSERT_CHECKING - elog(WARNING, "diskquota_shmem_size = %i", pg_atomic_read_u32(diskquota_shmem_size)); Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); #endif } From 0df528cf9f332693f60a9f6a455cb0227c292017 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 5 Dec 2025 10:04:45 +0500 Subject: [PATCH 05/37] void --- src/quotamodel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 73be8cd84..17124051a 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -243,7 +243,7 @@ static bool get_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag static void reset_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag flag); static void set_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag flag); -static Size diskquota_worker_shmem_size(); +static Size diskquota_worker_shmem_size(void); typedef struct { @@ -546,7 +546,7 @@ init_lwlocks(void) } static Size -diskquota_worker_shmem_size() +diskquota_worker_shmem_size(void) { Size size; size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry)); // table_size_map From 17da424854eb4f1650b50c9daa72e98fb638f970 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 5 Dec 2025 10:13:27 +0500 Subject: [PATCH 06/37] rm lock --- src/quotamodel.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 17124051a..175a20701 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -610,8 +610,6 @@ init_disk_quota_model(uint32 id) Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); #endif - LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); - format_name("TableSizeEntrymap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(TableSizeEntryKey); @@ -677,8 +675,6 @@ init_disk_quota_model(uint32 id) pfree(str.data); - LWLockRelease(AddinShmemInitLock); - #ifdef USE_ASSERT_CHECKING Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); #endif From f8411bcd179d0f05a0c19823b8a95356617657df Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 5 Dec 2025 10:45:34 +0500 Subject: [PATCH 07/37] 32 -> 64 --- src/diskquota.c | 4 ++-- src/gp_activetable.c | 6 +++--- src/quotamodel.c | 34 +++++++++++++++++----------------- src/relation_cache.c | 6 +++--- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 5b48bf56e..9fe1ad989 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -106,7 +106,7 @@ static DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; BackgroundWorkerHandle **bgworker_handles; #ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint32 *diskquota_shmem_size; +extern pg_atomic_uint64 *diskquota_shmem_size; #endif typedef enum @@ -1740,7 +1740,7 @@ init_launcher_shmem() diskquota_launcher_shmem_size(), &found); #ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, diskquota_launcher_shmem_size()); + if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, diskquota_launcher_shmem_size()); #endif memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); diff --git a/src/gp_activetable.c b/src/gp_activetable.c index e041ae5d9..4f34e1d6e 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -80,7 +80,7 @@ static file_unlink_hook_type prev_file_unlink_hook = NULL; static object_access_hook_type prev_object_access_hook = NULL; #ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint32 *diskquota_shmem_size; +extern pg_atomic_uint64 *diskquota_shmem_size; #endif static void active_table_hook_smgrcreate(RelFileNodeBackend rnode); @@ -119,7 +119,7 @@ init_shm_worker_active_tables(void) diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableFileEntry))); #endif @@ -130,7 +130,7 @@ init_shm_worker_active_tables(void) diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); #endif } diff --git a/src/quotamodel.c b/src/quotamodel.c index 175a20701..00111ff96 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -211,7 +211,7 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; #ifdef USE_ASSERT_CHECKING -pg_atomic_uint32 *diskquota_shmem_size; +pg_atomic_uint64 *diskquota_shmem_size; #endif /* functions to maintain the quota maps */ @@ -448,8 +448,8 @@ disk_quota_shmem_startup(void) LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); #ifdef USE_ASSERT_CHECKING - diskquota_shmem_size = ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint32), &found); - if (!found) pg_atomic_init_u32(diskquota_shmem_size, DiskQuotaShmemSize() - sizeof(pg_atomic_uint32)); + diskquota_shmem_size = ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint64), &found); + if (!found) pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize() - sizeof(pg_atomic_uint64)); #endif init_lwlocks(); @@ -464,7 +464,7 @@ disk_quota_shmem_startup(void) if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); #ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); + if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); #endif memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -475,7 +475,7 @@ disk_quota_shmem_startup(void) MAX_DISK_QUOTA_REJECT_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); #endif @@ -492,7 +492,7 @@ disk_quota_shmem_startup(void) diskquota_max_monitored_databases, &hash_ctl, HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_monitored_databases, sizeof(struct MonitorDBEntryStruct))); #endif @@ -501,10 +501,10 @@ disk_quota_shmem_startup(void) #ifdef USE_ASSERT_CHECKING if (IS_QUERY_DISPATCHER()) - Assert(pg_atomic_read_u32(diskquota_shmem_size) == + Assert(pg_atomic_read_u64(diskquota_shmem_size) == diskquota_worker_shmem_size() * diskquota_max_monitored_databases); else - Assert(pg_atomic_read_u32(diskquota_shmem_size) == 0); + Assert(pg_atomic_read_u64(diskquota_shmem_size) == 0); #endif } @@ -570,7 +570,7 @@ DiskQuotaShmemSize(void) size = sizeof(ExtensionDDLMessage); // extension_ddl_message #ifdef USE_ASSERT_CHECKING - size = add_size(size, sizeof(pg_atomic_uint32)); // diskquota_shmem_size + size = add_size(size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size #endif size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, @@ -607,7 +607,7 @@ init_disk_quota_model(uint32 id) initStringInfo(&str); #ifdef USE_ASSERT_CHECKING - Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); #endif format_name("TableSizeEntrymap", id, &str); @@ -618,7 +618,7 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry))); #endif @@ -627,7 +627,7 @@ init_disk_quota_model(uint32 id) if (!found) *table_size_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); + if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); #endif /* for localrejectmap */ @@ -641,7 +641,7 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); #endif @@ -650,7 +650,7 @@ init_disk_quota_model(uint32 id) if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); + if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); #endif /* for quota_info_map */ @@ -662,7 +662,7 @@ init_disk_quota_model(uint32 id) HASH_ELEM, DISKQUOTA_TAG_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); #endif format_name("QuotaInfoMap_last_overflow_report", id, &str); @@ -670,13 +670,13 @@ init_disk_quota_model(uint32 id) if (!found) *quota_info_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u32(diskquota_shmem_size, sizeof(TimestampTz)); + if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); #endif pfree(str.data); #ifdef USE_ASSERT_CHECKING - Assert(pg_atomic_read_u32(diskquota_shmem_size) >= 0); + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); #endif } diff --git a/src/relation_cache.c b/src/relation_cache.c index d5e81b4fc..2d489fc94 100644 --- a/src/relation_cache.c +++ b/src/relation_cache.c @@ -43,7 +43,7 @@ static const char *relid_cache_warning = "the GUC value for diskquota.max_active_tables."; #ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint32 *diskquota_shmem_size; +extern pg_atomic_uint64 *diskquota_shmem_size; #endif static void update_relation_entry(Oid relid, DiskQuotaRelationCacheEntry *relation_entry, @@ -63,7 +63,7 @@ init_shm_worker_relation_cache(void) &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); #endif @@ -74,7 +74,7 @@ init_shm_worker_relation_cache(void) HASH_ELEM, DISKQUOTA_OID_HASH); #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u32(diskquota_shmem_size, + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); #endif } From 3b4768f40036f77540d8d652e1a7119596e8c838 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 21:29:46 +0500 Subject: [PATCH 08/37] simplify --- src/diskquota.c | 10 +-------- src/diskquota.h | 1 + src/diskquota_utility.c | 17 ++++++++++++++ src/gp_activetable.c | 13 ----------- src/quotamodel.c | 49 ++++------------------------------------- src/relation_cache.c | 14 ------------ 6 files changed, 23 insertions(+), 81 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 9fe1ad989..95d779302 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -105,10 +105,6 @@ static DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; */ BackgroundWorkerHandle **bgworker_handles; -#ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint64 *diskquota_shmem_size; -#endif - typedef enum { SUCCESS, @@ -1736,13 +1732,9 @@ void init_launcher_shmem() { bool found; - DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)ShmemInitStruct("Diskquota launcher Data", + DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)DiskquotaShmemInitStruct("Diskquota launcher Data", diskquota_launcher_shmem_size(), &found); -#ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, diskquota_launcher_shmem_size()); -#endif - memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); if (!found) { diff --git a/src/diskquota.h b/src/diskquota.h index c46adb216..b9c12dad1 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -314,6 +314,7 @@ extern void diskquota_stop_worker(void); extern void update_monitordb_status(Oid dbid, uint32 status); extern HTAB *diskquota_hash_create(const char *tabname, long nelem, HASHCTL *info, int flags, DiskquotaHashFunction hashFunction); +extern void *DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr); 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); diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 43d0b0a15..ac983d5ad 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -114,6 +114,10 @@ static float4 get_per_segment_ratio(Oid spcoid); static bool to_delete_quota(QuotaType type, int64 quota_limit_mb, float4 segratio); static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb); +#ifdef USE_ASSERT_CHECKING +extern pg_atomic_uint64 *diskquota_shmem_size; +#endif + /* ---- Help Functions to set quota limit. ---- */ /* * Initialize table diskquota.table_size. @@ -1634,6 +1638,15 @@ diskquota_hash_create(const char *tabname, long nelem, HASHCTL *info, int flags, #endif /* GP_VERSION_NUM */ } +void * +DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr) +{ +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); +#endif + return ShmemInitStruct(name, size, foundPtr); +} + HTAB * DiskquotaShmemInitHash(const char *name, /* table string name for shmem index */ long init_size, /* initial table size */ @@ -1642,6 +1655,10 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo int hash_flags, /* info about infoP */ DiskquotaHashFunction hashFunction) { +#ifdef USE_ASSERT_CHECKING + pg_atomic_sub_fetch_u64(diskquota_shmem_size, + hash_estimate_size(max_size, infoP->entrysize)); +#endif #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) infoP->hash = tag_hash; diff --git a/src/gp_activetable.c b/src/gp_activetable.c index 4f34e1d6e..bf34e2ae0 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -79,10 +79,6 @@ static file_truncate_hook_type prev_file_truncate_hook = NULL; static file_unlink_hook_type prev_file_unlink_hook = NULL; static object_access_hook_type prev_object_access_hook = NULL; -#ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint64 *diskquota_shmem_size; -#endif - static void active_table_hook_smgrcreate(RelFileNodeBackend rnode); static void active_table_hook_smgrextend(RelFileNodeBackend rnode); static void active_table_hook_smgrtruncate(RelFileNodeBackend rnode); @@ -118,20 +114,11 @@ init_shm_worker_active_tables(void) active_tables_map = DiskquotaShmemInitHash("active_tables", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableFileEntry))); -#endif - memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); ctl.entrysize = sizeof(Oid); altered_reloid_cache = DiskquotaShmemInitHash("altered_reloid_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); - -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); -#endif } /* diff --git a/src/quotamodel.c b/src/quotamodel.c index 00111ff96..b97ac9f09 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -460,13 +460,8 @@ disk_quota_shmem_startup(void) * to store out-of-quota rejectmap. active_tables_map is used to store * active tables whose disk usage is changed. */ - extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); + extension_ddl_message = DiskquotaShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); - -#ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); -#endif - memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); hash_ctl.entrysize = sizeof(GlobalRejectMapEntry); @@ -474,11 +469,6 @@ disk_quota_shmem_startup(void) DiskquotaShmemInitHash("rejectmap whose quota limitation is reached", diskquota_max_local_reject_entries, MAX_DISK_QUOTA_REJECT_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, sizeof(GlobalRejectMapEntry))); -#endif - init_shm_worker_active_tables(); init_shm_worker_relation_cache(); @@ -491,11 +481,6 @@ disk_quota_shmem_startup(void) DiskquotaShmemInitHash("table oid cache which shoud tracking", diskquota_max_monitored_databases, diskquota_max_monitored_databases, &hash_ctl, HASH_ELEM, DISKQUOTA_OID_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(diskquota_max_monitored_databases, sizeof(struct MonitorDBEntryStruct))); -#endif - if (IS_QUERY_DISPATCHER()) init_launcher_shmem(); LWLockRelease(AddinShmemInitLock); @@ -617,19 +602,10 @@ init_disk_quota_model(uint32 id) table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry))); -#endif - format_name("TableSizeEntrymap_last_overflow_report", id, &str); - table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + table_size_map_last_overflow_report = DiskquotaShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *table_size_map_last_overflow_report = 0; -#ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); -#endif - /* for localrejectmap */ /* WARNNING: The max length of name of the map is 48 */ format_name("localrejectmap", id, &str); @@ -640,19 +616,10 @@ init_disk_quota_model(uint32 id) DiskquotaShmemInitHash(str.data, diskquota_max_local_reject_entries, diskquota_max_local_reject_entries, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); -#endif - format_name("localrejectmap_last_overflow_report", id, &str); - local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + local_disk_quota_reject_map_last_overflow_report = DiskquotaShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; -#ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); -#endif - /* for quota_info_map */ format_name("QuotaInfoMap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -661,18 +628,10 @@ init_disk_quota_model(uint32 id) quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); -#endif - format_name("QuotaInfoMap_last_overflow_report", id, &str); - quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + quota_info_map_last_overflow_report = DiskquotaShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *quota_info_map_last_overflow_report = 0; -#ifdef USE_ASSERT_CHECKING - if (!found) pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); -#endif - pfree(str.data); #ifdef USE_ASSERT_CHECKING diff --git a/src/relation_cache.c b/src/relation_cache.c index 2d489fc94..b5624c420 100644 --- a/src/relation_cache.c +++ b/src/relation_cache.c @@ -42,10 +42,6 @@ static const char *relid_cache_warning = "the number of relid cache entries reached the limit, please increase " "the GUC value for diskquota.max_active_tables."; -#ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint64 *diskquota_shmem_size; -#endif - static void update_relation_entry(Oid relid, DiskQuotaRelationCacheEntry *relation_entry, DiskQuotaRelidCacheEntry *relid_entry); @@ -62,21 +58,11 @@ init_shm_worker_relation_cache(void) relation_cache = DiskquotaShmemInitHash("relation_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); -#endif - memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); ctl.entrysize = sizeof(DiskQuotaRelidCacheEntry); relid_cache = DiskquotaShmemInitHash("relid_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); - -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); -#endif } Oid From fa0952b0719865a6af9ad79b8c3ee2b2954c5bf4 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 21:30:15 +0500 Subject: [PATCH 09/37] format --- src/diskquota.c | 4 ++-- src/diskquota.h | 2 +- src/diskquota_utility.c | 3 +-- src/quotamodel.c | 3 ++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 95d779302..b0e90d17f 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1732,8 +1732,8 @@ void init_launcher_shmem() { bool found; - DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)DiskquotaShmemInitStruct("Diskquota launcher Data", - diskquota_launcher_shmem_size(), &found); + DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)DiskquotaShmemInitStruct( + "Diskquota launcher Data", diskquota_launcher_shmem_size(), &found); memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); if (!found) diff --git a/src/diskquota.h b/src/diskquota.h index b9c12dad1..0bb4eb7c3 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -314,7 +314,7 @@ extern void diskquota_stop_worker(void); extern void update_monitordb_status(Oid dbid, uint32 status); extern HTAB *diskquota_hash_create(const char *tabname, long nelem, HASHCTL *info, int flags, DiskquotaHashFunction hashFunction); -extern void *DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr); +extern void *DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr); 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); diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index ac983d5ad..1baa2406a 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1656,8 +1656,7 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo DiskquotaHashFunction hashFunction) { #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - hash_estimate_size(max_size, infoP->entrysize)); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(max_size, infoP->entrysize)); #endif #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) diff --git a/src/quotamodel.c b/src/quotamodel.c index b97ac9f09..e1842c61e 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -460,7 +460,8 @@ disk_quota_shmem_startup(void) * to store out-of-quota rejectmap. active_tables_map is used to store * active tables whose disk usage is changed. */ - extension_ddl_message = DiskquotaShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); + extension_ddl_message = + DiskquotaShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); From a79dfa6e7592b02675b62f4e81f7cf28dadd64b9 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 21:55:25 +0500 Subject: [PATCH 10/37] simplify --- src/diskquota.c | 4 ++-- src/diskquota.h | 1 - src/diskquota_utility.c | 9 --------- src/quotamodel.c | 19 +++++++++++++------ 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index b0e90d17f..58b0fde45 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1732,8 +1732,8 @@ void init_launcher_shmem() { bool found; - DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)DiskquotaShmemInitStruct( - "Diskquota launcher Data", diskquota_launcher_shmem_size(), &found); + DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)ShmemInitStruct("Diskquota launcher Data", + diskquota_launcher_shmem_size(), &found); memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); if (!found) diff --git a/src/diskquota.h b/src/diskquota.h index 0bb4eb7c3..c46adb216 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -314,7 +314,6 @@ extern void diskquota_stop_worker(void); extern void update_monitordb_status(Oid dbid, uint32 status); extern HTAB *diskquota_hash_create(const char *tabname, long nelem, HASHCTL *info, int flags, DiskquotaHashFunction hashFunction); -extern void *DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr); 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); diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 1baa2406a..086c358c1 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1638,15 +1638,6 @@ diskquota_hash_create(const char *tabname, long nelem, HASHCTL *info, int flags, #endif /* GP_VERSION_NUM */ } -void * -DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr) -{ -#ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); -#endif - return ShmemInitStruct(name, size, foundPtr); -} - HTAB * DiskquotaShmemInitHash(const char *name, /* table string name for shmem index */ long init_size, /* initial table size */ diff --git a/src/quotamodel.c b/src/quotamodel.c index e1842c61e..c2a4f461c 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -449,7 +449,15 @@ disk_quota_shmem_startup(void) #ifdef USE_ASSERT_CHECKING diskquota_shmem_size = ShmemInitStruct("diskquota_shmem_size", sizeof(pg_atomic_uint64), &found); - if (!found) pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize() - sizeof(pg_atomic_uint64)); + if (!found) + { + pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize()); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size + pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); // extension_ddl_message + + if (IS_QUERY_DISPATCHER()) + pg_atomic_sub_fetch_u64(diskquota_shmem_size, diskquota_launcher_shmem_size()); // DiskquotaLauncherShmem + } #endif init_lwlocks(); @@ -460,8 +468,7 @@ disk_quota_shmem_startup(void) * to store out-of-quota rejectmap. active_tables_map is used to store * active tables whose disk usage is changed. */ - extension_ddl_message = - DiskquotaShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); + extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); @@ -604,7 +611,7 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("TableSizeEntrymap_last_overflow_report", id, &str); - table_size_map_last_overflow_report = DiskquotaShmemInitStruct(str.data, sizeof(TimestampTz), &found); + table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *table_size_map_last_overflow_report = 0; /* for localrejectmap */ @@ -618,7 +625,7 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("localrejectmap_last_overflow_report", id, &str); - local_disk_quota_reject_map_last_overflow_report = DiskquotaShmemInitStruct(str.data, sizeof(TimestampTz), &found); + local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; /* for quota_info_map */ @@ -630,7 +637,7 @@ init_disk_quota_model(uint32 id) HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("QuotaInfoMap_last_overflow_report", id, &str); - quota_info_map_last_overflow_report = DiskquotaShmemInitStruct(str.data, sizeof(TimestampTz), &found); + quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *quota_info_map_last_overflow_report = 0; pfree(str.data); From ceb42d32f1fa5e905bd3a58438d70b503b0b04a4 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 21:57:23 +0500 Subject: [PATCH 11/37] revert --- src/diskquota.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/diskquota.c b/src/diskquota.c index 58b0fde45..aa706f401 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1734,7 +1734,6 @@ init_launcher_shmem() bool found; DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)ShmemInitStruct("Diskquota launcher Data", diskquota_launcher_shmem_size(), &found); - memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); if (!found) { From 99e41d60c3489d9c95ee18b8edbc04aff881d35d Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 21:58:30 +0500 Subject: [PATCH 12/37] revet --- src/quotamodel.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index c2a4f461c..4dd517e45 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -488,7 +488,6 @@ disk_quota_shmem_startup(void) monitored_dbid_cache = DiskquotaShmemInitHash("table oid cache which shoud tracking", diskquota_max_monitored_databases, diskquota_max_monitored_databases, &hash_ctl, HASH_ELEM, DISKQUOTA_OID_HASH); - if (IS_QUERY_DISPATCHER()) init_launcher_shmem(); LWLockRelease(AddinShmemInitLock); From dced14deea89058c65e650bd13863933f581c174 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 21:59:44 +0500 Subject: [PATCH 13/37] revert --- src/quotamodel.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 4dd517e45..128e8e768 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -608,7 +608,6 @@ init_disk_quota_model(uint32 id) 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); - format_name("TableSizeEntrymap_last_overflow_report", id, &str); table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *table_size_map_last_overflow_report = 0; @@ -634,7 +633,6 @@ init_disk_quota_model(uint32 id) hash_ctl.keysize = sizeof(QuotaInfoEntryKey); quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); - format_name("QuotaInfoMap_last_overflow_report", id, &str); quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *quota_info_map_last_overflow_report = 0; From 0b7c8297dafd830e081b96061ab1519b44299af2 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 22:13:03 +0500 Subject: [PATCH 14/37] fix --- src/quotamodel.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/quotamodel.c b/src/quotamodel.c index 128e8e768..a0962001c 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -612,6 +612,16 @@ init_disk_quota_model(uint32 id) table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *table_size_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!found) + { + pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // table_size_map_last_overflow_report + pg_atomic_sub_fetch_u64(diskquota_shmem_size, + sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report + pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // quota_info_map_last_overflow_report + } +#endif + /* for localrejectmap */ /* WARNNING: The max length of name of the map is 48 */ format_name("localrejectmap", id, &str); From 8f7531eac9ab703b48bf76f2774562e05b666011 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 8 Dec 2025 22:33:29 +0500 Subject: [PATCH 15/37] fix --- src/diskquota.c | 4 ++-- src/diskquota_utility.c | 5 ++++- src/quotamodel.c | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index aa706f401..c723005c7 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -86,12 +86,12 @@ ExtensionDDLMessage *extension_ddl_message = NULL; // Only access in diskquota worker, different from each worker. // a pointer to DiskquotaLauncherShmem->workerEntries in shared memory -static DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL; +DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL; // how many database diskquota are monitoring on static int num_db = 0; -static DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; +DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem = NULL; #define MIN_SLEEPTIME 100 /* milliseconds */ #define BGWORKER_LOG_TIME 3600000 /* milliseconds */ diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 086c358c1..a1f2c4e9f 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -114,6 +114,8 @@ static float4 get_per_segment_ratio(Oid spcoid); static bool to_delete_quota(QuotaType type, int64 quota_limit_mb, float4 segratio); static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb); +extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; + #ifdef USE_ASSERT_CHECKING extern pg_atomic_uint64 *diskquota_shmem_size; #endif @@ -1647,7 +1649,8 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo DiskquotaHashFunction hashFunction) { #ifdef USE_ASSERT_CHECKING - pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(max_size, infoP->entrysize)); + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(max_size, infoP->entrysize)); #endif #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) diff --git a/src/quotamodel.c b/src/quotamodel.c index a0962001c..e4264ccf0 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -210,6 +210,8 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; +extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; + #ifdef USE_ASSERT_CHECKING pg_atomic_uint64 *diskquota_shmem_size; #endif @@ -599,7 +601,9 @@ init_disk_quota_model(uint32 id) initStringInfo(&str); #ifdef USE_ASSERT_CHECKING - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); + Assert(DiskquotaLauncherShmem); + + if (!DiskquotaLauncherShmem->isDynamicWorker) Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); #endif format_name("TableSizeEntrymap", id, &str); @@ -650,7 +654,7 @@ init_disk_quota_model(uint32 id) pfree(str.data); #ifdef USE_ASSERT_CHECKING - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); + if (!DiskquotaLauncherShmem->isDynamicWorker) Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); #endif } From 79ef88e2095058976dba5d516806178fa87fde46 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Tue, 9 Dec 2025 10:32:07 +0500 Subject: [PATCH 16/37] revert --- src/diskquota.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diskquota.c b/src/diskquota.c index c723005c7..104eab387 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -86,7 +86,7 @@ ExtensionDDLMessage *extension_ddl_message = NULL; // Only access in diskquota worker, different from each worker. // a pointer to DiskquotaLauncherShmem->workerEntries in shared memory -DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL; +static DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL; // how many database diskquota are monitoring on static int num_db = 0; From 994c9f19e35da0784ebf2815ca8372fa70739fbe Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Tue, 9 Dec 2025 10:33:39 +0500 Subject: [PATCH 17/37] revert --- src/quotamodel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/quotamodel.c b/src/quotamodel.c index e4264ccf0..61296c3a4 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -472,6 +472,7 @@ disk_quota_shmem_startup(void) */ extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); + memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); hash_ctl.entrysize = sizeof(GlobalRejectMapEntry); From 44918826a7b1ab83051b22f65f38b50076f53d97 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Thu, 11 Dec 2025 20:59:28 +0500 Subject: [PATCH 18/37] optimize --- src/diskquota.c | 5 ++++- src/diskquota_utility.c | 5 ++--- src/quotamodel.c | 5 ++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 104eab387..4d409a80c 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -91,7 +91,10 @@ static DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL; // how many database diskquota are monitoring on static int num_db = 0; -DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem = NULL; +#ifndef USE_ASSERT_CHECKING +static +#endif + DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem = NULL; #define MIN_SLEEPTIME 100 /* milliseconds */ #define BGWORKER_LOG_TIME 3600000 /* milliseconds */ diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index a1f2c4e9f..2b8d3e4cc 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -114,10 +114,9 @@ static float4 get_per_segment_ratio(Oid spcoid); static bool to_delete_quota(QuotaType type, int64 quota_limit_mb, float4 segratio); static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb); -extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; - #ifdef USE_ASSERT_CHECKING -extern pg_atomic_uint64 *diskquota_shmem_size; +extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; +extern pg_atomic_uint64 *diskquota_shmem_size; #endif /* ---- Help Functions to set quota limit. ---- */ diff --git a/src/quotamodel.c b/src/quotamodel.c index 61296c3a4..1f79aa5ff 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -210,10 +210,9 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; -extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; - #ifdef USE_ASSERT_CHECKING -pg_atomic_uint64 *diskquota_shmem_size; +extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; +pg_atomic_uint64 *diskquota_shmem_size; #endif /* functions to maintain the quota maps */ From 7cd475a3978c366065e543b3399d14fa08fd9872 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 12 Dec 2025 10:37:19 +0500 Subject: [PATCH 19/37] unify --- src/diskquota.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 4d409a80c..104eab387 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -91,10 +91,7 @@ static DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL; // how many database diskquota are monitoring on static int num_db = 0; -#ifndef USE_ASSERT_CHECKING -static -#endif - DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem = NULL; +DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem = NULL; #define MIN_SLEEPTIME 100 /* milliseconds */ #define BGWORKER_LOG_TIME 3600000 /* milliseconds */ From cf91fbcf18f6d3637d6568e61af06ebb2687e9ad Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 12 Dec 2025 21:26:15 +0500 Subject: [PATCH 20/37] fix assert --- src/diskquota_utility.c | 6 +++++- src/quotamodel.c | 26 ++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 2b8d3e4cc..31b4f0cc8 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1649,7 +1649,11 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo { #ifdef USE_ASSERT_CHECKING if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - pg_atomic_sub_fetch_u64(diskquota_shmem_size, hash_estimate_size(max_size, infoP->entrysize)); + { + Size size = hash_estimate_size(max_size, infoP->entrysize); + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); + } #endif #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) diff --git a/src/quotamodel.c b/src/quotamodel.c index 1f79aa5ff..53a92e98d 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -211,8 +211,7 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; #ifdef USE_ASSERT_CHECKING -extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; -pg_atomic_uint64 *diskquota_shmem_size; +pg_atomic_uint64 *diskquota_shmem_size; #endif /* functions to maintain the quota maps */ @@ -453,11 +452,17 @@ disk_quota_shmem_startup(void) if (!found) { pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize()); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(pg_atomic_uint64)); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(ExtensionDDLMessage)); pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); // extension_ddl_message if (IS_QUERY_DISPATCHER()) - pg_atomic_sub_fetch_u64(diskquota_shmem_size, diskquota_launcher_shmem_size()); // DiskquotaLauncherShmem + { + Size size = diskquota_launcher_shmem_size(); + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); // DiskquotaLauncherShmem + } } #endif @@ -600,12 +605,6 @@ init_disk_quota_model(uint32 id) bool found; initStringInfo(&str); -#ifdef USE_ASSERT_CHECKING - Assert(DiskquotaLauncherShmem); - - if (!DiskquotaLauncherShmem->isDynamicWorker) Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); -#endif - format_name("TableSizeEntrymap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(TableSizeEntryKey); @@ -619,9 +618,12 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING if (!found) { + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(TimestampTz)); pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // table_size_map_last_overflow_report + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(TimestampTz)); pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(TimestampTz)); pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // quota_info_map_last_overflow_report } #endif @@ -652,10 +654,6 @@ init_disk_quota_model(uint32 id) if (!found) *quota_info_map_last_overflow_report = 0; pfree(str.data); - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem->isDynamicWorker) Assert(pg_atomic_read_u64(diskquota_shmem_size) >= 0); -#endif } /* From 30b7e7c624938cf0c2c259375ddca60a06d892cc Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 08:37:35 +0500 Subject: [PATCH 21/37] optimize --- src/diskquota_utility.c | 7 ++----- src/quotamodel.c | 33 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 31b4f0cc8..de4b0e772 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -117,6 +117,7 @@ static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb); #ifdef USE_ASSERT_CHECKING extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; extern pg_atomic_uint64 *diskquota_shmem_size; +extern void diskquota_shmem_size_sub(Size size); #endif /* ---- Help Functions to set quota limit. ---- */ @@ -1649,11 +1650,7 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo { #ifdef USE_ASSERT_CHECKING if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - { - Size size = hash_estimate_size(max_size, infoP->entrysize); - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); - } + diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize)); #endif #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) diff --git a/src/quotamodel.c b/src/quotamodel.c index 53a92e98d..cf66f3961 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -212,6 +212,7 @@ static shmem_startup_hook_type prev_shmem_startup_hook = NULL; #ifdef USE_ASSERT_CHECKING pg_atomic_uint64 *diskquota_shmem_size; +void diskquota_shmem_size_sub(Size size); #endif /* functions to maintain the quota maps */ @@ -452,17 +453,10 @@ disk_quota_shmem_startup(void) if (!found) { pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize()); - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(pg_atomic_uint64)); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(ExtensionDDLMessage)); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(ExtensionDDLMessage)); // extension_ddl_message + diskquota_shmem_size_sub(sizeof(pg_atomic_uint64)); // diskquota_shmem_size + diskquota_shmem_size_sub(sizeof(ExtensionDDLMessage)); // extension_ddl_message - if (IS_QUERY_DISPATCHER()) - { - Size size = diskquota_launcher_shmem_size(); - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); // DiskquotaLauncherShmem - } + if (IS_QUERY_DISPATCHER()) diskquota_shmem_size_sub(diskquota_launcher_shmem_size()); // DiskquotaLauncherShmem } #endif @@ -618,13 +612,9 @@ init_disk_quota_model(uint32 id) #ifdef USE_ASSERT_CHECKING if (!found) { - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(TimestampTz)); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // table_size_map_last_overflow_report - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(TimestampTz)); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, - sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report - Assert(pg_atomic_read_u64(diskquota_shmem_size) >= sizeof(TimestampTz)); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, sizeof(TimestampTz)); // quota_info_map_last_overflow_report + diskquota_shmem_size_sub(sizeof(TimestampTz)); // table_size_map_last_overflow_report + diskquota_shmem_size_sub(sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report + diskquota_shmem_size_sub(sizeof(TimestampTz)); // quota_info_map_last_overflow_report } #endif @@ -2416,3 +2406,12 @@ set_table_size_entry_flag(TableSizeEntry *entry, TableSizeEntryFlag flag) { entry->flag |= flag; } + +#ifdef USE_ASSERT_CHECKING +void +diskquota_shmem_size_sub(Size size) +{ + Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); +} +#endif From f0f44f9e6e71dea4a525527f244406def869e0c2 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 08:47:46 +0500 Subject: [PATCH 22/37] mv --- src/quotamodel.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index cf66f3961..f8ca85e89 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -610,12 +610,7 @@ init_disk_quota_model(uint32 id) if (!found) *table_size_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) - { - diskquota_shmem_size_sub(sizeof(TimestampTz)); // table_size_map_last_overflow_report - diskquota_shmem_size_sub(sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report - diskquota_shmem_size_sub(sizeof(TimestampTz)); // quota_info_map_last_overflow_report - } + if (!found) diskquota_shmem_size_sub(sizeof(TimestampTz)); // table_size_map_last_overflow_report #endif /* for localrejectmap */ @@ -632,6 +627,10 @@ init_disk_quota_model(uint32 id) local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!found) diskquota_shmem_size_sub(sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report +#endif + /* for quota_info_map */ format_name("QuotaInfoMap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -643,6 +642,10 @@ init_disk_quota_model(uint32 id) quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); if (!found) *quota_info_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!found) diskquota_shmem_size_sub(sizeof(TimestampTz)); // quota_info_map_last_overflow_report +#endif + pfree(str.data); } From c1d8e148a6d9ebe4a6f132ad8bb335cfd11703ea Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 08:54:58 +0500 Subject: [PATCH 23/37] define --- src/quotamodel.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index f8ca85e89..202d30b99 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -71,6 +71,10 @@ ? ((entry->key.id + 1) * SEGMENT_SIZE_ARRAY_LENGTH - 1) \ : SEGCOUNT) +#define TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) +#define LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) +#define QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) + typedef struct TableSizeEntry TableSizeEntry; typedef struct NamespaceSizeEntry NamespaceSizeEntry; typedef struct RoleSizeEntry RoleSizeEntry; @@ -546,9 +550,9 @@ diskquota_worker_shmem_size(void) size = add_size(size, hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); // local_disk_quota_reject_map size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); // quota_info_map - size = add_size(size, sizeof(TimestampTz)); // table_size_map_last_overflow_report - size = add_size(size, sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report - size = add_size(size, sizeof(TimestampTz)); // quota_info_map_last_overflow_report + size = add_size(size, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); + size = add_size(size, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); + size = add_size(size, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); return size; } @@ -606,11 +610,11 @@ init_disk_quota_model(uint32 id) table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("TableSizeEntrymap_last_overflow_report", id, &str); - table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) diskquota_shmem_size_sub(sizeof(TimestampTz)); // table_size_map_last_overflow_report + if (!found) diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); #endif /* for localrejectmap */ @@ -624,11 +628,12 @@ init_disk_quota_model(uint32 id) &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("localrejectmap_last_overflow_report", id, &str); - local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + local_disk_quota_reject_map_last_overflow_report = + ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) diskquota_shmem_size_sub(sizeof(TimestampTz)); // local_disk_quota_reject_map_last_overflow_report + if (!found) diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); #endif /* for quota_info_map */ @@ -639,11 +644,11 @@ init_disk_quota_model(uint32 id) quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("QuotaInfoMap_last_overflow_report", id, &str); - quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) diskquota_shmem_size_sub(sizeof(TimestampTz)); // quota_info_map_last_overflow_report + if (!found) diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); #endif pfree(str.data); @@ -688,7 +693,7 @@ vacuum_disk_quota_model(uint32 id) } format_name("TableSizeEntrymap_last_overflow_report", id, &str); - table_size_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; /* localrejectmap */ format_name("localrejectmap", id, &str); @@ -704,7 +709,8 @@ vacuum_disk_quota_model(uint32 id) hash_search(local_disk_quota_reject_map, &localrejectentry->keyitem, HASH_REMOVE, NULL); } format_name("localrejectmap_last_overflow_report", id, &str); - local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + local_disk_quota_reject_map_last_overflow_report = + ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; /* quota_info_map */ @@ -720,7 +726,7 @@ vacuum_disk_quota_model(uint32 id) hash_search(quota_info_map, &qentry->key, HASH_REMOVE, NULL); } format_name("QuotaInfoMap_last_overflow_report", id, &str); - quota_info_map_last_overflow_report = ShmemInitStruct(str.data, sizeof(TimestampTz), &found); + quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; pfree(str.data); From 42f15f9cc79462820dfd8391360fd66e034cbb95 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 08:59:20 +0500 Subject: [PATCH 24/37] definine --- src/diskquota.c | 4 ++-- src/diskquota.h | 2 ++ src/quotamodel.c | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 104eab387..31e9848f8 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1130,7 +1130,7 @@ process_extension_ddl_message() ExtensionDDLMessage local_extension_ddl_message; LWLockAcquire(diskquota_locks.extension_ddl_message_lock, LW_SHARED); - memcpy(&local_extension_ddl_message, extension_ddl_message, sizeof(ExtensionDDLMessage)); + memcpy(&local_extension_ddl_message, extension_ddl_message, EXTENSION_DDL_MESSAGE_SIZE); LWLockRelease(diskquota_locks.extension_ddl_message_lock); /* create/drop extension message must be valid */ @@ -1146,7 +1146,7 @@ process_extension_ddl_message() /* Send createdrop extension diskquota result back to QD */ LWLockAcquire(diskquota_locks.extension_ddl_message_lock, LW_EXCLUSIVE); - memset(extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); + memset(extension_ddl_message, 0, EXTENSION_DDL_MESSAGE_SIZE); extension_ddl_message->launcher_pid = MyProcPid; extension_ddl_message->result = (int)code; LWLockRelease(diskquota_locks.extension_ddl_message_lock); diff --git a/src/diskquota.h b/src/diskquota.h index c46adb216..1fadeb3e8 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -75,6 +75,8 @@ extern int diskquota_worker_timeout; #define DiskquotaGetRelstorage(classForm) (0) #endif /* GP_VERSION_NUM */ +#define EXTENSION_DDL_MESSAGE_SIZE sizeof(ExtensionDDLMessage) + typedef enum { NAMESPACE_QUOTA = 0, diff --git a/src/quotamodel.c b/src/quotamodel.c index 202d30b99..43d461e01 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -457,8 +457,8 @@ disk_quota_shmem_startup(void) if (!found) { pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize()); - diskquota_shmem_size_sub(sizeof(pg_atomic_uint64)); // diskquota_shmem_size - diskquota_shmem_size_sub(sizeof(ExtensionDDLMessage)); // extension_ddl_message + diskquota_shmem_size_sub(sizeof(pg_atomic_uint64)); // diskquota_shmem_size + diskquota_shmem_size_sub(EXTENSION_DDL_MESSAGE_SIZE); if (IS_QUERY_DISPATCHER()) diskquota_shmem_size_sub(diskquota_launcher_shmem_size()); // DiskquotaLauncherShmem } @@ -472,8 +472,8 @@ disk_quota_shmem_startup(void) * to store out-of-quota rejectmap. active_tables_map is used to store * active tables whose disk usage is changed. */ - extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", sizeof(ExtensionDDLMessage), &found); - if (!found) memset((void *)extension_ddl_message, 0, sizeof(ExtensionDDLMessage)); + extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", EXTENSION_DDL_MESSAGE_SIZE, &found); + if (!found) memset((void *)extension_ddl_message, 0, EXTENSION_DDL_MESSAGE_SIZE); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); @@ -564,7 +564,7 @@ static Size DiskQuotaShmemSize(void) { Size size; - size = sizeof(ExtensionDDLMessage); // extension_ddl_message + size = EXTENSION_DDL_MESSAGE_SIZE; #ifdef USE_ASSERT_CHECKING size = add_size(size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size From 3623d49ce984b791dfeae2282fb50141267c2dce Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:03:05 +0500 Subject: [PATCH 25/37] define --- src/quotamodel.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 43d461e01..121e95cad 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -74,6 +74,7 @@ #define TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) #define LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) #define QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) +#define DISK_QUOTA_REJECT_MAP_ENTRY_SIZE sizeof(GlobalRejectMapEntry) typedef struct TableSizeEntry TableSizeEntry; typedef struct NamespaceSizeEntry NamespaceSizeEntry; @@ -477,7 +478,7 @@ disk_quota_shmem_startup(void) memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); - hash_ctl.entrysize = sizeof(GlobalRejectMapEntry); + hash_ctl.entrysize = DISK_QUOTA_REJECT_MAP_ENTRY_SIZE; disk_quota_reject_map = DiskquotaShmemInitHash("rejectmap whose quota limitation is reached", diskquota_max_local_reject_entries, MAX_DISK_QUOTA_REJECT_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); @@ -570,8 +571,7 @@ DiskQuotaShmemSize(void) size = add_size(size, sizeof(pg_atomic_uint64)); // diskquota_shmem_size #endif - size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, - sizeof(GlobalRejectMapEntry))); // disk_quota_reject_map + size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, DISK_QUOTA_REJECT_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaActiveTableFileEntry))); // active_tables_map size = add_size(size, hash_estimate_size(diskquota_max_active_tables, @@ -1973,7 +1973,7 @@ refresh_rejectmap(PG_FUNCTION_ARGS) */ memset(&hashctl, 0, sizeof(hashctl)); hashctl.keysize = sizeof(RejectMapEntry); - hashctl.entrysize = sizeof(GlobalRejectMapEntry); + hashctl.entrysize = DISK_QUOTA_REJECT_MAP_ENTRY_SIZE; hashctl.hcxt = CurrentMemoryContext; /* @@ -2223,7 +2223,7 @@ refresh_rejectmap(PG_FUNCTION_ARGS) check_hash_fullness(disk_quota_reject_map, MAX_DISK_QUOTA_REJECT_ENTRIES, disk_quota_reject_map_warning, &disk_quota_reject_map_last_overflow_report); new_entry = hash_search(disk_quota_reject_map, &rejectmapentry->keyitem, action, &found); - if (!found && new_entry) memcpy(new_entry, rejectmapentry, sizeof(GlobalRejectMapEntry)); + if (!found && new_entry) memcpy(new_entry, rejectmapentry, DISK_QUOTA_REJECT_MAP_ENTRY_SIZE); } LWLockRelease(diskquota_locks.reject_map_lock); @@ -2277,7 +2277,7 @@ show_rejectmap(PG_FUNCTION_ARGS) /* Create a local hash table and fill it with entries from shared memory. */ memset(&hashctl, 0, sizeof(hashctl)); hashctl.keysize = sizeof(RejectMapEntry); - hashctl.entrysize = sizeof(GlobalRejectMapEntry); + hashctl.entrysize = DISK_QUOTA_REJECT_MAP_ENTRY_SIZE; hashctl.hcxt = CurrentMemoryContext; rejectmap_ctx->rejectmap = diskquota_hash_create("rejectmap_ctx rejectmap", 1024, &hashctl, HASH_ELEM | HASH_CONTEXT, DISKQUOTA_TAG_HASH); From 515b7f316dab2640f8a6c1d7ebcd076b019839bf Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:05:54 +0500 Subject: [PATCH 26/37] define --- src/diskquota.h | 1 + src/gp_activetable.c | 10 +++++----- src/quotamodel.c | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/diskquota.h b/src/diskquota.h index 1fadeb3e8..1908fb68d 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -76,6 +76,7 @@ extern int diskquota_worker_timeout; #endif /* GP_VERSION_NUM */ #define EXTENSION_DDL_MESSAGE_SIZE sizeof(ExtensionDDLMessage) +#define ACTIVE_TABLES_MAP_ENTRY_SIZE sizeof(DiskQuotaActiveTableFileEntry) typedef enum { diff --git a/src/gp_activetable.c b/src/gp_activetable.c index bf34e2ae0..4937818ad 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -109,8 +109,8 @@ init_shm_worker_active_tables(void) HASHCTL ctl; memset(&ctl, 0, sizeof(ctl)); - ctl.keysize = sizeof(DiskQuotaActiveTableFileEntry); - ctl.entrysize = sizeof(DiskQuotaActiveTableFileEntry); + ctl.keysize = ACTIVE_TABLES_MAP_ENTRY_SIZE; + ctl.entrysize = ACTIVE_TABLES_MAP_ENTRY_SIZE; active_tables_map = DiskquotaShmemInitHash("active_tables", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); @@ -322,7 +322,7 @@ report_active_table_helper(const RelFileNodeBackend *relFileNode) } found = false; - MemSet(&item, 0, sizeof(DiskQuotaActiveTableFileEntry)); + MemSet(&item, 0, ACTIVE_TABLES_MAP_ENTRY_SIZE); item.dbid = relFileNode->node.dbNode; item.relfilenode = relFileNode->node.relNode; item.tablespaceoid = relFileNode->node.spcNode; @@ -730,8 +730,8 @@ get_active_tables_oid(void) refresh_monitored_dbid_cache(); memset(&ctl, 0, sizeof(ctl)); - ctl.keysize = sizeof(DiskQuotaActiveTableFileEntry); - ctl.entrysize = sizeof(DiskQuotaActiveTableFileEntry); + ctl.keysize = ACTIVE_TABLES_MAP_ENTRY_SIZE; + ctl.entrysize = ACTIVE_TABLES_MAP_ENTRY_SIZE; ctl.hcxt = CurrentMemoryContext; local_active_table_file_map = diskquota_hash_create("local active table map with relfilenode info", 1024, &ctl, HASH_ELEM | HASH_CONTEXT, DISKQUOTA_TAG_HASH); diff --git a/src/quotamodel.c b/src/quotamodel.c index 121e95cad..72c2c7354 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -572,8 +572,7 @@ DiskQuotaShmemSize(void) #endif size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, DISK_QUOTA_REJECT_MAP_ENTRY_SIZE)); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, - sizeof(DiskQuotaActiveTableFileEntry))); // active_tables_map + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, ACTIVE_TABLES_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelationCacheEntry))); // relation_cache size = add_size(size, From e326460e796e5e1d88b049203b7ccc734f45b05a Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:08:13 +0500 Subject: [PATCH 27/37] define --- src/diskquota.h | 1 + src/quotamodel.c | 3 +-- src/relation_cache.c | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/diskquota.h b/src/diskquota.h index 1908fb68d..436c37b9b 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -77,6 +77,7 @@ extern int diskquota_worker_timeout; #define EXTENSION_DDL_MESSAGE_SIZE sizeof(ExtensionDDLMessage) #define ACTIVE_TABLES_MAP_ENTRY_SIZE sizeof(DiskQuotaActiveTableFileEntry) +#define RELATION_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelationCacheEntry) typedef enum { diff --git a/src/quotamodel.c b/src/quotamodel.c index 72c2c7354..62661c0fa 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -573,8 +573,7 @@ DiskQuotaShmemSize(void) size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, DISK_QUOTA_REJECT_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, ACTIVE_TABLES_MAP_ENTRY_SIZE)); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, - sizeof(DiskQuotaRelationCacheEntry))); // relation_cache + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELATION_CACHE_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); // relid_cache size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); // altered_reloid_cache diff --git a/src/relation_cache.c b/src/relation_cache.c index b5624c420..1824cce08 100644 --- a/src/relation_cache.c +++ b/src/relation_cache.c @@ -54,7 +54,7 @@ init_shm_worker_relation_cache(void) memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); - ctl.entrysize = sizeof(DiskQuotaRelationCacheEntry); + ctl.entrysize = RELATION_CACHE_ENTRY_SIZE; relation_cache = DiskquotaShmemInitHash("relation_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); @@ -198,7 +198,7 @@ update_relation_cache(Oid relid) LWLockRelease(diskquota_locks.relation_cache_lock); return; } - memcpy(relation_entry, &relation_entry_data, sizeof(DiskQuotaRelationCacheEntry)); + memcpy(relation_entry, &relation_entry_data, RELATION_CACHE_ENTRY_SIZE); action = check_hash_fullness(relid_cache, diskquota_max_active_tables, relid_cache_warning, &active_tables_map_last_overflow_report); @@ -302,7 +302,7 @@ remove_committed_relation_from_cache(void) memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); - ctl.entrysize = sizeof(DiskQuotaRelationCacheEntry); + ctl.entrysize = RELATION_CACHE_ENTRY_SIZE; ctl.hcxt = CurrentMemoryContext; local_relation_cache = diskquota_hash_create("local relation cache", 1024, &ctl, HASH_ELEM | HASH_CONTEXT, DISKQUOTA_OID_HASH); @@ -314,7 +314,7 @@ remove_committed_relation_from_cache(void) /* The session of db1 should not see the table inside db2. */ if (entry->rnode.node.dbNode != MyDatabaseId) continue; local_entry = hash_search(local_relation_cache, &entry->relid, HASH_ENTER, NULL); - memcpy(local_entry, entry, sizeof(DiskQuotaRelationCacheEntry)); + memcpy(local_entry, entry, RELATION_CACHE_ENTRY_SIZE); } LWLockRelease(diskquota_locks.relation_cache_lock); @@ -380,7 +380,7 @@ show_relation_cache(PG_FUNCTION_ARGS) /* Create a local hash table and fill it with entries from shared memory. */ memset(&hashctl, 0, sizeof(hashctl)); hashctl.keysize = sizeof(Oid); - hashctl.entrysize = sizeof(DiskQuotaRelationCacheEntry); + hashctl.entrysize = RELATION_CACHE_ENTRY_SIZE; hashctl.hcxt = CurrentMemoryContext; relation_cache_ctx->relation_cache = diskquota_hash_create("relation_cache_ctx->relation_cache", 1024, &hashctl, @@ -396,7 +396,7 @@ show_relation_cache(PG_FUNCTION_ARGS) hash_search(relation_cache_ctx->relation_cache, &entry->relid, HASH_ENTER_NULL, NULL); if (local_entry) { - memcpy(local_entry, entry, sizeof(DiskQuotaRelationCacheEntry)); + memcpy(local_entry, entry, RELATION_CACHE_ENTRY_SIZE); } } LWLockRelease(diskquota_locks.relation_cache_lock); @@ -559,7 +559,7 @@ get_relation_entry(Oid relid, DiskQuotaRelationCacheEntry *entry) tentry = hash_search(relation_cache, &relid, HASH_FIND, NULL); if (tentry) { - memcpy(entry, tentry, sizeof(DiskQuotaRelationCacheEntry)); + memcpy(entry, tentry, RELATION_CACHE_ENTRY_SIZE); LWLockRelease(diskquota_locks.relation_cache_lock); return; } From 34167ec9da2d659f54ae87142ec49c084a77baf3 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:09:50 +0500 Subject: [PATCH 28/37] define --- src/diskquota.h | 1 + src/quotamodel.c | 3 +-- src/relation_cache.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diskquota.h b/src/diskquota.h index 436c37b9b..ee8078858 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -78,6 +78,7 @@ extern int diskquota_worker_timeout; #define EXTENSION_DDL_MESSAGE_SIZE sizeof(ExtensionDDLMessage) #define ACTIVE_TABLES_MAP_ENTRY_SIZE sizeof(DiskQuotaActiveTableFileEntry) #define RELATION_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelationCacheEntry) +#define RELID_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelidCacheEntry) typedef enum { diff --git a/src/quotamodel.c b/src/quotamodel.c index 62661c0fa..d40b02e72 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -574,8 +574,7 @@ DiskQuotaShmemSize(void) size = add_size(size, hash_estimate_size(MAX_DISK_QUOTA_REJECT_ENTRIES, DISK_QUOTA_REJECT_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, ACTIVE_TABLES_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELATION_CACHE_ENTRY_SIZE)); - size = add_size(size, - hash_estimate_size(diskquota_max_active_tables, sizeof(DiskQuotaRelidCacheEntry))); // relid_cache + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELID_CACHE_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); // altered_reloid_cache size = add_size(size, hash_estimate_size(diskquota_max_monitored_databases, sizeof(struct MonitorDBEntryStruct))); // monitored_dbid_cache diff --git a/src/relation_cache.c b/src/relation_cache.c index 1824cce08..f8af84296 100644 --- a/src/relation_cache.c +++ b/src/relation_cache.c @@ -60,7 +60,7 @@ init_shm_worker_relation_cache(void) memset(&ctl, 0, sizeof(ctl)); ctl.keysize = sizeof(Oid); - ctl.entrysize = sizeof(DiskQuotaRelidCacheEntry); + ctl.entrysize = RELID_CACHE_ENTRY_SIZE; relid_cache = DiskquotaShmemInitHash("relid_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); } @@ -208,7 +208,7 @@ update_relation_cache(Oid relid) LWLockRelease(diskquota_locks.relation_cache_lock); return; } - memcpy(relid_entry, &relid_entry_data, sizeof(DiskQuotaRelidCacheEntry)); + memcpy(relid_entry, &relid_entry_data, RELID_CACHE_ENTRY_SIZE); LWLockRelease(diskquota_locks.relation_cache_lock); prelid = get_primary_table_oid(relid, false); From e0a959b63c61be67734cb0e3ddbb9808359c62d0 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:12:53 +0500 Subject: [PATCH 29/37] define --- src/diskquota.h | 1 + src/gp_activetable.c | 8 ++++---- src/quotamodel.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/diskquota.h b/src/diskquota.h index ee8078858..235efeb31 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -79,6 +79,7 @@ extern int diskquota_worker_timeout; #define ACTIVE_TABLES_MAP_ENTRY_SIZE sizeof(DiskQuotaActiveTableFileEntry) #define RELATION_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelationCacheEntry) #define RELID_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelidCacheEntry) +#define ALTERED_RELOID_CACHE_ENTRY_SIZE sizeof(Oid) typedef enum { diff --git a/src/gp_activetable.c b/src/gp_activetable.c index 4937818ad..dba31b30a 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -115,8 +115,8 @@ init_shm_worker_active_tables(void) diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); memset(&ctl, 0, sizeof(ctl)); - ctl.keysize = sizeof(Oid); - ctl.entrysize = sizeof(Oid); + ctl.keysize = ALTERED_RELOID_CACHE_ENTRY_SIZE; + ctl.entrysize = ALTERED_RELOID_CACHE_ENTRY_SIZE; altered_reloid_cache = DiskquotaShmemInitHash("altered_reloid_cache", diskquota_max_active_tables, diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_OID_HASH); } @@ -737,8 +737,8 @@ get_active_tables_oid(void) HASH_ELEM | HASH_CONTEXT, DISKQUOTA_TAG_HASH); memset(&ctl, 0, sizeof(ctl)); - ctl.keysize = sizeof(Oid); - ctl.entrysize = sizeof(Oid); + ctl.keysize = ALTERED_RELOID_CACHE_ENTRY_SIZE; + ctl.entrysize = ALTERED_RELOID_CACHE_ENTRY_SIZE; ctl.hcxt = CurrentMemoryContext; local_altered_reloid_cache = diskquota_hash_create("local_altered_reloid_cache", 1024, &ctl, HASH_ELEM | HASH_CONTEXT, DISKQUOTA_OID_HASH); diff --git a/src/quotamodel.c b/src/quotamodel.c index d40b02e72..83b281d19 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -575,7 +575,7 @@ DiskQuotaShmemSize(void) size = add_size(size, hash_estimate_size(diskquota_max_active_tables, ACTIVE_TABLES_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELATION_CACHE_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELID_CACHE_ENTRY_SIZE)); - size = add_size(size, hash_estimate_size(diskquota_max_active_tables, sizeof(Oid))); // altered_reloid_cache + size = add_size(size, hash_estimate_size(diskquota_max_active_tables, ALTERED_RELOID_CACHE_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_monitored_databases, sizeof(struct MonitorDBEntryStruct))); // monitored_dbid_cache From 3892eaa9ea159f994181016bbdaa970091ff4bd7 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:14:25 +0500 Subject: [PATCH 30/37] define --- src/diskquota.h | 1 + src/monitored_db.c | 4 ++-- src/quotamodel.c | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/diskquota.h b/src/diskquota.h index 235efeb31..949a677bc 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -80,6 +80,7 @@ extern int diskquota_worker_timeout; #define RELATION_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelationCacheEntry) #define RELID_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelidCacheEntry) #define ALTERED_RELOID_CACHE_ENTRY_SIZE sizeof(Oid) +#define MONITORED_DBID_CACHE_ENTRY_SIZE sizeof(struct MonitorDBEntryStruct) typedef enum { diff --git a/src/monitored_db.c b/src/monitored_db.c index c2b29a1ba..93049ffbb 100644 --- a/src/monitored_db.c +++ b/src/monitored_db.c @@ -322,14 +322,14 @@ dump_monitored_dbid_cache(long *nitems) HASH_SEQ_STATUS seq; MonitorDBEntry curEntry; int count = *nitems = hash_get_num_entries(monitored_dbid_cache); - MonitorDBEntry entries = curEntry = (MonitorDBEntry)palloc(sizeof(struct MonitorDBEntryStruct) * count); + MonitorDBEntry entries = curEntry = (MonitorDBEntry)palloc(MONITORED_DBID_CACHE_ENTRY_SIZE * count); hash_seq_init(&seq, monitored_dbid_cache); MonitorDBEntry entry; while ((entry = hash_seq_search(&seq)) != NULL) { Assert(count > 0); - memcpy(curEntry, entry, sizeof(struct MonitorDBEntryStruct)); + memcpy(curEntry, entry, MONITORED_DBID_CACHE_ENTRY_SIZE); curEntry++; count--; } diff --git a/src/quotamodel.c b/src/quotamodel.c index 83b281d19..41456d189 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -489,7 +489,7 @@ disk_quota_shmem_startup(void) memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(Oid); - hash_ctl.entrysize = sizeof(struct MonitorDBEntryStruct); + hash_ctl.entrysize = MONITORED_DBID_CACHE_ENTRY_SIZE; monitored_dbid_cache = DiskquotaShmemInitHash("table oid cache which shoud tracking", diskquota_max_monitored_databases, @@ -576,8 +576,7 @@ DiskQuotaShmemSize(void) size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELATION_CACHE_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, RELID_CACHE_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(diskquota_max_active_tables, ALTERED_RELOID_CACHE_ENTRY_SIZE)); - size = add_size(size, hash_estimate_size(diskquota_max_monitored_databases, - sizeof(struct MonitorDBEntryStruct))); // monitored_dbid_cache + size = add_size(size, hash_estimate_size(diskquota_max_monitored_databases, MONITORED_DBID_CACHE_ENTRY_SIZE)); if (IS_QUERY_DISPATCHER()) { From a89e596ac3ed2ceb166f046d590af276bb9f68c8 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:16:16 +0500 Subject: [PATCH 31/37] define --- src/quotamodel.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 41456d189..c40ccf086 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -75,6 +75,7 @@ #define LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) #define QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) #define DISK_QUOTA_REJECT_MAP_ENTRY_SIZE sizeof(GlobalRejectMapEntry) +#define TABLE_SIZE_MAP_ENTRY_SIZE sizeof(TableSizeEntry) typedef struct TableSizeEntry TableSizeEntry; typedef struct NamespaceSizeEntry NamespaceSizeEntry; @@ -547,7 +548,7 @@ static Size diskquota_worker_shmem_size(void) { Size size; - size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, sizeof(TableSizeEntry)); // table_size_map + size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, TABLE_SIZE_MAP_ENTRY_SIZE); size = add_size(size, hash_estimate_size(diskquota_max_local_reject_entries, sizeof(LocalRejectMapEntry))); // local_disk_quota_reject_map size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); // quota_info_map @@ -602,7 +603,7 @@ init_disk_quota_model(uint32 id) format_name("TableSizeEntrymap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(TableSizeEntryKey); - hash_ctl.entrysize = sizeof(TableSizeEntry); + hash_ctl.entrysize = TABLE_SIZE_MAP_ENTRY_SIZE; table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("TableSizeEntrymap_last_overflow_report", id, &str); @@ -679,7 +680,7 @@ vacuum_disk_quota_model(uint32 id) format_name("TableSizeEntrymap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(TableSizeEntryKey); - hash_ctl.entrysize = sizeof(TableSizeEntry); + hash_ctl.entrysize = TABLE_SIZE_MAP_ENTRY_SIZE; table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); hash_seq_init(&iter, table_size_map); From 8cee3b4d31a27a466b2b53293c2225ec8ad66f21 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:18:09 +0500 Subject: [PATCH 32/37] define --- src/quotamodel.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index c40ccf086..9ceff3518 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -76,6 +76,7 @@ #define QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE sizeof(TimestampTz) #define DISK_QUOTA_REJECT_MAP_ENTRY_SIZE sizeof(GlobalRejectMapEntry) #define TABLE_SIZE_MAP_ENTRY_SIZE sizeof(TableSizeEntry) +#define LOCAL_DISK_QUOTA_REJECT_MAP_ENTRY_SIZE sizeof(LocalRejectMapEntry) typedef struct TableSizeEntry TableSizeEntry; typedef struct NamespaceSizeEntry NamespaceSizeEntry; @@ -549,8 +550,8 @@ diskquota_worker_shmem_size(void) { Size size; size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, TABLE_SIZE_MAP_ENTRY_SIZE); - size = add_size(size, hash_estimate_size(diskquota_max_local_reject_entries, - sizeof(LocalRejectMapEntry))); // local_disk_quota_reject_map + size = add_size(size, + hash_estimate_size(diskquota_max_local_reject_entries, LOCAL_DISK_QUOTA_REJECT_MAP_ENTRY_SIZE)); size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); // quota_info_map size = add_size(size, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); size = add_size(size, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); @@ -619,7 +620,7 @@ init_disk_quota_model(uint32 id) format_name("localrejectmap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); - hash_ctl.entrysize = sizeof(LocalRejectMapEntry); + hash_ctl.entrysize = LOCAL_DISK_QUOTA_REJECT_MAP_ENTRY_SIZE; local_disk_quota_reject_map = DiskquotaShmemInitHash(str.data, diskquota_max_local_reject_entries, diskquota_max_local_reject_entries, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); @@ -696,7 +697,7 @@ vacuum_disk_quota_model(uint32 id) format_name("localrejectmap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(RejectMapEntry); - hash_ctl.entrysize = sizeof(LocalRejectMapEntry); + hash_ctl.entrysize = LOCAL_DISK_QUOTA_REJECT_MAP_ENTRY_SIZE; local_disk_quota_reject_map = DiskquotaShmemInitHash(str.data, diskquota_max_local_reject_entries, diskquota_max_local_reject_entries, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); From b3f721c32b7ab7fdf851cb8524b7d92df5e412ef Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 09:19:32 +0500 Subject: [PATCH 33/37] define --- src/quotamodel.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 9ceff3518..e707f02be 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -77,6 +77,7 @@ #define DISK_QUOTA_REJECT_MAP_ENTRY_SIZE sizeof(GlobalRejectMapEntry) #define TABLE_SIZE_MAP_ENTRY_SIZE sizeof(TableSizeEntry) #define LOCAL_DISK_QUOTA_REJECT_MAP_ENTRY_SIZE sizeof(LocalRejectMapEntry) +#define QUOTA_INFO_MAP_ENTRY_SIZE sizeof(QuotaInfoEntry) typedef struct TableSizeEntry TableSizeEntry; typedef struct NamespaceSizeEntry NamespaceSizeEntry; @@ -552,7 +553,7 @@ diskquota_worker_shmem_size(void) size = hash_estimate_size(MAX_NUM_TABLE_SIZE_ENTRIES, TABLE_SIZE_MAP_ENTRY_SIZE); size = add_size(size, hash_estimate_size(diskquota_max_local_reject_entries, LOCAL_DISK_QUOTA_REJECT_MAP_ENTRY_SIZE)); - size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, sizeof(QuotaInfoEntry))); // quota_info_map + size = add_size(size, hash_estimate_size(MAX_QUOTA_MAP_ENTRIES, QUOTA_INFO_MAP_ENTRY_SIZE)); size = add_size(size, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); size = add_size(size, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); size = add_size(size, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); @@ -637,7 +638,7 @@ init_disk_quota_model(uint32 id) /* for quota_info_map */ format_name("QuotaInfoMap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); - hash_ctl.entrysize = sizeof(QuotaInfoEntry); + hash_ctl.entrysize = QUOTA_INFO_MAP_ENTRY_SIZE; hash_ctl.keysize = sizeof(QuotaInfoEntryKey); quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); @@ -714,7 +715,7 @@ vacuum_disk_quota_model(uint32 id) /* quota_info_map */ format_name("QuotaInfoMap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); - hash_ctl.entrysize = sizeof(QuotaInfoEntry); + hash_ctl.entrysize = QUOTA_INFO_MAP_ENTRY_SIZE; hash_ctl.keysize = sizeof(QuotaInfoEntryKey); quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); From 09211bbb593e14cdbabd4d9abe08dbc8105aa99b Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 12:03:51 +0500 Subject: [PATCH 34/37] fix condition --- src/quotamodel.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index e707f02be..cec2da47e 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -219,8 +219,9 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; #ifdef USE_ASSERT_CHECKING -pg_atomic_uint64 *diskquota_shmem_size; -void diskquota_shmem_size_sub(Size size); +extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; +pg_atomic_uint64 *diskquota_shmem_size; +void diskquota_shmem_size_sub(Size size); #endif /* functions to maintain the quota maps */ @@ -613,7 +614,8 @@ init_disk_quota_model(uint32 id) if (!found) *table_size_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); #endif /* for localrejectmap */ @@ -632,7 +634,8 @@ init_disk_quota_model(uint32 id) if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); #endif /* for quota_info_map */ @@ -647,7 +650,8 @@ init_disk_quota_model(uint32 id) if (!found) *quota_info_map_last_overflow_report = 0; #ifdef USE_ASSERT_CHECKING - if (!found) diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); #endif pfree(str.data); @@ -694,6 +698,12 @@ vacuum_disk_quota_model(uint32 id) format_name("TableSizeEntrymap_last_overflow_report", id, &str); table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; + +#ifdef USE_ASSERT_CHECKING + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); +#endif + /* localrejectmap */ format_name("localrejectmap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -712,6 +722,11 @@ vacuum_disk_quota_model(uint32 id) ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); +#endif + /* quota_info_map */ format_name("QuotaInfoMap", id, &str); memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -728,6 +743,11 @@ vacuum_disk_quota_model(uint32 id) quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; +#ifdef USE_ASSERT_CHECKING + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); +#endif + pfree(str.data); } From c998e359ab30ed119803cf1e9f4cb104f2393701 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 12:57:49 +0500 Subject: [PATCH 35/37] optimize --- src/diskquota_utility.c | 7 +++---- src/quotamodel.c | 42 +++++++++++------------------------------ 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index de4b0e772..676e58103 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -118,6 +118,8 @@ static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb); extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; extern pg_atomic_uint64 *diskquota_shmem_size; extern void diskquota_shmem_size_sub(Size size); +#else +#define diskquota_shmem_size_sub(size) ((void)true) #endif /* ---- Help Functions to set quota limit. ---- */ @@ -1648,10 +1650,7 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo int hash_flags, /* info about infoP */ DiskquotaHashFunction hashFunction) { -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize)); -#endif + diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize)); #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) infoP->hash = tag_hash; diff --git a/src/quotamodel.c b/src/quotamodel.c index cec2da47e..8f699cc65 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -222,6 +222,8 @@ static shmem_startup_hook_type prev_shmem_startup_hook = NULL; extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; pg_atomic_uint64 *diskquota_shmem_size; void diskquota_shmem_size_sub(Size size); +#else +#define diskquota_shmem_size_sub(size) ((void)true) #endif /* functions to maintain the quota maps */ @@ -612,11 +614,7 @@ init_disk_quota_model(uint32 id) format_name("TableSizeEntrymap_last_overflow_report", id, &str); table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); -#endif + diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); /* for localrejectmap */ /* WARNNING: The max length of name of the map is 48 */ @@ -632,11 +630,7 @@ init_disk_quota_model(uint32 id) local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); -#endif + diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); /* for quota_info_map */ format_name("QuotaInfoMap", id, &str); @@ -648,11 +642,7 @@ init_disk_quota_model(uint32 id) format_name("QuotaInfoMap_last_overflow_report", id, &str); quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); -#endif + diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); pfree(str.data); } @@ -698,11 +688,7 @@ vacuum_disk_quota_model(uint32 id) format_name("TableSizeEntrymap_last_overflow_report", id, &str); table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); -#endif + diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); /* localrejectmap */ format_name("localrejectmap", id, &str); @@ -721,11 +707,7 @@ vacuum_disk_quota_model(uint32 id) local_disk_quota_reject_map_last_overflow_report = ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); -#endif + diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); /* quota_info_map */ format_name("QuotaInfoMap", id, &str); @@ -742,11 +724,7 @@ vacuum_disk_quota_model(uint32 id) format_name("QuotaInfoMap_last_overflow_report", id, &str); quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; - -#ifdef USE_ASSERT_CHECKING - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); -#endif + diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); pfree(str.data); } @@ -2440,6 +2418,8 @@ void diskquota_shmem_size_sub(Size size) { Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); - pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); + + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); } #endif From 1edbc06dcfcefecd35250b8186450ae07e87bb93 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 13:11:17 +0500 Subject: [PATCH 36/37] optimize --- src/diskquota.c | 4 ++-- src/diskquota.h | 1 + src/diskquota_utility.c | 15 +++++++++++---- src/quotamodel.c | 38 +++++++++++++++----------------------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 31e9848f8..00faba4b5 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1732,8 +1732,8 @@ void init_launcher_shmem() { bool found; - DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)ShmemInitStruct("Diskquota launcher Data", - diskquota_launcher_shmem_size(), &found); + DiskquotaLauncherShmem = (DiskquotaLauncherShmemStruct *)DiskquotaShmemInitStruct( + "Diskquota launcher Data", diskquota_launcher_shmem_size(), &found); memset(DiskquotaLauncherShmem, 0, diskquota_launcher_shmem_size()); if (!found) { diff --git a/src/diskquota.h b/src/diskquota.h index 949a677bc..a726d8cf9 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -323,6 +323,7 @@ extern HTAB *diskquota_hash_create(const char *tabname, long nelem, HASHC DiskquotaHashFunction hashFunction); extern HTAB *DiskquotaShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags, DiskquotaHashFunction hash_function); +extern void *DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr); extern void refresh_monitored_dbid_cache(void); extern HASHACTION check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, TimestampTz *last_overflow_report); diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 676e58103..8b64a2e06 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -116,10 +116,7 @@ static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb); #ifdef USE_ASSERT_CHECKING extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; -extern pg_atomic_uint64 *diskquota_shmem_size; extern void diskquota_shmem_size_sub(Size size); -#else -#define diskquota_shmem_size_sub(size) ((void)true) #endif /* ---- Help Functions to set quota limit. ---- */ @@ -1650,7 +1647,9 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo int hash_flags, /* info about infoP */ DiskquotaHashFunction hashFunction) { - diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize)); + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) + diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize)); + #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) infoP->hash = tag_hash; @@ -1664,6 +1663,14 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo #endif /* GP_VERSION_NUM */ } +void * +DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr) +{ + if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) diskquota_shmem_size_sub(size); + + return ShmemInitStruct(name, size, foundPtr); +} + /* * Returns HASH_FIND if hash table is full and HASH_ENTER otherwise. * It can be used only under lock. diff --git a/src/quotamodel.c b/src/quotamodel.c index 8f699cc65..740e99c1a 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -219,11 +219,8 @@ static const char *local_disk_quota_reject_map_warning = static shmem_startup_hook_type prev_shmem_startup_hook = NULL; #ifdef USE_ASSERT_CHECKING -extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem; -pg_atomic_uint64 *diskquota_shmem_size; -void diskquota_shmem_size_sub(Size size); -#else -#define diskquota_shmem_size_sub(size) ((void)true) +static pg_atomic_uint64 *diskquota_shmem_size; +void diskquota_shmem_size_sub(Size size); #endif /* functions to maintain the quota maps */ @@ -465,9 +462,6 @@ disk_quota_shmem_startup(void) { pg_atomic_init_u64(diskquota_shmem_size, DiskQuotaShmemSize()); diskquota_shmem_size_sub(sizeof(pg_atomic_uint64)); // diskquota_shmem_size - diskquota_shmem_size_sub(EXTENSION_DDL_MESSAGE_SIZE); - - if (IS_QUERY_DISPATCHER()) diskquota_shmem_size_sub(diskquota_launcher_shmem_size()); // DiskquotaLauncherShmem } #endif @@ -479,7 +473,8 @@ disk_quota_shmem_startup(void) * to store out-of-quota rejectmap. active_tables_map is used to store * active tables whose disk usage is changed. */ - extension_ddl_message = ShmemInitStruct("disk_quota_extension_ddl_message", EXTENSION_DDL_MESSAGE_SIZE, &found); + extension_ddl_message = + DiskquotaShmemInitStruct("disk_quota_extension_ddl_message", EXTENSION_DDL_MESSAGE_SIZE, &found); if (!found) memset((void *)extension_ddl_message, 0, EXTENSION_DDL_MESSAGE_SIZE); memset(&hash_ctl, 0, sizeof(hash_ctl)); @@ -612,9 +607,9 @@ init_disk_quota_model(uint32 id) table_size_map = DiskquotaShmemInitHash(str.data, INIT_NUM_TABLE_SIZE_ENTRIES, MAX_NUM_TABLE_SIZE_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("TableSizeEntrymap_last_overflow_report", id, &str); - table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); + table_size_map_last_overflow_report = + DiskquotaShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; - diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); /* for localrejectmap */ /* WARNNING: The max length of name of the map is 48 */ @@ -628,9 +623,8 @@ init_disk_quota_model(uint32 id) format_name("localrejectmap_last_overflow_report", id, &str); local_disk_quota_reject_map_last_overflow_report = - ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); + DiskquotaShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; - diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); /* for quota_info_map */ format_name("QuotaInfoMap", id, &str); @@ -640,9 +634,9 @@ init_disk_quota_model(uint32 id) quota_info_map = DiskquotaShmemInitHash(str.data, INIT_QUOTA_MAP_ENTRIES, MAX_QUOTA_MAP_ENTRIES, &hash_ctl, HASH_ELEM, DISKQUOTA_TAG_HASH); format_name("QuotaInfoMap_last_overflow_report", id, &str); - quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); + quota_info_map_last_overflow_report = + DiskquotaShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; - diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); pfree(str.data); } @@ -686,9 +680,9 @@ vacuum_disk_quota_model(uint32 id) } format_name("TableSizeEntrymap_last_overflow_report", id, &str); - table_size_map_last_overflow_report = ShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); + table_size_map_last_overflow_report = + DiskquotaShmemInitStruct(str.data, TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *table_size_map_last_overflow_report = 0; - diskquota_shmem_size_sub(TABLE_SIZE_MAP_LAST_OVERFLOW_REPORT_SIZE); /* localrejectmap */ format_name("localrejectmap", id, &str); @@ -705,9 +699,8 @@ vacuum_disk_quota_model(uint32 id) } format_name("localrejectmap_last_overflow_report", id, &str); local_disk_quota_reject_map_last_overflow_report = - ShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); + DiskquotaShmemInitStruct(str.data, LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *local_disk_quota_reject_map_last_overflow_report = 0; - diskquota_shmem_size_sub(LOCAL_DISK_QUOTA_REJECT_MAP_LAST_OVERFLOW_REPORT_SIZE); /* quota_info_map */ format_name("QuotaInfoMap", id, &str); @@ -722,9 +715,9 @@ vacuum_disk_quota_model(uint32 id) hash_search(quota_info_map, &qentry->key, HASH_REMOVE, NULL); } format_name("QuotaInfoMap_last_overflow_report", id, &str); - quota_info_map_last_overflow_report = ShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); + quota_info_map_last_overflow_report = + DiskquotaShmemInitStruct(str.data, QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE, &found); if (!found) *quota_info_map_last_overflow_report = 0; - diskquota_shmem_size_sub(QUOTA_INFO_MAP_LAST_OVERFLOW_REPORT_SIZE); pfree(str.data); } @@ -2419,7 +2412,6 @@ diskquota_shmem_size_sub(Size size) { Assert(pg_atomic_read_u64(diskquota_shmem_size) >= size); - if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) - pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); + pg_atomic_sub_fetch_u64(diskquota_shmem_size, size); } #endif From deef7f76a3def6166be30a36a3dfe00ce4d94f19 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Mon, 15 Dec 2025 13:15:33 +0500 Subject: [PATCH 37/37] assert --- src/diskquota_utility.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 8b64a2e06..514bbfa0a 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1647,8 +1647,10 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo int hash_flags, /* info about infoP */ DiskquotaHashFunction hashFunction) { +#ifdef USE_ASSERT_CHECKING if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize)); +#endif #if GP_VERSION_NUM < 70000 if (hashFunction == DISKQUOTA_TAG_HASH) @@ -1666,7 +1668,9 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo void * DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr) { +#ifdef USE_ASSERT_CHECKING if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) diskquota_shmem_size_sub(size); +#endif return ShmemInitStruct(name, size, foundPtr); }