The library automatically retries requests that fail with transient errors, and follows the recommended practice to backoff between retries.
Application developers can override the default retry and backoff policies:
namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](std::string const& bucket_name, std::string const& object_name,
std::string const& contents) {
auto client =
gcs::LimitedErrorCountRetryPolicy(3).clone()));
StatusOr<gcs::ObjectMetadata> object_metadata =
client.InsertObject(bucket_name, object_name, std::move(contents),
gcs::IfGenerationMatch(0));
if (!object_metadata) throw std::move(object_metadata).status();
std::cout << "The object " << object_metadata->name()
<< " was created in bucket " << object_metadata->bucket()
<< "\nFull metadata: " << *object_metadata << "\n";
}
Options & set(ValueTypeT< T > v)
The default policies are to continue retrying for up to 15 minutes, and to use truncated (at 5 minutes) exponential backoff, doubling the maximum backoff period between retries.
By default the library retries all operations, even those that are not idempotent. Application developers can override the idempotency policy to follow a more conservative approach:
namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](std::string const& bucket_name, std::string const& object_name,
std::string const& contents) {
auto client =
gcs::StrictIdempotencyPolicy().clone()));
StatusOr<gcs::ObjectMetadata> object_metadata =
client.InsertObject(bucket_name, object_name, std::move(contents),
gcs::IfGenerationMatch(0));
if (!object_metadata) throw std::move(object_metadata).status();
std::cout << "The object " << object_metadata->name()
<< " was created in bucket " << object_metadata->bucket()
<< "\nFull metadata: " << *object_metadata << "\n";
}
- See also
- LimitedTimeRetryPolicy and LimitedErrorCountRetryPolicy for alternative retry policies.
-
ExponentialBackoffPolicy to configure different parameters for the exponential backoff policy.
-
AlwaysRetryIdempotencyPolicy and StrictIdempotencyPolicy for alternative idempotency policies.