Skip to content

Quota limit was not reached, but the limit was exceeded #31174

@sunny19930321

Description

@sunny19930321

Describe what's wrong

quota limit was not reached, but the limit was exceeded,Changes from #20106

Does it reproduce on recent release?

Version 21.3 or later

How to reproduce

1、Set the quota of the account

CREATE USER IF NOT EXISTS jd_olap IDENTIFIED WITH double_sha1_password BY '123456'

GRANT SHOW, SELECT, INSERT, ALTER, CREATE DATABASE, CREATE TABLE, CREATE VIEW, CREATE DICTIONARY, DROP, TRUNCATE, OPTIMIZE, SYSTEM MERGES, SYSTEM TTL MERGES, SYSTEM FETCHES, SYSTEM MOVES, SYSTEM SENDS, SYSTEM REPLICATION QUEUES, SYSTEM SYNC REPLICA, SYSTEM RESTART REPLICA, SYSTEM FLUSH DISTRIBUTED, dictGet ON jd_olap.* TO jd_olap

CREATE QUOTA jd_olap_10s FOR INTERVAL 10 second MAX queries = 2 TO jd_olap;

2、create table

CREATE DATABASE IF NOT EXISTS jd_olap on cluster system_cluster;

CREATE TABLE IF NOT EXISTS jd_olap.quota_test_local on cluster system_cluster 
( 
`user` String, 
`max_concurrent_queries` UInt32, 
`max_execution_time` UInt32, 
`requests_per_minute` UInt32,
`dt` Date 
) 
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/system_cluster/jdob_ha/jd_olap/quota_test_local/{shard}', '{replica}') 
PARTITION BY dt 
ORDER BY user 
SETTINGS storage_policy = 'jdob_ha', index_granularity = 8192;

3、execute the query(insert, select, alter), will trigger the problem
image

Expected behavior**

there is a bug where end time is 1970, causing end_loaded.count =0;
image

the used quota is not reset when it is first calculated (e.g., when a node is restarted or created for the first time) because 1970 is the first end time, the initial used logic is incremented from the first calculated value to the next interval. Used quota values are reset only at the next interval, as must be shown in the following figure: 16:45 and 16:47 are both calculated for the first time on the node restart, and the quota is not reset;

2021.11.09 16:49:17.481461 [ 14825 ] {1686DC283041A762} <Information> EnabledQuota: current_time: 2021-11-09 16:49:17, end: 1970-01-01 08:00:00
2021.11.09 16:49:17.481479 [ 14825 ] {1686DC283041A762} <Information> EnabledQuota: need_reset_counters: false, end_load_count: 0, interval.used: 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    potential bugTo be reviewed by developers and confirmed/rejected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions