Skip to content

Query Cache: Allow per-user quotas#48284

Merged
rschu1ze merged 3 commits intomasterfrom
rs/qc-quota
Apr 24, 2023
Merged

Query Cache: Allow per-user quotas#48284
rschu1ze merged 3 commits intomasterfrom
rs/qc-quota

Conversation

@rschu1ze
Copy link
Copy Markdown
Member

@rschu1ze rschu1ze commented Mar 31, 2023

It is now possible to limit the query cache usage of individual users using settings profiles and settings constraints. More specifically, you can restrict the maximum amount of memory (in bytes) a user may allocate in the query cache and the the maximum number of stored query results. For that, first provide configurations query_cache_max_sizeand query_cache_max_entries in a user profile in users.xml, then make both settings readonly:

<profiles>
    <default>
        <!-- The maximum cache size in bytes for user/profile 'default' -->
        <query_cache_max_size>10000</query_cache_max_size>
        <!-- The maximum number of SELECT query results stored in the cache for user/profile 'default' -->
        <query_cache_max_entries></query_cache_max_entries>
        <!-- Make both settings read-only so the user cannot change them -->
        <constraints>
            <query_cache_max_size>
                <readonly/>
            </query_cache_max_size>
            <query_cache_max_entries>
                <readonly/>
            <query_cache_max_entries>
        </constraints>
    </default>
</profiles>

The main motivation is to prevent users from spamming the cache, i.e. evicting other user's query results. Other internal caches are generally also vulnerable to such misuse but the query cache makes misuse particularly easy.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

It is now possible to define per-user quotas in the query cache

@rschu1ze rschu1ze marked this pull request as draft March 31, 2023 11:06
@rschu1ze rschu1ze added the do not test disable testing on pull request label Mar 31, 2023
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-improvement Pull request with some product improvements label Mar 31, 2023
@rschu1ze rschu1ze force-pushed the rs/qc-quota branch 9 times, most recently from 1d8049a to f29d154 Compare April 14, 2023 16:17
@rschu1ze rschu1ze removed the do not test disable testing on pull request label Apr 14, 2023
@rschu1ze rschu1ze marked this pull request as ready for review April 14, 2023 16:17
@rschu1ze rschu1ze changed the title Query Cache: Implement per-user quotas Query Cache: Allow per-user quotas Apr 14, 2023
@rschu1ze rschu1ze force-pushed the rs/qc-quota branch 3 times, most recently from a418fc1 to ee14e29 Compare April 18, 2023 07:16
@serxa serxa self-assigned this Apr 20, 2023
@rschu1ze rschu1ze force-pushed the rs/qc-quota branch 2 times, most recently from 4577a93 to 18803b9 Compare April 23, 2023 16:11
@rschu1ze rschu1ze merged commit ded8eca into master Apr 24, 2023
@rschu1ze rschu1ze deleted the rs/qc-quota branch April 24, 2023 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants