/// <summary> /// Returns a <see cref="RetrySettings"/> using the specified maximum number of attempts and an exponential backoff. /// </summary> /// <param name="maxAttempts">The maximum number of attempts to make. Must be positive.</param> /// <param name="initialBackoff">The backoff after the initial failure. Must be non-negative.</param> /// <param name="maxBackoff">The maximum backoff. Must be at least <paramref name="initialBackoff"/>.</param> /// <param name="backoffMultiplier">The multiplier to apply to backoff times. Must be at least 1.0.</param> /// <param name="retryFilter">The predicate to use to check whether an error should be retried. Must not be null.</param> /// <param name="backoffJitter">The jitter to use on each backoff. May be null, in which case <see cref="RandomJitter"/> is used.</param> /// <returns>A retry with exponential backoff.</returns> public static RetrySettings FromExponentialBackoff(int maxAttempts, TimeSpan initialBackoff, TimeSpan maxBackoff, double backoffMultiplier, Predicate <Exception> retryFilter, IJitter backoffJitter = null) => new RetrySettings(maxAttempts, initialBackoff, maxBackoff, backoffMultiplier, retryFilter, backoffJitter ?? RandomJitter);
internal RetryState(IScheduler scheduler, BackoffSettings backoffSettings, IJitter backoffJitter, int maxConsecutiveErrors) { _scheduler = scheduler; _backoffSettings = backoffSettings; _backoffJitter = backoffJitter; _maxConsecutiveErrors = maxConsecutiveErrors; Reset(); }
/// <summary> /// Constructs an instance with the given configuration. /// </summary> /// <param name="retryBackoff">The backoff policy for the time between retries. Must not be null.</param> /// <param name="timeoutBackoff">The backoff policy for timeouts of retries. Must not be null.</param> /// <param name="totalExpiration">The total expiration, across all retries. Must not be null.</param> /// <param name="retryFilter">A predicate to determine whether or not a particular exception should cause the operation to be retried, /// or null for the default filter.</param> /// <param name="delayJitter">The delay jitter to apply for delays, or null for the defautl (random) jitter.</param> public RetrySettings( BackoffSettings retryBackoff, BackoffSettings timeoutBackoff, Expiration totalExpiration, Predicate <RpcException> retryFilter, IJitter delayJitter) { RetryBackoff = GaxPreconditions.CheckNotNull(retryBackoff, nameof(retryBackoff)); TimeoutBackoff = GaxPreconditions.CheckNotNull(timeoutBackoff, nameof(timeoutBackoff)); TotalExpiration = GaxPreconditions.CheckNotNull(totalExpiration, nameof(totalExpiration)); RetryFilter = retryFilter ?? DefaultFilter; DelayJitter = delayJitter ?? RandomJitter; }
/// <summary> /// Creates a new instance with the given settings. /// </summary> /// <param name="maxAttempts">The maximum number of attempts to make. Must be positive.</param> /// <param name="initialBackoff">The backoff after the initial failure. Must be non-negative.</param> /// <param name="maxBackoff">The maximum backoff. Must be at least <paramref name="initialBackoff"/>.</param> /// <param name="backoffMultiplier">The multiplier to apply to backoff times. Must be at least 1.0.</param> /// <param name="retryFilter">The predicate to use to check whether an error should be retried. Must not be null.</param> /// <param name="backoffJitter">The jitter to use on each backoff. Must not be null.</param> internal RetrySettings( int maxAttempts, TimeSpan initialBackoff, TimeSpan maxBackoff, double backoffMultiplier, Predicate <Exception> retryFilter, IJitter backoffJitter) { MaxAttempts = GaxPreconditions.CheckArgumentRange(maxAttempts, nameof(maxAttempts), 1, int.MaxValue); InitialBackoff = GaxPreconditions.CheckNonNegativeDelay(initialBackoff, nameof(initialBackoff)); MaxBackoff = GaxPreconditions.CheckNonNegativeDelay(maxBackoff, nameof(maxBackoff)); GaxPreconditions.CheckArgument(maxBackoff >= initialBackoff, nameof(maxBackoff), "Maximum backoff must be at least as large as initial backoff"); BackoffMultiplier = GaxPreconditions.CheckArgumentRange(backoffMultiplier, nameof(backoffMultiplier), 1.0, double.MaxValue); RetryFilter = GaxPreconditions.CheckNotNull(retryFilter, nameof(retryFilter)); BackoffJitter = GaxPreconditions.CheckNotNull(backoffJitter, nameof(backoffJitter)); }
/// <summary> /// Constructor with complete control, for testing purposes. /// </summary> internal SqlResultStream( SpannerClient client, ExecuteSqlRequest request, Session session, CallSettings callSettings, int maxBufferSize, BackoffSettings backoffSettings, IJitter backoffJitter) { _buffer = new LinkedList <PartialResultSet>(); _client = GaxPreconditions.CheckNotNull(client, nameof(client)); _request = GaxPreconditions.CheckNotNull(request, nameof(request)); _session = GaxPreconditions.CheckNotNull(session, nameof(session)); _callSettings = callSettings; _maxBufferSize = GaxPreconditions.CheckArgumentRange(maxBufferSize, nameof(maxBufferSize), 1, 10_000); _backoffSettings = GaxPreconditions.CheckNotNull(backoffSettings, nameof(backoffSettings)); _backoffJitter = GaxPreconditions.CheckNotNull(backoffJitter, nameof(backoffJitter)); }
/// <summary> /// Returns a <see cref="RetrySettings"/> using the specified maximum number of attempts and a constant backoff. /// Jitter is still applied to each backoff, but the "base" value of the backoff is always <paramref name="backoff"/>. /// </summary> /// <param name="maxAttempts">The maximum number of attempts to make. Must be positive.</param> /// <param name="backoff">The backoff after each failure. Must be non-negative.</param> /// <param name="retryFilter">The predicate to use to check whether an error should be retried. Must not be null.</param> /// <param name="backoffJitter">The jitter to use on each backoff. May be null, in which case <see cref="RandomJitter"/> is used.</param> /// <returns>A retry with constant backoff.</returns> public static RetrySettings FromConstantBackoff(int maxAttempts, TimeSpan backoff, Predicate <Exception> retryFilter, IJitter backoffJitter = null) => new RetrySettings(maxAttempts, backoff, backoff, 1.0, retryFilter, backoffJitter ?? RandomJitter);
public PatternCompiler(ICompiler compiler, IOptimizer optimizer, IJitter jitter) { Compiler = compiler; Optimizer = optimizer; Jitter = jitter; }
internal RetryState(IScheduler scheduler, BackoffSettings backoffSettings, IJitter backoffJitter) : this(scheduler, backoffSettings, backoffJitter, DefaultMaxConsecutiveErrors) { }
/// <summary> /// Constructs an instance with the given configuration. /// </summary> /// <param name="retryBackoff">The backoff policy for the time between retries. Must not be null.</param> /// <param name="timeoutBackoff">The backoff policy for timeouts of retries. Must not be null.</param> /// <param name="totalExpiration">The total expiration, across all retries. Must not be null.</param> /// <param name="retryFilter">A predicate to determine whether or not a particular exception should cause the operation to be retried, /// or null for the default filter.</param> /// <param name="delayJitter">The delay jitter to apply for delays, or null for the defautl (random) jitter.</param> public RetrySettings( BackoffSettings retryBackoff, BackoffSettings timeoutBackoff, Expiration totalExpiration, Predicate<RpcException> retryFilter, IJitter delayJitter) { RetryBackoff = GaxPreconditions.CheckNotNull(retryBackoff, nameof(retryBackoff)); TimeoutBackoff = GaxPreconditions.CheckNotNull(timeoutBackoff, nameof(timeoutBackoff)); TotalExpiration = GaxPreconditions.CheckNotNull(totalExpiration, nameof(totalExpiration)); RetryFilter = retryFilter ?? DefaultFilter; DelayJitter = delayJitter ?? RandomJitter; }