Skip to content

[BugFix] fix mem leak when caching mv plan context#72300

Merged
satanson merged 2 commits into
StarRocks:mainfrom
kaijianding:pending_cache_leak
Apr 30, 2026
Merged

[BugFix] fix mem leak when caching mv plan context#72300
satanson merged 2 commits into
StarRocks:mainfrom
kaijianding:pending_cache_leak

Conversation

@kaijianding

@kaijianding kaijianding commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

There are lots of LakeTablet object on FOLLOWER after frequently drop&create same materialized view.
And objects can't be releazed after fe transfers to LEADER.

 num     #instances         #bytes  class name (module)
-------------------------------------------------------
   1:      24469095     1080226352  [B (java.base@17.0.2)
   2:      13197226     1055778080  com.starrocks.lake.LakeTablet

What I'm doing:

Removed dropped materialized view object from pending cache and double check materialized view still exists before be added to context cache.

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5
    • 3.4

@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@github-actions github-actions Bot requested a review from HangyuanLiu April 28, 2026 15:38
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Signed-off-by: kaijian.ding <kaijian.ding@gmail.com>
@kevincai kevincai requested review from Copilot and kevincai April 29, 2026 03:25
kevincai
kevincai previously approved these changes Apr 29, 2026
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a FE-side memory leak where dropped materialized views could remain referenced via the MV plan-context pending cache during replay/startup, causing stale/heavy MV objects to be retained and potentially loaded into the context cache later.

Changes:

  • Remove evicted/dropped MVs from MV_PLAN_CACHE_PENDING during evictMaterializedViewCache().
  • When triggering pending loads, re-fetch MV metadata from LocalMetastore and skip loading if the MV no longer exists.
  • Add regression tests covering pending-cache eviction and replay “pending load after drop” scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/CachingMvPlanContextBuilder.java Ensures dropped MVs don’t linger in pending cache; avoids loading stale pending entries by re-validating against metastore.
fe/fe-core/src/test/java/com/starrocks/planner/MaterializedViewTextBasedRewriteTest.java Adds regression tests to prevent reintroducing pending-cache retention and stale-load issues.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Signed-off-by: kaijian.ding <kaijian.ding@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[FE Incremental Coverage Report]

pass : 9 / 9 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/CachingMvPlanContextBuilder.java 9 9 100.00% []

@github-actions

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@satanson satanson enabled auto-merge (squash) April 30, 2026 03:37
@satanson satanson merged commit 33ccc4a into StarRocks:main Apr 30, 2026
70 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.1

@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-3.5

@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.0

@mergify

mergify Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.1

✅ Backports have been created

Details

@mergify

mergify Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

backport branch-3.5

✅ Backports have been created

Details

Cherry-pick of 33ccc4a has failed:

On branch mergify/bp/branch-3.5/pr-72300
Your branch is up to date with 'origin/branch-3.5'.

You are currently cherry-picking commit 33ccc4ae03.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   fe/fe-core/src/main/java/com/starrocks/sql/optimizer/CachingMvPlanContextBuilder.java

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   fe/fe-core/src/test/java/com/starrocks/planner/MaterializedViewTextBasedRewriteTest.java

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify

mergify Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.0

✅ Backports have been created

Details

Cherry-pick of 33ccc4a has failed:

On branch mergify/bp/branch-4.0/pr-72300
Your branch is up to date with 'origin/branch-4.0'.

You are currently cherry-picking commit 33ccc4ae03.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   fe/fe-core/src/main/java/com/starrocks/sql/optimizer/CachingMvPlanContextBuilder.java

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   fe/fe-core/src/test/java/com/starrocks/planner/MaterializedViewTextBasedRewriteTest.java

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

robd003 pushed a commit to robd003/starrocks that referenced this pull request May 6, 2026
Signed-off-by: kaijian.ding <kaijian.ding@gmail.com>
@kaijianding kaijianding deleted the pending_cache_leak branch May 6, 2026 11:34
xiangguangyxg pushed a commit to xiangguangyxg/starrocks that referenced this pull request May 7, 2026
Signed-off-by: kaijian.ding <kaijian.ding@gmail.com>
Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
wanpengfei-git pushed a commit that referenced this pull request May 8, 2026
…72388)

Signed-off-by: kaijian.ding <kaijian.ding@gmail.com>
Co-authored-by: kaijianding <kaijian.ding@gmail.com>
wanpengfei-git pushed a commit that referenced this pull request May 8, 2026
…72390)

Co-authored-by: kaijianding <kaijian.ding@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kevincai <771299+kevincai@users.noreply.github.com>
wanpengfei-git pushed a commit that referenced this pull request May 9, 2026
…72389)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Co-authored-by: kaijianding <kaijian.ding@gmail.com>
Co-authored-by: Kevin Cai <kevin.cai@celerdata.com>
wanpengfei-git pushed a commit that referenced this pull request May 12, 2026
…(backport #72389) (#73091)

Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: kaijianding <kaijian.ding@gmail.com>
Co-authored-by: Kevin Cai <kevin.cai@celerdata.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants