Skip to content

refactor(storage): stream vacuum2 block gc - #20402

Open
dantengsky wants to merge 4 commits into
databendlabs:mainfrom
dantengsky:fix-vacuum2-stream-block-gc
Open

refactor(storage): stream vacuum2 block gc#20402
dantengsky wants to merge 4 commits into
databendlabs:mainfrom
dantengsky:fix-vacuum2-stream-block-gc

Conversation

@dantengsky

@dantengsky dantengsky commented Aug 27, 2026

Copy link
Copy Markdown
Member

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Reduce peak memory usage in fuse_vacuum2 block garbage collection for very large tables.

This PR is a follow-up to the protected-segment chunking change. It avoids materializing all candidate block listing results in memory before deletion while preserving the existing vacuumed result contract.

The main memory reduction is to avoid keeping all listed block Entry values and intermediate block path vectors in memory at once. This matters for very large _b/ directories because each OpenDAL Entry carries both the object path and metadata; the metadata portion is significant and should not be treated as negligible when millions of entries are listed.

This PR intentionally preserves the existing result contract and still returns the complete list of removed files. The remaining memory pressure from retaining all removed file paths for the result set will be addressed in a follow-up PR with an explicit API/behavior design.

Changes:

  • Stream block listing for non-FS object stores and stop at the same vacuum2 timestamp-derived until prefix as before.
  • Filter and remove block chunks while listing, instead of building full Vec<Entry> / candidate block path vectors.
  • Preserve the existing FS behavior by sorting listed entries before applying the until boundary, because FS listing order is not guaranteed.
  • Reuse the existing common fuse vacuum candidate safety helper for block eligibility checks, including conservative legacy-object last_modified handling.
  • Preserve the complete returned vacuumed file list.

Safety notes:

  • The deletion condition remains candidate-before-gc-root AND not referenced by the protected block set.
  • Index files are still removed before their data blocks for each delete chunk.
  • Errors while proving legacy-object eligibility are still propagated instead of ignored by reusing the existing common vacuum logic.

Tests

  • Unit Test
    • cargo test -p databend-enterprise-query vacuum_table_v2 --lib -- --nocapture
  • Logic Test
    • cargo test -p databend-enterprise-query --test it storages::fuse::operations::vacuum2 -- --nocapture
  • Build/Check
    • cargo check -p databend-common-storages-fuse
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

AI assistance

  • AI usage: Assisted with diagnosing the vacuum2 memory path, implementing streaming block GC, reviewing conservative error handling, adding focused tests, and preparing this PR.
  • Responsible human: @dantengsky
  • The responsible human has read every line of this diff and can explain each change

This change is Reviewable

@github-actions github-actions Bot added the pr-bugfix this PR patches a bug in codebase label Aug 27, 2026

@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: f81aa48312

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/ee/src/storages/fuse/operations/vacuum_table_v2.rs Outdated
@dantengsky dantengsky changed the title fix: stream vacuum2 block gc refactor(storage): stream vacuum2 block gc Aug 27, 2026
@github-actions github-actions Bot added the pr-refactor this PR changes the code base without new features or bugfix label Aug 27, 2026
@dantengsky
dantengsky force-pushed the fix-vacuum2-stream-block-gc branch 2 times, most recently from 2c40df1 to 8e9550e Compare August 27, 2026 15:12
@dantengsky

Copy link
Copy Markdown
Member Author

@codex review

@dantengsky dantengsky removed the pr-bugfix this PR patches a bug in codebase label Aug 27, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 8e9550e75b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@dantengsky
dantengsky force-pushed the fix-vacuum2-stream-block-gc branch 4 times, most recently from b50286e to ec8f22b Compare August 28, 2026 04:11
@dantengsky

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ec8f22b3be

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@dantengsky
dantengsky force-pushed the fix-vacuum2-stream-block-gc branch from ec8f22b to 28ec851 Compare August 28, 2026 06:24
@SkyFan2002
SkyFan2002 self-requested a review August 28, 2026 06:42
@dantengsky
dantengsky force-pushed the fix-vacuum2-stream-block-gc branch from 28ec851 to 295b3f1 Compare August 28, 2026 06:55
@dantengsky
dantengsky force-pushed the fix-vacuum2-stream-block-gc branch from 295b3f1 to ed176b4 Compare August 28, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-refactor this PR changes the code base without new features or bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants