[fix](delta writer) Fix shared delta writer state lifetime#64349
Merged
liaoxin01 merged 2 commits intoJun 12, 2026
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 |
Contributor
Author
|
/review |
Contributor
There was a problem hiding this comment.
Automated review completed for PR #64349.
I did not find a blocking correctness issue in the changed production code. No existing inline review threads were present, and there were no additional user-provided focus points.
Critical checkpoint conclusions:
- Goal and tests: the patch removes the shared DeltaWriterV2's retained RuntimeState pointer, passes cancellation from the current VTabletWriterV2 call, and adds a BE unit test covering the destroyed creator RuntimeState lifetime boundary.
- Scope: the change is small and focused on the DeltaWriterV2/VTabletWriterV2 API boundary plus targeted tests.
- Concurrency and lifecycle: shared writer access remains serialized by DeltaWriterV2Map and DeltaWriterV2 locks; RuntimeState is no longer retained across sink lifetimes; WorkloadGroup is retained by shared_ptr only for MemTableWriter initialization.
- Config, protocol, and compatibility: no new config item, thrift/protocol field, symbol registration, or storage-format compatibility concern was introduced.
- Parallel code paths: the only DeltaWriterV2 write call site was updated; the legacy DeltaWriter path is separate and not affected by the shared-writer RuntimeState lifetime issue.
- Error handling and data correctness: Status propagation remains checked; the change does not alter transaction visibility, rowset versioning, delete bitmap handling, or persistence.
- Test coverage: the added BE unit test exercises the reported use-after-free path; PR metadata reports the targeted BE UTs. Compile and Linux BE UT checks are passing. The macOS BE UT failure is environmental before tests run (JDK 25 vs required JDK 17). The coverage TeamCity log requires authentication, so I could not inspect that failure from this runner.
- Observability and performance: no new observability appears necessary; the added cancellation callback is limited to the flush-limit wait path.
No inline comments submitted.
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 12, 2026
### 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*` 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 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: - one `VTabletWriterV2` creates the shared `DeltaWriterV2`; - the creator writer and its `RuntimeState` are destroyed without cancelling the shared writer; - a second writer reuses the shared writer and is forced into the `DeltaWriterV2::write()` flush-limit wait path; - the old code reads the destroyed creator state, while the fixed code observes the current writer's cancel state and exits cleanly. The fix removes the stored `RuntimeState*` from `DeltaWriterV2`. The shared writer now keeps only the stable `WorkloadGroup` shared pointer needed by `MemTableWriter` initialization, and `VTabletWriterV2` passes a per-call cancel checker into `DeltaWriterV2::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.
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.