2019-11-16 13:54:41 +00:00
import os
import re
import time
2020-09-16 04:26:10 +00:00
import pytest
2024-09-27 10:19:39 +00:00
2020-09-16 04:26:10 +00:00
from helpers . cluster import ClickHouseCluster
2024-09-27 10:19:39 +00:00
from helpers . test_tools import TSV , assert_eq_with_retry
2020-09-16 04:26:10 +00:00
2019-11-16 13:54:41 +00:00
cluster = ClickHouseCluster ( __file__ )
2022-03-22 16:39:58 +00:00
instance = cluster . add_instance (
" instance " ,
2024-03-18 15:07:10 +00:00
main_configs = [ " configs/remote_servers.xml " ] ,
2022-03-22 16:39:58 +00:00
user_configs = [
" configs/users.d/assign_myquota_to_default_user.xml " ,
" configs/users.d/drop_default_quota.xml " ,
" configs/users.d/myquota.xml " ,
" configs/users.d/user_with_no_quota.xml " ,
] ,
)
2019-11-16 13:54:41 +00:00
2020-08-12 08:55:04 +00:00
def check_system_quotas ( canonical ) :
canonical_tsv = TSV ( canonical )
r = TSV ( instance . query ( " SELECT * FROM system.quotas ORDER BY name " ) )
2020-10-02 16:54:07 +00:00
print ( ( " system_quotas: {} , \n canonical: {} " . format ( r , TSV ( canonical_tsv ) ) ) )
2020-08-12 08:55:04 +00:00
assert r == canonical_tsv
2020-05-08 12:50:45 +00:00
2020-09-16 04:26:10 +00:00
2020-08-12 08:55:04 +00:00
def system_quota_limits ( canonical ) :
canonical_tsv = TSV ( canonical )
2022-03-22 16:39:58 +00:00
r = TSV (
instance . query (
" SELECT * FROM system.quota_limits ORDER BY quota_name, duration "
)
)
2020-10-02 16:54:07 +00:00
print ( ( " system_quota_limits: {} , \n canonical: {} " . format ( r , TSV ( canonical_tsv ) ) ) )
2020-08-12 08:55:04 +00:00
assert r == canonical_tsv
2019-11-16 13:54:41 +00:00
2020-09-16 04:26:10 +00:00
2020-08-12 08:55:04 +00:00
def system_quota_usage ( canonical ) :
canonical_tsv = TSV ( canonical )
2022-03-22 16:39:58 +00:00
query = (
" SELECT quota_name, quota_key, duration, queries, max_queries, query_selects, max_query_selects, query_inserts, max_query_inserts, errors, max_errors, result_rows, max_result_rows, "
2024-01-29 23:20:38 +00:00
" result_bytes, max_result_bytes, read_rows, max_read_rows, read_bytes, max_read_bytes, max_execution_time, max_failed_sequential_authentications "
2022-03-22 16:39:58 +00:00
" FROM system.quota_usage ORDER BY duration "
)
2020-08-12 08:55:04 +00:00
r = TSV ( instance . query ( query ) )
2020-10-02 16:54:07 +00:00
print ( ( " system_quota_usage: {} , \n canonical: {} " . format ( r , TSV ( canonical_tsv ) ) ) )
2020-08-12 08:55:04 +00:00
assert r == canonical_tsv
2020-05-08 12:50:45 +00:00
2020-09-16 04:26:10 +00:00
2020-08-12 08:55:04 +00:00
def system_quotas_usage ( canonical ) :
canonical_tsv = TSV ( canonical )
2022-03-22 16:39:58 +00:00
query = (
" SELECT quota_name, quota_key, is_current, duration, queries, max_queries, query_selects, max_query_selects, query_inserts, max_query_inserts, errors, max_errors, result_rows, max_result_rows, "
2024-01-29 23:20:38 +00:00
" result_bytes, max_result_bytes, read_rows, max_read_rows, read_bytes, max_read_bytes, max_execution_time, max_failed_sequential_authentications "
2022-03-22 16:39:58 +00:00
" FROM system.quotas_usage ORDER BY quota_name, quota_key, duration "
)
2020-08-12 08:55:04 +00:00
r = TSV ( instance . query ( query ) )
2020-10-02 16:54:07 +00:00
print ( ( " system_quotas_usage: {} , \n canonical: {} " . format ( r , TSV ( canonical_tsv ) ) ) )
2020-08-12 08:55:04 +00:00
assert r == canonical_tsv
2019-11-16 13:54:41 +00:00
2020-09-16 04:26:10 +00:00
def copy_quota_xml ( local_file_name , reload_immediately = True ) :
2019-11-16 13:54:41 +00:00
script_dir = os . path . dirname ( os . path . realpath ( __file__ ) )
2022-03-22 16:39:58 +00:00
instance . copy_file_to_container (
os . path . join ( script_dir , local_file_name ) ,
" /etc/clickhouse-server/users.d/myquota.xml " ,
)
2019-11-16 13:54:41 +00:00
if reload_immediately :
2022-03-22 16:39:58 +00:00
# We use the special user 'user_with_no_quota' here because
# we don't want SYSTEM RELOAD CONFIG to mess our quota consuming checks.
instance . query ( " SYSTEM RELOAD CONFIG " , user = " user_with_no_quota " )
2019-11-16 13:54:41 +00:00
@pytest.fixture ( scope = " module " , autouse = True )
def started_cluster ( ) :
try :
cluster . start ( )
2021-03-16 10:00:49 +00:00
instance . query ( " DROP TABLE IF EXISTS test_table " )
2022-03-22 16:39:58 +00:00
instance . query (
" CREATE TABLE test_table(x UInt32) ENGINE = MergeTree ORDER BY tuple() "
)
2019-11-16 13:54:41 +00:00
instance . query ( " INSERT INTO test_table SELECT number FROM numbers(50) " )
yield cluster
finally :
cluster . shutdown ( )
@pytest.fixture ( autouse = True )
def reset_quotas_and_usage_info ( ) :
try :
2019-12-01 22:01:05 +00:00
instance . query ( " DROP QUOTA IF EXISTS qA, qB " )
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " simpliest.xml " ) # To reset usage info.
copy_quota_xml ( " normal_limits.xml " )
2021-02-04 15:59:05 +00:00
yield
finally :
pass
2019-11-16 13:54:41 +00:00
def test_quota_from_users_xml ( ) :
2022-03-22 16:39:58 +00:00
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
[ 31556952 ] ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-09-16 04:26:10 +00:00
system_quotas_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
1 ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
1 ,
1000 ,
1 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
" \\ N " ,
50 ,
1000 ,
200 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
2022-02-02 18:31:45 +00:00
instance . query ( " SELECT SUM(x) from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
2 ,
1000 ,
2 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
51 ,
" \\ N " ,
208 ,
" \\ N " ,
100 ,
1000 ,
400 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
def test_simpliest_quota ( ) :
# Simpliest quota doesn't even track usage.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " simpliest.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
2020-08-12 08:55:04 +00:00
system_quota_limits ( " " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
def test_tracking_quota ( ) :
# Now we're tracking usage.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " tracking.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
1 ,
" \\ N " ,
1 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
2022-02-02 18:31:45 +00:00
instance . query ( " SELECT SUM(x) from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
2 ,
" \\ N " ,
2 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
51 ,
" \\ N " ,
208 ,
" \\ N " ,
100 ,
" \\ N " ,
400 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
def test_exceed_quota ( ) :
# Change quota, now the limits are tiny so we will exceed the quota.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " tiny_limits.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
2024-01-29 23:20:38 +00:00
[ [ " myQuota " , 31556952 , 0 , 1 , 1 , 1 , 1 , 1 , " \\ N " , 1 , " \\ N " , " \\ N " , " \\ N " , " 1 " ] ]
2022-03-22 16:39:58 +00:00
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
1 ,
0 ,
1 ,
0 ,
1 ,
0 ,
1 ,
0 ,
1 ,
0 ,
" \\ N " ,
0 ,
1 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" 1 " ,
2022-03-22 16:39:58 +00:00
]
]
)
assert re . search (
2022-07-11 04:36:37 +00:00
" Quota.*has been exceeded " ,
2022-03-22 16:39:58 +00:00
instance . query_and_get_error ( " SELECT * from test_table " ) ,
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
1 ,
1 ,
1 ,
1 ,
0 ,
1 ,
1 ,
1 ,
0 ,
1 ,
0 ,
" \\ N " ,
50 ,
1 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" 1 " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Change quota, now the limits are enough to execute queries.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " normal_limits.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
1 ,
1000 ,
1 ,
500 ,
0 ,
500 ,
1 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
50 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-08-12 08:55:04 +00:00
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
2 ,
1000 ,
2 ,
500 ,
0 ,
500 ,
1 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
" \\ N " ,
100 ,
1000 ,
200 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
def test_add_remove_interval ( ) :
2022-03-22 16:39:58 +00:00
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
[ 31556952 ] ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Add interval.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " two_intervals.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952,63113904] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
[
" myQuota " ,
63113904 ,
1 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
30000 ,
" \\ N " ,
20000 ,
120 ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
1000 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
[
" myQuota " ,
" default " ,
63113904 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
30000 ,
0 ,
" \\ N " ,
0 ,
20000 ,
120 ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
]
)
2020-08-12 08:55:04 +00:00
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
1 ,
1000 ,
1 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
" \\ N " ,
50 ,
1000 ,
200 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
[
" myQuota " ,
" default " ,
63113904 ,
1 ,
" \\ N " ,
1 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
30000 ,
50 ,
" \\ N " ,
200 ,
20000 ,
120 ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
]
)
2019-11-16 13:54:41 +00:00
# Remove interval.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " normal_limits.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
[ 31556952 ] ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
1 ,
1000 ,
1 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
50 ,
" \\ N " ,
200 ,
" \\ N " ,
50 ,
1000 ,
200 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-08-12 08:55:04 +00:00
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
2 ,
1000 ,
2 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
100 ,
" \\ N " ,
400 ,
" \\ N " ,
100 ,
1000 ,
400 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Remove all intervals.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " simpliest.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
2020-08-12 08:55:04 +00:00
system_quota_limits ( " " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-08-12 08:55:04 +00:00
2019-11-16 13:54:41 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Add one interval back.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " normal_limits.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
[ 31556952 ] ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
def test_add_remove_quota ( ) :
2022-03-22 16:39:58 +00:00
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
[ 31556952 ] ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-09-16 04:26:10 +00:00
system_quotas_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
1 ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Add quota.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " two_quotas.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
] ,
[
" myQuota2 " ,
" 4590510c-4d13-bf21-ec8a-c2187b092e73 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' client_key ' , ' user_name ' ] " ,
" [3600,2629746] " ,
0 ,
" [] " ,
" [] " ,
] ,
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
[
" myQuota2 " ,
3600 ,
1 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
4000 ,
400000 ,
4000 ,
400000 ,
60 ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" 3 " ,
2022-03-22 16:39:58 +00:00
] ,
[
" myQuota2 " ,
2629746 ,
0 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1800 ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
] ,
]
)
2020-09-16 04:26:10 +00:00
system_quotas_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
1 ,
31556952 ,
0 ,
1000 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Drop quota.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " normal_limits.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-09-16 04:26:10 +00:00
system_quotas_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
1 ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
# Drop all quotas.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " no_quotas.xml " )
2020-08-12 08:55:04 +00:00
check_system_quotas ( " " )
system_quota_limits ( " " )
system_quotas_usage ( " " )
2019-11-16 13:54:41 +00:00
# Add one quota back.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " normal_limits.xml " )
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2020-09-16 04:26:10 +00:00
system_quotas_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
1 ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
def test_reload_users_xml_by_timer ( ) :
2022-03-22 16:39:58 +00:00
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2019-11-16 13:54:41 +00:00
2020-09-16 04:26:10 +00:00
time . sleep ( 1 ) # The modification time of the 'quota.xml' file should be different,
# because config files are reload by timer only when the modification time is changed.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " tiny_limits.xml " , reload_immediately = False )
assert_eq_with_retry (
instance ,
" SELECT * FROM system.quotas " ,
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
[ " user_name " ] ,
" [31556952] " ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
] ,
)
assert_eq_with_retry (
instance ,
" SELECT * FROM system.quota_limits " ,
2024-01-29 23:20:38 +00:00
[ [ " myQuota " , 31556952 , 0 , 1 , 1 , 1 , 1 , 1 , " \\ N " , 1 , " \\ N " , " \\ N " , " \\ N " , " 1 " ] ] ,
2022-03-22 16:39:58 +00:00
)
2019-12-01 22:01:05 +00:00
def test_dcl_introspection ( ) :
assert instance . query ( " SHOW QUOTAS " ) == " myQuota \n "
2022-03-22 16:39:58 +00:00
assert (
instance . query ( " SHOW CREATE QUOTA " )
== " CREATE QUOTA myQuota KEYED BY user_name FOR INTERVAL 1 year MAX queries = 1000, query_selects = 500, query_inserts = 500, read_rows = 1000 TO default \n "
)
assert (
instance . query ( " SHOW CREATE QUOTAS " )
== " CREATE QUOTA myQuota KEYED BY user_name FOR INTERVAL 1 year MAX queries = 1000, query_selects = 500, query_inserts = 500, read_rows = 1000 TO default \n "
)
2020-09-16 04:26:10 +00:00
assert re . match (
2021-01-26 08:11:46 +00:00
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t0 \\ t1000 \\ t0 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t1000 \\ t0 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
assert re . match (
2021-01-26 08:11:46 +00:00
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t1000 \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
2021-01-26 08:11:46 +00:00
expected_access = " CREATE QUOTA myQuota KEYED BY user_name FOR INTERVAL 1 year MAX queries = 1000, query_selects = 500, query_inserts = 500, read_rows = 1000 TO default \n "
2020-06-10 23:08:37 +00:00
assert expected_access in instance . query ( " SHOW ACCESS " )
2019-12-01 22:01:05 +00:00
# Add interval.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " two_intervals.xml " )
2019-12-01 22:01:05 +00:00
assert instance . query ( " SHOW QUOTAS " ) == " myQuota \n "
2022-03-22 16:39:58 +00:00
assert (
instance . query ( " SHOW CREATE QUOTA " )
== " CREATE QUOTA myQuota KEYED BY user_name FOR INTERVAL 1 year MAX queries = 1000, read_rows = 1000, FOR RANDOMIZED INTERVAL 2 year MAX result_bytes = 30000, read_bytes = 20000, execution_time = 120 TO default \n "
)
2020-09-16 04:26:10 +00:00
assert re . match (
2021-01-26 08:11:46 +00:00
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t1000 \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \n "
" myQuota \\ tdefault \\ t.* \\ t63113904 \\ t0 \\ t \\ \\ N \t 0 \\ t \\ \\ N \t 0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t30000 \\ t0 \\ t \\ \\ N \\ t0 \\ t20000 \\ t.* \\ t120 " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
# Drop interval, add quota.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " two_quotas.xml " )
2019-12-01 22:01:05 +00:00
assert instance . query ( " SHOW QUOTAS " ) == " myQuota \n myQuota2 \n "
2022-03-22 16:39:58 +00:00
assert (
instance . query ( " SHOW CREATE QUOTA myQuota " )
== " CREATE QUOTA myQuota KEYED BY user_name FOR INTERVAL 1 year MAX queries = 1000, read_rows = 1000 TO default \n "
)
assert (
instance . query ( " SHOW CREATE QUOTA myQuota2 " )
2024-01-29 23:20:38 +00:00
== " CREATE QUOTA myQuota2 KEYED BY client_key, user_name FOR RANDOMIZED INTERVAL 1 hour MAX result_rows = 4000, result_bytes = 400000, read_rows = 4000, read_bytes = 400000, execution_time = 60, failed_sequential_authentications = 3, FOR INTERVAL 1 month MAX execution_time = 1800 \n "
2022-03-22 16:39:58 +00:00
)
assert (
instance . query ( " SHOW CREATE QUOTAS " )
== " CREATE QUOTA myQuota KEYED BY user_name FOR INTERVAL 1 year MAX queries = 1000, read_rows = 1000 TO default \n "
2024-01-29 23:20:38 +00:00
" CREATE QUOTA myQuota2 KEYED BY client_key, user_name FOR RANDOMIZED INTERVAL 1 hour MAX result_rows = 4000, result_bytes = 400000, read_rows = 4000, read_bytes = 400000, execution_time = 60, failed_sequential_authentications = 3, FOR INTERVAL 1 month MAX execution_time = 1800 \n "
2022-03-22 16:39:58 +00:00
)
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t1000 \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2020-05-08 12:50:45 +00:00
# Drop all quotas.
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " no_quotas.xml " )
2020-05-08 12:50:45 +00:00
assert instance . query ( " SHOW QUOTAS " ) == " "
assert instance . query ( " SHOW CREATE QUOTA " ) == " "
assert instance . query ( " SHOW QUOTA " ) == " "
2019-12-01 22:01:05 +00:00
def test_dcl_management ( ) :
2022-03-22 16:39:58 +00:00
copy_quota_xml ( " no_quotas.xml " )
2020-05-08 12:50:45 +00:00
assert instance . query ( " SHOW QUOTA " ) == " "
2020-08-12 08:55:04 +00:00
2022-03-22 16:39:58 +00:00
instance . query (
" CREATE QUOTA qA FOR INTERVAL 15 MONTH MAX QUERIES 123 TO CURRENT_USER "
)
assert (
instance . query ( " SHOW CREATE QUOTA qA " )
== " CREATE QUOTA qA FOR INTERVAL 5 quarter MAX queries = 123 TO default \n "
)
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qA \\ t \\ t.* \\ t39446190 \\ t0 \\ t123 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2020-05-08 12:50:45 +00:00
2019-12-01 22:01:05 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qA \\ t \\ t.* \\ t39446190 \\ t1 \\ t123 \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2020-09-16 04:26:10 +00:00
instance . query (
2022-03-22 16:39:58 +00:00
" ALTER QUOTA qA FOR INTERVAL 15 MONTH MAX QUERIES 321, MAX ERRORS 10, FOR INTERVAL 0.5 HOUR MAX EXECUTION TIME 0.5 "
)
assert (
instance . query ( " SHOW CREATE QUOTA qA " )
== " CREATE QUOTA qA FOR INTERVAL 30 minute MAX execution_time = 0.5, FOR INTERVAL 5 quarter MAX queries = 321, errors = 10 TO default \n "
)
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qA \\ t \\ t.* \\ t1800 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t.* \\ t0.5 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n "
" qA \\ t \\ t.* \\ t39446190 \\ t1 \\ t321 \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t10 \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2020-05-08 12:50:45 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qA \\ t \\ t.* \\ t1800 \\ t1 \\ t \\ \\ N \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t.* \\ t0.5 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n "
" qA \\ t \\ t.* \\ t39446190 \\ t2 \\ t321 \\ t2 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t10 \\ t100 \\ t \\ \\ N \\ t400 \\ t \\ \\ N \\ t100 \\ t \\ \\ N \\ t400 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
2020-09-16 04:26:10 +00:00
instance . query (
2022-03-22 16:39:58 +00:00
" ALTER QUOTA qA FOR INTERVAL 15 MONTH NO LIMITS, FOR RANDOMIZED INTERVAL 16 MONTH TRACKING ONLY, FOR INTERVAL 1800 SECOND NO LIMITS "
)
2020-09-16 04:26:10 +00:00
assert re . match (
2021-01-26 08:11:46 +00:00
" qA \\ t \\ t.* \\ t42075936 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qA \\ t \\ t.* \\ t42075936 \\ t1 \\ t \\ \\ N \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
instance . query ( " ALTER QUOTA qA RENAME TO qB " )
2022-03-22 16:39:58 +00:00
assert (
instance . query ( " SHOW CREATE QUOTA qB " )
== " CREATE QUOTA qB FOR RANDOMIZED INTERVAL 16 month TRACKING ONLY TO default \n "
)
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qB \\ t \\ t.* \\ t42075936 \\ t1 \\ t \\ \\ N \\ t1 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t50 \\ t \\ \\ N \\ t200 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2020-05-08 12:50:45 +00:00
instance . query ( " SELECT * from test_table " )
2020-09-16 04:26:10 +00:00
assert re . match (
2024-01-29 23:20:38 +00:00
" qB \\ t \\ t.* \\ t42075936 \\ t2 \\ t \\ \\ N \\ t2 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t100 \\ t \\ \\ N \\ t400 \\ t \\ \\ N \\ t100 \\ t \\ \\ N \\ t400 \\ t \\ \\ N \\ t.* \\ t \\ \\ N \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N \n " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2019-12-01 22:01:05 +00:00
instance . query ( " DROP QUOTA qB " )
2020-05-08 12:50:45 +00:00
assert instance . query ( " SHOW QUOTA " ) == " "
2019-12-01 22:01:05 +00:00
def test_users_xml_is_readonly ( ) :
2022-03-22 16:39:58 +00:00
assert re . search (
" storage is readonly " , instance . query_and_get_error ( " DROP QUOTA myQuota " )
)
2021-01-26 08:11:46 +00:00
2021-03-30 15:13:25 +00:00
2021-01-26 08:11:46 +00:00
def test_query_inserts ( ) :
2022-03-22 16:39:58 +00:00
check_system_quotas (
[
[
" myQuota " ,
" e651da9c-a748-8703-061a-7e5e5096dae7 " ,
2023-07-28 03:37:09 +00:00
" users_xml " ,
2022-03-22 16:39:58 +00:00
" [ ' user_name ' ] " ,
[ 31556952 ] ,
0 ,
" [ ' default ' ] " ,
" [] " ,
]
]
)
system_quota_limits (
[
[
" myQuota " ,
31556952 ,
0 ,
1000 ,
500 ,
500 ,
" \\ N " ,
" \\ N " ,
" \\ N " ,
1000 ,
" \\ N " ,
" \\ N " ,
2022-04-01 15:02:49 +00:00
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
system_quota_usage (
[
[
" myQuota " ,
" default " ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2021-01-26 08:11:46 +00:00
system_quotas_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
1 ,
31556952 ,
0 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2021-01-26 08:11:46 +00:00
2021-03-30 15:13:25 +00:00
instance . query ( " DROP TABLE IF EXISTS test_table_ins " )
2022-03-22 16:39:58 +00:00
instance . query (
" CREATE TABLE test_table_ins(x UInt32) ENGINE = MergeTree ORDER BY tuple() "
)
2021-03-30 15:13:25 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
2 ,
1000 ,
0 ,
500 ,
0 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2021-03-30 15:13:25 +00:00
instance . query ( " INSERT INTO test_table_ins values(1) " )
2021-01-26 08:11:46 +00:00
system_quota_usage (
2022-03-22 16:39:58 +00:00
[
[
" myQuota " ,
" default " ,
31556952 ,
3 ,
1000 ,
0 ,
500 ,
1 ,
500 ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
" \\ N " ,
0 ,
1000 ,
0 ,
" \\ N " ,
" \\ N " ,
2024-01-29 23:20:38 +00:00
" \\ N " ,
2022-03-22 16:39:58 +00:00
]
]
)
2021-03-30 15:13:25 +00:00
instance . query ( " DROP TABLE test_table_ins " )
2021-02-04 15:59:05 +00:00
2021-02-25 12:50:44 +00:00
def test_consumption_of_show_tables ( ) :
assert instance . query ( " SHOW TABLES " ) == " test_table \n "
assert re . match (
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N \\ t1 \\ t \\ \\ N.* " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2021-02-25 12:50:44 +00:00
def test_consumption_of_show_databases ( ) :
2022-03-22 16:39:58 +00:00
assert (
instance . query ( " SHOW DATABASES " )
== " INFORMATION_SCHEMA \n default \n information_schema \n system \n "
)
2021-02-25 12:50:44 +00:00
assert re . match (
2021-09-09 09:37:51 +00:00
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N \\ t4 \\ t \\ \\ N.* " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2021-02-25 12:50:44 +00:00
def test_consumption_of_show_clusters ( ) :
assert len ( instance . query ( " SHOW CLUSTERS " ) ) > 0
assert re . match (
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N.* " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2021-02-25 12:50:44 +00:00
def test_consumption_of_show_processlist ( ) :
instance . query ( " SHOW PROCESSLIST " )
assert re . match (
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N \\ t0 \\ t \\ \\ N.* " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)
2021-02-04 15:59:05 +00:00
2021-02-25 12:50:44 +00:00
def test_consumption_of_show_privileges ( ) :
assert len ( instance . query ( " SHOW PRIVILEGES " ) ) > 0
2021-02-04 15:59:05 +00:00
assert re . match (
2021-02-25 12:50:44 +00:00
" myQuota \\ tdefault \\ t.* \\ t31556952 \\ t1 \\ t1000 \\ t1 \\ t500 \\ t0 \\ t500 \\ t0 \\ t \\ \\ N.* " ,
2022-03-22 16:39:58 +00:00
instance . query ( " SHOW QUOTA " ) ,
)