Skip to content

Skip the Keeper RemoveRecursive preprocessing timing check under sanitizers - #121331

Merged
antonio2368 merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/keeper-remove-recursive-guard-thread-cpu-time
Sep 29, 2026
Merged

antonio2368 merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/keeper-remove-recursive-guard-thread-cpu-time

Conversation

@groeneai

@groeneai groeneai commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

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

Related: #117778. Failing runs: Unit tests (tsan), 1a80fe54b903, Unit tests (tsan), 5ba372289ba9.

TestRemoveRecursivePreprocessWithUncommittedBacklog/Mem is #117778's regression guard: preprocessing a RemoveRecursive batch must not scale with unrelated uncommitted nodes, checked as backlog_us <= max(base_us * 10, 20000). It went red twice in Unit tests (tsan), at 108883 us and 77802 us, each time with a normal ~850 us baseline and a normal /LSMT arm in the same process: one ~1 ms sample stalled, the product code did not regress. CIDB, 30 days, this case: 2 failures in 10375 tsan runs, 0 in 29096 asan_ubsan, msan and coverage runs.

As suggested in review, the bound is now checked only in builds without ASan, TSan or MSan. The measurement, its printed trend line and the functional assertions still run everywhere.

The bound keeps running in Unit tests (amd_llvm_coverage), the unit-test job built without a sanitizer, on PRs and master: there /Mem measures 121-139 us without backlog and 221-264 us with it, against the 20 ms floor. Release-branch CI has only sanitizer unit-test jobs, so the bound no longer runs there.

Validation, Debug build without a sanitizer: with the pre-#117778 storage code restored (0ddbd00d4daaa and 4f8f8f5d79f8 reverse-applied to KeeperMemNodesStorage only) the test fails at 318624 us against a 142 us baseline. With the fix, 10 repeated runs are green and Storage/CoordinationTest.* passes 164/164. Preprocessing the test with -fsanitize=thread, address or memory drops the assertion; without a sanitizer, and with the coverage flags, it stays.


Workflow [PR]
Sync PR [sync-upstream/pr/121331]

Version info

  • Merged into: 26.10.1.964-master (included in 26.10 and later)

…caling guard

Storage/CoordinationTest.TestRemoveRecursivePreprocessWithUncommittedBacklog/Mem
failed once in Unit tests (tsan) at 108883 us against its
max(base_us * 10, 20000) allowance, the first failure since the guard landed in
ClickHouse#117778 seventeen days earlier.

The product code is not at fault. Seven sibling Unit tests (tsan) runs that
morning measured 813-944 us to 1046-1232 us, a ratio of 1.17x to 1.53x, and the
/LSMT arm inside the failing process itself measured 1.2x while its neighbouring
tests took the same milliseconds as in a passing run: one sample moved and
nothing else did. The by-parent index added by ClickHouse#117778 still covers the
exercised path, and nothing reachable from preprocessRequest here is linear in
the uncommitted set. The observed rate is one failure in 27022 rows over 30 days.

The assertion bounds the wall time the host granted a single unrepeated ~1 ms
window, while the property it guards is the work the algorithm performs. A stall
the algorithm did not cause, such as thread preemption on a loaded runner, a
ThreadSanitizer stop-the-world shadow flush or kernel reclaim, adds its full
duration to a wall-clock sample and can never subtract from it, so roughly
107 ms of stall crossed the 20 ms floor.

Constructing the two Stopwatch objects with CLOCK_THREAD_CPUTIME_ID makes the
guard bound the quantity it actually claims. The allowance, the EXPECT_LE
message, the subtree sets, the 100000-node backlog and every functional
assertion are unchanged. Raising the threshold was rejected: surviving a 107 ms
stall would need a floor above 110 ms, and this batch cost hundreds of
milliseconds before ClickHouse#117778, so such a floor would leave the guard almost no
detection margin.

Validated in a Debug build. Reverse-applying 0ddbd00 and 4f8f8f5 on
KeeperMemNodesStorage only makes the fixed test fail at 323253 us of CPU time,
16x over the floor, so the guard still catches the regression it exists for. A
150 ms sleep_for injected into the measured window fails on wall clock
(150451 us) and passes on the new clock (587 us), while a 150 ms CPU spin fails
on both, so the new clock filters the observed failure class without going
blind. Fifty consecutive runs are 100/100 green with backlog samples of
233-840 us, against 236-495 us on wall clock before the change, and the maximum
base_us of 565 us keeps base_us * 10 below the 20 ms floor, so the effective
bound is unchanged.

Related: ClickHouse#117778

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding;
bounded: 1 full pass + 1 fix round + 1 delta recheck), plus my own cold review of the same tree.

# Sev Finding Verdict Evidence / action
1 💡 Relationship links should be standalone full URLs, and the PR whose CI run failed is not linked DISAGREE The template's relationship block is kept verbatim with one full-URL line, Related: https://github.com/ClickHouse/ClickHouse/pull/117778; the visible Related: #117778 is the rendered duplicate of it. I deliberately do not link the PR whose job failed: its diff is 62 unrelated files and linking it would only backlink an unrelated author, so I cite the CI report URL instead
2 💡 The flakiness rate was stated over an unnamed population AGREE, fixed before publication Now the conservative figure for the exact failing case: 1 failure in 7140 Unit tests (tsan) runs over 30 days, 0 in 19931 asan/msan/coverage runs
3 💡 "50 runs are 100/100 green" leaned on the reader knowing the test is parameterized AGREE, fixed before publication Reworded to "50 runs are green (100/100 cases)"

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Noted, not blocking, and not raised as work: reading cleanupUncommittedState
(src/Coordination/KeeperMemNodesStorage.cpp:523-537), the per-node applied_zxids
(KeeperMemNodesStorage.h:160) is a vector erased linearly per committed transaction, so
committing N pending transactions that all touch one node is quadratic in N. That shape is why this
test spends most of its time in its final commit loop rather than in the preprocessing it measures.
I have not profiled it and claim no user-facing consequence.

Session id: cron:clickhouse-review-slot-11:20260921-105200

@clickhouse-gh clickhouse-gh Bot closed this Sep 21, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 21, 2026
@groeneai
groeneai requested a review from davenger September 21, 2026 11:29
@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [162c374]

Summary: ✅


AI Review

Summary

This PR makes TestRemoveRecursivePreprocessWithUncommittedBacklog skip its timing bound in sanitizer builds to avoid the observed Unit tests (tsan) flake. The CI-only scope and changelog metadata are appropriate, but the new preprocessor guard is broader than the evidence in the PR description and drops ASan/MSan coverage on workflows that do not have the unsanitized Unit tests (amd_llvm_coverage) job.

Findings

⚠️ Majors

  • [src/Coordination/tests/gtest_coordination_storage.cpp:752] The PR description says the false positives were specific to Unit tests (tsan) and reports 0 failures in asan_ubsan / msan / coverage runs, but this #if disables the regression bound for ADDRESS_SANITIZER and MEMORY_SANITIZER too. On release and backport workflows that means the only remaining Keeper regression guard disappears from Unit tests (asan_ubsan) and Unit tests (msan) even though those jobs were stable. Narrow the exclusion to THREAD_SANITIZER, or include concrete ASan/MSan flakes if those builds also need to skip the bound.
Final Verdict

⚠️ Needs changes before merge: keep the timing guard on the ASan/MSan unit-test jobs, or justify disabling those builds with data comparable to the TSan evidence.

LLVM Coverage Report

Measured on commit 162c374.

Metric Baseline Current Δ
Lines 87.90% 87.90% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 79.30% 79.30% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +202 lines in 56 files (-82 lines lost coverage) · Details

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c8ff3ef

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra: the job raised RuntimeError: CI logs cluster query failed at build_profile_diff_job.py:234, so nothing was compiled or compared #121048 (external, merged 16:14Z today). Rule 3c: the run started 14:38Z, so the fix is absent from the tree that ran
PR praktika rollup of the row above, not an independent failure #121048 (external, merged)

Unit tests (tsan) passed, which is the end-to-end check for this change: it carries
CoordinationTest.TestRemoveRecursivePreprocessWithUncommittedBacklog, the guard this PR
re-instruments with CLOCK_THREAD_CPUTIME_ID. Style check, Fast test, Finish Workflow and
CH Inc sync are green, and Mergeable Check is green, so the single red does not gate merge.
The master merge that would pick up #121048 is deferred on that measured ground rather than
spending a full CI cycle on a reporting job that compiles nothing.

Session id: cron:our-pr-ci-monitor:20260921-173143

@clickhouse-gh clickhouse-gh Bot added the comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... label Sep 22, 2026
@antonio2368 antonio2368 self-assigned this Sep 28, 2026
@antonio2368

Copy link
Copy Markdown
Member

@groeneai should such timing based checks be rather excluded for sanitizer builds?

As suggested in review, exclude the timing assertion of
TestRemoveRecursivePreprocessWithUncommittedBacklog from ASan, TSan and MSan
builds instead of switching its clock, and restore the wall clock.

Both failures of the bound so far were one-off stalls of about 80-110 ms in
Unit tests (tsan), with a normal baseline and the /LSMT arm of the same process
unaffected. A thread CPU clock removes host preemption, but still counts any
sanitizer runtime work done on the measured thread.

The bound keeps running in Unit tests (amd_llvm_coverage), the unit-test job
built without a sanitizer, on PRs and master. There /Mem measures 121-139 us
without backlog and 221-264 us with it, against the 20 ms floor. With the
pre-ClickHouse#117778 storage code restored (0ddbd00 and 4f8f8f5
reverse-applied to KeeperMemNodesStorage only) the test still fails in a
non-sanitizer Debug build, at 318624 us against a 142 us baseline. The rest of
the test, including its functional assertions, still runs under sanitizers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Measure thread CPU time in the Keeper RemoveRecursive preprocessing scaling guard Skip the Keeper RemoveRecursive preprocessing timing check under sanitizers Sep 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes. Done in 162c374: the bound is now checked only in builds without ASan, TSan or MSan (the rest of the test still runs under them), and I restored the wall clock, so the PR diff is just the #if plus one comment line.

The bound keeps running in Unit tests (amd_llvm_coverage), the only unit-test job built without a sanitizer, on PRs and master. There /Mem measures 121-139 us without backlog and 221-264 us with it against the 20 ms floor, and with the pre-#117778 storage code restored the test still fails in a local non-sanitizer build (318624 us). The one place it stops running is release and backport branch CI, which only has sanitizer unit-test jobs.

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 162c374cd with master a25168fe6 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@antonio2368
antonio2368 added this pull request to the merge queue Sep 29, 2026
Merged via the queue into ClickHouse:master with commit 9ed8ee6 Sep 29, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 29, 2026
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 comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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