Skip to content

columnar: gc ia meta & schema files in cloud_helper - #10988

Merged
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
yongman:gc-schema-files
Jul 30, 2026
Merged

columnar: gc ia meta & schema files in cloud_helper#10988
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
yongman:gc-schema-files

Conversation

@yongman

@yongman yongman commented Jul 17, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #10995
ref https://github.com/tidbcloud/cloud-storage-engine/issues/5686
close https://github.com/tidbcloud/cloud-storage-engine/issues/5716

Problem Summary:
The disk or memory can be keep increasing in the long run with no background gc.

What is changed and how it works?


  1. Add gc for ia_meta files in disk. (In TiKV there has a background gc task to scan the local meta files and do the gc)
  2. Add gc for schema_files map in memory.
  3. Decrease the ia mem_cap default value from 20% to 10%.
  4. Update kvengine to latest cloud-storage-engine commit b49d94ae594914225390e3914f92025f1486d95b to fix the columnar file decryption with re-mapped file id during packed restoration.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Summary by CodeRabbit

  • New Features
    • Added a configuration option to cap cached schema keyspaces.
    • Added an optional background cleanup loop to evict stale schema files and perform IA metadata GC.
  • Bug Fixes
    • Improved schema cache eviction by updating keyspace recency on snapshot access.
    • Refined shutdown coordination so the heartbeat and background cleanup stop reliably.
  • Tests
    • Extended coverage for stale-version pruning, recency updates, and GC eviction (with and without keyspace limits), plus adjusted default assertions.
  • Chores
    • Updated the cloud storage engine submodule and refreshed dependency pinning/config defaults.

Signed-off-by: yongman <yming0221@gmail.com>
@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Schema-file cache recency tracking and global eviction are added to CloudHelper. Runtime configuration now controls IA metadata and schema cache GC, with a background thread, coordinated shutdown, updated defaults, and pinned dependency wiring.

Changes

Runtime garbage collection

Layer / File(s) Summary
Schema cache tracking and eviction
contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs
Adds shared per-keyspace cache state, recency updates, stale-version pruning, configurable keyspace eviction, and unit tests.
Snapshot access recency integration
contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs
Propagates shared cache state through snapshot loading and touches the active keyspace after snapshot creation or reuse.
Configurable background GC lifecycle
contrib/tiflash-columnar-hub/hub-runtime/src/run.rs
Adds GC configuration, starts periodic IA metadata and schema cache cleanup, coordinates shutdown, and joins the background thread.
Dependency and engine wiring
contrib/tiflash-columnar-hub/Cargo.toml, contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml, contrib/cloud-storage-engine
Pins workspace kvproto resolution and updates the cloud-storage-engine submodule reference.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EngineStoreLifecycle
  participant BackgroundGCLoop
  participant IAMetaFiles
  participant CloudHelper
  EngineStoreLifecycle->>BackgroundGCLoop: start when gc_interval is non-zero
  BackgroundGCLoop->>IAMetaFiles: run IA metadata GC
  BackgroundGCLoop->>CloudHelper: gc_schema_file_cache()
  CloudHelper->>CloudHelper: prune and evict schema-file entries
  EngineStoreLifecycle->>BackgroundGCLoop: set service_shutdown
  BackgroundGCLoop-->>EngineStoreLifecycle: exit and join
Loading

Suggested reviewers: lloyd-pottiger

Poem

I’m a rabbit with cache in my burrow tonight,
Touching keyspaces and pruning bytes light.
IA files hop cleanly, GC loops with care,
Shutdown bells whisper through runtime air.
~( ,_,_,/)
( •ㅅ• )

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.58% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses #10995 by adding background GC for ia_meta files on disk and schema_files in memory.
Out of Scope Changes check ✅ Passed The dependency pinning and submodule bump appear tied to the GC and kvengine fixes, with no clear unrelated changes.
Title check ✅ Passed The title matches the main change: GC for IA meta and schema files in cloud_helper.
Description check ✅ Passed The description covers the problem, changes, testing, side effects, docs, and release note sections.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: yongman <yming0221@gmail.com>
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 21, 2026
Signed-off-by: yongman <yming0221@gmail.com>
@yongman
yongman marked this pull request as ready for review July 21, 2026 06:49
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 21, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs`:
- Around line 1390-1399: Update the cache-state insertion in the
latest_by_keyspace loop to capture the current access_seq and assign it to
last_access_seq for newly discovered keyspaces instead of 0. Keep existing
entries’ latest_version updates unchanged, so freshly loaded keyspaces are
treated as recently accessed during gc_schema_file_cache_global eviction.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9faf5786-67f3-4e03-b576-cc762b795186

📥 Commits

Reviewing files that changed from the base of the PR and between 3d986e3 and f7f5c20.

📒 Files selected for processing (2)
  • contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs
  • contrib/tiflash-columnar-hub/hub-runtime/src/run.rs

Comment thread contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs Outdated
@yongman yongman changed the title columnar: gc schema files in cloud_helper columnar: gc ia meta & schema files in cloud_helper Jul 21, 2026
Signed-off-by: yongman <yming0221@gmail.com>
@yongman

yongman commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

/test pull-integration-test

@yongman

yongman commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

/hold

@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 23, 2026

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
contrib/tiflash-columnar-hub/hub-runtime/src/run.rs (1)

1096-1119: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add an end-to-end GC lifecycle test.

The added test only validates TOML parsing; it does not prove the spawned loop removes expired IA metadata, evicts schema-cache entries, or exits promptly on shutdown. Add a deterministic integration test using a temporary data directory and a short interval.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contrib/tiflash-columnar-hub/hub-runtime/src/run.rs` around lines 1096 -
1119, Add a deterministic end-to-end test for spawn_background_gc_loop using a
temporary data directory and short GC interval. Exercise expired IA metadata
cleanup and schema-cache eviction, then signal shutdown and join the returned
thread, asserting the loop exits promptly and both cleanup effects occur rather
than only validating TOML parsing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@contrib/tiflash-columnar-hub/hub-runtime/src/run.rs`:
- Around line 1096-1119: Add a deterministic end-to-end test for
spawn_background_gc_loop using a temporary data directory and short GC interval.
Exercise expired IA metadata cleanup and schema-cache eviction, then signal
shutdown and join the returned thread, asserting the loop exits promptly and
both cleanup effects occur rather than only validating TOML parsing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 693b2191-cd14-42c7-9df9-92a185f8b26c

📥 Commits

Reviewing files that changed from the base of the PR and between 97f3f53 and d39fe33.

📒 Files selected for processing (2)
  • contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs
  • contrib/tiflash-columnar-hub/hub-runtime/src/run.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs

yongman added 2 commits July 28, 2026 14:40
Signed-off-by: yongman <yming0221@gmail.com>
Signed-off-by: yongman <yming0221@gmail.com>
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 28, 2026
@yongman yongman removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 28, 2026

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
contrib/tiflash-columnar-hub/hub-runtime/src/run.rs (1)

1707-1707: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the stale Linux ia.mem_cap assertion.

ConfigFile::default() now sets config.ia.mem_cap to Percent(10.0), but Line 1693 still expects Percent(20.0), so the Linux test will fail.

Proposed fix
-            assert_eq!(config.ia.mem_cap, AbsoluteOrPercentSize::Percent(20.0));
+            assert_eq!(config.ia.mem_cap, AbsoluteOrPercentSize::Percent(10.0));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contrib/tiflash-columnar-hub/hub-runtime/src/run.rs` at line 1707, Update the
Linux test’s stale ia.mem_cap assertion in the ConfigFile::default() validation
to expect AbsoluteOrPercentSize::Percent(10.0), matching the current default;
leave the existing ia_meta_cap assertion unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@contrib/tiflash-columnar-hub/hub-runtime/src/run.rs`:
- Line 1707: Update the Linux test’s stale ia.mem_cap assertion in the
ConfigFile::default() validation to expect AbsoluteOrPercentSize::Percent(10.0),
matching the current default; leave the existing ia_meta_cap assertion
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 359b9a0b-fa7a-48fa-9e22-a6cb64a917bd

📥 Commits

Reviewing files that changed from the base of the PR and between d39fe33 and 6f83a78.

⛔ Files ignored due to path filters (1)
  • contrib/tiflash-columnar-hub/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • contrib/cloud-storage-engine
  • contrib/tiflash-columnar-hub/Cargo.toml
  • contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml
  • contrib/tiflash-columnar-hub/hub-runtime/src/run.rs

Comment thread contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs Outdated
Comment thread contrib/tiflash-columnar-hub/hub-runtime/src/run.rs
Comment thread contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs Outdated
Signed-off-by: yongman <yming0221@gmail.com>

@JaySon-Huang JaySon-Huang 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.

LGTM

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 30, 2026
@yongman
yongman requested a review from JinheLin July 30, 2026 03:26

@windtalker windtalker 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.

lgtm

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 30, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

[LGTM Timeline notifier]

Timeline:

  • 2026-07-30 03:25:05.013900435 +0000 UTC m=+2066491.049995492: ☑️ agreed by JaySon-Huang.
  • 2026-07-30 03:38:20.644356923 +0000 UTC m=+2067286.680451979: ☑️ agreed by windtalker.

@ti-chi-bot

ti-chi-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, JinheLin, windtalker

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,JinheLin,windtalker]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
ti-chi-bot Bot merged commit 4c8fd1e into pingcap:master Jul 30, 2026
11 checks passed
@yongman

yongman commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

/cherry-pick release-nextgen-202603

@ti-chi-bot

Copy link
Copy Markdown
Member

@yongman: new pull request created to branch release-nextgen-202603: #11006.

Details

In response to this:

/cherry-pick release-nextgen-202603

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

ti-chi-bot Bot pushed a commit that referenced this pull request Jul 30, 2026
close #10995\n\nSigned-off-by: yongman <yming0221@gmail.com>\n\nCo-authored-by: yongman <yming0221@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

columnar: lack of gc for ia_meta_files in disk and schema_files in memory

5 participants