Repository navigation
Conversation
Start query accounting before the Native and HTTP initial `Context` copy, then admit retained setup memory into the user tracker without charging its existing global ancestor twice. Keep bookkeeping that outlives query detachment in global accounting, and cover setup peaks, admission rejection, lifetime cleanup, and repeated synchronous-query balance.
Contributor
|
Workflow [PR], commit [e9032f6] Summary: ❌
AI ReviewSummaryReviewed #120422 at Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit e9032f6.
Changed lines: Changed C/C++ lines covered: 324/329 (98.48%) · Uncovered code |
qoega
marked this pull request as ready for review
September 16, 2026 15:44
qoega
marked this pull request as draft
September 16, 2026 17:21
Initialize admission snapshot variables and make the allocator-rebinding constructors of `GlobalMemoryAllocator` and `QueryContextControlBlockAllocator` explicit. Targeted compiler and clang-tidy checks pass for the four affected translation units on `dev`. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=3b3b592ae1f2756d6a50c5971e872e2b3ecd8ebe&name_0=PR&name_1=Build%20%28arm_tidy%29 Related: ClickHouse#120422
Sanitizer runtimes supply their own `new` and `delete`, so ordinary allocation deltas remain zero in the context accounting tests. Skip the two accounting-only unit cases and integration scenarios for sanitizer builds, while preserving failure-cleanup and cross-thread weak-release coverage. Keep all ordinary-build accounting assertions unchanged. Validated both normal and sanitizer compilation and six integration cases on `dev`; full sanitizer runtime validation remains with CI. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=b616fd15ca456c3882f9f4a156a9ada7a7de5521&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%29 ClickHouse#120422
Check retained setup memory against the query limit without rechecking the global limit at admission. Preserve the configured batching allowance for authenticated recovery users during `Native` query reception. Return queued async-insert key allocations to their originating query tracker when a background thread destroys them. Keep the tracker alive through key ownership and keep shared-pointer bookkeeping global. Give the rejected-admission fixture room for a successful small query and verify that precondition. Let malformed async inserts reach the queue so the failure-counter test exercises queue failures instead of setup rejection. ClickHouse#120422 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=e54ae894387ca398fde8294d81d1a30e47792194&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%207%2F8%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=e54ae894387ca398fde8294d81d1a30e47792194&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=e54ae894387ca398fde8294d81d1a30e47792194&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29 Validation on `dev`: 16 focused checks, 9 context/failed-insert cases, unchanged async user-memory drift test (14,096-byte growth), recovery queries under total memory pressure, and both explicit async flush paths. Runtime used a targeted relink of the feature baseline; merged-head CI remains required.
Contributor
Build profile diff (arm_release)Commit See the job log for details. |
Allow error reporting in `HTTPHandler` to allocate after setup or authentication rejects a request at a memory limit. Keep allocations tracked while `LockMemoryExceptionInThread` prevents a second memory-limit exception from suppressing the original response. Cover GET and POST in the early-memory-limit integration test and bound curl requests so a missing response produces a prompt transport failure. ClickHouse#120422 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=71f5cde010d02c3a6078a366a6303a0e135a9441&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20targeted%29 Validation on `dev`: GET and POST return the expected Code `241` under 2 GB memory pressure; both full pressure-test cases and all nine context and async-insert regression cases passed without skips. Real server restarts and config reloads used a standalone transport harness. Runtime used a targeted relink of the feature baseline; full CI is required.
Start `QueryScope` before copying the query `Context` in MySQL, PostgreSQL, gRPC, Arrow Flight, and Prometheus handlers. Give each PostgreSQL statement its own context and release retained contexts under their original tracker, including Flight polling and cancellation. Preserve memory-limit errors during Flight preparation and gRPC error delivery. Add query/user setup-limit, recovery, and cleanup coverage for 24 protocol paths, plus session-setting and multi-statement checks. Related: ClickHouse#120422 (comment)
Register Prometheus remote reads, formatting and empty writes, plus Arrow Flight session options and non-SELECT preparation, before using their query contexts. Tear down cancelled Flight pipelines under their original tracker. Preserve inherited profiles with `MODIFY SETTINGS` in endpoint tests, wait for context cleanup before sampling the baseline, and cover 33 operations with 200 regression cases. Related: ClickHouse#120422
Release query-owned buffers in `Call::close` before detaching their memory tracker. Destroy the responder after detachment, matching its allocation before query setup. The endpoint cleanup regression detects excess user-memory credits across repeated gRPC calls.
Compare identical Prometheus writes with a small-context control while keeping the 64 KiB tolerance for memory retained by the 8 MiB setup value. Other endpoint cleanup checks still require zero drift. The unchanged test already accumulated 192864/192576 bytes on the pre-endpoint binary. Paired checks on the newer binary differ by only -1152/4392 bytes and pass in both batching modes.
Extend `QueryScope` through response finalization and destruction instead of allocating live response buffers globally. Allocate write responses before admission so their memory is checked before the user tracker resets. Keep error delivery bounded and tracked after a memory-limit exception. Add 16 response-buffer limit and recovery cases across query, format, read, and empty-write handlers, covering query/user limits and batching. All 16 detect missing rejection on the prior binary; the changed source compiles cleanly. Full endpoint runtime validation remains pending.
Apply query and user limits to unsupported routes and parsing errors. Preserve the original memory-limit exception and close plain remote-write error responses so clients can read their complete body. Add 32 limit and recovery cases covering early context and response allocation.
Disable `query_metric_log` collection only for endpoint cleanup-test users. The pre-endpoint binary also retains metric bookkeeping on PostgreSQL `COPY` and Flight cancellation/schema-preparation paths. Keep all endpoint cases and the 64 KiB cleanup tolerance unchanged. Validation: reproduce all eight CI failures by enabling `query_metric_log` on the current CI binary; confirm retained bookkeeping with an empty context payload on the pre-endpoint binary. All 248 endpoint cases passed on `dev` in 110.42 seconds with CI-style logging, profiling, and pool size. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=d4c8618b8e10d1497b3aaba18f75a8547c1cbff5&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%202%2F4%29 Related: ClickHouse#120422
qoega
added a commit
that referenced
this pull request
Nov 4, 2026
Keep the existing include so the ARM tidy build passes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=77aefe19621d5a205ed6cd011c77e63487b50425&name_0=PR&name_1=Build%20%28arm_tidy%2C%203%2F4%29 Related: #120422 CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123112&sha=b4fa280d34853c18c7631c3ab0a627e54ae7e33c&name_0=PR&name_1=Build%20%28arm_tidy%2C%203%2F4%29 Related: #123112
qoega
added a commit
that referenced
this pull request
Nov 4, 2026
Construct and replace `ConnectionPeer` under `total_memory_tracker` because its strings survive the request. Otherwise replacing a retained `User-Agent` can debit the next query's setup tracker. Add a stateless keep-alive regression for unbatched and batched accounting. The published CI binary undercounts the reused request by 131568 bytes in both modes. The exact new test fails on it; the modified translation unit passes a supplemental syntax-only check. Fixed runtime validation awaits CI. #123112 (comment) #120422
Construct and replace `ConnectionPeer` under `total_memory_tracker` because its strings survive the request. Otherwise replacing a retained `User-Agent` can debit the next query's setup tracker. Add a stateless keep-alive regression for unbatched and batched accounting. The published CI binary undercounts the reused request by 131568 bytes in both modes. The exact new test fails on it; the modified translation unit passes a supplemental syntax-only check. Fixed runtime validation awaits CI. ClickHouse#123112 (comment) ClickHouse#120422
The first request and a later keep-alive request differed by 80120 bytes in Fast tests even with the connection metadata fix. Issue one small-header request before collecting the baseline, keeping the 64 KiB tolerance and the large-to-small `User-Agent` replacement check. The updated test passes five repetitions on each fixed CI binary with both batching settings. The unfixed binary still fails by 130992 bytes. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=d4aea6d1d5d5c1083ab70c8ec25ede2772b3fe51&name_0=PR&name_1=Fast%20test ClickHouse#120422 ClickHouse#123112
qoega
added a commit
that referenced
this pull request
Nov 4, 2026
The first request and a later keep-alive request differed by 80120 bytes in Fast tests even with the connection metadata fix. Issue one small-header request before collecting the baseline, keeping the 64 KiB tolerance and the large-to-small `User-Agent` replacement check. The updated test passes five repetitions on each fixed CI binary with both batching settings. The unfixed binary still fails by 130992 bytes. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=d4aea6d1d5d5c1083ab70c8ec25ede2772b3fe51&name_0=PR&name_1=Fast%20test #120422 #123112
Reading `system.processes` copies other running queries before filtering, so measuring its own `memory_usage` varies with parallel test activity. Read the final peak for `SELECT 1` from `X-ClickHouse-Summary` instead. Keep the 64 KiB tolerance and large-to-small header replacement check. Both fixed CI binaries pass five repetitions with two batching modes under four concurrent workers. The old binary still fails by 130992 bytes. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123112&sha=49aeb75b88e1a6554499bdc6a9ab105f0f750ea4&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123112&sha=49aeb75b88e1a6554499bdc6a9ab105f0f750ea4&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 ClickHouse#123112 ClickHouse#120422
qoega
added a commit
that referenced
this pull request
Nov 5, 2026
Reading `system.processes` copies other running queries before filtering, so measuring its own `memory_usage` varies with parallel test activity. Read the final peak for `SELECT 1` from `X-ClickHouse-Summary` instead. Keep the 64 KiB tolerance and large-to-small header replacement check. Both fixed CI binaries pass five repetitions with two batching modes under four concurrent workers. The old binary still fails by 130992 bytes. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123112&sha=49aeb75b88e1a6554499bdc6a9ab105f0f750ea4&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123112&sha=49aeb75b88e1a6554499bdc6a9ab105f0f750ea4&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 #123112 #120422
Copy the retained context inside the worker `QueryScope` and keep its admission entry until context cleanup is flushed. Preserve the source context tracker across the handoff and allocate shared task bookkeeping globally. Add Native/HTTP coverage for setup admission, live memory and cleanup with another query active. The previous ARM CI binary fails the setup-admission assertion on both protocols.
Use `QueryScope::initialized` for the two profile-event guards added by master. This PR uses a direct scope object instead of an optional scope.
Rename the local holder to `source_context` so the `source` init-capture does not trigger `-Wshadow-uncaptured-local`. Ownership is unchanged. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=cf2abf100848dad625c9200c5bdbc13941ce7bed&name_0=PR&name_1=Fast%20test Related: ClickHouse#120422
Include the upstream S3 path-list race fix without changing the query-context accounting scope. The previous core run failed on ThreadSanitizer STID 5233-4bfc. Related: ClickHouse#114995 Related: ClickHouse#120422 CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=3a5afb647af4c784ea193d741ea03c598534388d&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29
The master header cleanup leaves only a forward declaration through `Context.h`, so the numeric `setSetting` arguments cannot convert to `Field`. Include its definition directly. CI: https://github.com/ClickHouse/ClickHouse/actions/runs/43296931202/job/131458994429 Related: ClickHouse#120422
Copy the retained SQL buffer under the worker setup tracker and release the global handoff copy before admission. Destroy the worker buffer before its process-list entry so inline `INSERT` data is charged and released with the query. Keep scheduler and promise bookkeeping global. Add a Native inline-data regression for query/user setup limits, live usage and cleanup with another query still active. Review: ClickHouse#123112 (comment) Related: ClickHouse#120422
Disable `async_insert` explicitly so the regression covers the retained Native `Query` buffer. Accept `NOTHING_TO_KILL` only during cleanup, where it is expected after an admission failure. The historical CI binary accepts the 8 MiB inline payload under a 4 MiB query limit, reproducing the missing setup charge. Review: ClickHouse#123112 (comment) Related: ClickHouse#120422
The materialized `sleepEachRow` expression receives all 1024 rows in one block despite `max_insert_block_size=16`, so its 5.12-second observation window exceeds the default three-second per-block limit. Allow six seconds in this test so the worker remains observable instead of throwing `TOO_SLOW`. Keep the query/user limits and accounting assertions unchanged. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=6edbc2a3559cf8e2482a10047bb48d7917cddaa4&name_0=PR&name_1=Fast%20test Related: ClickHouse#120422
A protocol override can clear an inherited `log_comment` while the request context retains its allocation. Nest the idle request tracker under the worker tracker before admission, and retain that parent through request cleanup. Preserve the source peak without charging server memory again. The request flushes before scheduling and waits under global accounting, so the worker can move the setup charge while it is stable. Query and user limits still apply at the usual `ProcessList` admission point. Add a stateless regression for Native/HTTP query and user admission, reported peak after an override, and cleanup with another active query. Related: ClickHouse#120422 (comment) Related: ClickHouse#120422
Replace the dedicated single-server integration cluster with a stateless shell test. Preserve inherited settings, Native/HTTP peaks, query and user admission, batching and cleanup assertions with another query active. All 11 former parameterizations run through the default stateless server. The protocol-specific integration module remains for configured endpoints. Related: ClickHouse#120422 (comment) Related: ClickHouse#120422
qoega
added a commit
that referenced
this pull request
Nov 23, 2026
A protocol override can clear an inherited `log_comment` while the request context retains its allocation. Nest the idle request tracker under the worker tracker before admission, and retain that parent through request cleanup. Preserve the source peak without charging server memory again. The request flushes before scheduling and waits under global accounting, so the worker can move the setup charge while it is stable. Query and user limits still apply at the usual `ProcessList` admission point. Add a stateless regression for Native/HTTP query and user admission, reported peak after an override, and cleanup with another active query. Related: #120422 (comment) Related: #120422
qoega
added a commit
that referenced
this pull request
Nov 23, 2026
Replace the dedicated single-server integration cluster with a stateless shell test. Preserve inherited settings, Native/HTTP peaks, query and user admission, batching and cleanup assertions with another query active. All 11 former parameterizations run through the default stateless server. The protocol-specific integration module remains for configured endpoints. Related: #120422 (comment) Related: #120422
Filter `system.query_log` by `current_database = currentDatabase()` and send HTTP requests to `CLICKHOUSE_DATABASE`, matching Native requests. This keeps both new stateless regressions compatible with database isolation and the CI query-log style check. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=0c066193b2f2e50ec7cea1ef6c7228ea0bfc5c21&name_0=PR&name_1=Style%20check ClickHouse#120422
An HTTP response can finish before the handler releases its query context, and the user and sentinel counters are independent snapshots. Wait for server EOF and three stable counter pairs before comparing cleanup balances. Keep the 2 KiB bound, positive floor and both batching modes. Reduce cleanup requests from 832 to 304; 144 queries after each baseline still expose a persistent 16-byte per-query residue above that bound. Validated 20 runs with uninterrupted concurrent load on current AMD debug and binary CI builds. A retained-query control still fails by 33,663,880 bytes. This is standalone validation; the original CI jitter did not reproduce in five bounded original-test runs. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120422&sha=7e6fd6daa71e2c549d616593fa60887e3ac9300a&name_0=PR&name_1=Stateless%20tests%20(amd_debug%2C%20flaky%20check) ClickHouse#120422
An admission failure can leave the query context above its limit. With `min_allocation_size_to_throw_on_memory_limit=1`, copying the exception in `TCPHandler::runImpl` then throws before the error packet reaches the client. Keep memory-limit exceptions blocked from exception capture through delivery and context cleanup; successful query execution keeps normal limit checks. Reuse the existing memory-limit integration server with a temporary config change. The focused test requires the original setup error and a successful subsequent query. Three bounded query-limit attempts on the published AMD binary returned transport EOF with the setting enabled and the original setup error when disabled; the server stack identifies `Exception::clone`. The exact new test also detects the missing error packet. Fixed-code build and runtime validation remain for CI; standalone evidence is not full CI. ClickHouse#123112 (comment) ClickHouse#120422
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Include the initial
Contextin Native and HTTP query memory usage, includingSELECT 1. Start tracking before copying the context, then use the existing query admission andMemoryTracker::reparentto apply query/user limits without charging the server total twice.Reuses the lifetime accounting merged in #113647; no async-queue or system-table changes remain. Coverage checks inherited context bytes, limits, cleanup and recovery-user batching. Errors before query admission retain their existing precedence.
Related: #113647
Related: #123112
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Include initial query-context allocations in memory usage and limits at query admission for Native and HTTP queries.
Workflow [PR]
Sync PR [sync-upstream/pr/120422]