[fix](set) fix coredump of set op if total data size exceeds 4G (#61471)#62203
Merged
yiguolei merged 1 commit intoapache:branch-4.1from Apr 8, 2026
Merged
[fix](set) fix coredump of set op if total data size exceeds 4G (#61471)#62203yiguolei merged 1 commit intoapache:branch-4.1from
yiguolei merged 1 commit intoapache:branch-4.1from
Conversation
…he#61471) ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: Root Cause Analysis 核心原因:SetSinkOperatorX::sink() 中 build_block 被多次覆盖,导致哈希表中的旧条目成为悬空引用。 问题链路 1. build_block 被覆盖 在 set_sink_operator.cpp:52-56: if (eos || local_state._mutable_block.allocated_bytes() >= BUILD_BLOCK_MAX_SIZE) { // 4GB build_block = local_state._mutable_block.to_block(); // 覆盖 build_block! RETURN_IF_ERROR(_process_build_block(local_state, build_block, state)); local_state._mutable_block.clear(); } 当数据总量超过 BUILD_BLOCK_MAX_SIZE(4GB)时,这个 flush 会触发多次: - 第一次 flush(allocated_bytes >= 4GB时):build_block = batch1(假设包含 rows 0..N1),哈希表存入 row_num = 0, 1, ..., N1 - 第二次 flush(eos 时):build_block = batch2(新数据,rows 0..N2),batch1 的数据被销毁。哈希表新增 row_num = 0, 1, ..., N2 2. 哈希表只存 row_num,不存 block 引用 RowRefListWithFlags 继承自 RowRef,只存储 uint32_t row_num(join_op.h:46),没有 block 指针或 offset。 在 hash_table_set_build.h:39,构建时存入的是:Mapped {k},即行号 k。 3. 输出阶段使用单一 build_block 在 set_source_operator.cpp:161-162: auto& column = *build_block.get_by_position(idx->second).column; local_state._mutable_cols[idx->first]->insert_from(column, it->row_num); 此时 build_block 是最后一次 flush 的 batch2。但哈希表中来自 batch1 的条目的 row_num 可能超出 batch2 的行数范围。 4. 越界访问导致 SIGSEGV 当 batch1 的 row_num = X(X > batch2 的行数)被用于 insert_from(column, X) 时: // column_string.h:180-197 const size_t size_to_append = src.offsets[X] - src.offsets[X - 1]; // 越界读取 → 垃圾值 const size_t offset = src.offsets[X - 1]; // 垃圾值 // ... memcpy(..., &src.chars[offset], size_to_append); // 垃圾 offset → 访问未映射内存 → SIGSEGV ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
yiguolei
approved these changes
Apr 8, 2026
Contributor
|
skip buildall |
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
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.
What problem does this PR solve?
Issue Number: pick #61471
Problem Summary:
Root Cause Analysis
核心原因:SetSinkOperatorX::sink() 中 build_block
被多次覆盖,导致哈希表中的旧条目成为悬空引用。
问题链路
在 set_sink_operator.cpp:52-56:
if (eos || local_state._mutable_block.allocated_bytes() >= BUILD_BLOCK_MAX_SIZE) { // 4GB
build_block = local_state._mutable_block.to_block(); // 覆盖 build_block! RETURN_IF_ERROR(_process_build_block(local_state, build_block, state));
local_state._mutable_block.clear();
}
当数据总量超过 BUILD_BLOCK_MAX_SIZE(4GB)时,这个 flush 会触发多次:
RowRefListWithFlags 继承自 RowRef,只存储 uint32_t row_num(join_op.h:46),没有 block
指针或 offset。
在 hash_table_set_build.h:39,构建时存入的是:Mapped {k},即行号 k。
在 set_source_operator.cpp:161-162:
auto& column = *build_block.get_by_position(idx->second).column;
local_state._mutable_cols[idx->first]->insert_from(column, it->row_num);
此时 build_block 是最后一次 flush 的 batch2。但哈希表中来自 batch1 的条目的 row_num
可能超出 batch2 的行数范围。
当 batch1 的 row_num = X(X > batch2 的行数)被用于 insert_from(column, X) 时:
// column_string.h:180-197
const size_t size_to_append = src.offsets[X] - src.offsets[X - 1]; // 越界读取 → 垃圾值
const size_t offset = src.offsets[X - 1]; // 垃圾值
// ...
memcpy(..., &src.chars[offset], size_to_append); // 垃圾 offset → 访问未映射内存 →
SIGSEGV
Release note
None
Check List (For Author)
Test
This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason
Behavior changed:
Does this need documentation?
Yes.
Check List (For Reviewer who merge this PR)
What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)