Skip to content

Commit

Permalink
add gc
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Aug 13, 2024
1 parent 650b0c3 commit 1d399d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions cluster/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,31 @@ func (c *HTTPClient) fetchFileWithBuf(
return
}

func (c *HTTPClient) Gc(
ctx context.Context,
manager *storage.Manager,
files map[string]*StorageFileInfo,
) error {
errs := make([]error, len(manager.Storages))
var wg sync.WaitGroup
for i, s := range manager.Storages {
wg.Add(1)
go func(i int, s storage.Storage) {
defer wg.Done()
errs[i] = s.WalkDir(func(hash string, size int64) error {
info, ok := files[hash]
ok = ok && slices.Contains(info.Storages, s)
if !ok {
s.Remove(hash)
}
return nil
})
}(i, s)
}
wg.Wait()
return errors.Join(errs...)
}

func getHashMethod(l int) (hashMethod crypto.Hash, err error) {
switch l {
case 32:
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ func (r *Runner) InitSynchronizer(ctx context.Context) {
}
go r.UpdateFileRecords(fileMap, nil)

// if !r.Config.Advanced.NoGC {
// go r.cluster.Gc()
// }
if !r.Config.Advanced.NoGC {
go r.client.Gc(context.TODO(), r.storageManager, fileMap)
}
}
// else if fl != nil {
// if err := r.cluster.SetFilesetByExists(ctx, fl); err != nil {
Expand Down

0 comments on commit 1d399d9

Please sign in to comment.