@@ -2,6 +2,7 @@ package s3
22
33import (
44 "context"
5+ "fmt"
56 "io"
67 "time"
78
@@ -102,7 +103,7 @@ type BucketWithRetries struct {
102103 retryMaxBackoff time.Duration
103104}
104105
105- func (b * BucketWithRetries ) retry (ctx context.Context , f func () error ) error {
106+ func (b * BucketWithRetries ) retry (ctx context.Context , f func () error , operationInfo string ) error {
106107 var lastErr error
107108 retries := backoff .New (ctx , backoff.Config {
108109 MinBackoff : b .retryMinBackoff ,
@@ -120,7 +121,8 @@ func (b *BucketWithRetries) retry(ctx context.Context, f func() error) error {
120121 retries .Wait ()
121122 }
122123 if lastErr != nil {
123- level .Error (b .logger ).Log ("msg" , "bucket operation fail after retries" , "err" , lastErr )
124+ level .Error (b .logger ).Log ("msg" , "bucket operation fail after retries" , "err" , lastErr , "operation" , operationInfo )
125+ return lastErr
124126 }
125127 return nil
126128}
@@ -132,30 +134,30 @@ func (b *BucketWithRetries) Name() string {
132134func (b * BucketWithRetries ) Iter (ctx context.Context , dir string , f func (string ) error , options ... objstore.IterOption ) error {
133135 return b .retry (ctx , func () error {
134136 return b .bucket .Iter (ctx , dir , f , options ... )
135- })
137+ }, fmt . Sprintf ( "Iter %s" , dir ) )
136138}
137139
138140func (b * BucketWithRetries ) Get (ctx context.Context , name string ) (reader io.ReadCloser , err error ) {
139141 err = b .retry (ctx , func () error {
140142 reader , err = b .bucket .Get (ctx , name )
141143 return err
142- })
144+ }, fmt . Sprintf ( "Get %s" , name ) )
143145 return
144146}
145147
146148func (b * BucketWithRetries ) GetRange (ctx context.Context , name string , off , length int64 ) (closer io.ReadCloser , err error ) {
147149 err = b .retry (ctx , func () error {
148150 closer , err = b .bucket .GetRange (ctx , name , off , length )
149151 return err
150- })
152+ }, fmt . Sprintf ( "GetRange %s (off: %d, length: %d)" , name , off , length ) )
151153 return
152154}
153155
154156func (b * BucketWithRetries ) Exists (ctx context.Context , name string ) (exists bool , err error ) {
155157 err = b .retry (ctx , func () error {
156158 exists , err = b .bucket .Exists (ctx , name )
157159 return err
158- })
160+ }, fmt . Sprintf ( "Exists %s" , name ) )
159161 return
160162}
161163
@@ -171,21 +173,21 @@ func (b *BucketWithRetries) Upload(ctx context.Context, name string, r io.Reader
171173 return err
172174 }
173175 return b .bucket .Upload (ctx , name , rs )
174- })
176+ }, fmt . Sprintf ( "Upload %s" , name ) )
175177}
176178
177179func (b * BucketWithRetries ) Attributes (ctx context.Context , name string ) (attributes objstore.ObjectAttributes , err error ) {
178180 err = b .retry (ctx , func () error {
179181 attributes , err = b .bucket .Attributes (ctx , name )
180182 return err
181- })
183+ }, fmt . Sprintf ( "Attributes %s" , name ) )
182184 return
183185}
184186
185187func (b * BucketWithRetries ) Delete (ctx context.Context , name string ) error {
186188 return b .retry (ctx , func () error {
187189 return b .bucket .Delete (ctx , name )
188- })
190+ }, fmt . Sprintf ( "Delete %s" , name ) )
189191}
190192
191193func (b * BucketWithRetries ) IsObjNotFoundErr (err error ) bool {
0 commit comments