From 800adc15d971e211809fbf2a5b66696f9801d377 Mon Sep 17 00:00:00 2001 From: Viktor Kurilko Date: Thu, 30 Nov 2023 18:37:14 +0700 Subject: [PATCH] remake shm_hash_enter --- src/diskquota_utility.c | 13 ++++--------- tests/regress/expected/test_activetable_limit.out | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index e1ccec5a..29d3bc0e 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1691,16 +1691,11 @@ 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)) { @@ -1708,5 +1703,5 @@ shm_hash_enter(HTAB *hashp, const void *keyPtr, bool *foundPtr, int max_size, co *last_overflow_report = current_time; } } - return result; + return hash_search(hashp, keyPtr, HASH_FIND, foundPtr); } diff --git a/tests/regress/expected/test_activetable_limit.out b/tests/regress/expected/test_activetable_limit.out index ad87865a..bb1caa25 100644 --- a/tests/regress/expected/test_activetable_limit.out +++ b/tests/regress/expected/test_activetable_limit.out @@ -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