filer: retryable data chunk upload

This commit is contained in:
chrislu 2022-08-20 19:15:44 -07:00
parent 4081d50607
commit f8fa430257

View file

@ -256,12 +256,18 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa
func (fs *FilerServer) saveAsChunk(so *operation.StorageOption) filer.SaveDataAsChunkFunctionType { func (fs *FilerServer) saveAsChunk(so *operation.StorageOption) filer.SaveDataAsChunkFunctionType {
return func(reader io.Reader, name string, offset int64) (*filer_pb.FileChunk, error) { return func(reader io.Reader, name string, offset int64) (*filer_pb.FileChunk, error) {
var fileId string
var uploadResult *operation.UploadResult
err := util.Retry("saveAsChunk", func() error {
// assign one file id for one chunk // assign one file id for one chunk
fileId, urlLocation, auth, assignErr := fs.assignNewFileInfo(so) assignedFileId, urlLocation, auth, assignErr := fs.assignNewFileInfo(so)
if assignErr != nil { if assignErr != nil {
return nil, assignErr return assignErr
} }
fileId = assignedFileId
// upload the chunk to the volume server // upload the chunk to the volume server
uploadOption := &operation.UploadOption{ uploadOption := &operation.UploadOption{
UploadUrl: urlLocation, UploadUrl: urlLocation,
@ -272,9 +278,15 @@ func (fs *FilerServer) saveAsChunk(so *operation.StorageOption) filer.SaveDataAs
PairMap: nil, PairMap: nil,
Jwt: auth, Jwt: auth,
} }
uploadResult, uploadErr, _ := operation.Upload(reader, uploadOption) var uploadErr error
uploadResult, uploadErr, _ = operation.Upload(reader, uploadOption)
if uploadErr != nil { if uploadErr != nil {
return nil, uploadErr return uploadErr
}
return nil
})
if err != nil {
return nil, err
} }
return uploadResult.ToPbFileChunk(fileId, offset), nil return uploadResult.ToPbFileChunk(fileId, offset), nil