mount:exponentially backoff if read error for about 10 minutes

This commit is contained in:
Chris Lu
2020-10-08 23:31:26 -07:00
parent 6e1f936efd
commit 8d34eb0050
2 changed files with 18 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"time"
"github.com/golang/protobuf/proto" "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) glog.Errorf("operation LookupFileId %s failed, err: %v", fileId, err)
return nil, 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 err error
var buffer bytes.Buffer var buffer bytes.Buffer
for _, urlString := range urlStrings {
err = util.ReadUrlAsStream(urlString, cipherKey, isGzipped, isFullChunk, offset, size, func(data []byte) { for waitTime := time.Second; waitTime < 10*time.Minute; waitTime+=waitTime/2 {
buffer.Write(data) for _, urlString := range urlStrings {
}) err = util.ReadUrlAsStream(urlString, cipherKey, isGzipped, isFullChunk, offset, size, func(data []byte) {
if err != nil { buffer.Write(data)
glog.V(0).Infof("read %s failed, err: %v", urlString, err) })
buffer.Reset() if err != nil {
} else { glog.V(0).Infof("read %s failed, err: %v", urlString, err)
break buffer.Reset()
} else {
break
}
} }
time.Sleep(waitTime)
} }
return buffer.Bytes(), err return buffer.Bytes(), err

View File

@@ -33,7 +33,7 @@ func StreamContent(masterClient *wdclient.MasterClient, w io.Writer, chunks []*f
urlStrings := fileId2Url[chunkView.FileId] 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 { if err == nil {
return err return err
} }
@@ -64,7 +64,7 @@ func ReadAll(masterClient *wdclient.MasterClient, chunks []*filer_pb.FileChunk)
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }