Repository navigation
log internal queries - #83277
log internal queries#83277
Conversation
|
Workflow [PR], commit [38a41d9] Summary: ❌
|
4d2e191 to
1c060e8
Compare
Algunenano
left a comment
There was a problem hiding this comment.
Please review the test and style failures
| /// We should not include internal queries for limiting the number of simultaneous queries. | ||
| if (!is_internal) | ||
| { | ||
| ++non_internal_processes; |
There was a problem hiding this comment.
It's unclear to me which mutex protects this variable (or query_kind_amounts). I don't see a mutex here, and they are not atomic
There was a problem hiding this comment.
All the accesses of ProcessList::non_internal_processes are guarded by ProcessList::mutex. And all the accesses of ProcessListForUser::non_internal_queries are also guarded by ProcessList::mutex.
| /// limit for waiting queries. 0 means no limit. Otherwise, when limit exceeded, an exception is thrown. | ||
| std::atomic<UInt64> max_waiting_queries_amount{0}; | ||
|
|
||
| /// amounts of waiting queries |
There was a problem hiding this comment.
What happened with all the code around waiting queries?
There was a problem hiding this comment.
I don't think it's dead code. We have server settings max_waiting_queries, max_concurrent_select_queries, max_concurrent_insert_queries, etc. How will they work now?
There was a problem hiding this comment.
Neither incrementWaiters nor decrementWaiters was ever invoked, so increaseWaitingQueryAmount and decreaseWaitingQueryAmount were never invoked either. Consequently, all of waiting_queries_amount, waiting_insert_queries_amount, and waiting_select_queries_amount were always zero and all the checks worked without taking the number of waiting queries into account.
But now that you've raised this, I think I should've kept all this logic and started calling incrementWaiters and decrementWaiters instead.
There was a problem hiding this comment.
It seems to be not fully implemented. AsyncLoader callbacks on_waiters_increment and on_waiters_decrement should be passed to all places where makeLodJob is called and they should call corresponding function of ProcessList. And it requires some tests, which I obviously skipped, so now it does not work at all. Let me fix it separately.
| query_scope = std::make_unique<CurrentThread::QueryScope>(context_copy); | ||
| } | ||
|
|
||
| context_copy->setCurrentQueryId({}); |
There was a problem hiding this comment.
I believe this is not enough, it does not set query_id for current_thread - and this means that you cannot find logs for this queries in text_log/trace_log/..., we need this as well
current_thread->setQueryId(...);
And this
current_thread->clearQueryId();
There was a problem hiding this comment.
good point, will do! (I was just debugging an incident where this information would have been quite handy...)
…ing_queries Restores the accounting added in ClickHouse#61053 and removed as dead code in ClickHouse#83277, with the two defects that kept it from working in the first place fixed. `limit == 0` is documented as "no limit", but the original check was `if (value >= limit) throw`, which refuses the very first waiter on a default-configured server. The limit is now consulted only when it is set. The per-query election used `waiting_threads.fetch_add(1) == 0` to decide which thread registers the query. When the limit check then threw, `waiting_threads` was left at 1 with the query never registered, so that query stayed exempt from the limit forever; rolling the counter back instead would race a second thread of the same query into a follower with no leader, which underflows the global counter. A per-query mutex makes the check run strictly before the counter moves, so a refused query is left exactly as it was. A query that the concurrency limits exempt (`KILL QUERY`, `SELECT FROM system.processes`, the introspection port) is counted but never refused: it is counted by the limits that the waiting amounts are subtracted from, and the admin needs it to work on a server that has hit the limit. Internal queries are outside both, matching `non_internal_processes` and `query_kind_amounts`. Nothing calls this yet; the load jobs are wired up in the next commit. Co-Authored-By: Claude Opus 5 <[email protected]>
`max_waiting_queries` documents that a query waiting for an asynchronously loading table is not counted when `max_concurrent_queries`, `max_concurrent_insert_queries`, `max_concurrent_select_queries`, `max_concurrent_queries_for_user` and `max_concurrent_queries_for_all_users` are checked, "to avoid hitting these limits just after server startup". That correction was added in ClickHouse#61053 and removed together with the rest of the waiting accounting in ClickHouse#83277, so the second half of the paragraph defining this setting has been false since then. It also makes the two limits compose. A waiting query holds a `max_concurrent_queries` slot without it, so with `max_concurrent_queries = 100` and `max_waiting_queries = 200` the 101st waiter is refused by the wrong limit and the configured 200 is unreachable. The discount is applied to all five checks including the `have_space` predicate, otherwise a query would be parked for `queue_max_wait_ms` and then refused despite it. The reported ", waiting: N" is emitted only when the count is non-zero, so an operator can tell why a limit did or did not fire; the existing tests that match these messages all match a prefix. In steady state all four waiting counters are zero and the behaviour is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Log internal queries (those executed internally by dictionaries, refreshable materialized views, etc) and add the new
is_internalcolumn tosystem.query_log.Documentation entry for user-facing changes