aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/filechunk_manifest.go
diff options
context:
space:
mode:
authorhilimd <68371223+hilimd@users.noreply.github.com>2020-10-10 13:07:57 +0800
committerGitHub <noreply@github.com>2020-10-10 13:07:57 +0800
commit411e49f96494629fa3da334e8dc7cc15bd4d19cd (patch)
tree1756f0a2f86c871a6db67df7ecbd509c9df32233 /weed/filer/filechunk_manifest.go
parentac162fc85769cb1b2a1f8694f9644eae7d0ce6c8 (diff)
parent4a15e9c830de1b654515308e5be8380ffa34aefa (diff)
downloadseaweedfs-411e49f96494629fa3da334e8dc7cc15bd4d19cd.tar.xz
seaweedfs-411e49f96494629fa3da334e8dc7cc15bd4d19cd.zip
Merge pull request #23 from chrislusf/master
sync
Diffstat (limited to 'weed/filer/filechunk_manifest.go')
-rw-r--r--weed/filer/filechunk_manifest.go36
1 files changed, 28 insertions, 8 deletions
diff --git a/weed/filer/filechunk_manifest.go b/weed/filer/filechunk_manifest.go
index 37b172357..9e53e008f 100644
--- a/weed/filer/filechunk_manifest.go
+++ b/weed/filer/filechunk_manifest.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"math"
+ "time"
"github.com/golang/protobuf/proto"
@@ -84,21 +85,40 @@ func ResolveOneChunkManifest(lookupFileIdFn LookupFileIdFunctionType, chunk *fil
// TODO fetch from cache for weed mount?
func fetchChunk(lookupFileIdFn LookupFileIdFunctionType, fileId string, cipherKey []byte, isGzipped bool) ([]byte, error) {
- urlString, err := lookupFileIdFn(fileId)
+ urlStrings, err := lookupFileIdFn(fileId)
if err != nil {
glog.Errorf("operation LookupFileId %s failed, err: %v", fileId, err)
return nil, err
}
+ return retriedFetchChunkData(urlStrings, cipherKey, isGzipped, true, 0, 0)
+}
+
+func retriedFetchChunkData(urlStrings []string, cipherKey []byte, isGzipped bool, isFullChunk bool, offset int64, size int) ([]byte, error) {
+
+ var err error
var buffer bytes.Buffer
- err = util.ReadUrlAsStream(urlString, cipherKey, isGzipped, true, 0, 0, func(data []byte) {
- buffer.Write(data)
- })
- if err != nil {
- glog.V(0).Infof("read %s failed, err: %v", fileId, err)
- return nil, err
+
+ for waitTime := time.Second; waitTime < 10*time.Second; waitTime += waitTime / 2 {
+ for _, urlString := range urlStrings {
+ err = util.ReadUrlAsStream(urlString, cipherKey, isGzipped, isFullChunk, offset, size, func(data []byte) {
+ buffer.Write(data)
+ })
+ if err != nil {
+ glog.V(0).Infof("read %s failed, err: %v", urlString, err)
+ buffer.Reset()
+ } else {
+ break
+ }
+ }
+ if err != nil {
+ glog.V(0).Infof("sleep for %v before retrying reading", waitTime)
+ time.Sleep(waitTime)
+ } else {
+ break
+ }
}
- return buffer.Bytes(), nil
+ return buffer.Bytes(), err
}
func MaybeManifestize(saveFunc SaveDataAsChunkFunctionType, inputChunks []*filer_pb.FileChunk) (chunks []*filer_pb.FileChunk, err error) {