15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_RPC_RETRY_POLICY_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_RPC_RETRY_POLICY_H
18#include "google/cloud/bigtable/internal/rpc_policy_parameters.h"
19#include "google/cloud/bigtable/version.h"
20#include "google/cloud/grpc_error_delegate.h"
21#include "google/cloud/internal/retry_policy.h"
22#include "google/cloud/status.h"
23#include <grpcpp/grpcpp.h>
28namespace bigtable_internal {
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
32class CommonRetryPolicy;
34GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
37GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
41 static inline bool IsOk(
Status const& status) {
return status
.ok(); }
42 static inline bool IsTransientFailure(
Status const& status) {
43 auto const code = status
.code();
45 google::
cloud::internal::IsTransientInternalError(status);
47 static inline bool IsPermanentFailure(
Status const& status) {
48 return !IsOk(status) && !IsTransientFailure(status);
52 static inline bool IsOk(grpc::Status
const& status) {
return status.ok(); }
53 static inline bool IsTransientFailure(grpc::Status
const& status) {
56 static inline bool IsPermanentFailure(grpc::Status
const& status) {
57 return !IsOk(status) && !IsTransientFailure(status);
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
80 using RetryableTraits = internal::SafeGrpcRetry;
85
86
87
88
89
90
91
95
96
97 virtual void Setup(grpc::ClientContext& context)
const = 0;
100
101
102
103
106 virtual bool OnFailure(grpc::Status
const& status) = 0;
109 return internal::SafeGrpcRetry::IsPermanentFailure(status);
113 return internal::SafeGrpcRetry::IsPermanentFailure(status);
116 virtual bool IsExhausted()
const {
return exhausted_; }
119 template <
typename T>
120 friend class bigtable_internal::CommonRetryPolicy;
122 bool exhausted_ =
false;
127 internal::RPCPolicyParameters defaults);
130
131
135 : impl_(maximum_failures) {}
138 void Setup(grpc::ClientContext& context)
const override;
141 bool OnFailure(grpc::Status
const& status)
override;
145 using Impl = ::
google::
cloud::internal::LimitedErrorCountRetryPolicy<
146 internal::SafeGrpcRetry>;
151
152
156 template <
typename DurationT>
158 : impl_(maximum_duration) {}
161 void Setup(grpc::ClientContext& context)
const override;
164 bool OnFailure(grpc::Status
const& status)
override;
168 using Impl = ::
google::
cloud::internal::LimitedTimeRetryPolicy<
169 internal::SafeGrpcRetry>;
173GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
175namespace bigtable_internal {
176GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
178template <
typename ReturnType>
179class CommonRetryPolicy :
public ReturnType {
182 : impl_(std::move(impl)) {}
183 ~CommonRetryPolicy()
override =
default;
185 std::unique_ptr<ReturnType> clone()
const override {
186 return std::make_unique<CommonRetryPolicy>(impl_->
clone());
188 bool OnFailure(
Status const& s)
override {
190 if (!retry && !IsPermanentFailure(s)) impl_->exhausted_ =
true;
193 bool IsExhausted()
const override {
return impl_->
IsExhausted(); }
194 bool IsPermanentFailure(
Status const& s)
const override {
197 void OnFailureImpl()
override {}
203template <
typename ReturnType>
204std::unique_ptr<ReturnType> MakeCommonRetryPolicy(
206 return std::make_unique<CommonRetryPolicy<ReturnType>>(std::move(policy));
209GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Implement a simple "count errors and then stop" retry policy.
Definition: rpc_retry_policy.h:132
void Setup(grpc::ClientContext &context) const override
Update the ClientContext for the next call.
bool OnFailure(Status const &status) override
Handle an RPC failure.
std::unique_ptr< RPCRetryPolicy > clone() const override
Return a new copy of this object.
bool IsExhausted() const override
LimitedErrorCountRetryPolicy(int maximum_failures)
Definition: rpc_retry_policy.h:134
bool OnFailure(grpc::Status const &status) override
Implement a simple "keep trying for this time" retry policy.
Definition: rpc_retry_policy.h:153
LimitedTimeRetryPolicy(DurationT maximum_duration)
Definition: rpc_retry_policy.h:157
bool OnFailure(Status const &status) override
Handle an RPC failure.
LimitedTimeRetryPolicy(internal::RPCPolicyParameters defaults)
std::unique_ptr< RPCRetryPolicy > clone() const override
Return a new copy of this object.
bool IsExhausted() const override
bool OnFailure(grpc::Status const &status) override
void Setup(grpc::ClientContext &context) const override
Update the ClientContext for the next call.
Define the interface for controlling how the Bigtable client retries RPC operations.
Definition: rpc_retry_policy.h:78
virtual bool OnFailure(grpc::Status const &status)=0
virtual bool OnFailure(Status const &status)=0
Handle an RPC failure.
static bool IsPermanentFailure(grpc::Status const &status)
Definition: rpc_retry_policy.h:112
virtual bool IsExhausted() const
Definition: rpc_retry_policy.h:116
static bool IsPermanentFailure(Status const &status)
Definition: rpc_retry_policy.h:108
virtual std::unique_ptr< RPCRetryPolicy > clone() const =0
Return a new copy of this object.
virtual ~RPCRetryPolicy()=default
virtual void Setup(grpc::ClientContext &context) const =0
Update the ClientContext for the next call.
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
std::unique_ptr< RPCRetryPolicy > DefaultRPCRetryPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCRetryPolicy.
google::cloud::Status MakeStatusFromRpcError(grpc::Status const &status)