Skip to content

Use fewer insert threads for sanitizer bugfix-validation data prep - #109954

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-bugfix-validation-msan-reprep-oom
Jul 10, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-bugfix-validation-msan-reprep-oom

Conversation

@groeneai

@groeneai groeneai commented Jul 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108593

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

The Bugfix validation (functional tests, amd64/aarch64) job swaps in each sanitizer binary and re-runs prepare_stateful_data(). On the msan leg the server's baseline RSS already sits near max_server_memory_usage (the host RSS ceiling), so the re-prepare INSERTs running with max_insert_threads=16 push the total memory tracker over the limit and fail:

Code: 241. DB::Exception: (total) memory limit exceeded: would use 19.53 GiB
(attempt to allocate chunk of 7.00 MiB), current RSS: 53.62 GiB, maximum: 53.62 GiB.
... While writing to ForkWriteBuffer. (MEMORY_LIMIT_EXCEEDED)
(query: INSERT INTO test.hits_s3 SELECT * FROM test.hits SETTINGS ... max_insert_threads=16)

This surfaces as an Environment setup (*_msan) ERROR in bugfix-validation. The concrete reason is now visible thanks to the observability plumbing added in #108593.

Fix: lower max_insert_threads to 4 when the binary under test is a sanitizer build (asan/tsan/msan/ubsan), keeping 16 for non-sanitizer builds. The exact same data is loaded; only the transient per-insert working set shrinks. The ERROR-on-failed-reprepare guard is unchanged (no test weakening, no blind retry).

Example CI report (aarch64 msan leg of PR #109747 head 9a632c9): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109747&sha=9a632c97fb47&name_0=PR&name_1=Bugfix%20validation%20%28functional%20tests%2C%20aarch64%29

Version info

  • Merged into: 26.7.1.770 (included in 26.7 and later)

The bugfix-validation job swaps in each sanitizer binary and re-runs
prepare_stateful_data(). On the msan leg the server's baseline RSS
already sits near max_server_memory_usage (the host RSS ceiling), so
the re-prepare INSERTs running with max_insert_threads=16 push the
total memory tracker over the limit and fail with

  Code: 241. DB::Exception: (total) memory limit exceeded: would use
  19.53 GiB ..., current RSS: 53.62 GiB, maximum: 53.62 GiB ...
  (query: INSERT INTO test.hits_s3 SELECT * FROM test.hits
   SETTINGS ... max_insert_threads=16)

This surfaces as an 'Environment setup (*_msan)' ERROR (the concrete
reason is now visible thanks to the observability plumbing in ClickHouse#108593).

Lower max_insert_threads to 4 when the binary under test is a sanitizer
build (asan/tsan/msan/ubsan), keeping 16 for non-sanitizer builds. The
exact same data is loaded; only the transient per-insert working set
shrinks. The ERROR-on-failed-reprepare guard is unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Not locally reproducible (host-load-dependent OOM on the shared CI runner: msan baseline RSS sits at the host ceiling). The concrete failing sub-command + Code 241 error are captured from CI via #108593's observability plumbing.
b Root cause explained? On the msan bugfix-validation leg the server's baseline RSS is already near max_server_memory_usage (host RSS ceiling). The re-prepare INSERT ... max_insert_threads=16 spins up 16 parallel insert pipelines whose transient working set pushes the total memory tracker over the limit -> Code 241 MEMORY_LIMIT_EXCEEDED -> Environment setup (*_msan) ERROR.
c Fix matches root cause? Yes. Lowering max_insert_threads from 16 to 4 on sanitizer binaries directly shrinks the transient per-insert working set that trips the total limit.
d Test intent preserved? Yes. The exact same data is loaded into the exact same tables; only insert concurrency changes. The ERROR-on-failed-reprepare guard is untouched (no false bug reproductions).
e Demonstrated both directions? N/A for a host-load OOM that is not locally reproducible. Verified via a standalone harness that the generated bash blob selects 4 threads for asan/tsan/msan/ubsan and 16 otherwise, prepends MAX_INSERT_THREADS, and that all 3 INSERT queries reference $MAX_INSERT_THREADS (0 hardcoded 16).
f Fix general, not narrow? Applies to ALL sanitizer legs (asan/tsan/msan/ubsan) and both callers (START stage first build type + the re-prepare leg for build_types[1:]), not just the one msan query that was observed to OOM.
g Generalizes across inputs? N/A (CI harness change, not a code path over user inputs).
h Backward compatible? N/A (CI-only Python; no user-facing setting/format change).
i Invariants/contracts preserved? Yes. prepare_stateful_data success semantics unchanged (return rc == 0); build_type is an optional kwarg defaulting to None (16 threads, prior behavior for all non-bugfix-validation callers).

Session id: cron:clickhouse-worker-slot-0:20260710-021000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @leshikus for review: this lowers insert-thread concurrency for the sanitizer legs of the bugfix-validation stateful re-prepare, which OOMs on the msan binary because its baseline RSS is already at the host memory ceiling.

@clickhouse-gh

clickhouse-gh Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0390f12]

Summary: ✅


AI Review

Summary

This PR lowers prepare_stateful_data insert parallelism from 16 to 4 for sanitizer binaries in bugfix-validation runs, and it threads the active build_type through both stateful-setup call sites so the lower limit is applied during the initial setup and each re-prepare after a binary swap. I did not find a correctness, coverage, or metadata issue in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 0390f12

CI fully finished on head `0390f1232ecc`: Finish Workflow SUCCESS (2026-07-10T09:12:07Z), no checks queued/in_progress/pending, all checks SUCCESS or SKIPPED, zero test failures in CIDB. No PR-caused failures; nothing to own.

Check / test Reason Owner / fixing PR
(all checks) — pass (50 SUCCESS / 124 SKIPPED, 0 FAIL/ERROR)

Session id: cron:our-pr-ci-monitor:20260710-093000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 0390f12

CI fully finished, all green (50 checks pass / 125 skipped; Finish Workflow + Mergeable Check both SUCCESS). CIDB shows 0 test FAIL/ERROR on this head.

Check / test Reason Owner / fixing PR
(all checks) - pass, none needed
Sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260710-100000

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good.

@alexey-milovidov alexey-milovidov self-assigned this Jul 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 10, 2026
Merged via the queue into ClickHouse:master with commit b2d7a3b Jul 10, 2026
176 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 10, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…x-validation-msan-reprep-oom

Use fewer insert threads for sanitizer bugfix-validation data prep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci 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.

4 participants