mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
remote: filer cache remote content on read
This commit is contained in:
parent
9096f6f4f7
commit
8d3e275735
|
@ -3,6 +3,7 @@ package weed_server
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -163,19 +164,23 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
chunks := entry.Chunks
|
||||||
if entry.IsInRemoteOnly() {
|
if entry.IsInRemoteOnly() {
|
||||||
var data []byte
|
dir, name := entry.FullPath.DirAndName()
|
||||||
data, err = fs.filer.ReadRemote(entry, offset, size)
|
if resp, err := fs.DownloadToLocal(context.Background(), &filer_pb.DownloadToLocalRequest{
|
||||||
if err != nil {
|
Directory: dir,
|
||||||
glog.Errorf("failed to read remote %s: %v", r.URL, err)
|
Name: name,
|
||||||
}
|
}); err != nil {
|
||||||
_, err = w.Write(data)
|
return fmt.Errorf("cache %s: %v", entry.FileSize, err)
|
||||||
} else {
|
} else {
|
||||||
err = filer.StreamContent(fs.filer.MasterClient, writer, entry.Chunks, offset, size)
|
chunks = resp.Entry.Chunks
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("failed to stream content %s: %v", r.URL, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = filer.StreamContent(fs.filer.MasterClient, writer, chunks, offset, size)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("failed to stream content %s: %v", r.URL, err)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue