diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-08-09 22:11:57 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-08-09 22:11:57 -0700 |
| commit | 69655ba8e56c94cc1ef6fea5420c5a66d8fe650a (patch) | |
| tree | 0bd2cf29571edbab12cfbe44e8e07f830449d4ec /weed/filesys | |
| parent | a7012d9729cc5277114ac93580949fb487371395 (diff) | |
| download | seaweedfs-69655ba8e56c94cc1ef6fea5420c5a66d8fe650a.tar.xz seaweedfs-69655ba8e56c94cc1ef6fea5420c5a66d8fe650a.zip | |
mount: cache on reading remote storage
Diffstat (limited to 'weed/filesys')
| -rw-r--r-- | weed/filesys/file.go | 27 | ||||
| -rw-r--r-- | weed/filesys/filehandle.go | 10 |
2 files changed, 37 insertions, 0 deletions
diff --git a/weed/filesys/file.go b/weed/filesys/file.go index 7f021619c..b990b20d1 100644 --- a/weed/filesys/file.go +++ b/weed/filesys/file.go @@ -360,3 +360,30 @@ func (file *File) saveEntry(entry *filer_pb.Entry) error { func (file *File) getEntry() *filer_pb.Entry { return file.entry } + +func (file *File) downloadRemoteEntry(entry *filer_pb.Entry) (*filer_pb.Entry, error) { + err := file.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { + + request := &filer_pb.DownloadToLocalRequest{ + Directory: file.dir.FullPath(), + Name: entry.Name, + } + + glog.V(4).Infof("download entry: %v", request) + resp, err := client.DownloadToLocal(context.Background(), request) + if err != nil { + glog.Errorf("DownloadToLocal file %s/%s: %v", file.dir.FullPath(), file.Name, err) + return fuse.EIO + } + + entry = resp.Entry + + file.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, resp.Entry)) + + file.dirtyMetadata = false + + return nil + }) + + return entry, err +} diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 9acede330..5cd7ca948 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -114,6 +114,16 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) { return 0, io.EOF } + if entry.IsInRemoteOnly() { + glog.V(4).Infof("download remote entry %s", fh.f.fullpath()) + newEntry, err := fh.f.downloadRemoteEntry(entry) + if err != nil { + glog.V(1).Infof("download remote entry %s: %v", fh.f.fullpath(), err) + return 0, err + } + entry = newEntry + } + fileSize := int64(filer.FileSize(entry)) fileFullPath := fh.f.fullpath() |
