Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generator): document retry policies #12024

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,128 @@ namespace cloud {
namespace golden_v1 {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

using GoldenKitchenSinkRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy<
golden_v1_internal::GoldenKitchenSinkRetryTraits>;

using GoldenKitchenSinkLimitedTimeRetryPolicy = ::google::cloud::internal::LimitedTimeRetryPolicy<
golden_v1_internal::GoldenKitchenSinkRetryTraits>;
/// The retry policy for `GoldenKitchenSinkConnection`.
class GoldenKitchenSinkRetryPolicy : public ::google::cloud::RetryPolicy {
public:
/// Creates a new instance of the policy, reset to the initial state.
virtual std::unique_ptr<GoldenKitchenSinkRetryPolicy> clone() const = 0;
};

/**
* A retry policy for `GoldenKitchenSinkConnection` based on counting errors.
*
* This policy stops retrying if:
* - An RPC returns a non-transient error.
* - More than a prescribed number of transient failures is detected.
*
* In this class the following status codes are treated as transient errors:
* - [`kInternal`](@ref google::cloud::StatusCode)
* - [`kUnavailable`](@ref google::cloud::StatusCode)
*/
class GoldenKitchenSinkLimitedErrorCountRetryPolicy : public GoldenKitchenSinkRetryPolicy {
public:
/**
* Create an instance that tolerates up to @p maximum_failures transient
* errors.
*
* @note Disable the retry loop by providing an instance of this policy with
* @p maximum_failures == 0.
*/
explicit GoldenKitchenSinkLimitedErrorCountRetryPolicy(int maximum_failures)
: impl_(maximum_failures) {}

GoldenKitchenSinkLimitedErrorCountRetryPolicy(
GoldenKitchenSinkLimitedErrorCountRetryPolicy&& rhs) noexcept
: GoldenKitchenSinkLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {}
GoldenKitchenSinkLimitedErrorCountRetryPolicy(
GoldenKitchenSinkLimitedErrorCountRetryPolicy const& rhs) noexcept
: GoldenKitchenSinkLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {}

int maximum_failures() const { return impl_.maximum_failures(); }

bool OnFailure(Status const& status) override {
return impl_.OnFailure(status);
}
bool IsExhausted() const override { return impl_.IsExhausted(); }
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenKitchenSinkRetryPolicy> clone() const override {
return std::make_unique<GoldenKitchenSinkLimitedErrorCountRetryPolicy>(
maximum_failures());
}

// This is provided only for backwards compatibility.
using BaseType = GoldenKitchenSinkRetryPolicy;
private:
google::cloud::internal::LimitedErrorCountRetryPolicy<golden_v1_internal::GoldenKitchenSinkRetryTraits> impl_;
};

using GoldenKitchenSinkLimitedErrorCountRetryPolicy =
::google::cloud::internal::LimitedErrorCountRetryPolicy<
golden_v1_internal::GoldenKitchenSinkRetryTraits>;
/**
* A retry policy for `GoldenKitchenSinkConnection` based on elapsed time.
*
* This policy stops retrying if:
* - An RPC returns a non-transient error.
* - The elapsed time in the retry loop exceeds a prescribed duration.
*
* In this class the following status codes are treated as transient errors:
* - [`kInternal`](@ref google::cloud::StatusCode)
* - [`kUnavailable`](@ref google::cloud::StatusCode)
*/
class GoldenKitchenSinkLimitedTimeRetryPolicy : public GoldenKitchenSinkRetryPolicy {
public:
/**
* Constructor given a `std::chrono::duration<>` object.
*
* @tparam DurationRep a placeholder to match the `Rep` tparam for @p
* duration's type. The semantics of this template parameter are
* documented in `std::chrono::duration<>`. In brief, the underlying
* arithmetic type used to store the number of ticks. For our purposes it
* is simply a formal parameter.
* @tparam DurationPeriod a placeholder to match the `Period` tparam for @p
* duration's type. The semantics of this template parameter are
* documented in `std::chrono::duration<>`. In brief, the length of the
* tick in seconds, expressed as a `std::ratio<>`. For our purposes it is
* simply a formal parameter.
* @param maximum_duration the maximum time allowed before the policy expires.
* While the application can express this time in any units they desire,
* the class truncates to milliseconds.
*
* @see https://en.cppreference.com/w/cpp/chrono/duration for more information
* about `std::chrono::duration`.
*/
template <typename DurationRep, typename DurationPeriod>
explicit GoldenKitchenSinkLimitedTimeRetryPolicy(
std::chrono::duration<DurationRep, DurationPeriod> maximum_duration)
: impl_(maximum_duration) {}

GoldenKitchenSinkLimitedTimeRetryPolicy(GoldenKitchenSinkLimitedTimeRetryPolicy&& rhs) noexcept
: GoldenKitchenSinkLimitedTimeRetryPolicy(rhs.maximum_duration()) {}
GoldenKitchenSinkLimitedTimeRetryPolicy(GoldenKitchenSinkLimitedTimeRetryPolicy const& rhs) noexcept
: GoldenKitchenSinkLimitedTimeRetryPolicy(rhs.maximum_duration()) {}

std::chrono::milliseconds maximum_duration() const {
return impl_.maximum_duration();
}

bool OnFailure(Status const& status) override {
return impl_.OnFailure(status);
}
bool IsExhausted() const override { return impl_.IsExhausted(); }
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenKitchenSinkRetryPolicy> clone() const override {
return std::make_unique<GoldenKitchenSinkLimitedTimeRetryPolicy>(
maximum_duration());
}

// This is provided only for backwards compatibility.
using BaseType = GoldenKitchenSinkRetryPolicy;
private:
google::cloud::internal::LimitedTimeRetryPolicy<golden_v1_internal::GoldenKitchenSinkRetryTraits> impl_;
};

/**
* The `GoldenKitchenSinkConnection` object for `GoldenKitchenSinkClient`.
Expand Down
125 changes: 118 additions & 7 deletions generator/integration_tests/golden/v1/golden_rest_only_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,126 @@ namespace cloud {
namespace golden_v1 {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

using GoldenRestOnlyRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy<
golden_v1_internal::GoldenRestOnlyRetryTraits>;

using GoldenRestOnlyLimitedTimeRetryPolicy = ::google::cloud::internal::LimitedTimeRetryPolicy<
golden_v1_internal::GoldenRestOnlyRetryTraits>;
/// The retry policy for `GoldenRestOnlyConnection`.
class GoldenRestOnlyRetryPolicy : public ::google::cloud::RetryPolicy {
public:
/// Creates a new instance of the policy, reset to the initial state.
virtual std::unique_ptr<GoldenRestOnlyRetryPolicy> clone() const = 0;
};

/**
* A retry policy for `GoldenRestOnlyConnection` based on counting errors.
*
* This policy stops retrying if:
* - An RPC returns a non-transient error.
* - More than a prescribed number of transient failures is detected.
*
* In this class the following status codes are treated as transient errors:
* - [`kUnavailable`](@ref google::cloud::StatusCode)
*/
class GoldenRestOnlyLimitedErrorCountRetryPolicy : public GoldenRestOnlyRetryPolicy {
public:
/**
* Create an instance that tolerates up to @p maximum_failures transient
* errors.
*
* @note Disable the retry loop by providing an instance of this policy with
* @p maximum_failures == 0.
*/
explicit GoldenRestOnlyLimitedErrorCountRetryPolicy(int maximum_failures)
: impl_(maximum_failures) {}

GoldenRestOnlyLimitedErrorCountRetryPolicy(
GoldenRestOnlyLimitedErrorCountRetryPolicy&& rhs) noexcept
: GoldenRestOnlyLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {}
GoldenRestOnlyLimitedErrorCountRetryPolicy(
GoldenRestOnlyLimitedErrorCountRetryPolicy const& rhs) noexcept
: GoldenRestOnlyLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {}

int maximum_failures() const { return impl_.maximum_failures(); }

bool OnFailure(Status const& status) override {
return impl_.OnFailure(status);
}
bool IsExhausted() const override { return impl_.IsExhausted(); }
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenRestOnlyRetryPolicy> clone() const override {
return std::make_unique<GoldenRestOnlyLimitedErrorCountRetryPolicy>(
maximum_failures());
}

// This is provided only for backwards compatibility.
using BaseType = GoldenRestOnlyRetryPolicy;
private:
google::cloud::internal::LimitedErrorCountRetryPolicy<golden_v1_internal::GoldenRestOnlyRetryTraits> impl_;
};

using GoldenRestOnlyLimitedErrorCountRetryPolicy =
::google::cloud::internal::LimitedErrorCountRetryPolicy<
golden_v1_internal::GoldenRestOnlyRetryTraits>;
/**
* A retry policy for `GoldenRestOnlyConnection` based on elapsed time.
*
* This policy stops retrying if:
* - An RPC returns a non-transient error.
* - The elapsed time in the retry loop exceeds a prescribed duration.
*
* In this class the following status codes are treated as transient errors:
* - [`kUnavailable`](@ref google::cloud::StatusCode)
*/
class GoldenRestOnlyLimitedTimeRetryPolicy : public GoldenRestOnlyRetryPolicy {
public:
/**
* Constructor given a `std::chrono::duration<>` object.
*
* @tparam DurationRep a placeholder to match the `Rep` tparam for @p
* duration's type. The semantics of this template parameter are
* documented in `std::chrono::duration<>`. In brief, the underlying
* arithmetic type used to store the number of ticks. For our purposes it
* is simply a formal parameter.
* @tparam DurationPeriod a placeholder to match the `Period` tparam for @p
* duration's type. The semantics of this template parameter are
* documented in `std::chrono::duration<>`. In brief, the length of the
* tick in seconds, expressed as a `std::ratio<>`. For our purposes it is
* simply a formal parameter.
* @param maximum_duration the maximum time allowed before the policy expires.
* While the application can express this time in any units they desire,
* the class truncates to milliseconds.
*
* @see https://en.cppreference.com/w/cpp/chrono/duration for more information
* about `std::chrono::duration`.
*/
template <typename DurationRep, typename DurationPeriod>
explicit GoldenRestOnlyLimitedTimeRetryPolicy(
std::chrono::duration<DurationRep, DurationPeriod> maximum_duration)
: impl_(maximum_duration) {}

GoldenRestOnlyLimitedTimeRetryPolicy(GoldenRestOnlyLimitedTimeRetryPolicy&& rhs) noexcept
: GoldenRestOnlyLimitedTimeRetryPolicy(rhs.maximum_duration()) {}
GoldenRestOnlyLimitedTimeRetryPolicy(GoldenRestOnlyLimitedTimeRetryPolicy const& rhs) noexcept
: GoldenRestOnlyLimitedTimeRetryPolicy(rhs.maximum_duration()) {}

std::chrono::milliseconds maximum_duration() const {
return impl_.maximum_duration();
}

bool OnFailure(Status const& status) override {
return impl_.OnFailure(status);
}
bool IsExhausted() const override { return impl_.IsExhausted(); }
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenRestOnlyRetryPolicy> clone() const override {
return std::make_unique<GoldenRestOnlyLimitedTimeRetryPolicy>(
maximum_duration());
}

// This is provided only for backwards compatibility.
using BaseType = GoldenRestOnlyRetryPolicy;
private:
google::cloud::internal::LimitedTimeRetryPolicy<golden_v1_internal::GoldenRestOnlyRetryTraits> impl_;
};

/**
* The `GoldenRestOnlyConnection` object for `GoldenRestOnlyClient`.
Expand Down
Loading