[fix](delta writer) Fix shared delta writer state lifetime#64349
Open
bobhan1 wants to merge 2 commits into
Open
[fix](delta writer) Fix shared delta writer state lifetime#64349bobhan1 wants to merge 2 commits into
bobhan1 wants to merge 2 commits into
Conversation
### What problem does this PR solve?
Issue Number: None
Problem Summary: Add a backend unit test that reproduces a shared DeltaWriterV2 lifetime bug. When shared delta writers are enabled, the first local sink can create the shared DeltaWriterV2 and the writer stores that sink's RuntimeState pointer. If that creator sink and its RuntimeState are destroyed while another local sink still reuses the shared writer, DeltaWriterV2::write() can access the destroyed RuntimeState in the flush-limit cancel check path. The test builds two VTabletWriterV2 instances for the same load, destroys the creator state after the shared writer is created, and then forces the second writer into the same wait path. On the unfixed code this deterministically reports an ASAN heap-use-after-free in DeltaWriterV2::write().
### Release note
None
### Check List (For Author)
- Test: Unit Test
- ./run-be-ut.sh --run --filter=TestVTabletWriterV2.shared_delta_writer_should_not_access_destroyed_creator_runtime_state -j 100 (fails as expected before the fix with AddressSanitizer heap-use-after-free in DeltaWriterV2::write())
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?
Issue Number: None
Problem Summary: Shared DeltaWriterV2 instances can be reused by multiple local sinks from the same load. Before this change the shared writer stored the RuntimeState pointer from the sink that first created it. If that creator sink finished and its RuntimeState was destroyed while another local sink continued to reuse the same shared writer, DeltaWriterV2::write() could access the destroyed RuntimeState while checking cancellation in the memtable flush-limit wait path, causing a BE crash or ASAN use-after-free. The fix removes the stored RuntimeState pointer from DeltaWriterV2. The writer now stores only the stable WorkloadGroup shared pointer needed by MemTableWriter initialization, and VTabletWriterV2 passes a per-call cancel checker for the current sink into DeltaWriterV2::write(). This keeps cancellation tied to the active caller and avoids retaining sink-local RuntimeState inside the shared writer.
### Release note
Fix a possible BE crash when shared delta writers are reused by multiple local sinks.
### Check List (For Author)
- Test: Unit Test
- ./run-be-ut.sh --run --filter=TestVTabletWriterV2.shared_delta_writer_should_not_access_destroyed_creator_runtime_state -j 100
- ./run-be-ut.sh --run --filter=DeltaWriterV2PoolTest.* -j 100
- Behavior changed: Yes. Shared DeltaWriterV2 cancellation now uses the current sink's RuntimeState instead of the creator sink's RuntimeState.
- Does this need documentation: No
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
TPC-H: Total hot run time: 29299 ms |
Contributor
TPC-DS: Total hot run time: 169654 ms |
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: None
Problem Summary:
Shared
DeltaWriterV2instances can be reused by multiple local sinks from the same load. Before this change, the shared writer stored theRuntimeState*from the sink that first created it. If that creator sink finished and itsRuntimeStatewas destroyed while another local sink continued to reuse the shared writer,DeltaWriterV2::write()could access the destroyed state in the memtable flush-limit cancellation path, causing a BE crash or ASAN use-after-free.This PR adds a BE unit test that reproduces the lifetime boundary:
VTabletWriterV2creates the sharedDeltaWriterV2;RuntimeStateare destroyed without cancelling the shared writer;DeltaWriterV2::write()flush-limit wait path;The fix removes the stored
RuntimeState*fromDeltaWriterV2. The shared writer now keeps only the stableWorkloadGroupshared pointer needed byMemTableWriterinitialization, andVTabletWriterV2passes a per-call cancel checker intoDeltaWriterV2::write()so cancellation is evaluated against the current sink.Release note
Fix a possible BE crash when shared delta writers are reused by multiple local sinks.
Check List (For Author)
./run-be-ut.sh --run --filter=TestVTabletWriterV2.shared_delta_writer_should_not_access_destroyed_creator_runtime_state -j 100./run-be-ut.sh --run --filter=DeltaWriterV2PoolTest.* -j 100DeltaWriterV2cancellation now uses the current sink's state instead of the creator sink's state.