Skip to content

Add written_rows quota resource - #118272

Merged
alexey-milovidov merged 19 commits into
masterfrom
quota-written-rows
Oct 7, 2026
Merged

alexey-milovidov merged 19 commits into
masterfrom
quota-written-rows

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Related: #118257

Changelog category (leave one):

  • New Feature

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

Quotas can now limit the number of rows written by INSERT queries with the new written_rows resource, for example CREATE QUOTA q KEYED BY ip_address FOR INTERVAL 1 minute MAX written_rows = 100000, query_inserts = 250 TO user. Until now only the written bytes could be limited (written_bytes), which is awkward when the natural unit of the workload is rows. The current and maximum values are exposed as written_rows and max_written_rows in system.quota_usage, system.quotas_usage and system.quota_limits, and the resource can also be set in users.xml as <written_rows>.

Details

written_rows is accounted in CountingTransform next to written_bytes (using the same usedForQuery call, so NORMALIZED_QUERY_HASH quotas bucket it per query pattern like the other pipeline-fed counters), and InterpreterInsertQuery pre-checks it together with written_bytes so that an already exceeded quota rejects the next insert before any data is written. Everything else (SQL parser and formatter, users.xml parsing, the three system tables) iterates over QuotaType, so no further changes were needed there.

The new stateless test 05060_written_rows_quota covers synchronous inserts, asynchronous inserts, INSERT ... SELECT, the pre-check after exceeding, both spellings (WRITTEN ROWS / written_rows), and that the rows and bytes counters are independent. 01297_create_quota and 02117_show_create_table_system references are updated for the new columns. Documentation is updated at the source of truth: the CREATE QUOTA and ALTER QUOTA registrations in registerStatementQuota, the QuotaTypeInfo descriptions that the three system-table pages are generated from, and the hand-written users.xml quota configuration page. The resource lists in those two registrations are now generated from QuotaType instead of being written out by hand, because they had drifted from what parseQuotaType accepts: failed_sequential_authentications and queries_per_normalized_hash were missing from some of them, so system.statements, system.documentation and the generated reference pages told users that valid quota resources are unsupported.

Quota accounting now starts a new interval (resetting its counters) before accounting or checking any counter, in every EnabledQuota entrypoint. Previously an ended interval was advanced only after a counter overflowed, so the usage at the beginning of the new interval was added to the stale value of the ended one and partially lost on the first overflow. 05239_written_rows_quota_interval_rollover and 05320_queries_quota_interval_rollover cover this for the batched (written_rows/written_bytes) and single-counter (queries) paths.

Motivation: I wanted to cap a public demo to N pixels per minute per IP, where a pixel is a row, and found there was no way to express that.


Workflow [PR]
Sync PR [sync-upstream/pr/118272]

Version info

  • Merged into: 26.10.1.1784-master (included in 26.10 and later)

Quotas could limit the bytes written by INSERT queries (written_bytes) but not the
number of rows. Add written_rows, accounted in the counting transform next to
written_bytes and pre-checked in InterpreterInsertQuery, with the corresponding
columns in system.quota_limits, system.quota_usage and system.quotas_usage.
@mintlify

mintlify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 7, 2026, 2:59 AM

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d61ba6e]

Summary: ✅


AI Review

Summary

This PR adds the new written_rows quota resource, wires it through insert accounting and quota docs, and fixes several rollover/accounting edge cases that came up during review. The remaining issue is a public compatibility regression: the new resource is inserted into the middle of QuotaType, so every surface that iterates QuotaType::MAX now shifts existing system.quota_* / SHOW QUOTA columns after written_bytes by one slot.

Findings

⚠️ Majors

  • [src/Access/Common/QuotaDefs.h:24] Adding WRITTEN_ROWS in the middle of QuotaType reorders existing fields in system.quota_limits, system.quota_usage, system.quotas_usage, and therefore SHOW QUOTA (which reads from quota_usage). The updated references in this PR already show the positions after max_written_bytes moving right by one, so tooling that reads those outputs positionally breaks even if it never uses the new resource. Suggested fix: append WRITTEN_ROWS at the end of the public iteration order, or decouple public column order from QuotaType iteration and only keep the new resource grouped in docs/parser rendering.
Final Verdict

⚠️ One merge-blocking compatibility issue remains: keep the existing quota output columns stable while adding written_rows.

LLVM Coverage Report

Measured on commit d61ba6e.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.80% 79.80% +0.00%

Changed lines: Changed C/C++ lines covered: 142/144 (98.61%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Sep 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit d61ba6e726944de2e02bc15723d5017ee624e990 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

alexey-milovidov and others added 2 commits September 10, 2026 23:09
`docs/reference/statements/create/quota.mdx` and the `system.quota_limits` /
`system.quota_usage` / `system.quotas_usage` pages are autogenerated, so the
direct edits there failed the `No direct edits to generated or read-only docs`
check. Revert them and add `written_rows` to the real source of truth in
`registerStatementQuota` in `src/Parsers/Access/ParserCreateQuotaQuery.cpp`
instead (both the description prose and the `.syntax` strings of `CREATE QUOTA`
and `ALTER QUOTA`, which were also missing `written_bytes`). The system-table
pages regenerate from the `QuotaTypeInfo` descriptions already added in
`QuotaDefs.cpp`.

Also fix `test_quota/test.py::test_dcl_management`: `SHOW QUOTA` gained one more
`used`/`max` column pair for the new resource, so the expected regexes now spell
out all four resources that follow `execution_time`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update after merging master and addressing the review:

  • Docs check (Mintlify) — No direct edits to generated or read-only docs: fixed. The edits inside the autogenerated regions of docs/reference/statements/create/quota.mdx, quota_limits.mdx, quota_usage.mdx and quotas_usage.mdx are reverted, and written_rows is added to the source of truth in registerStatementQuota in src/Parsers/Access/ParserCreateQuotaQuery.cpp instead. This is the Request changes action from the AI review.
  • Integration tests — test_quota/test.py::test_dcl_management (5 jobs): fixed. SHOW QUOTA gained one more used/max column pair for the new resource, so the expected regexes now spell out all four resources that follow execution_time. Verified against the exact SHOW QUOTA output captured in the failing CI run.
  • BuzzHouse (amd_debug) — Logical error: Not-ready Set is passed as the second argument for function 'globalNullIn' (STID 0250-4e52): unrelated to this change, this is the already-tracked Not-ready Set inside a running FilterTransform: the plan hands the pipeline an unbuilt IN set (STID: 0250-4e52) #118722 (same STID). Nothing in this pull request touches set building.

Locally verified with the merged branch: 05060_written_rows_quota and 02117_show_create_table_system pass; 01297_create_quota matches the reference up to the point where the local server lacks ZooKeeper for the ON CLUSTER query (it is green in CI).

@groeneai, #118722 is still open — please provide a fix in a separate pull request, or link it here if it is already in progress.

@groeneai

Copy link
Copy Markdown
Collaborator

#118722 is still open. The in-progress fix is #118817 (mine, open since 2026-09-08): it removes one producer, the server-wide one-shot prepared_sets_build_ordered_set_inplace_fail injection, which lands on whatever set build comes next and leaves the set uncreated for every build except the one that clones its subquery source. BuzzHouse arms failpoints deliberately, so that route is live in exactly the job that reported here. CI is green on it (153 success, 0 failures) and it has no reviewer yet.

Your attribution is right. The row for 2990d705 (BuzzHouse (amd_debug), 2026-09-05 16:50Z) carries FilterTransform::doTransform, the frame #118722 pins, and no set-building frame from this pull request. Whether the failpoint was armed in that run I cannot say: the stored context is truncated at 23 KB, above the failpoint state.

I am not linking #102308 or #102192 as the fix. Both change the recovery after a failed in-place build rather than this carrier's producer, and I have not measured that they reach it.

What keeps the issue open is the producer for the rest of the carrier: 45 of 108 reports over 60 days carry the failing query, and 16 of those put the set in a QUALIFY predicate, the largest single shape. Breadth is flat, 21 reports over 20 pull requests in 14 days with 1 on true master, newest 2026-09-10 13:10Z. I will link that fix on #118722 when it opens.

alexey-milovidov and others added 2 commits September 18, 2026 06:56
…e checking overflow

The multi-counter `EnabledQuota::usedForQuery` applied each usage sequentially and threw on the
first overflow, so when a chunk took `written_rows` over the limit its bytes were never added to
`written_bytes`: `system.quota_usage` underreported the attempted usage and the two write
counters were not independent. Now every usage is accounted with `check_exceeded = false` first,
and only then each counter is checked with `checkExceeded`. The regression test
`05060_written_rows_quota` now asserts that `written_bytes` grows for the chunk rejected by the
`written_rows` limit.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update, 2026-09-18:

  • Merged master (the branch was about 3800 commits behind), no conflicts.
  • AI review Changes requested (the CountingTransform thread): adopted in 53c089a. The multi-counter EnabledQuota::usedForQuery now accounts all usages before checking any of them for overflow, so written_rows and written_bytes are accounted independently for the same chunk. 05060_written_rows_quota has a regression for a quota with both limits.
  • Upgrade check (amd_release) Logical error: Virtual row has different type (STID 1637-309b): unrelated to this change. It was the fleet-wide cast_keep_nullable randomization against the 26.8 server, fixed on master by Do not randomize cast_keep_nullable in the upgrade check's pre-upgrade load #119768 (merged 2026-09-13), which the merge pulls in.

Locally, 05060_written_rows_quota and 02117_show_create_table_system pass with the merged branch.

alexey-milovidov and others added 3 commits September 19, 2026 22:22
`parseQuotaType` accepts every `QuotaType`, but the four resource lists in the `CREATE QUOTA`
and `ALTER QUOTA` registrations were written out by hand and had drifted: the `ALTER QUOTA`
description omitted `failed_sequential_authentications`, and both `.syntax` blocks omitted it
together with `queries_per_normalized_hash`. Since these registrations feed `system.statements`,
`system.documentation` and the generated reference pages, users were told that valid quota
resources are unsupported.

The lists are now built from the enum metadata (`QuotaTypeInfo::get(...).name`) and substituted
into the documentation, so adding a resource cannot leave them behind. `written_rows` and the
two previously missing resources are now listed everywhere.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`test_exceed_quota` expected `read_bytes` to stay at 0 when a query is rejected by the
`read_rows` limit. Since 53c089a, `EnabledQuota::usedForQuery`
accounts every counter of one call before checking any of them for overflow, so the 200 bytes of
the 50 rows the query reads are recorded as well. That is the intended behaviour - the counters
of one chunk of work must not depend on which of them overflows first - so the canonical value
is updated.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118272&sha=53c089a7c94f968e6c5797346662b36b885b8c85&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%203%2F8%29
Pull request: #118272

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update, 2026-09-19 — pushed fa5ebfbb29a:

  • AI review Changes requested (ParserCreateQuotaQuery.cpp, the resource lists): adopted in b10d89a3925. The four lists in the CREATE QUOTA / ALTER QUOTA registrations are now generated from QuotaType instead of being written out by hand, so all 13 resources that parseQuotaType accepts — including the two that were missing before this pull request, failed_sequential_authentications and queries_per_normalized_hash — appear in both .description blocks and both .syntax strings. Details in the thread.
  • Integration tests — test_quota/test.py::test_exceed_quota (2 jobs): fixed in 7fe8f42511b. This is a real consequence of 53c089a7c94: now that EnabledQuota::usedForQuery accounts every counter of one call before checking any of them, the 200 bytes of the 50 rows the query reads are recorded even though it is the read_rows limit that rejects it. That is the intended behaviour, so the canonical read_bytes is updated from 0 to 200, next to a comment saying why.
  • Merged master (the branch was 909 commits behind), no conflicts.

The three remaining failures are infrastructure, not this change:

  • Build profile diff — every attempt at the CI logs cluster ended in requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='t6h0zvqlgy.us-east-2.aws.clickhouse-staging.com', port=443): Read timed out. (read timeout=60), i.e. the cluster never answered. This is exactly the class CI: "Build profile diff" is green when the CI logs cluster does not answer #121048 makes green (an unanswered query is excused, a rejected one still fails the job); it is open and waiting for review.
  • Stateless tests (amd_tsan, parallel, selected tests) — Failed to select tests: CIDB query failed, response code [500], body [Code: 202. DB::Exception: Too many simultaneous queries. Maximum: 1000. (TOO_MANY_SIMULTANEOUS_QUERIES)]. The job died in test selection, before running anything, which is why it has no rows in CIDB at all.
  • Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential, selected tests) — Failed to select tests: Failed to get previously failed tests required for test selection, in the same minutes and against the same overloaded database.

@groeneai, please investigate the two Failed to select tests failures — https://s3.amazonaws.com/clickhouse-test-reports/PRs/118272/53c089a7c94f968e6c5797346662b36b885b8c85/pr/stateless_tests_amd_tsan_parallel_selected_tests/job.log and https://s3.amazonaws.com/clickhouse-test-reports/PRs/118272/53c089a7c94f968e6c5797346662b36b885b8c85/pr/stateless_tests_amd_asan_ubsan_db_disk_distributed_plan_sequential_selected_tests/job.log — and provide a fix in a separate pull request; a transient overload of the CI database should not turn into a red required check. I could not find an open issue for it. If a fix is already in progress, link it here.

Comment thread src/Access/EnabledQuota.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Both reds are the same failure at the same call site, and #120928 fixes it. That PR merged 2026-09-19 07:25:05Z, about 23 hours after this run started, so the report you linked could not carry it.

Test selection reaches the CI database only through CIDB.query() -> CIDB._post_with_retries(). The amd_asan_ubsan wording differs only because get_previously_failed_tests_with_info(strict=True) re-raises with its own message and drops the cause. Its job log has the same rejection five times:

[2026-09-18 08:13:40] WARNING: CIDB query failed, response code [500], body [Code: 202. DB::Exception: Too many simultaneous queries. Maximum: 1000. ...] - attempt 1/5
[2026-09-18 08:13:43] ... attempt 2/5   [08:13:47] 3/5   [08:13:55] 4/5   [08:14:11] 5/5
[2026-09-18 08:14:11]   | Failed to select tests: Failed to get previously failed tests required for test selection

(stateless_tests_amd_asan_ubsan_db_disk_distributed_plan_sequential_selected_tests/job.log, lines 197-209.) The five-attempt ladder burned out in 31 seconds of instant rejections, and both jobs then lost their own result insert to the same overload, which is why neither left rows in the database.

#120928 sends queue_max_wait_ms=30000 (half the query timeout) on every CI database request, so the server queues instead of rejecting. Too many simultaneous queries. Maximum: 1000 is the max_size check in ProcessList.cpp:184-192, the only one of the five TOO_MANY_SIMULTANEOUS_QUERIES throws gated by that setting; the per-user and all-users variants are not gated, and I have seen no occurrence of those. Tolerance across the five retries goes from 31 seconds to roughly 3 minutes. The same PR appends traceback.format_exc() to Failed to select tests, so the cause the strict wrapper hid is visible in the report next time, and inserts share the patched helper, so the dropped results are covered too.

fa5ebfbb29a contains the fix (12bfa4e979d is an ancestor); its selected tests jobs have not started yet. Since the merge there is no occurrence of either message in the CI database, the last visible one being PR #116585 at 2026-09-19 01:26Z, and 267 PRs ran the six selected tests variants normally between 07:26Z and 23:50Z today, which also rules out the new parameter breaking the query path. I would not call the class closed on absence of rows alone, since a job that dies in selection leaves none.

…h of counters

In the multi-counter `EnabledQuota::usedForQuery`, `Impl::used` advances an ended interval only
when the counter it is applying overflows. So when the first insert of a new interval overflows
the stale `written_bytes` of the ended interval, the reset wipes the `written_rows` of the same
chunk, which was added just before: `system.quota_usage` undercounts `written_rows` and the new
interval can accept an extra block. Now every target interval is advanced for `current_time`
once, before any counter of the batch is applied.

`05239_written_rows_quota_interval_rollover` crosses the end of a 5-second interval within one
session (a login starts the new interval by itself) and checks `written_rows = 1` after the
rollover; it printed `0` before the fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/Access/EnabledQuota.cpp Resolved
alexey-milovidov and others added 3 commits October 3, 2026 05:58
# Conflicts:
#	src/Parsers/Access/ParserCreateQuotaQuery.cpp
…re accounting or checking

`Impl::used` advanced an ended interval only after the counter overflowed, so the
single-counter `used` / `usedForQuery` entrypoints carried the stale usage of the
ended interval into the new one and dropped the first part of the new interval on
the first overflow (e.g. `max_queries = 10` effectively allowed 14 queries).
Now `Impl::used` and `Impl::checkExceeded` call `getEndOfInterval` first, which
starts a new interval if needed, so every entrypoint behaves the same; the extra
normalization in the batched `usedForQuery` is no longer needed.

Also fix `test_quota::test_exceed_quota`: the usage is kept when the quota
configuration is reloaded, so the 200 `read_bytes` recorded by the rejected query
(all counters of one call are accounted before checking) carry over to the later
checks.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118272&sha=4c10820cba916214b0b5914e4ceb3c6debfcc044&name_0=PR&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%207%2F8%29
PR: #118272

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a new interval

The `queries` counter is accounted by itself; with `max_queries = 4` and 3 queries
used in the ended interval, the first two queries of the new interval must both be
counted (before the fix the second one overflowed the stale value, reset the
counters and only re-added itself).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`05320_queries_quota_interval_rollover` failed in the `CH Inc sync` private CI,
`Stateless tests (amd_asan_ubsan, flaky check, s3 storage, meta in keeper)`: it read `0`
instead of `2`, because the separate client that read `system.quotas_usage` started
after the second quota interval had already ended.

Both rollover tests now read the usage in the same session from `system.quota_usage`,
check that their checkpoints fell into the intended intervals (by `end_time`), and repeat
the attempt otherwise.

https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/praktika.html?PR=72812&sha=e5d88141153ba3b68c77d6cd0bca6c3255bc604d&name_0=PR
Related: #118272

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update, 2026-10-06 — pushed 5c32229c4a7:

  • CH Inc sync (tests failed): the failure came from this PR's new test 05320_queries_quota_interval_rollover. In Stateless tests (amd_asan_ubsan, flaky check, s3 storage, meta in keeper) of the sync PR it read 0 instead of 2. The separate client that reads system.quotas_usage started after the second 5-second quota interval had already ended. Both rollover tests (05320 and 05239) now read the usage in the same session from system.quota_usage. They use end_time to check that each checkpoint fell into the intended interval, and repeat the attempt if it did not. I ran them locally, including 8 runs of each in parallel; all passed.
  • Public CI was green otherwise, and there are no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update, 2026-10-07 — pushed 550eb6f5ef9:

  • Style check (various): the new tests 05239_written_rows_quota_interval_rollover and 05320_queries_quota_interval_rollover were flagged for querying system.tables without a database condition. That was a false positive. The check treats system.tables as a regex, so the phrase "system tables" in a comment matched it. I reworded the comments in 414bd888a98.
  • Merged master. There were no conflicts, and the changed translation units build locally.
  • There are no unresolved review threads.

Comment thread src/Access/EnabledQuota.cpp Resolved
…to writers

`EnabledQuota::Interval::getEndOfInterval` published the new `end_of_interval`
with a CAS and only then zeroed `used`, so a concurrent thread could observe the
new interval, account its usage, and have it wiped by the reset. Now the rollover
is serialized by a per-interval mutex and the counters are reset before the new
end of the interval is published. The fast path (interval not ended) stays
lock-free.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Access/Common/QuotaDefs.h Resolved
Comment thread src/Access/EnabledQuota.h
mutable std::atomic<std::chrono::system_clock::duration> end_of_interval;

/// Serializes the rollover to a new interval in `getEndOfInterval`.
mutable std::mutex rollover_mutex;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, I'd be okay with imprecise calculation here, and it was not part of this task. Still acceptable.


if (quota)
quota->usedForQuery(normalized_query_hash, QuotaType::WRITTEN_BYTES, written_bytes);
quota->usedForQuery(normalized_query_hash, {{QuotaType::WRITTEN_ROWS, written_rows}, {QuotaType::WRITTEN_BYTES, written_bytes}});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those who will read - this is the main change.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit 228b487 Oct 7, 2026
269 of 290 checks passed
@alexey-milovidov
alexey-milovidov deleted the quota-written-rows branch October 7, 2026 23:41
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 13, 2026
The test crossed the end of its 5 s quota interval with a fixed
`sleep(3)` + `sleep(2.5)`. A fixed sleep adds all the latency before it
(client start, three accounted queries, the first usage read) to the
time after the boundary. On a loaded MSan runner every trivial query
took about 400 ms, so in all 10 attempts the final usage read started
0.10-0.38 s after the end of the second interval and reported the
third one; nothing was printed. The latency was the same in every
attempt, so the retry loop could not help.

Sleep until 0.1 s after the end of the first interval instead, computed
on the server from `now64(3)`. Quota intervals are aligned to the epoch,
so `END + 5` is a whole second known before the session. One `sleep` is
limited to 3 s (`function_sleep_max_microseconds_per_block`), hence two
calls clamped to [0, 3]. The sleeps still read only `system.one`, which
is not accounted, and no quota state, so they do not start the new
interval. The assertion, the reference and the checkpoints are
unchanged.

Validated with per-query latency injected via
`sleep_after_receiving_query_ms`: the old test fails with the CI diff at
600 and 700 ms, the new one passes at 700 and 900 ms on its first
attempt and first fails at 1300 ms. 50/50 randomized runs (debug) and
20/20 on ASan pass. On 26.9.25.15, before ClickHouse#118272, the test still prints
1 instead of 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants