Repository navigation
Conversation
|
Workflow [PR], commit [a4b2f94] Summary: ❌
AI ReviewSummaryThe change counts qualifying Missing context / blind spots
Findings
Final VerdictStatus: |
| auto query_id = context_.getCurrentQueryId(); | ||
| /// The limit counts whole queries: `initial_query_id` is shared by every fragment and secondary | ||
| /// query of one client query, and is empty only when the client itself sent a secondary query. | ||
| auto query_id = context_.getInitialQueryId(); |
There was a problem hiding this comment.
Keying the slot by initial_query_id alone is not enough to identify one logical statement on this server.
ProcessList explicitly avoids initial_* for server-side limits because those fields are client-supplied and not uniqueness-checked on the receiving host (see the rationale around current_query_id in ProcessList.cpp). After this change, two unrelated distributed queries that reuse the same root query_id on different initiators will collapse onto one query_id_set entry here and only consume one max_concurrent_queries slot.
We need a server-unique logical-query key (or at least a key that includes trusted initiator identity), otherwise reusing query_id becomes a way to undercount the table limit.
There was a problem hiding this comment.
Unrelated statements that reuse one root query_id already share the table read lock, since IStorage::lockForShare is keyed on getInitialQueryId() with the same last-holder-frees count, so this limit follows that convention. The per-user limit max_concurrent_queries_for_user is unaffected: ProcessList still keys it on the authenticated user.
CI finish ledger - 377f0ecEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260924-210057 |
A table's max_concurrent_queries counts query ids, and several kinds of one statement read the same table under ids of their own: a replica read under parallel replicas, and a fragment of a distributed query plan. A single statement then competes against itself for the table's slots and is rejected with TOO_MANY_SIMULTANEOUS_QUERIES. Measured on master, one shard with three replicas of this server and a table with max_concurrent_queries = 1: a SELECT under enable_parallel_replicas = 1 fails with Code 202 while the identical SELECT without parallel replicas is served, and a dispatched distributed-plan query over the same table fails the same way. The limit is taken under the initial query id, which every fragment and secondary query of one statement shares, and the running set holds a reader count per id so the slot is freed by the last reader rather than the first. 01666's comment loses the workaround it described.
The comment said only the dispatched arm tells a slot released by the last reader from one released by the first, because in-process fragments never stop early. On master with ClickHouse#120949, a build that keeps the new key but drops the reader count now fails the in-process arm too, in 8 of 10 runs, so the claim no longer holds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
377f0ec to
74f0a73
Compare
Build profile diff (arm_release)Commit See the job log for details. |
The test arms the server-global fail point parallel_replicas_wait_for_unused_replicas, and master's Style check (failpoint_tests_are_isolated) now requires every stateless test that arms a fail point to be tagged no-parallel and no-fasttest. The test already carries no-fasttest; 04207_pr_additional_filters.sql, which arms the same fail point, is tagged the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixing PR for the |
|
Dear @antoniofilipovic, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@groeneai can you merge master into this one and fix conflicts if there are some? |
antoniofilipovic
left a comment
There was a problem hiding this comment.
Change looks reasonable, please merge master before and fix new conflicts if there are some
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged current master into the branch, new head 3249da8. There were no conflicts, and the PR's own diff is unchanged. On the merged tree |
A client can send a statement as a secondary query with no initial query id. `RemoteQueryExecutor` forwarded that empty id unchanged, so each parallel replica fell back to its own `current_query_id` in `ReadFromMergeTree::checkLimits`, took a slot of its own in the table's `max_concurrent_queries`, and the statement could refuse itself with TOO_MANY_SIMULTANEOUS_QUERIES. Fill the empty initial query id with this query's id before sending, as the distributed plan already does for its tasks. 05232's parallel-replica case now also runs as a client-sent secondary query: it fails 5/5 on the previous head (Code 202 from a replica) and passes with this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #120949
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
SELECTthat reads oneMergeTreetable through several readers of a single statement on one server, the fragments of a distributed query plan or the replicas of a cluster whose entries resolve to that server, now counts as one query against the table'smax_concurrent_querieslimit instead of competing against itself for its slots. The limit is taken under the statement's initial query id, and its slot is released by the last of the statement's readers rather than the first.Description
ReadFromMergeTree::AnalysisResult::checkLimitskeys the slot ongetCurrentQueryId(), and each read of one statement carries a query id of its own, so a statement whose readers meet on one server competes against itself and is refused withTOO_MANY_SIMULTANEOUS_QUERIES. Measured on master618a561273dfb, table withmax_concurrent_queries = 1:Scope, which decides the category:
query_id_setis aMergeTreeDatamember, so the limit counts per server process and a statement that reaches each process once cannot collide with itself. Measured earlier on a cluster with one entry per process: 0 failures in 80 parallel-replica runs, against 6 in 120 with one process listed three times. Reachable in a deployment is the distributed-plan case, where several fragments of one plan go to one worker, andmake_distributed_planisPRIVATE_PREVIEW. So this goes in as anImprovementrather than a bug fix, even though01666_merge_tree_max_query_limit.shhas carried--enable_parallel_replicas 0since 26.8 for exactly this reason.getInitialQueryId()is what every fragment and secondary query of one statement shares, with a fallback for a client-sent secondary query, which has none;RemoteQueryExecutorfills that empty id with the statement's own before sending, so its parallel replicas share it too. The running set holds a reader count per id, so the slot is freed by the last reader: the readers of one statement stop at different times.05232covers the slot's lifetime in both distributed-plan cases and the parallel-replicas case, each also for a client-sent secondary query.05232's in-process case relies on the per-task process-list entries of #120949 (merged) to observe two fragments reading one table.Workflow [PR]
Sync PR [sync-upstream/pr/122056]