Repository navigation
Cherry pick #128291 to 26.3: Fix segfault in ReverseIndex::insert after an exception while building the index - #128640
Merged
Conversation
…safe `ReverseIndex::buildIndex` assigned `index` before `saved_hash = calcHashes()`. If the allocation in `calcHashes` threw (in production: `MEMORY_LIMIT_EXCEEDED` on a server over its total memory limit), the object was left with a non-null hash table and a null `saved_hash`. The exception was handled by `StreamingFormatExecutor` (asynchronous insert flush rolls the columns back and continues with the next entry using the same result columns), and the next `insert` into the same `LowCardinality(String)` dictionary dereferenced the null `saved_hash` at `ReverseIndex.h:506`, a segmentation fault at address 0x18. Build the hash table and the saved hashes into locals and publish them only at the end. Also drop the index when an exception escapes `insert`, because the hash table may then reference a row that `insertData` failed to add; it is rebuilt from the column on the next use. Add a `ONCE` failpoint inside `buildIndex` and a unit test that reproduces the scenario: the first insert fails, the dictionary is reused, later inserts must work. A stateless test is not possible here because the row input format builds a fresh dictionary per chunk and consumes a one-shot failpoint before the result column does. Incident: ClickHouse/clickhouse-core-incidents#1422 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…appending them `ColumnString::insertData` appends to `chars` before growing `offsets`. If the latter throws, the bytes of the row that was never added stay in `chars`, and after the index is rebuilt they become a prefix of the next inserted value. Trim `chars` back to the last offset in the recovery path. Add a unit test that fails the `offsets` growth through the memory tracker, reuses the dictionary and checks the stored values and lookups. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ception-safety Fix segfault in `ReverseIndex::insert` after an exception while building the index
Resolve conflicts:
- `src/Common/FailPoint.cpp`: keep only the new `reverse_index_build_index_throw`
failpoint; the other failpoints on the master side do not exist in 26.3.
- `src/Columns/ReverseIndex.h`: take the PR's version of `ReverseIndex::insert`
(the release branch only differed by `bool inserted;` without an initializer).
Adapt `gtest_reverse_index_exception_safety.cpp` to 26.3: drop the calls to
`CurrentMemoryTracker::{get,set}MinAllocationSizeBytesToThrow`, which do not exist
there. The test relies on growing `offsets` through `Allocator`, which already
throws `MEMORY_LIMIT_EXCEEDED` in 26.3 regardless of that setting.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Original pull-request #128291
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job