Skip to content

cmd/gc: support external sort - #7230

Merged
jiefenghuang merged 24 commits into
mainfrom
extsort-gc
Aug 19, 2026
Merged

cmd/gc: support external sort#7230
jiefenghuang merged 24 commits into
mainfrom
extsort-gc

Conversation

@zxh326

@zxh326 zxh326 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Signed-off-by: Xuhui zhang xuhui@juicedata.io

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.52555% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.89%. Comparing base (801e8df) to head (1198a76).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
pkg/meta/tkv.go 26.66% 17 Missing and 5 partials ⚠️
pkg/meta/redis.go 31.81% 12 Missing and 3 partials ⚠️
pkg/meta/sql.go 30.00% 11 Missing and 3 partials ⚠️
pkg/utils/extsort/sharded.go 72.91% 9 Missing and 4 partials ⚠️
pkg/chunk/cached_store.go 29.41% 11 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7230       +/-   ##
===========================================
+ Coverage   33.58%   54.89%   +21.30%     
===========================================
  Files         137      139        +2     
  Lines       48007    48835      +828     
===========================================
+ Hits        16123    26807    +10684     
+ Misses      30267    19118    -11149     
- Partials     1617     2910     +1293     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zxh326
zxh326 marked this pull request as ready for review July 17, 2026 06:11
@zxh326
zxh326 requested a review from Copilot July 17, 2026 06:11

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

This PR adds an external-sort-based GC mode to juicefs gc to reduce memory usage on large volumes by streaming slice/object records through disk-backed sorters instead of loading all slices into memory. It also extends the metadata engine interface to support streaming slice scans.

Changes:

  • Add --work-dir flag to juicefs gc to enable an external sort pipeline for GC (plus supporting merge/scan helpers and tests).
  • Introduce Meta.ScanSlices (Redis/SQL/TKV implementations) to stream slice records via callback, while keeping ListSlices as a wrapper.
  • Add a small generic external sort wrapper (pkg/utils/extsort) and tests; plus an opt-in env flag to probabilistically skip object deletes.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pkg/utils/extsort/sharded.go New generic wrapper around external sorter with temp-dir lifecycle management.
pkg/utils/extsort/sharded_test.go Unit tests for the new external sorter wrapper.
pkg/meta/interface.go Add ScanSlices streaming API to Meta interface.
pkg/meta/redis.go Implement ScanSlices and make ListSlices a wrapper.
pkg/meta/sql.go Implement ScanSlices and make ListSlices a wrapper.
pkg/meta/tkv.go Implement ScanSlices and make ListSlices a wrapper (with callback error handling).
cmd/gc.go Add --work-dir external-sort GC path and helper functions for scanning/merging records.
cmd/gc_test.go Update GC test fixture layout to match hashed-prefix chunk paths; add external sort coverage.
cmd/gc_external_test.go Add focused tests for external sort merge and chunk object scanning.
pkg/chunk/cached_store.go Add JFS_OBJECT_DELETE_SKIP behavior to optionally skip object deletes.
go.mod / go.sum Add lanrat/extsort dependency with replace to juicedata/extsort.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/gc.go
Comment thread cmd/gc.go
Comment thread cmd/gc.go Outdated
Comment thread pkg/chunk/cached_store.go Outdated
Comment thread pkg/chunk/cached_store.go Outdated
Comment thread cmd/gc_external_test.go Outdated
Comment thread pkg/meta/redis.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go
@jiefenghuang

Copy link
Copy Markdown
Contributor

mark:

  1. 相同代码抽象
  2. gc主函数抽象: 初始化, 预处理(删除/回调注册), 扫描对比(外排或者全内存), 后处理, 输出结果

zxh326 added 20 commits August 12, 2026 18:20
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>

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

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (2)

cmd/gc.go:79

  • This adds a user-facing GC mode, but the existing English and Chinese GC guides (docs/en/administration/status_check_and_maintenance.md and docs/zh_cn/administration/status_check_and_maintenance.md) do not mention the flag, its disk-space requirements, or how to select a work directory. Please document the new mode in both guides.
				Name:  "external-sort-dir",
				Usage: "working directory for external sort temporary files (enables external sort mode)",

pkg/utils/extsort/sharded.go:107

  • The cleanup error is discarded, so repeated GC runs can report success while leaving potentially very large external-sort shards on disk. Return the RemoveAll failure from Done (while preserving any sort error) and propagate both Done results from gcExternalSort.
	_ = os.RemoveAll(s.workDir)

Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
@zxh326
zxh326 requested a review from jiefenghuang August 17, 2026 09:03
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc.go Outdated
Comment thread cmd/gc_external.go
Comment thread pkg/utils/extsort/sharded.go Outdated
Comment thread cmd/gc_external.go
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
@jiefenghuang

Copy link
Copy Markdown
Contributor

TODO:

  1. ScanSlice中不要耦合cleanup, 单独抽出来一个接口.
  2. 新实现接口获取异步删除清理任务是否结束. 开了delflag的话, gc要清理完待删除slice, 并且不影响外排.

Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
@jiefenghuang
jiefenghuang merged commit d178e3d into main Aug 19, 2026
45 of 50 checks passed
@jiefenghuang
jiefenghuang deleted the extsort-gc branch August 19, 2026 09:56
Sign up for free to 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.

4 participants