Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/gc: fix delete slice #5451

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions cmd/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
osync "github.com/juicedata/juicefs/pkg/sync"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/vfs"
"github.com/pkg/errors"

"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -122,27 +123,13 @@ func gc(ctx *cli.Context) error {

var wg sync.WaitGroup
var delSpin *utils.Bar
var sliceChan chan meta.Slice // pending delete slices

if delete || compact {
delSpin = progress.AddCountSpinner("Cleaned pending slices")
sliceChan = make(chan meta.Slice, 10240)
m.OnMsg(meta.DeleteSlice, func(args ...interface{}) error {
delSpin.Increment()
sliceChan <- meta.Slice{Id: args[0].(uint64), Size: args[1].(uint32)}
return nil
return store.Remove(args[0].(uint64), int(args[1].(uint32)))
})
for i := 0; i < threads; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for s := range sliceChan {
if err := store.Remove(s.Id, int(s.Size)); err != nil {
logger.Warnf("remove %d_%d: %s", s.Id, s.Size, err)
}
}
}()
}
}

c := meta.WrapContext(ctx.Context)
Expand Down Expand Up @@ -367,11 +354,8 @@ func gc(ctx *cli.Context) error {
}
}
m.OnMsg(meta.DeleteSlice, func(args ...interface{}) error {
return nil
return errors.New("stop deleting slice")
})
if sliceChan != nil {
close(sliceChan)
}
close(leakedObj)
wg.Wait()
if delete || compact {
Expand Down
Loading