Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
retry_policy.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
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 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_RETRY_POLICY_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_RETRY_POLICY_H
17 
18 #include "google/cloud/spanner/internal/status_utils.h"
20 #include "google/cloud/internal/retry_policy.h"
21 #include "google/cloud/status.h"
22 
23 namespace google {
24 namespace cloud {
25 namespace spanner {
26 inline namespace SPANNER_CLIENT_NS {
27 
28 namespace internal {
30 struct SafeGrpcRetry {
31  static inline bool IsOk(google::cloud::Status const& status) {
32  return status.ok();
33  }
34  static inline bool IsTransientFailure(google::cloud::Status const& status) {
35  return status.code() == StatusCode::kUnavailable ||
36  status.code() == StatusCode::kResourceExhausted;
37  }
38  static inline bool IsPermanentFailure(google::cloud::Status const& status) {
39  return !IsOk(status) && !IsTransientFailure(status);
40  }
41 };
42 
44 struct SafeTransactionRerun {
45  static inline bool IsOk(google::cloud::Status const& status) {
46  return status.ok();
47  }
48  static inline bool IsTransientFailure(google::cloud::Status const& status) {
49  return status.code() == StatusCode::kAborted || IsSessionNotFound(status);
50  }
51  static inline bool IsPermanentFailure(google::cloud::Status const& status) {
52  return !IsOk(status) && !IsTransientFailure(status);
53  }
54 };
55 } // namespace internal
56 
58 using RetryPolicy =
59  google::cloud::internal::RetryPolicy<google::cloud::Status,
60  internal::SafeGrpcRetry>;
61 
65  internal::SafeGrpcRetry>;
66 
70  google::cloud::Status, internal::SafeGrpcRetry>;
71 
74  google::cloud::internal::RetryPolicy<google::cloud::Status,
75  internal::SafeTransactionRerun>;
76 
80  google::cloud::Status, internal::SafeTransactionRerun>;
81 
85  google::cloud::Status, internal::SafeTransactionRerun>;
86 
87 } // namespace SPANNER_CLIENT_NS
88 } // namespace spanner
89 } // namespace cloud
90 } // namespace google
91 
92 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_RETRY_POLICY_H
google::cloud::internal::LimitedErrorCountRetryPolicy< google::cloud::Status, internal::SafeTransactionRerun > LimitedErrorCountTransactionRerunPolicy
A transaction rerun policy that limits the number of failures.
Definition: retry_policy.h:85
google::cloud::internal::LimitedTimeRetryPolicy< google::cloud::Status, internal::SafeTransactionRerun > LimitedTimeTransactionRerunPolicy
A transaction rerun policy that limits the duration of the rerun loop.
Definition: retry_policy.h:80
Contains all the Cloud Spanner C++ client types and functions.
google::cloud::internal::RetryPolicy< google::cloud::Status, internal::SafeGrpcRetry > RetryPolicy
The base class for retry policies.
Definition: retry_policy.h:60
google::cloud::internal::LimitedTimeRetryPolicy< google::cloud::Status, internal::SafeGrpcRetry > LimitedTimeRetryPolicy
A retry policy that limits based on time.
Definition: retry_policy.h:65
google::cloud::internal::RetryPolicy< google::cloud::Status, internal::SafeTransactionRerun > TransactionRerunPolicy
The base class for transaction rerun policies.
Definition: retry_policy.h:75
#define SPANNER_CLIENT_NS
Definition: version.h:22
google::cloud::internal::LimitedErrorCountRetryPolicy< google::cloud::Status, internal::SafeGrpcRetry > LimitedErrorCountRetryPolicy
A retry policy that limits the number of times a request can fail.
Definition: retry_policy.h:70