aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-10-08 23:31:26 -0700
committerChris Lu <chris.lu@gmail.com>2020-10-08 23:31:26 -0700
commit8d34eb005087f6cb305b8934d8614a88b62cff99 (patch)
tree260ac298e35a40052acb6a1d4b094e6a172b54a1
parent6e1f936efd5b28ef15c2f3b388f07c34bbdb527b (diff)
downloadseaweedfs-8d34eb005087f6cb305b8934d8614a88b62cff99.tar.xz
seaweedfs-8d34eb005087f6cb305b8934d8614a88b62cff99.zip
mount:exponentially backoff if read error for about 10 minutes
-rw-r--r--weed/filer/filechunk_manifest.go27
-rw-r--r--weed/filer/stream.go4
2 files changed, 18 insertions, 13 deletions
diff --git a/weed/filer/filechunk_manifest.go b/weed/filer/filechunk_manifest.go
index 200fde438..0f84de4cd 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"
@@ -89,23 +90,27 @@ func fetchChunk(lookupFileIdFn LookupFileIdFunctionType, fileId string, cipherKe
glog.Errorf("operation LookupFileId %s failed, err: %v", fileId, err)
return nil, err
}
- return fetchChunkData(urlStrings, cipherKey, isGzipped, true, 0, 0)
+ return retriedFetchChunkData(urlStrings, cipherKey, isGzipped, true, 0, 0)
}
-func fetchChunkData(urlStrings []string, cipherKey []byte, isGzipped bool, isFullChunk bool, offset int64, size int) ([]byte, error) {
+func retriedFetchChunkData(urlStrings []string, cipherKey []byte, isGzipped bool, isFullChunk bool, offset int64, size int) ([]byte, error) {
var err error
var buffer bytes.Buffer
- 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
+
+ for waitTime := time.Second; waitTime < 10*time.Minute; 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
+ }
}
+ time.Sleep(waitTime)
}
return buffer.Bytes(), err
diff --git a/weed/filer/stream.go b/weed/filer/stream.go
index e1be18f69..f6e2a7643 100644
--- a/weed/filer/stream.go
+++ b/weed/filer/stream.go
@@ -33,7 +33,7 @@ func StreamContent(masterClient *wdclient.MasterClient, w io.Writer, chunks []*f
urlStrings := fileId2Url[chunkView.FileId]
- data, err := fetchChunkData(urlStrings, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size))
+ data, err := retriedFetchChunkData(urlStrings, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size))
if err == nil {
return err
}
@@ -64,7 +64,7 @@ func ReadAll(masterClient *wdclient.MasterClient, chunks []*filer_pb.FileChunk)
return nil, err
}
- data, err := fetchChunkData(urlStrings, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size))
+ data, err := retriedFetchChunkData(urlStrings, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size))
if err != nil {
return nil, err
}