s3: pass blob length to minio in PutBlob()
also added retry loop
"io"
"io/ioutil"
"net/http"
+ "strings"
"github.com/efarrer/iothrottler"
minio "github.com/minio/minio-go/v6"
@@ -89,6 +90,11 @@ func isRetriableError(err error) bool {
return me.StatusCode >= 500
}
+ if strings.Contains(strings.ToLower(err.Error()), "http") {
+ // retry http transport errors, unfortunately no other way to detect them
+ return true
+ }
+
return false
}
@@ -107,6 +113,7 @@ func translateError(err error) error {
}
func (s *s3Storage) PutBlob(ctx context.Context, b blob.ID, data []byte) error {
+ return translateError(retry.WithExponentialBackoffNoValue(ctx, fmt.Sprintf("PutBlob(%v)", b), func() error {
throttled, err := s.uploadThrottler.AddReader(ioutil.NopCloser(bytes.NewReader(data)))
if err != nil {
return err
@@ -118,7 +125,7 @@ func (s *s3Storage) PutBlob(ctx context.Context, b blob.ID, data []byte) error {
defer progressCallback(string(b), int64(len(data)), int64(len(data)))
}
- n, err := s.cli.PutObject(s.BucketName, s.getObjectNameString(b), throttled, -1, minio.PutObjectOptions{
+ n, err := s.cli.PutObject(s.BucketName, s.getObjectNameString(b), throttled, int64(len(data)), minio.PutObjectOptions{
ContentType: "application/x-kopia",
Progress: newProgressReader(progressCallback, string(b), int64(len(data))),
})
@@ -130,7 +137,8 @@ func (s *s3Storage) PutBlob(ctx context.Context, b blob.ID, data []byte) error {
})
}
- return translateError(err)
+ return err
+ }, isRetriableError))
}
func (s *s3Storage) DeleteBlob(ctx context.Context, b blob.ID) error {
