Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(storage): improve retry package docs #5300

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions storage/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ Google Cloud Storage stores data in named objects, which are grouped into bucket
More information about Google Cloud Storage is available at
https://cloud.google.com/storage/docs.

See https://godoc.org/cloud.google.com/go for authentication, timeouts,
See https://pkg.go.dev/cloud.google.com/go for authentication, timeouts,
connection pooling and similar aspects of this package.

All of the methods of this package use exponential backoff to retry calls that fail
with certain errors, as described in
https://cloud.google.com/storage/docs/exponential-backoff. Retrying continues
indefinitely unless the controlling context is canceled or the client is closed. See
context.WithTimeout and context.WithCancel.


Creating a Client

Expand Down Expand Up @@ -246,12 +240,52 @@ as the documentation of GenerateSignedPostPolicyV4.

Errors

Errors returned by this client are often of the type [`googleapi.Error`](https://godoc.org/google.golang.org/api/googleapi#Error).
These errors can be introspected for more information by using `errors.As` with the richer `googleapi.Error` type. For example:
Errors returned by this client are often of the type googleapi.Error.
tritone marked this conversation as resolved.
Show resolved Hide resolved
These errors can be introspected for more information by using errors.As
with the richer googleapi.Error type. For example:

var e *googleapi.Error
if ok := errors.As(err, &e); ok {
if e.Code == 409 { ... }
}

See https://pkg.go.dev/google.golang.org/api/googleapi#Error for more information.

Retrying failed requests

Methods of this package may use exponential backoff to retry calls
tritone marked this conversation as resolved.
Show resolved Hide resolved
tritone marked this conversation as resolved.
Show resolved Hide resolved
that fail with transient errors. Retrying continues indefinitely unless the
controlling context is canceled, the client is closed, or a non-transient error
is received. See context.WithTimeout and context.WithCancel.
tritone marked this conversation as resolved.
Show resolved Hide resolved

Retry strategy in this library follows best practices for Cloud Storage. By
tritone marked this conversation as resolved.
Show resolved Hide resolved
default, only idempotent operations are retried, exponential backoff with jitter
tritone marked this conversation as resolved.
Show resolved Hide resolved
is employed, and only transient network errors and response codes defined as
transient by the service and will be retried. See
https://cloud.google.com/storage/docs/retry-strategy for more information.

Users can configure non-default retry behavior for a particular operation (using
tritone marked this conversation as resolved.
Show resolved Hide resolved
BucketHandle.Retryer and ObjectHandle.Retryer) or for all calls made by a
client (using Client.SetRetry). For example:

o := client.Bucket(bucket).Object(object).Retryer(
// Use WithBackoff to change the timing of the exponential backoff.
storage.WithBackoff(gax.Backoff{
Initial: 2 * time.Second,
}),
// Use WithPolicy to configure the idempotency policy. RetryAlways will
// retry the operation even if it is non-idempotent.
storage.WithPolicy(storage.RetryAlways),
)

// Use context timeouts to set an overall deadline on the call, including all
// potential retries.
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

// Delete an object using the specified strategy and timeout.
if err := o.Delete(ctx); err != nil {
// Handle err.
}
*/
package storage // import "cloud.google.com/go/storage"