Repository navigation
fix: bound clickHouse v2 s3 copy memory - #7407
Merged
achettyiitr merged 4 commits intoSep 18, 2026
Merged
Conversation
The copy engine reads a whole folder of gzipped CSV in one INSERT ... SELECT FROM s3(), so its peak memory follows ClickHouse's parse and insert parallelism, not anything batched client-side. A large enough folder exhausts the instance: code: 241 (total) memory limit exceeded: would use 47.01 GiB, maximum: 46.80 GiB ... While executing CSVRowInputFormat: While executing ReadFromObjectStorage The statement carried only two settings, both about parsing semantics, so there was no lever for this short of resizing the instance. Add max_threads, max_insert_threads, max_memory_usage, min_insert_block_size_bytes, min_insert_block_size_rows and input_format_parallel_parsing, each resolved per workspace with a global fallback. Every one is unset by default, so a deployment that configures none of them sends the statement it sent before. Unset is -1 rather than 0 because min_insert_block_size_rows is meant to take 0 alongside min_insert_block_size_bytes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> 🔒 Scanned for secrets using gitleaks 8.29.1
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> 🔒 Scanned for secrets using gitleaks 8.29.1
Only the server rejects a bad setting name or a malformed settings clause, so the unit tests cannot tell whether what the copy engine builds is something ClickHouse will run. Add a case that loads through the s3 engine with every supported setting applied, including the two that have to be sendable as zero. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> 🔒 Scanned for secrets using gitleaks 8.29.1
cisse21
approved these changes
Sep 18, 2026
Parallel CSV parsing defaults to one thread per core — auto(18) on the instance that ran out of memory — and each holds a buffer, which is what the failing allocation was inside. disableParallelParsing could only give that up altogether; bounding the threads keeps most of the parallelism the copy path is fast because of. Also spell the full name mapping out in a test, so a typo in a ClickHouse setting name fails there rather than on the server mid-load. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> 🔒 Scanned for secrets using gitleaks 8.29.1
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/1.87.x #7407 +/- ##
==================================================
+ Coverage 84.38% 84.87% +0.49%
==================================================
Files 620 620
Lines 62706 62729 +23
==================================================
+ Hits 52912 53239 +327
+ Misses 9791 9487 -304
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
saikumarrs
approved these changes
Sep 18, 2026
Merged
achettyiitr
pushed a commit
that referenced
this pull request
Sep 18, 2026
🤖 I have created a release *beep* *boop* --- ## [1.87.1](v1.87.0...v1.87.1) (2026-09-18) ### Bug Fixes * bound clickHouse v2 s3 copy memory ([#7407](#7407)) ([ee78070](ee78070)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
achettyiitr
added a commit
that referenced
this pull request
Sep 18, 2026
# Description Syncing patch release v1.87.1 to main branch **↓↓ Please review and edit commit overrides before merging ↓↓** BEGIN_COMMIT_OVERRIDE fix: bound clickHouse v2 s3 copy memory (#7407) END_COMMIT_OVERRIDE --------- Co-authored-by: Akash Chetty <[email protected]> Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
This was referenced Sep 21, 2026
Merged
achettyiitr
pushed a commit
that referenced
this pull request
Sep 21, 2026
🤖 I have created a release *beep* *boop* --- ## [1.88.0-rc.1](v1.87.0...v1.88.0-rc.1) (2026-09-21) ### Features * **warehouse:** bigquery workload identity federation authentication ([#7361](#7361)) ([d16ab5f](d16ab5f)) ### Bug Fixes * bound clickHouse v2 s3 copy memory ([#7407](#7407)) ([a17a78f](a17a78f)) ### Miscellaneous * cleanup python mirroring ([#7395](#7395)) ([9f9bcde](9f9bcde)) * default failed-keys error capture on ([#7404](#7404)) ([db84987](db84987)) * sync release v1.87.0 to main branch ([#7394](#7394)) ([80353d1](80353d1)) * tag namespace config http client stats with version and mode ([#7401](#7401)) ([d152ae5](d152ae5)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
mihir20
pushed a commit
that referenced
this pull request
Sep 22, 2026
🤖 I have created a release *beep* *boop* --- ## [1.88.0](v1.87.0...v1.88.0) (2026-09-21) ### Features * **warehouse:** bigquery workload identity federation authentication ([#7361](#7361)) ([d16ab5f](d16ab5f)) ### Bug Fixes * bound clickHouse v2 s3 copy memory ([#7407](#7407)) ([a17a78f](a17a78f)) ### Miscellaneous * cleanup python mirroring ([#7395](#7395)) ([9f9bcde](9f9bcde)) * default failed-keys error capture on ([#7404](#7404)) ([db84987](db84987)) * sync release v1.87.0 to main branch ([#7394](#7394)) ([80353d1](80353d1)) * tag namespace config http client stats with version and mode ([#7401](#7401)) ([d152ae5](d152ae5)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.
Description
The ClickHouse v2 copy engine loads a table with a single statement that globs the whole load-file folder:
ClickHouse downloads, decompresses and parses every file server-side, so peak memory follows its parse and insert parallelism — not anything batched client-side (
commitEverybelongs toloadByDownloadingLoadFiles, the other branch, and is never reached when the S3 engine is on).A large enough folder exhausts the instance:
Both settings on the statement are parsing semantics, so there was no lever for this short of resizing the ClickHouse instance.
Change
Adds seven settings to the copy statement, each resolved per workspace with a global fallback, matching the existing
disableLoadTableStats/maxLoadDelaypattern:s3Copy.maxThreadsmax_threadsauto(18)s3Copy.maxParsingThreadsmax_parsing_threadsauto(18)s3Copy.maxInsertThreadsmax_insert_threads0(auto; Cloud sets 4 here)s3Copy.maxMemoryUsagemax_memory_usage0— no per-query limits3Copy.minInsertBlockSizeBytesmin_insert_block_size_bytes268402944(~256 MiB)s3Copy.minInsertBlockSizeRowsmin_insert_block_size_rows1048449s3Copy.disableParallelParsinginput_format_parallel_parsing1(enabled)Resolved as
Warehouse.clickhouse.v2.<workspaceID>.s3Copy.<name>thenWarehouse.clickhouse.v2.s3Copy.<name>. The same links are in the code beside the settings list.Defaults above are read from
system.settingson the affected instance (ClickHouse Cloud 26.4.1.2359, 18 cores), not just the docs — Cloud has already setmax_insert_threads = 4there, and the docs quotemin_insert_block_size_rowsas1,048,545against the server's1,048,449.Why these, and what to reach for first
ClickHouse's own S3 insert tuning guidance sizes block size against thread count:
min_insert_block_size_bytes ≈ peak_memory / (3 * max_insert_threads). On the affected instance that is46.8 GiB / (3 * 4)≈ 3.9 GiB, well above the 256 MiB already in effect — so block size is not what is driving this.The likelier driver is parse-side parallelism:
max_parsing_threadsdefaults to one per core,auto(18)here, and each thread holds a buffer across a folder of many gzipped files, which is the frame the failing allocation is inside.input_format_parallel_parsing = 0is the documented workaround, but it gives the parallelism up altogether;max_parsing_threadsbounds it instead, which matters because the copy path is currently ~7-10x faster than the insert path it replaced.Worth noting
max_memory_usagedefaults to0, i.e. no per-query ceiling: the copy was not stopped by its own limit, it grew until it hit the server-wide budget. Where several workspaces share an instance, one oversized copy can starve the others rather than just failing itself, so a per-query cap is useful containment even though it does not reduce usage.max_download_threads/max_download_buffer_sizeare deliberately left out: downloads are already capped at 4 threads by default on this instance, and the stack points at the parse stage, not the fetch.Every setting is unset by default, so a deployment that configures none of them sends a byte-identical statement. This matters: the S3 copy path is currently ~7-10x faster than the previous insert path in production, and this change must not regress that by default.
Unset is
-1rather than0becausemin_insert_block_size_rowsis meant to take0when paired withmin_insert_block_size_bytes.Test plan
go build ./warehouse/...,go vet,gofmtcleanTestS3CopySettingsV2: unset default, global keys, per-workspace override beating global,0reaching the statement rather than reading as unset, parallel parsing disabled by name, the full name mapping spelled out so a typo in a ClickHouse setting name fails in the test rather than on the server, and the clause staying a singlesettingslistTestS3CredentialsRegexV2(credential masking) still passes against the rebuilt statementusing s3 engine with memory settingscase inTestIntegrationloads through the s3 engine with every supported setting applied, including the two that must be sendable as0. Only the server rejects a bad setting name or a malformed clause, so this is the layer that proves what the copy engine builds is something ClickHouse will actually run. (Compiles and vets locally; needsSLOW=1and a running docker daemon, so it runs in CI.)maxParsingThreads(ordisableParallelParsing) for the affected workspace and confirm the load completes withoutcode: 241Linear Ticket
https://linear.app/rudderstack/issue/INT-7100
Security
Every setting value is read through
GetInt64Var/GetBoolVarand formatted with%d, so only integers and a fixed boolean reach the SQL — config cannot inject arbitrary text into the statement. Credential masking is unchanged and still covered byTestS3CredentialsRegexV2.🤖 Generated with Claude Code