Showing content from https://cloud.google.com/cpp/docs/reference/datastream/2.27.0/datastream-override-retry below:
C++ Client Libraries | Google Cloud
Skip to main content
- Overview
-
Library reference docs
- Datastream API C++ Client Library
-
Namespaces
-
google::cloud::datastream_mocks
-
google::cloud::datastream_v1
- Overview
-
Classes
-
DatastreamClient
- Overview
-
Functions
- ListConnectionProfiles(std::string const &, Options)
- ListConnectionProfiles(google::cloud::datastream::v1::ListConnectionProfilesRequest, Options)
- GetConnectionProfile(std::string const &, Options)
- GetConnectionProfile(google::cloud::datastream::v1::GetConnectionProfileRequest const &, Options)
- CreateConnectionProfile(std::string const &, google::cloud::datastream::v1::ConnectionProfile const &, std::string const &, Options)
- CreateConnectionProfile(NoAwaitTag, std::string const &, google::cloud::datastream::v1::ConnectionProfile const &, std::string const &, Options)
- CreateConnectionProfile(google::cloud::datastream::v1::CreateConnectionProfileRequest const &, Options)
- CreateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::CreateConnectionProfileRequest const &, Options)
- CreateConnectionProfile(google::longrunning::Operation const &, Options)
- UpdateConnectionProfile(google::cloud::datastream::v1::ConnectionProfile const &, google::protobuf::FieldMask const &, Options)
- UpdateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::ConnectionProfile const &, google::protobuf::FieldMask const &, Options)
- UpdateConnectionProfile(google::cloud::datastream::v1::UpdateConnectionProfileRequest const &, Options)
- UpdateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::UpdateConnectionProfileRequest const &, Options)
- UpdateConnectionProfile(google::longrunning::Operation const &, Options)
- DeleteConnectionProfile(std::string const &, Options)
- DeleteConnectionProfile(NoAwaitTag, std::string const &, Options)
- DeleteConnectionProfile(google::cloud::datastream::v1::DeleteConnectionProfileRequest const &, Options)
- DeleteConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::DeleteConnectionProfileRequest const &, Options)
- DeleteConnectionProfile(google::longrunning::Operation const &, Options)
- DiscoverConnectionProfile(google::cloud::datastream::v1::DiscoverConnectionProfileRequest const &, Options)
- ListStreams(std::string const &, Options)
- ListStreams(google::cloud::datastream::v1::ListStreamsRequest, Options)
- GetStream(std::string const &, Options)
- GetStream(google::cloud::datastream::v1::GetStreamRequest const &, Options)
- CreateStream(std::string const &, google::cloud::datastream::v1::Stream const &, std::string const &, Options)
- CreateStream(NoAwaitTag, std::string const &, google::cloud::datastream::v1::Stream const &, std::string const &, Options)
- CreateStream(google::cloud::datastream::v1::CreateStreamRequest const &, Options)
- CreateStream(NoAwaitTag, google::cloud::datastream::v1::CreateStreamRequest const &, Options)
- CreateStream(google::longrunning::Operation const &, Options)
- UpdateStream(google::cloud::datastream::v1::Stream const &, google::protobuf::FieldMask const &, Options)
- UpdateStream(NoAwaitTag, google::cloud::datastream::v1::Stream const &, google::protobuf::FieldMask const &, Options)
- UpdateStream(google::cloud::datastream::v1::UpdateStreamRequest const &, Options)
- UpdateStream(NoAwaitTag, google::cloud::datastream::v1::UpdateStreamRequest const &, Options)
- UpdateStream(google::longrunning::Operation const &, Options)
- DeleteStream(std::string const &, Options)
- DeleteStream(NoAwaitTag, std::string const &, Options)
- DeleteStream(google::cloud::datastream::v1::DeleteStreamRequest const &, Options)
- DeleteStream(NoAwaitTag, google::cloud::datastream::v1::DeleteStreamRequest const &, Options)
- DeleteStream(google::longrunning::Operation const &, Options)
- GetStreamObject(std::string const &, Options)
- GetStreamObject(google::cloud::datastream::v1::GetStreamObjectRequest const &, Options)
- LookupStreamObject(google::cloud::datastream::v1::LookupStreamObjectRequest const &, Options)
- ListStreamObjects(std::string const &, Options)
- ListStreamObjects(google::cloud::datastream::v1::ListStreamObjectsRequest, Options)
- StartBackfillJob(std::string const &, Options)
- StartBackfillJob(google::cloud::datastream::v1::StartBackfillJobRequest const &, Options)
- StopBackfillJob(std::string const &, Options)
- StopBackfillJob(google::cloud::datastream::v1::StopBackfillJobRequest const &, Options)
- FetchStaticIps(std::string const &, Options)
- FetchStaticIps(google::cloud::datastream::v1::FetchStaticIpsRequest, Options)
- CreatePrivateConnection(std::string const &, google::cloud::datastream::v1::PrivateConnection const &, std::string const &, Options)
- CreatePrivateConnection(NoAwaitTag, std::string const &, google::cloud::datastream::v1::PrivateConnection const &, std::string const &, Options)
- CreatePrivateConnection(google::cloud::datastream::v1::CreatePrivateConnectionRequest const &, Options)
- CreatePrivateConnection(NoAwaitTag, google::cloud::datastream::v1::CreatePrivateConnectionRequest const &, Options)
- CreatePrivateConnection(google::longrunning::Operation const &, Options)
- GetPrivateConnection(std::string const &, Options)
- GetPrivateConnection(google::cloud::datastream::v1::GetPrivateConnectionRequest const &, Options)
- ListPrivateConnections(std::string const &, Options)
- ListPrivateConnections(google::cloud::datastream::v1::ListPrivateConnectionsRequest, Options)
- DeletePrivateConnection(std::string const &, Options)
- DeletePrivateConnection(NoAwaitTag, std::string const &, Options)
- DeletePrivateConnection(google::cloud::datastream::v1::DeletePrivateConnectionRequest const &, Options)
- DeletePrivateConnection(NoAwaitTag, google::cloud::datastream::v1::DeletePrivateConnectionRequest const &, Options)
- DeletePrivateConnection(google::longrunning::Operation const &, Options)
- CreateRoute(std::string const &, google::cloud::datastream::v1::Route const &, std::string const &, Options)
- CreateRoute(NoAwaitTag, std::string const &, google::cloud::datastream::v1::Route const &, std::string const &, Options)
- CreateRoute(google::cloud::datastream::v1::CreateRouteRequest const &, Options)
- CreateRoute(NoAwaitTag, google::cloud::datastream::v1::CreateRouteRequest const &, Options)
- CreateRoute(google::longrunning::Operation const &, Options)
- GetRoute(std::string const &, Options)
- GetRoute(google::cloud::datastream::v1::GetRouteRequest const &, Options)
- ListRoutes(std::string const &, Options)
- ListRoutes(google::cloud::datastream::v1::ListRoutesRequest, Options)
- DeleteRoute(std::string const &, Options)
- DeleteRoute(NoAwaitTag, std::string const &, Options)
- DeleteRoute(google::cloud::datastream::v1::DeleteRouteRequest const &, Options)
- DeleteRoute(NoAwaitTag, google::cloud::datastream::v1::DeleteRouteRequest const &, Options)
- DeleteRoute(google::longrunning::Operation const &, Options)
-
DatastreamConnection
- Overview
-
Functions
- virtual options()
- virtual ListConnectionProfiles(google::cloud::datastream::v1::ListConnectionProfilesRequest)
- virtual GetConnectionProfile(google::cloud::datastream::v1::GetConnectionProfileRequest const &)
- virtual CreateConnectionProfile(google::cloud::datastream::v1::CreateConnectionProfileRequest const &)
- virtual CreateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::CreateConnectionProfileRequest const &)
- virtual CreateConnectionProfile(google::longrunning::Operation const &)
- virtual UpdateConnectionProfile(google::cloud::datastream::v1::UpdateConnectionProfileRequest const &)
- virtual UpdateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::UpdateConnectionProfileRequest const &)
- virtual UpdateConnectionProfile(google::longrunning::Operation const &)
- virtual DeleteConnectionProfile(google::cloud::datastream::v1::DeleteConnectionProfileRequest const &)
- virtual DeleteConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::DeleteConnectionProfileRequest const &)
- virtual DeleteConnectionProfile(google::longrunning::Operation const &)
- virtual DiscoverConnectionProfile(google::cloud::datastream::v1::DiscoverConnectionProfileRequest const &)
- virtual ListStreams(google::cloud::datastream::v1::ListStreamsRequest)
- virtual GetStream(google::cloud::datastream::v1::GetStreamRequest const &)
- virtual CreateStream(google::cloud::datastream::v1::CreateStreamRequest const &)
- virtual CreateStream(NoAwaitTag, google::cloud::datastream::v1::CreateStreamRequest const &)
- virtual CreateStream(google::longrunning::Operation const &)
- virtual UpdateStream(google::cloud::datastream::v1::UpdateStreamRequest const &)
- virtual UpdateStream(NoAwaitTag, google::cloud::datastream::v1::UpdateStreamRequest const &)
- virtual UpdateStream(google::longrunning::Operation const &)
- virtual DeleteStream(google::cloud::datastream::v1::DeleteStreamRequest const &)
- virtual DeleteStream(NoAwaitTag, google::cloud::datastream::v1::DeleteStreamRequest const &)
- virtual DeleteStream(google::longrunning::Operation const &)
- virtual GetStreamObject(google::cloud::datastream::v1::GetStreamObjectRequest const &)
- virtual LookupStreamObject(google::cloud::datastream::v1::LookupStreamObjectRequest const &)
- virtual ListStreamObjects(google::cloud::datastream::v1::ListStreamObjectsRequest)
- virtual StartBackfillJob(google::cloud::datastream::v1::StartBackfillJobRequest const &)
- virtual StopBackfillJob(google::cloud::datastream::v1::StopBackfillJobRequest const &)
- virtual FetchStaticIps(google::cloud::datastream::v1::FetchStaticIpsRequest)
- virtual CreatePrivateConnection(google::cloud::datastream::v1::CreatePrivateConnectionRequest const &)
- virtual CreatePrivateConnection(NoAwaitTag, google::cloud::datastream::v1::CreatePrivateConnectionRequest const &)
- virtual CreatePrivateConnection(google::longrunning::Operation const &)
- virtual GetPrivateConnection(google::cloud::datastream::v1::GetPrivateConnectionRequest const &)
- virtual ListPrivateConnections(google::cloud::datastream::v1::ListPrivateConnectionsRequest)
- virtual DeletePrivateConnection(google::cloud::datastream::v1::DeletePrivateConnectionRequest const &)
- virtual DeletePrivateConnection(NoAwaitTag, google::cloud::datastream::v1::DeletePrivateConnectionRequest const &)
- virtual DeletePrivateConnection(google::longrunning::Operation const &)
- virtual CreateRoute(google::cloud::datastream::v1::CreateRouteRequest const &)
- virtual CreateRoute(NoAwaitTag, google::cloud::datastream::v1::CreateRouteRequest const &)
- virtual CreateRoute(google::longrunning::Operation const &)
- virtual GetRoute(google::cloud::datastream::v1::GetRouteRequest const &)
- virtual ListRoutes(google::cloud::datastream::v1::ListRoutesRequest)
- virtual DeleteRoute(google::cloud::datastream::v1::DeleteRouteRequest const &)
- virtual DeleteRoute(NoAwaitTag, google::cloud::datastream::v1::DeleteRouteRequest const &)
- virtual DeleteRoute(google::longrunning::Operation const &)
-
DatastreamConnectionIdempotencyPolicy
-
DatastreamLimitedErrorCountRetryPolicy
-
DatastreamLimitedTimeRetryPolicy
-
Structs
-
google::cloud::datastream_v1_mocks
- Overview
-
Classes
-
MockDatastreamConnection
- Overview
-
Functions
- virtual options()
- virtual ListConnectionProfiles(google::cloud::datastream::v1::ListConnectionProfilesRequest)
- virtual GetConnectionProfile(google::cloud::datastream::v1::GetConnectionProfileRequest const &)
- virtual CreateConnectionProfile(google::cloud::datastream::v1::CreateConnectionProfileRequest const &)
- virtual CreateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::CreateConnectionProfileRequest const &)
- virtual CreateConnectionProfile(google::longrunning::Operation const &)
- virtual UpdateConnectionProfile(google::cloud::datastream::v1::UpdateConnectionProfileRequest const &)
- virtual UpdateConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::UpdateConnectionProfileRequest const &)
- virtual UpdateConnectionProfile(google::longrunning::Operation const &)
- virtual DeleteConnectionProfile(google::cloud::datastream::v1::DeleteConnectionProfileRequest const &)
- virtual DeleteConnectionProfile(NoAwaitTag, google::cloud::datastream::v1::DeleteConnectionProfileRequest const &)
- virtual DeleteConnectionProfile(google::longrunning::Operation const &)
- virtual DiscoverConnectionProfile(google::cloud::datastream::v1::DiscoverConnectionProfileRequest const &)
- virtual ListStreams(google::cloud::datastream::v1::ListStreamsRequest)
- virtual GetStream(google::cloud::datastream::v1::GetStreamRequest const &)
- virtual CreateStream(google::cloud::datastream::v1::CreateStreamRequest const &)
- virtual CreateStream(NoAwaitTag, google::cloud::datastream::v1::CreateStreamRequest const &)
- virtual CreateStream(google::longrunning::Operation const &)
- virtual UpdateStream(google::cloud::datastream::v1::UpdateStreamRequest const &)
- virtual UpdateStream(NoAwaitTag, google::cloud::datastream::v1::UpdateStreamRequest const &)
- virtual UpdateStream(google::longrunning::Operation const &)
- virtual DeleteStream(google::cloud::datastream::v1::DeleteStreamRequest const &)
- virtual DeleteStream(NoAwaitTag, google::cloud::datastream::v1::DeleteStreamRequest const &)
- virtual DeleteStream(google::longrunning::Operation const &)
- virtual GetStreamObject(google::cloud::datastream::v1::GetStreamObjectRequest const &)
- virtual LookupStreamObject(google::cloud::datastream::v1::LookupStreamObjectRequest const &)
- virtual ListStreamObjects(google::cloud::datastream::v1::ListStreamObjectsRequest)
- virtual StartBackfillJob(google::cloud::datastream::v1::StartBackfillJobRequest const &)
- virtual StopBackfillJob(google::cloud::datastream::v1::StopBackfillJobRequest const &)
- virtual FetchStaticIps(google::cloud::datastream::v1::FetchStaticIpsRequest)
- virtual CreatePrivateConnection(google::cloud::datastream::v1::CreatePrivateConnectionRequest const &)
- virtual CreatePrivateConnection(NoAwaitTag, google::cloud::datastream::v1::CreatePrivateConnectionRequest const &)
- virtual CreatePrivateConnection(google::longrunning::Operation const &)
- virtual GetPrivateConnection(google::cloud::datastream::v1::GetPrivateConnectionRequest const &)
- virtual ListPrivateConnections(google::cloud::datastream::v1::ListPrivateConnectionsRequest)
- virtual DeletePrivateConnection(google::cloud::datastream::v1::DeletePrivateConnectionRequest const &)
- virtual DeletePrivateConnection(NoAwaitTag, google::cloud::datastream::v1::DeletePrivateConnectionRequest const &)
- virtual DeletePrivateConnection(google::longrunning::Operation const &)
- virtual CreateRoute(google::cloud::datastream::v1::CreateRouteRequest const &)
- virtual CreateRoute(NoAwaitTag, google::cloud::datastream::v1::CreateRouteRequest const &)
- virtual CreateRoute(google::longrunning::Operation const &)
- virtual GetRoute(google::cloud::datastream::v1::GetRouteRequest const &)
- virtual ListRoutes(google::cloud::datastream::v1::ListRoutesRequest)
- virtual DeleteRoute(google::cloud::datastream::v1::DeleteRouteRequest const &)
- virtual DeleteRoute(NoAwaitTag, google::cloud::datastream::v1::DeleteRouteRequest const &)
- virtual DeleteRoute(google::longrunning::Operation const &)
Stay organized with collections Save and categorize content based on your preferences.
Override Retry, Backoff, and Idempotency Policies
When it is safe to do so, the library automatically retries requests that fail due to a transient error. The library then uses exponential backoff to backoff before trying again. Which operations are considered safe to retry, which errors are treated as transient failures, the details of the exponential backoff algorithm, and for how long the library retries are all configurable via policies.
This document provides examples showing how to override the default policies.
The policies can be set when the *Connection
object is created. The library provides default policies for any policy that is not set. The application can also override some (or all) policies when the *Client
object is created. This can be useful if multiple *Client
objects share the same *Connection
object, but you want different retry behavior in some of the clients. Finally, the application can override some retry policies when calling a specific member function.
The library uses three different options to control the retry loop. The options have per-client names.
Configuring the transient errors and retry duration
The *RetryPolicyOption
controls:
- Which errors are to be treated as transient errors.
- How long the library will keep retrying transient errors.
You can provide your own class for this option. The library also provides two built-in policies:
*LimitedErrorCountRetryPolicy
: stops retrying after a specified number of transient errors.
*LimitedTimeRetryPolicy
: stops retrying after a specified time.
Note that a library may have more than one version of these classes. Their name match the *Client
and *Connection
object they are intended to be used with. Some *Client
objects treat different error codes as transient errors. In most cases, only kUnavailable is treated as a transient error.
Controlling the backoff algorithm
The *BackoffPolicyOption
controls how long the client library will wait before retrying a request that failed with a transient error. You can provide your own class for this option.
The only built-in backoff policy is ExponentialBackoffPolicy
. This class implements a truncated exponential backoff algorithm, with jitter. In summary, it doubles the current backoff time after each failure. The actual backoff time for an RPC is chosen at random, but never exceeds the current backoff. The current backoff is doubled after each failure, but never exceeds (or is "truncated") if it reaches a prescribed maximum.
Controlling which operations are retryable
The *IdempotencyPolicyOption
controls which requests are retryable, as some requests are never safe to retry.
Only one built-in idempotency policy is provided by the library. The name matches the name of the client it is intended for. For example, FooBarClient
will use FooBarIdempotencyPolicy
. This policy is very conservative.
Example
For example, this will override the retry policies for datastream_v1::DatastreamClient
:
auto options =
google::cloud::Options{}
.set<google::cloud::datastream_v1::
DatastreamConnectionIdempotencyPolicyOption>(
CustomIdempotencyPolicy().clone())
.set<google::cloud::datastream_v1::DatastreamRetryPolicyOption>(
google::cloud::datastream_v1::
DatastreamLimitedErrorCountRetryPolicy(3)
.clone())
.set<google::cloud::datastream_v1::DatastreamBackoffPolicyOption>(
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection =
google::cloud::datastream_v1::MakeDatastreamConnection(options);
// c1 and c2 share the same retry policies
auto c1 = google::cloud::datastream_v1::DatastreamClient(connection);
auto c2 = google::cloud::datastream_v1::DatastreamClient(connection);
// You can override any of the policies in a new client. This new client
// will share the policies from c1 (or c2) *except* for the retry policy.
auto c3 = google::cloud::datastream_v1::DatastreamClient(
connection,
google::cloud::Options{}
.set<google::cloud::datastream_v1::DatastreamRetryPolicyOption>(
google::cloud::datastream_v1::DatastreamLimitedTimeRetryPolicy(
std::chrono::minutes(5))
.clone()));
// You can also override the policies in a single call:
// c3.SomeRpc(..., google::cloud::Options{}
// .set<google::cloud::datastream_v1::DatastreamRetryPolicyOption>(
// google::cloud::datastream_v1::DatastreamLimitedErrorCountRetryPolicy(10).clone()));
This assumes you have created a custom idempotency policy. Such as:
class CustomIdempotencyPolicy : public google::cloud::datastream_v1::
DatastreamConnectionIdempotencyPolicy {
public:
~CustomIdempotencyPolicy() override = default;
std::unique_ptr<
google::cloud::datastream_v1::DatastreamConnectionIdempotencyPolicy>
clone() const override {
return std::make_unique<CustomIdempotencyPolicy>(*this);
}
// Override inherited functions to define as needed.
};
This will override the polling policies for datastream_v1::DatastreamClient
// The polling policy controls how the client waits for long-running
// operations. `GenericPollingPolicy<>` combines existing policies.
// In this case, keep polling until the operation completes (with success
// or error) or 45 minutes, whichever happens first. Initially pause for
// 10 seconds between polling requests, increasing the pause by a factor
// of 4 until it becomes 2 minutes.
auto options =
google::cloud::Options{}
.set<google::cloud::datastream_v1::DatastreamPollingPolicyOption>(
google::cloud::GenericPollingPolicy<
google::cloud::datastream_v1::DatastreamRetryPolicyOption::
Type,
google::cloud::datastream_v1::DatastreamBackoffPolicyOption::
Type>(
google::cloud::datastream_v1::
DatastreamLimitedTimeRetryPolicy(
/*maximum_duration=*/std::chrono::minutes(45))
.clone(),
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::seconds(10),
/*maximum_delay=*/std::chrono::minutes(2),
/*scaling=*/4.0)
.clone())
.clone());
auto connection =
google::cloud::datastream_v1::MakeDatastreamConnection(options);
// c1 and c2 share the same polling policies.
auto c1 = google::cloud::datastream_v1::DatastreamClient(connection);
auto c2 = google::cloud::datastream_v1::DatastreamClient(connection);
More Information See Also
google::cloud::Options
See Also
google::cloud::BackoffPolicy
See Also
google::cloud::ExponentialBackoffPolicy
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["This page documents the override options for retry, backoff, and idempotency policies within the client library when handling transient errors."],["The library automatically retries requests that fail due to transient errors, using exponential backoff and configurable policies for retries, transient errors, and backoff."],["Retry policies can be customized using options like `*RetryPolicyOption`, `*BackoffPolicyOption`, and `*IdempotencyPolicyOption`, and there are also pre-built options such as `*LimitedErrorCountRetryPolicy` and `*LimitedTimeRetryPolicy`."],["Retry policies can be set when creating the `*Connection` object, `*Client` object, or when calling specific member functions."],["The library uses `ExponentialBackoffPolicy` to set a truncated exponential backoff, doubling the time after each failure, and `GenericPollingPolicy` to configure the time between polling requests for operations."]]],[]]
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4