Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a6be5c7
Restore old logic for limiting sizes of table_size and quota_info_map
RekGRpth Dec 1, 2025
0636aaa
fix test_many_active_tables
RekGRpth Dec 4, 2025
26d0a0e
Fix shared memory allocation and usage in diskquota
RekGRpth Dec 4, 2025
5a86831
fix
RekGRpth Dec 5, 2025
393f5ab
assert
RekGRpth Dec 5, 2025
899e809
rm warning
RekGRpth Dec 5, 2025
0df528c
void
RekGRpth Dec 5, 2025
17da424
rm lock
RekGRpth Dec 5, 2025
f8411bc
32 -> 64
RekGRpth Dec 5, 2025
3b4768f
simplify
RekGRpth Dec 8, 2025
fa0952b
format
RekGRpth Dec 8, 2025
a79dfa6
simplify
RekGRpth Dec 8, 2025
ceb42d3
revert
RekGRpth Dec 8, 2025
99e41d6
revet
RekGRpth Dec 8, 2025
dced14d
revert
RekGRpth Dec 8, 2025
0b7c829
fix
RekGRpth Dec 8, 2025
8f7531e
fix
RekGRpth Dec 8, 2025
79ef88e
revert
RekGRpth Dec 9, 2025
994c9f1
revert
RekGRpth Dec 9, 2025
987a6b0
Merge branch 'ADBDEV-8953' into ADBDEV-8922
RekGRpth Dec 10, 2025
5ab2417
updates
RekGRpth Dec 10, 2025
ce9fc98
fix
RekGRpth Dec 10, 2025
42b4482
optimize
RekGRpth Dec 10, 2025
f84badc
format
RekGRpth Dec 10, 2025
a324cbe
fix
RekGRpth Dec 11, 2025
3064862
fix
RekGRpth Dec 11, 2025
fd56b9b
fix
RekGRpth Dec 11, 2025
eca4df4
Merge branch 'gpdb' into ADBDEV-8922
RekGRpth Dec 16, 2025
83143a8
fix
RekGRpth Dec 16, 2025
e4798da
fix assert
RekGRpth Dec 16, 2025
c1fa28d
rm
RekGRpth Dec 16, 2025
e023d81
rework
RekGRpth Dec 16, 2025
9d0eaca
fix
RekGRpth Dec 16, 2025
e56b228
fix
RekGRpth Dec 18, 2025
0d42629
unify
RekGRpth Dec 18, 2025
ec8c480
avoid mix
RekGRpth Dec 18, 2025
ae2b42a
fix and reorder
RekGRpth Dec 18, 2025
0aea6f7
comments
RekGRpth Dec 18, 2025
3808e3c
rename
RekGRpth Dec 18, 2025
2e84115
fix
RekGRpth Dec 18, 2025
264e8da
fix
RekGRpth Dec 18, 2025
3fbe56c
fix
RekGRpth Dec 18, 2025
4ec3ed9
optimize
RekGRpth Dec 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/diskquota.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,18 @@ static DiskQuotaWorkerEntry *volatile MyWorkerInfo = NULL;
// how many database diskquota are monitoring on
static int num_db = 0;

DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem = NULL;
static DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem;

/* how many TableSizeEntry are maintained in all the table_size_map in shared memory */
pg_atomic_uint32 *diskquota_table_size_entry_num;

/* how many QuotaInfoEntry are maintained in all the quota_info_map in shared memory */
pg_atomic_uint32 *diskquota_quota_info_entry_num;

#ifdef USE_ASSERT_CHECKING
extern pg_atomic_flag *diskquota_table_size_flag;
extern pg_atomic_flag *diskquota_quota_info_flag;
Comment thread
KnightMurloc marked this conversation as resolved.
#endif

#define MIN_SLEEPTIME 100 /* milliseconds */
#define BGWORKER_LOG_TIME 3600000 /* milliseconds */
Expand Down Expand Up @@ -1772,6 +1783,25 @@ init_launcher_shmem()
DiskquotaLauncherShmem->dbArray[i].workerId = INVALID_WORKER_ID;
}
}
/* init TableSizeEntry counter */
diskquota_table_size_entry_num =
DiskquotaShmemInitStruct("diskquota TableSizeEntry counter", DISKQUOTA_TABLE_SIZE_ENTRY_NUM_SIZE, &found);
if (!found) pg_atomic_init_u32(diskquota_table_size_entry_num, 0);

/* init QuotaInfoEntry counter */
diskquota_quota_info_entry_num =
DiskquotaShmemInitStruct("diskquota QuotaInfoEntry counter", DISKQUOTA_QUOTA_INFO_ENTRY_NUM_SIZE, &found);
if (!found) pg_atomic_init_u32(diskquota_quota_info_entry_num, 0);

#ifdef USE_ASSERT_CHECKING
diskquota_table_size_flag =
DiskquotaShmemInitStruct("diskquota TableSizeEntry flag", DISKQUOTA_TABLE_SIZE_FLAG_SIZE, &found);
if (!found) pg_atomic_init_flag(diskquota_table_size_flag);

diskquota_quota_info_flag =
DiskquotaShmemInitStruct("diskquota QuotaInfoEntry flag", DISKQUOTA_QUOTA_INFO_FLAG_SIZE, &found);
if (!found) pg_atomic_init_flag(diskquota_quota_info_flag);
#endif
}

/*
Expand Down
17 changes: 14 additions & 3 deletions src/diskquota.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
#define MAX_NUM_KEYS_QUOTA_MAP 8
/* init number of QuotaInfoEntry in quota_info_map */
#define INIT_QUOTA_MAP_ENTRIES 128
#define AVG_QUOTA_MAP_ENTRIES (diskquota_max_quota_probes / diskquota_max_monitored_databases)
/* max number of QuotaInfoEntry in quota_info_map */
#define MAX_QUOTA_MAP_ENTRIES (AVG_QUOTA_MAP_ENTRIES < 1024 ? 1024 : AVG_QUOTA_MAP_ENTRIES)
#define MAX_QUOTA_MAP_ENTRIES \
(diskquota_max_quota_probes < 1024 * diskquota_max_monitored_databases ? 1024 * diskquota_max_monitored_databases \
: diskquota_max_quota_probes)

typedef enum
{
Expand Down Expand Up @@ -81,6 +82,14 @@ extern int diskquota_worker_timeout;
#define RELID_CACHE_ENTRY_SIZE sizeof(DiskQuotaRelidCacheEntry)
#define ALTERED_RELOID_CACHE_ENTRY_SIZE sizeof(Oid)
#define MONITORED_DBID_CACHE_ENTRY_SIZE sizeof(struct MonitorDBEntryStruct)
#define DISKQUOTA_TABLE_SIZE_ENTRY_NUM_SIZE sizeof(pg_atomic_uint32)
#define DISKQUOTA_QUOTA_INFO_ENTRY_NUM_SIZE sizeof(pg_atomic_uint32)

#ifdef USE_ASSERT_CHECKING
#define DISKQUOTA_TABLE_SIZE_FLAG_SIZE sizeof(pg_atomic_flag)
#define LOCAL_DISK_QUOTA_REJECT_FLAG_SIZE sizeof(pg_atomic_flag)
#define DISKQUOTA_QUOTA_INFO_FLAG_SIZE sizeof(pg_atomic_flag)
#endif

typedef enum
{
Expand Down Expand Up @@ -322,9 +331,11 @@ 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 HTAB *DiskquotaShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags,
DiskquotaHashFunction hash_function);
DiskquotaHashFunction hash_function, pg_atomic_flag *foundPtr);
extern void *DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr);
extern void refresh_monitored_dbid_cache(void);
extern HASHACTION check_hash_fullness_num(HTAB *hashp, int num_entries, int max_size, const char *warning_message,
TimestampTz *last_overflow_report);
extern HASHACTION check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message,
TimestampTz *last_overflow_report);
bool SPI_push_cond_and_connect(void);
Expand Down
48 changes: 30 additions & 18 deletions src/diskquota_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ static bool to_delete_quota(QuotaType type, int64 quota_limit_mb, float4 segra
static void check_role(Oid roleoid, char *rolname, int64 quota_limit_mb);

#ifdef USE_ASSERT_CHECKING
extern DiskquotaLauncherShmemStruct *DiskquotaLauncherShmem;
extern void diskquota_shmem_size_sub(Size size);
extern void diskquota_shmem_size_sub(Size size);
#endif

/* ---- Help Functions to set quota limit. ---- */
Expand Down Expand Up @@ -1645,12 +1644,9 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo
long max_size, /* max size of the table */
HASHCTL *infoP, /* info about key and bucket size */
int hash_flags, /* info about infoP */
DiskquotaHashFunction hashFunction)
DiskquotaHashFunction hashFunction, pg_atomic_flag *foundPtr)
Comment thread
KnightMurloc marked this conversation as resolved.
{
#ifdef USE_ASSERT_CHECKING
if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker)
diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize));
#endif
HTAB *hashp;

#if GP_VERSION_NUM < 70000
if (hashFunction == DISKQUOTA_TAG_HASH)
Expand All @@ -1659,31 +1655,37 @@ DiskquotaShmemInitHash(const char *name, /* table string name fo
infoP->hash = oid_hash;
else
infoP->hash = string_hash;
return ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_FUNCTION);
hashp = ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_FUNCTION);
#else
return ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_BLOBS);
hashp = ShmemInitHash(name, init_size, max_size, infoP, hash_flags | HASH_BLOBS);
#endif /* GP_VERSION_NUM */

#ifdef USE_ASSERT_CHECKING
AssertImply(IsBackgroundWorker, foundPtr != NULL); /* foundPtr only used in background worker */

if (foundPtr == NULL || pg_atomic_test_set_flag(foundPtr))
diskquota_shmem_size_sub(hash_estimate_size(max_size, infoP->entrysize));
#endif

return hashp;
}

void *
DiskquotaShmemInitStruct(const char *name, Size size, bool *foundPtr)
{
void *structPtr = ShmemInitStruct(name, size, foundPtr);

#ifdef USE_ASSERT_CHECKING
if (!DiskquotaLauncherShmem || !DiskquotaLauncherShmem->isDynamicWorker) diskquota_shmem_size_sub(size);
if (!*foundPtr) diskquota_shmem_size_sub(size);
#endif

return ShmemInitStruct(name, size, foundPtr);
return structPtr;
}

/*
* Returns HASH_FIND if hash table is full and HASH_ENTER otherwise.
* It can be used only under lock.
*/
HASHACTION
check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, TimestampTz *last_overflow_report)
check_hash_fullness_num(HTAB *hashp, int num_entries, int max_size, const char *warning_message,
Comment thread
dkovalev1 marked this conversation as resolved.
TimestampTz *last_overflow_report)
{
long num_entries = hash_get_num_entries(hashp);

if (num_entries < max_size) return HASH_ENTER;

if (num_entries == max_size)
Expand All @@ -1701,6 +1703,16 @@ check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, Time
return HASH_FIND;
}

/*
* Returns HASH_FIND if hash table is full and HASH_ENTER otherwise.
* It can be used only under lock.
*/
HASHACTION
check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, TimestampTz *last_overflow_report)
{
return check_hash_fullness_num(hashp, hash_get_num_entries(hashp), max_size, warning_message, last_overflow_report);
}

bool
SPI_push_cond_and_connect(void)
{
Expand Down
11 changes: 6 additions & 5 deletions src/gp_activetable.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ init_shm_worker_active_tables(void)
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);
diskquota_max_active_tables, &ctl, HASH_ELEM, DISKQUOTA_TAG_HASH, NULL);
Comment thread
dkovalev1 marked this conversation as resolved.

memset(&ctl, 0, sizeof(ctl));
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);
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, NULL);
}

/*
Expand Down
Loading