Skip to content

[BugFix] Retain lake vacuum files by version interval across tablet reshard#76209

Merged
xiangguangyxg merged 1 commit into
StarRocks:mainfrom
xiangguangyxg:fix-lake-vacuum-tolerate-missing-retain-version
Jul 15, 2026
Merged

[BugFix] Retain lake vacuum files by version interval across tablet reshard#76209
xiangguangyxg merged 1 commit into
StarRocks:mainfrom
xiangguangyxg:fix-lake-vacuum-tolerate-missing-retain-version

Conversation

@xiangguangyxg

@xiangguangyxg xiangguangyxg commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

Shared-data range-distribution tables support tablet split/merge. When a cluster snapshot pins a
pre-reshard version V and the partition is then split/merged, the FE vacuum daemon enumerates the
partition's current (post-reshard child) tablets and ships the retained-version set (including V)
to the BE. A child tablet's earliest metadata is the reshard publish version (> V), so it has no
{child}_{V}.meta.

TabletRetainInfo::init read {tablet}_{V}.meta for every retained version to build its protect set.
For a child, V returns NotFound, so init failed. vacuum_tablet_metadata calls init under
RETURN_IF_ERROR before any deletion, so the whole partition's vacuum RPC failed every cycle,
lastSuccVacuumVersion never advanced, and expired metadata / data files / txn logs accumulated for
as long as the snapshot existed — an auto-vacuum stall / storage leak.

Naively skipping the NotFound version is unsafe: the incremental vacuum can delete a pre-reshard
segment that the snapshot still needs (the grace-time clamp that protects automated snapshots does
not hold for a finished manual / external snapshot), and only-suppressing shared file cleanup is
also unsafe because the reshard "identical tablet" path does not mark its inherited files shared,
so they route through the regular deleter.

What I'm doing:

Decide vacuum retention by version interval instead of by reading the pinned version's metadata.

A garbage file must be kept iff it was live at a retained version, i.e. there is a retained version
V with create_version <= V < remove_version, where remove_version is the metadata version that
moved the file into compaction_inputs / orphan_files.

  • TabletRetainInfo now holds only the retained-version set. It reads no per-version metadata, so
    the NotFound failure mode cannot occur by construction. It exposes
    retained_by_version(create_version, remove_version) (data-file liveness) and contains_version(v)
    (tablet-metadata-file retention, unchanged). The old metadata read and the
    contains_file/contains_rowset name/id sets are removed.
  • Segments are retained by their rowset's creation version (RowsetMetadataPB.version, preserved
    through split CopyFrom and compaction).
  • Del files can be transferred by a cloud-native PK compaction onto a higher-versioned output rowset,
    so they carry a new optional DelfileWithRowsetId.version, stamped at creation and retained per
    file (independent of the containing rowset's version).
  • Orphan files carry a new optional FileMetaPB.version, stamped from the source object's own
    version at each orphaning site (dcg versions[i], delvec version_to_file key, sstable generation_version,
    idg entry version; same-txn transient segment orphans are stamped with the metadata version being
    built). An unset/0 version means "unknown → retain conservatively", never a false delete.
  • collect_garbage_files uses retained_by_version(candidate.version(), metadata.version()). Because
    the decision is keyed on version rather than the per-file shared flag, it correctly protects both
    shared and exclusive/identical inherited files.

Note for reviewers: this changes the internal vacuum retain mechanism and adds two backward-compatible
optional fields (FileMetaPB.version and DelfileWithRowsetId.version) to the storage metadata proto.
There is no user-facing SQL / config /
API / metric change, so this is classified as a bug fix (behavior change: No). Range distribution is a
new, new-tables-only feature with no on-disk compatibility burden.

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

@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@github-actions github-actions Bot requested review from luohaha and srlch July 10, 2026 10:23
@github-actions

Copy link
Copy Markdown
Contributor

Module-risk briefing for Codex review

This is review focus, not a finding list. Validate against the diff.

High-confidence risks


Note: my attempt to post this directly via gh pr comment failed (Resource not accessible by integration — the token lacks write scope). Per the skill design, this briefing text is meant to be captured and posted by the CI pipeline, not by me directly, so no action is needed on that front — but flagging it in case you expected the comment to already be live on the PR.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e91e6b31e2

ℹ️ 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".

Comment thread be/src/storage/lake/vacuum.cpp Outdated
@xiangguangyxg xiangguangyxg force-pushed the fix-lake-vacuum-tolerate-missing-retain-version branch 5 times, most recently from 3e064c7 to 299c3f4 Compare July 11, 2026 08:28
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 299c3f4d9c

ℹ️ 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".

Comment thread be/src/storage/lake/meta_file.cpp Outdated

@xiangguangyxg xiangguangyxg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review (version-interval vacuum retention). The redesign is correct: keying retention on each file [create, remove) version interval removes the NotFound failure by construction and protects both shared and identical-tablet inherited files (reshard does not mark the latter shared). Retaining del files by their own version and stamping the orphan sites is thorough, and unset(0)->conservative-retain is the right fail-safe. Dependency: this needs #76208 for sstable.version() to be meaningful (remove_compacted_sst). Land #76208 first or together; if this lands alone, sstable orphans read version 0 -> conservatively retained (safe, just over-retains). Two inline notes below.

Comment thread be/src/storage/lake/meta_file.cpp Outdated
Comment thread be/src/storage/lake/vacuum.cpp
@xiangguangyxg xiangguangyxg requested a review from kevincai July 13, 2026 02:05
kevincai
kevincai previously approved these changes Jul 13, 2026
Comment thread be/src/storage/lake/vacuum.cpp Outdated
@xiangguangyxg xiangguangyxg force-pushed the fix-lake-vacuum-tolerate-missing-retain-version branch from 299c3f4 to a2753bc Compare July 14, 2026 03:40
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: a2753bc576

ℹ️ 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".

@xiangguangyxg xiangguangyxg requested a review from kevincai July 14, 2026 04:28
…eshard

Auto-vacuum stalled and could lose snapshot data on shared-data
range-distribution partitions after a tablet split/merge when a cluster
snapshot pinned a pre-reshard version V:

- TabletRetainInfo::init read {tablet}_{V}.meta for each retained version to
  build its protect set. On a reshard child, a pinned pre-reshard version V
  predates the child's earliest metadata, so the read returned NotFound and
  init failed. vacuum_tablet_metadata runs init before any deletion, so the
  whole partition's vacuum RPC failed every cycle and expired metadata / data
  files / txn logs accumulated for as long as the snapshot existed.
- Skipping the NotFound version, or only suppressing shared-file cleanup, is
  unsafe: the incremental vacuum can delete a pre-reshard file the snapshot
  still needs, and the reshard "identical tablet" path does not mark inherited
  files shared, so a shared-flag-based guard misses them.

Decide retention by version interval instead of by reading the pinned version's
metadata. A garbage file is kept iff it was live at a retained version, i.e.
there is a retained version V with create_version <= V < remove_version, where
remove_version is the metadata version that moved it into compaction_inputs /
orphan_files.

- TabletRetainInfo now holds only the retained-version set (no metadata reads,
  so the NotFound stall cannot occur) and answers
  retained_by_version(create, remove) and contains_version(v).
- collect_garbage_files decides each garbage file's creation version:
  - compaction_inputs segments share the rowset's version and are retained by
    rowset.version(). Lake partial-segment compaction can carry older segments
    into a higher-versioned rowset, but it is config-gated (off by default),
    non-PK, and being retired in favor of parallel compaction, so it is
    deliberately not special-cased;
  - del files can be transferred by cloud-native PK compaction onto a
    higher-versioned rowset, so they carry a new optional DelfileWithRowsetId
    .version and are retained per file;
  - orphan files carry a new optional FileMetaPB.version, stamped at each
    orphaning site from the source object's own version.
  An unset/0 version means "unknown -> retain conservatively", never a false
  delete. Keyed on version rather than the per-file shared flag, this protects
  both shared and exclusive/identical inherited files.

No user-facing SQL/config/API/metric change; adds two backward-compatible
optional fields to the storage metadata proto. Range distribution is a new,
new-tables-only feature with no on-disk compatibility burden.

Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
@xiangguangyxg xiangguangyxg force-pushed the fix-lake-vacuum-tolerate-missing-retain-version branch from a2753bc to 0589b36 Compare July 14, 2026 08:48
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 0589b36656

ℹ️ 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".

@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 : 0 / 0 (0%)

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 49 / 60 (81.67%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/storage/lake/txn_log_applier.cpp 5 9 55.56% [238, 644, 645, 649]
🔵 be/src/storage/lake/meta_file.cpp 18 24 75.00% [521, 790, 1416, 1417, 1421, 1422]
🔵 be/src/storage/lake/vacuum.cpp 17 18 94.44% [327]
🔵 be/src/storage/lake/tablet_merger.cpp 1 1 100.00% []
🔵 be/src/storage/lake/tablet_retain_info.cpp 8 8 100.00% []

@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@xiangguangyxg xiangguangyxg merged commit 2b7d675 into StarRocks:main Jul 15, 2026
80 of 82 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.1

@github-actions github-actions Bot removed the 4.1 label Jul 15, 2026
@xiangguangyxg xiangguangyxg deleted the fix-lake-vacuum-tolerate-missing-retain-version branch July 15, 2026 07:48
@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.1

✅ Backports have been created

Details

Cherry-pick of 2b7d675 has failed:

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

You are currently cherry-picking commit 2b7d67548b.
  (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:   be/src/storage/lake/tablet_retain_info.cpp
	modified:   be/src/storage/lake/tablet_retain_info.h
	modified:   gensrc/proto/lake_types.proto

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   be/src/storage/lake/meta_file.cpp
	both modified:   be/src/storage/lake/tablet_merger.cpp
	both modified:   be/src/storage/lake/txn_log_applier.cpp
	both modified:   be/src/storage/lake/vacuum.cpp
	both modified:   be/test/storage/lake/tablet_retain_info_test.cpp
	both modified:   be/test/storage/lake/vacuum_test.cpp

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

xiangguangyxg added a commit that referenced this pull request Jul 15, 2026
…eshard (#76209)

Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
(cherry picked from commit 2b7d675)
xiangguangyxg added a commit that referenced this pull request Jul 15, 2026
…eshard (#76209)

Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
(cherry picked from commit 2b7d675)
wanpengfei-git pushed a commit that referenced this pull request Jul 15, 2026
…eshard (backport #76209) (#76416)

Signed-off-by: xiangguangyxg <xiangguangyxg@gmail.com>
Co-authored-by: xiangguangyxg <xiangguangyxg@gmail.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.

5 participants