Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
rpc_retry_policy.cc
Go to the documentation of this file.
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/rpc_retry_policy.h"
16 #include "google/cloud/grpc_utils/grpc_error_delegate.h"
17 #include <sstream>
18 
19 namespace google {
20 namespace cloud {
21 namespace bigtable {
22 inline namespace BIGTABLE_CLIENT_NS {
25  return std::unique_ptr<RPCRetryPolicy>(
26  new LimitedTimeRetryPolicy(defaults.maximum_retry_period));
27 }
28 
30  return std::unique_ptr<RPCRetryPolicy>(
31  new LimitedErrorCountRetryPolicy(*this));
32 }
33 
35 
37  google::cloud::Status const& status) {
38  return impl_.OnFailure(status);
39 }
40 
41 bool LimitedErrorCountRetryPolicy::OnFailure(grpc::Status const& status) {
42  return impl_.OnFailure(grpc_utils::MakeStatusFromRpcError(status));
43 }
44 
45 LimitedTimeRetryPolicy::LimitedTimeRetryPolicy(
46  internal::RPCPolicyParameters defaults)
47  : impl_(defaults.maximum_retry_period) {}
48 
49 std::unique_ptr<RPCRetryPolicy> LimitedTimeRetryPolicy::clone() const {
50  return std::unique_ptr<RPCRetryPolicy>(new LimitedTimeRetryPolicy(*this));
51 }
52 
53 void LimitedTimeRetryPolicy::Setup(grpc::ClientContext& context) const {
54  if (context.deadline() >= impl_.deadline()) {
55  context.set_deadline(impl_.deadline());
56  }
57 }
58 
59 bool LimitedTimeRetryPolicy::OnFailure(google::cloud::Status const& status) {
60  return impl_.OnFailure(status);
61 }
62 
63 bool LimitedTimeRetryPolicy::OnFailure(grpc::Status const& status) {
64  return impl_.OnFailure(grpc_utils::MakeStatusFromRpcError(status));
65 }
66 
67 } // namespace BIGTABLE_CLIENT_NS
68 } // namespace bigtable
69 } // namespace cloud
70 } // namespace google
std::unique_ptr< RPCRetryPolicy > clone() const override
Return a new copy of this object.
std::unique_ptr< RPCRetryPolicy > DefaultRPCRetryPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCRetryPolicy.
bool OnFailure(google::cloud::Status const &status) override
Handle an RPC failure.
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
void Setup(grpc::ClientContext &context) const override
Update the ClientContext for the next call.
Implement a simple "count errors and then stop" retry policy.
Contains all the Cloud Bigtable C++ client APIs.