|
| 1 | +/*! |
| 2 | +@page golden-override-retry Override Retry, Backoff, and Idempotency Policies |
| 3 | + |
| 4 | +When it is safe to do so, the library automatically retries requests that fail |
| 5 | +due to a transient error. The library then uses [exponential backoff] to backoff |
| 6 | +before trying again. Which operations are considered safe to retry, which |
| 7 | +errors are treated as transient failures, the details of the exponential backoff |
| 8 | +algorithm, and for how long the library retries are all configurable via |
| 9 | +policies. |
| 10 | + |
| 11 | +This document provides examples showing how to override the default policies. |
| 12 | + |
| 13 | +The policies can be set when the `*Connection` object is created. The library |
| 14 | +provides default policies for any policy that is not set. The application can |
| 15 | +also override some (or all) policies when the `*Client` object is created. This |
| 16 | +can be useful if multiple `*Client` objects share the same `*Connection` object, |
| 17 | +but you want different retry behavior in some of the clients. Finally, the |
| 18 | +application can override some retry policies when calling a specific member |
| 19 | +function. |
| 20 | + |
| 21 | +The library uses three different options to control the retry loop. The options |
| 22 | +have per-client names. |
| 23 | + |
| 24 | +@section golden-override-retry-retry-policy Configuring the transient errors and retry duration |
| 25 | + |
| 26 | +The `*RetryPolicyOption` controls: |
| 27 | + |
| 28 | +- Which errors are to be treated as transient errors. |
| 29 | +- How long the library will keep retrying transient errors. |
| 30 | + |
| 31 | +You can provide your own class for this option. The library also provides two |
| 32 | +built-in policies: |
| 33 | + |
| 34 | +- `*LimitedErrorCountRetryPolicy`: stops retrying after a specified number |
| 35 | + of transient errors. |
| 36 | +- `*LimitedTimeRetryPolicy`: stops retrying after a specified time. |
| 37 | + |
| 38 | +Note that a library may have more than one version of these classes. Their name |
| 39 | +match the `*Client` and `*Connection` object they are intended to be used |
| 40 | +with. Some `*Client` objects treat different error codes as transient errors. |
| 41 | +In most cases, only [kUnavailable](@ref google::cloud::StatusCode) is treated |
| 42 | +as a transient error. |
| 43 | + |
| 44 | +@section golden-override-retry-backoff-policy Controlling the backoff algorithm |
| 45 | + |
| 46 | +The `*BackoffPolicyOption` controls how long the client library will wait |
| 47 | +before retrying a request that failed with a transient error. You can provide |
| 48 | +your own class for this option. |
| 49 | + |
| 50 | +The only built-in backoff policy is |
| 51 | +[`ExponentialBackoffPolicy`](@ref google::cloud::ExponentialBackoffPolicy). |
| 52 | +This class implements a truncated exponential backoff algorithm, with jitter. |
| 53 | +In summary, it doubles the current backoff time after each failure. The actual |
| 54 | +backoff time for an RPC is chosen at random, but never exceeds the current |
| 55 | +backoff. The current backoff is doubled after each failure, but never exceeds |
| 56 | +(or is "truncated") if it reaches a prescribed maximum. |
| 57 | + |
| 58 | +@section golden-override-retry-idempotency-policy Controlling which operations are retryable |
| 59 | + |
| 60 | +The `*IdempotencyPolicyOption` controls which requests are retryable, as some |
| 61 | +requests are never safe to retry. |
| 62 | + |
| 63 | +Only one built-in idempotency policy is provided by the library. The name |
| 64 | +matches the name of the client it is intended for. For example, `FooBarClient` |
| 65 | +will use `FooBarIdempotencyPolicy`. This policy is very conservative. |
| 66 | + |
| 67 | +@section golden-override-retry-example Example |
| 68 | + |
| 69 | +<!-- inject-retry-snippet-start --> |
| 70 | +<!-- inject-retry-snippet-end --> |
| 71 | + |
| 72 | +@section golden-override-retry-more-information More Information |
| 73 | + |
| 74 | +@see google::cloud::Options |
| 75 | +@see google::cloud::BackoffPolicy |
| 76 | +@see google::cloud::ExponentialBackoffPolicy |
| 77 | + |
| 78 | +[exponential backoff]: https://en.wikipedia.org/wiki/Exponential_backoff |
| 79 | + |
| 80 | +*/ |
| 81 | + |
| 82 | +// <!-- inject-retry-pages-start --> |
| 83 | +// <!-- inject-retry-pages-end --> |
0 commit comments