Skip to content

branch-4.1: [fix](delta writer) Fix shared delta writer state lifetime - #64504

Merged
yiguolei merged 1 commit into
apache:branch-4.1from
bobhan1:branch-4.1-pick-64349-shared-delta-writer-state
Jun 16, 2026
Merged

branch-4.1: [fix](delta writer) Fix shared delta writer state lifetime#64504
yiguolei merged 1 commit into
apache:branch-4.1from
bobhan1:branch-4.1-pick-64349-shared-delta-writer-state

Conversation

@bobhan1

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Backport #64349 to branch-4.1.

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 removes the stored RuntimeState* from DeltaWriterV2. The shared writer keeps only the stable WorkloadGroup pointer needed by MemTableWriter initialization, and VTabletWriterV2 passes a per-call cancel checker into DeltaWriterV2::write() so cancellation is evaluated against the current sink.

Branch-4.1 adaptation:

  • keep the detailed delta-writer profile gate at the VTabletWriterV2 call site before passing a profile into the shared writer;
  • construct the new BE test schema with branch-local test helpers and protobuf fields.

Check List

  • git diff HEAD^ HEAD --check
  • ./run-be-ut.sh --run --filter=TestVTabletWriterV2.shared_delta_writer_should_not_access_destroyed_creator_runtime_state:DeltaWriterV2PoolTest.* -j100

Release note

Fix a possible BE crash when shared delta writers are reused by multiple local sinks.

)
### 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.
(cherry picked from commit c33e1b3)
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@bobhan1bobhan1 changed the title [branch-4.1][fix](delta writer) Fix shared delta writer state lifetimebranch-4.1: [fix](delta writer) Fix shared delta writer state lifetimeJun 15, 2026
@bobhan1
bobhan1 marked this pull request as ready for review June 15, 2026 06:14
@bobhan1
bobhan1 requested a review from yiguolei as a code ownerJune 15, 2026 06:14
@bobhan1

Copy link
Copy Markdown
ContributorAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 47.83% (11/23) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage53.96% (20417/37839)
Line Coverage37.51% (193685/516407)
Region Coverage33.88% (150939/445451)
Branch Coverage34.86% (66046/189475)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 69.57% (16/23) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.74% (26548/37008)
Line Coverage54.80% (281943/514489)
Region Coverage52.32% (235082/449351)
Branch Coverage53.51% (101648/189962)

@yiguolei
yiguolei merged commit b1fdbb3 into apache:branch-4.1Jun 16, 2026
31 of 35 checks passed
@yiguoleiyiguolei mentioned this pull request Jul 7, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@bobhan1@hello-stephen@yiguolei