@@ -2,6 +2,7 @@ package s3
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"io"
6
7
"time"
7
8
@@ -102,7 +103,7 @@ type BucketWithRetries struct {
102
103
retryMaxBackoff time.Duration
103
104
}
104
105
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 {
106
107
var lastErr error
107
108
retries := backoff .New (ctx , backoff.Config {
108
109
MinBackoff : b .retryMinBackoff ,
@@ -120,7 +121,8 @@ func (b *BucketWithRetries) retry(ctx context.Context, f func() error) error {
120
121
retries .Wait ()
121
122
}
122
123
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
124
126
}
125
127
return nil
126
128
}
@@ -132,30 +134,30 @@ func (b *BucketWithRetries) Name() string {
132
134
func (b * BucketWithRetries ) Iter (ctx context.Context , dir string , f func (string ) error , options ... objstore.IterOption ) error {
133
135
return b .retry (ctx , func () error {
134
136
return b .bucket .Iter (ctx , dir , f , options ... )
135
- })
137
+ }, fmt . Sprintf ( "Iter %s" , dir ) )
136
138
}
137
139
138
140
func (b * BucketWithRetries ) Get (ctx context.Context , name string ) (reader io.ReadCloser , err error ) {
139
141
err = b .retry (ctx , func () error {
140
142
reader , err = b .bucket .Get (ctx , name )
141
143
return err
142
- })
144
+ }, fmt . Sprintf ( "Get %s" , name ) )
143
145
return
144
146
}
145
147
146
148
func (b * BucketWithRetries ) GetRange (ctx context.Context , name string , off , length int64 ) (closer io.ReadCloser , err error ) {
147
149
err = b .retry (ctx , func () error {
148
150
closer , err = b .bucket .GetRange (ctx , name , off , length )
149
151
return err
150
- })
152
+ }, fmt . Sprintf ( "GetRange %s (off: %d, length: %d)" , name , off , length ) )
151
153
return
152
154
}
153
155
154
156
func (b * BucketWithRetries ) Exists (ctx context.Context , name string ) (exists bool , err error ) {
155
157
err = b .retry (ctx , func () error {
156
158
exists , err = b .bucket .Exists (ctx , name )
157
159
return err
158
- })
160
+ }, fmt . Sprintf ( "Exists %s" , name ) )
159
161
return
160
162
}
161
163
@@ -171,21 +173,21 @@ func (b *BucketWithRetries) Upload(ctx context.Context, name string, r io.Reader
171
173
return err
172
174
}
173
175
return b .bucket .Upload (ctx , name , rs )
174
- })
176
+ }, fmt . Sprintf ( "Upload %s" , name ) )
175
177
}
176
178
177
179
func (b * BucketWithRetries ) Attributes (ctx context.Context , name string ) (attributes objstore.ObjectAttributes , err error ) {
178
180
err = b .retry (ctx , func () error {
179
181
attributes , err = b .bucket .Attributes (ctx , name )
180
182
return err
181
- })
183
+ }, fmt . Sprintf ( "Attributes %s" , name ) )
182
184
return
183
185
}
184
186
185
187
func (b * BucketWithRetries ) Delete (ctx context.Context , name string ) error {
186
188
return b .retry (ctx , func () error {
187
189
return b .bucket .Delete (ctx , name )
188
- })
190
+ }, fmt . Sprintf ( "Delete %s" , name ) )
189
191
}
190
192
191
193
func (b * BucketWithRetries ) IsObjNotFoundErr (err error ) bool {
0 commit comments