@@ -37,6 +37,7 @@ import (
3737 "syscall"
3838 "time"
3939
40+ "github.com/charlievieth/fastwalk"
4041 "github.com/davies/groupcache/consistenthash"
4142 "github.com/dustin/go-humanize"
4243 "github.com/google/uuid"
@@ -917,7 +918,8 @@ func (cache *cacheStore) scanCached() {
917918
918919 cachePrefix := filepath .Join (cache .dir , cacheDir )
919920 logger .Debugf ("Scan %s to find cached blocks" , cachePrefix )
920- _ = filepath .WalkDir (cachePrefix , func (path string , d fs.DirEntry , err error ) error {
921+ err := fastwalk .Walk (nil , cachePrefix , func (path string , d fs.DirEntry , err error ) error {
922+ // this func should be concurrent safe
921923 if err != nil {
922924 return nil
923925 }
@@ -953,6 +955,9 @@ func (cache *cacheStore) scanCached() {
953955 }
954956 return nil
955957 })
958+ if err != nil {
959+ logger .Errorf ("Scan cached files in %s failed: %s" , cachePrefix , err )
960+ }
956961
957962 cache .Lock ()
958963 cache .scanned = true
@@ -972,7 +977,8 @@ func (cache *cacheStore) scanStaging() {
972977 var count , usage uint64
973978 stagingPrefix := filepath .Join (cache .dir , stagingDir )
974979 logger .Debugf ("Scan %s to find staging blocks" , stagingPrefix )
975- _ = filepath .WalkDir (stagingPrefix , func (path string , d fs.DirEntry , err error ) error {
980+ err := fastwalk .Walk (nil , stagingPrefix , func (path string , d fs.DirEntry , err error ) error {
981+ // this func should be concurrent safe
976982 if err != nil {
977983 return nil // ignore it
978984 }
@@ -1002,11 +1008,14 @@ func (cache *cacheStore) scanStaging() {
10021008 cache .m .stageBlocks .Add (1 )
10031009 cache .m .stageBlockBytes .Add (float64 (origSize ))
10041010 cache .uploader (key , path , false )
1005- count ++
1006- usage += uint64 (origSize )
1011+ atomic . AddUint64 ( & count , 1 )
1012+ atomic . AddUint64 ( & usage , uint64 (origSize ) )
10071013 }
10081014 return nil
10091015 })
1016+ if err != nil {
1017+ logger .Errorf ("Scan staging files in %s failed: %s" , stagingPrefix , err )
1018+ }
10101019 if count > 0 {
10111020 logger .Infof ("Found %d staging blocks (%s) in %s with %s" , count , humanize .IBytes (usage ), cache .dir , time .Since (start ))
10121021 }
0 commit comments