Repository navigation
Keep a live posting list builder in the text index token map when its construction throws - #122699
Conversation
… construction throws `MergeTreeIndexTextGranuleBuilder::addToken` inserts the token into the `HashMap` first and only then placement-news the `PostingListBuilder` into the mapped slot, which `HashMapCell` leaves unconstructed. With `support_phrase_search = 1` the builder starts in the `Large` state, whose constructor allocates. When that allocation throws (`MEMORY_LIMIT_EXCEEDED` from a memory limit or from `memory_tracker_fault_probability`), the builder's lifetime ends inside a cell the map still owns, and `HashTable::destroyElements` destroys it a second time when the exception destroys the index aggregator. MemorySanitizer (use-after-dtor) reports that as `use-of-uninitialized-value` in `~variant`, which aborted a `Stress test (amd_msan)` run; other builds destroy a valueless variant. If the construction throws, construct a `Filtered` builder in the same cell before rethrowing. It holds no postings, is constructed without allocating, is trivially destroyed and is skipped by `build`, and no caller reuses the builder after `update` throws. The test injects allocation faults into INSERTs that build such an index. Without the fix it aborts an MSan build in every run. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120319&sha=256c2d13b6eb62d207bdf619104186595f5b3366&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With more than one thread the pipeline executor schedules its threads on a local pool when the INSERT starts, and an injected fault inside `ThreadPoolImpl::scheduleImpl` is reported as `CANNOT_SCHEDULE_TASK`, not `MEMORY_LIMIT_EXCEEDED`, which fails the statement's error hint under a randomized `max_threads`. The index build runs in the sink's thread either way, so the reproduction is unchanged. Measured on a debug build with 500 such INSERTs per arm, every one failed with `MEMORY_LIMIT_EXCEEDED` at `max_threads = 3` as at `max_threads = 1`, with and without `async_insert`, so the scheduling fault is rare (0 of 1000 multi-threaded INSERTs) and the pin removes its code path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review in two rounds by an independent model (engine: codex; 2 findings, then 0 on the fix round) plus my own review (4 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20260928-143900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260928-113059 |
|
Workflow [PR], commit [b76e3f9] Summary: ✅
AI ReviewSummaryThis PR fixes the failure path when a phrase-search text index allocates its first Final Verdict
LLVM Coverage ReportMeasured on commit b76e3f9.
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 18 s compile time in total, 7 of them have a recent master baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A failed allocation while building a text index with
support_phrase_search = 1no longer leaves a destroyed posting list builder in the token map.Description
Related: #113856
Stress test (amd_msan)aborted withMemorySanitizer: use-of-uninitialized-value(STID 1003-358c) in~PostingListBuilder, called fromHashTable::destroyElementswhile an INSERT that failed withMEMORY_LIMIT_EXCEEDEDwas unwinding (report, on an unrelated PR).MergeTreeIndexTextGranuleBuilder::addTokeninserts the token into the map first and then placement-news the builder into the cell. Withsupport_phrase_search = 1the builder starts in theLargestate, whose constructor allocates. When that allocation throws, the builder's lifetime ends inside a cell the map still owns, and the map destroys it a second time when the index aggregator is destroyed. MemorySanitizer reports that second destruction; other builds silently destroy a valueless variant.constructBuildernow constructs aFilteredbuilder in the cell when the construction throws, then rethrows.Filteredholds no postings, is constructed without allocating, is trivially destroyed and is skipped bybuild. The success path is unchanged: the handler only runs when the construction throws.The new test injects allocation faults into five single-threaded INSERTs of 20000 new tokens into a phrase search text index. On an MSan build it aborts in 20/20 runs without the fix (5/5 with the CI binary) and passes 20/20 with it, with 37 of 50 injected faults landing in the repaired constructor. Other builds only exercise the failure path, since the second destruction has no visible effect there.
Not for changelog: the code is from #113856, which is not in any release, and needs the experimentalallow_experimental_text_index_phrase_search.Workflow [PR]
Sync PR [sync-upstream/pr/122699]
Version info
26.10.1.948-master(included in26.10and later)