Skip to content

Commit b1cf7f0

Browse files
authored
doc(storage): improve retry package docs (#5300)
Add more information to package docs about retry strategy, and give a short example. This will appear in the docs at https://pkg.go.dev/cloud.google.com/go/storage
1 parent 6d1f3f8 commit b1cf7f0

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

storage/doc.go

+43-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ Google Cloud Storage stores data in named objects, which are grouped into bucket
1919
More information about Google Cloud Storage is available at
2020
https://cloud.google.com/storage/docs.
2121
22-
See https://godoc.org/cloud.google.com/go for authentication, timeouts,
22+
See https://pkg.go.dev/cloud.google.com/go for authentication, timeouts,
2323
connection pooling and similar aspects of this package.
2424
25-
All of the methods of this package use exponential backoff to retry calls that fail
26-
with certain errors, as described in
27-
https://cloud.google.com/storage/docs/exponential-backoff. Retrying continues
28-
indefinitely unless the controlling context is canceled or the client is closed. See
29-
context.WithTimeout and context.WithCancel.
30-
3125
3226
Creating a Client
3327
@@ -246,12 +240,52 @@ as the documentation of GenerateSignedPostPolicyV4.
246240
247241
Errors
248242
249-
Errors returned by this client are often of the type [`googleapi.Error`](https://godoc.org/google.golang.org/api/googleapi#Error).
250-
These errors can be introspected for more information by using `errors.As` with the richer `googleapi.Error` type. For example:
243+
Errors returned by this client are often of the type googleapi.Error.
244+
These errors can be introspected for more information by using errors.As
245+
with the richer googleapi.Error type. For example:
251246
252247
var e *googleapi.Error
253248
if ok := errors.As(err, &e); ok {
254249
if e.Code == 409 { ... }
255250
}
251+
252+
See https://pkg.go.dev/google.golang.org/api/googleapi#Error for more information.
253+
254+
Retrying failed requests
255+
256+
Methods of this package may use exponential backoff to retry calls
257+
that fail with transient errors. Retrying continues indefinitely unless the
258+
controlling context is canceled, the client is closed, or a non-transient error
259+
is received. See context.WithTimeout and context.WithCancel.
260+
261+
Retry strategy in this library follows best practices for Cloud Storage. By
262+
default, only idempotent operations are retried, exponential backoff with jitter
263+
is employed, and only transient network errors and response codes defined as
264+
transient by the service and will be retried. See
265+
https://cloud.google.com/storage/docs/retry-strategy for more information.
266+
267+
Users can configure non-default retry behavior for a particular operation (using
268+
BucketHandle.Retryer and ObjectHandle.Retryer) or for all calls made by a
269+
client (using Client.SetRetry). For example:
270+
271+
o := client.Bucket(bucket).Object(object).Retryer(
272+
// Use WithBackoff to change the timing of the exponential backoff.
273+
storage.WithBackoff(gax.Backoff{
274+
Initial: 2 * time.Second,
275+
}),
276+
// Use WithPolicy to configure the idempotency policy. RetryAlways will
277+
// retry the operation even if it is non-idempotent.
278+
storage.WithPolicy(storage.RetryAlways),
279+
)
280+
281+
// Use context timeouts to set an overall deadline on the call, including all
282+
// potential retries.
283+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
284+
defer cancel()
285+
286+
// Delete an object using the specified strategy and timeout.
287+
if err := o.Delete(ctx); err != nil {
288+
// Handle err.
289+
}
256290
*/
257291
package storage // import "cloud.google.com/go/storage"

0 commit comments

Comments
 (0)