Skip to content

Commit

Permalink
remake shm_hash_enter
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMurloc committed Nov 30, 2023
1 parent 7158307 commit 800adc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/diskquota_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,22 +1691,17 @@ void *
shm_hash_enter(HTAB *hashp, const void *keyPtr, bool *foundPtr, int max_size, const char *warning_message,
TimestampTz *last_overflow_report, int guc_value)
{
void *result;
TimestampTz current_time;
if (hash_get_num_entries(hashp) < max_size) return hash_search(hashp, keyPtr, HASH_ENTER, foundPtr);

if (hash_get_num_entries(hashp) >= max_size) return hash_search(hashp, keyPtr, HASH_FIND, foundPtr);

result = hash_search(hashp, keyPtr, HASH_ENTER, foundPtr);

if (hash_get_num_entries(hashp) >= max_size)
if (hash_get_num_entries(hashp) == max_size)
{
current_time = GetCurrentTimestamp();
TimestampTz current_time = GetCurrentTimestamp();
if (TimestampDifferenceExceeds(*last_overflow_report, current_time,
diskquota_hashmap_overflow_report_timeout * 1000))
{
ereport(WARNING, (errmsg(warning_message, guc_value)));
*last_overflow_report = current_time;
}
}
return result;
return hash_search(hashp, keyPtr, HASH_FIND, foundPtr);
}
2 changes: 1 addition & 1 deletion tests/regress/expected/test_activetable_limit.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ SELECT diskquota.wait_for_worker_new_epoch();
CREATE TABLE s.t1(i int) DISTRIBUTED BY (i); -- activetable = 3
CREATE TABLE s.t2(i int) DISTRIBUTED BY (i); -- activetable = 4
CREATE TABLE s.t3(i int) DISTRIBUTED BY (i); -- activetable = 5. expected warning.
CREATE TABLE s.t4(i int) DISTRIBUTED BY (i);
WARNING: [diskquota] the number of active tables reached the limit, please increase the GUC value for diskquota.max_active_tables. Current diskquota.max_active_tables value: 5 (seg0 127.0.1.1:6002 pid=995937)
WARNING: [diskquota] the number of active tables reached the limit, please increase the GUC value for diskquota.max_active_tables. Current diskquota.max_active_tables value: 5 (seg2 127.0.1.1:6004 pid=995938)
WARNING: [diskquota] the number of active tables reached the limit, please increase the GUC value for diskquota.max_active_tables. Current diskquota.max_active_tables value: 5 (seg1 127.0.1.1:6003 pid=995939)
CREATE TABLE s.t4(i int) DISTRIBUTED BY (i);
INSERT INTO s.t4 SELECT generate_series(1, 100000);
SELECT diskquota.wait_for_worker_new_epoch();
wait_for_worker_new_epoch
Expand Down

0 comments on commit 800adc1

Please sign in to comment.