Skip to content

Commit

Permalink
fix: pre read dir file infos into cache
Browse files Browse the repository at this point in the history
  • Loading branch information
likeazir committed Oct 7, 2023
1 parent 32465ec commit 092c5c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/pkg/cacheclient/cacheclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/rs/zerolog/log"
"io/fs"
"path/filepath"
"readnetfs/internal/pkg/fsclient"
"sync"
"syscall"
Expand Down Expand Up @@ -105,9 +106,12 @@ func (c *CacheClient) ReadDir(path fsclient.RemotePath) ([]fs.FileInfo, error) {
}

func (c *CacheClient) FileInfo(path fsclient.RemotePath) (fs.FileInfo, error) {
//trigger parent dir read to fill cache for future requests
go c.ReadDir(fsclient.RemotePath(filepath.Dir(string(path))))
if info, ok := c.infos.Get(path); ok {
return info, nil
}
log.Warn().Msgf("reading single file info from %s", path)
c.infoLock.Lock()
defer c.infoLock.Unlock()
info, err := c.client.FileInfo(path)
Expand Down
3 changes: 0 additions & 3 deletions internal/pkg/netclient/netclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"io/fs"
"math"
"net"
"path/filepath"
"readnetfs/internal/pkg/cacheclient"
"readnetfs/internal/pkg/common"
"readnetfs/internal/pkg/fsclient"
Expand Down Expand Up @@ -176,8 +175,6 @@ func (f *NetClient) FileInfo(path fsclient.RemotePath) (fs.FileInfo, error) {
return info, nil
}
}
//trigger parent dir read to fill cache for future requests
go f.ReadDir(fsclient.RemotePath(filepath.Dir(string(path))))
_, _ = fmt.Fprintf(f.statsdSocket, "requests.outgoing.file_info:1|c\n")
return nil, errors.New("no peer has file" + string(path))
}
Expand Down

0 comments on commit 092c5c5

Please sign in to comment.