Skip to content

Commit 1d399d9

Browse files
committed
add gc
1 parent 650b0c3 commit 1d399d9

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

cluster/storage.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,31 @@ func (c *HTTPClient) fetchFileWithBuf(
702702
return
703703
}
704704

705+
func (c *HTTPClient) Gc(
706+
ctx context.Context,
707+
manager *storage.Manager,
708+
files map[string]*StorageFileInfo,
709+
) error {
710+
errs := make([]error, len(manager.Storages))
711+
var wg sync.WaitGroup
712+
for i, s := range manager.Storages {
713+
wg.Add(1)
714+
go func(i int, s storage.Storage) {
715+
defer wg.Done()
716+
errs[i] = s.WalkDir(func(hash string, size int64) error {
717+
info, ok := files[hash]
718+
ok = ok && slices.Contains(info.Storages, s)
719+
if !ok {
720+
s.Remove(hash)
721+
}
722+
return nil
723+
})
724+
}(i, s)
725+
}
726+
wg.Wait()
727+
return errors.Join(errs...)
728+
}
729+
705730
func getHashMethod(l int) (hashMethod crypto.Hash, err error) {
706731
switch l {
707732
case 32:

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ func (r *Runner) InitSynchronizer(ctx context.Context) {
543543
}
544544
go r.UpdateFileRecords(fileMap, nil)
545545

546-
// if !r.Config.Advanced.NoGC {
547-
// go r.cluster.Gc()
548-
// }
546+
if !r.Config.Advanced.NoGC {
547+
go r.client.Gc(context.TODO(), r.storageManager, fileMap)
548+
}
549549
}
550550
// else if fl != nil {
551551
// if err := r.cluster.SetFilesetByExists(ctx, fl); err != nil {

0 commit comments

Comments
 (0)