Browse Source

use util.Retry to retry

pull/3472/head
chrislu 2 years ago
parent
commit
28b862f45f
  1. 19
      weed/server/filer_server_handlers_write_upload.go

19
weed/server/filer_server_handlers_write_upload.go

@ -171,28 +171,27 @@ func (fs *FilerServer) dataToChunk(fileName, contentType string, data []byte, ch
var auth security.EncodedJwt
var uploadErr error
var uploadResult *operation.UploadResult
for i := 0; i < 3; i++ {
err := util.Retry("filerDataToChunk", func() error {
// assign one file id for one chunk
fileId, urlLocation, auth, uploadErr = fs.assignNewFileInfo(so)
if uploadErr != nil {
glog.V(4).Infof("retry later due to assign error: %v", uploadErr)
stats.FilerRequestCounter.WithLabelValues(stats.ChunkAssignRetry).Inc()
time.Sleep(time.Duration(i+1) * 251 * time.Millisecond)
continue
return uploadErr
}
// upload the chunk to the volume server
uploadResult, uploadErr, _ = fs.doUpload(urlLocation, dataReader, fileName, contentType, nil, auth)
if uploadErr != nil {
glog.V(4).Infof("retry later due to upload error: %v", uploadErr)
stats.FilerRequestCounter.WithLabelValues(stats.ChunkDoUploadRetry).Inc()
time.Sleep(time.Duration(i+1) * 251 * time.Millisecond)
continue
}
break
return uploadErr
}
if uploadErr != nil {
glog.Errorf("upload error: %v", uploadErr)
return nil, uploadErr
return nil
})
if err != nil {
glog.Errorf("upload error: %v", err)
return nil, err
}
// if last chunk exhausted the reader exactly at the border

Loading…
Cancel
Save