GRPC Core  9.0.0
backoff.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_BACKOFF_BACKOFF_H
20 #define GRPC_CORE_LIB_BACKOFF_BACKOFF_H
21 
23 
25 
26 namespace grpc_core {
27 
30 class BackOff {
31  public:
32  class Options;
33 
35  explicit BackOff(const Options& options);
36 
39 
42  void Reset();
43 
44  void SetRandomSeed(unsigned int seed);
45 
46  class Options {
47  public:
49  initial_backoff_ = initial_backoff;
50  return *this;
51  }
53  multiplier_ = multiplier;
54  return *this;
55  }
57  jitter_ = jitter;
58  return *this;
59  }
61  max_backoff_ = max_backoff;
62  return *this;
63  }
65  grpc_millis initial_backoff() const { return initial_backoff_; }
67  double multiplier() const { return multiplier_; }
69  double jitter() const { return jitter_; }
71  grpc_millis max_backoff() const { return max_backoff_; }
72 
73  private:
74  grpc_millis initial_backoff_;
75  double multiplier_;
76  double jitter_;
77  grpc_millis max_backoff_;
78  }; // class Options
79 
80  private:
81  const Options options_;
82  uint32_t rng_state_;
83  bool initial_;
85  grpc_millis current_backoff_;
86 };
87 
88 } // namespace grpc_core
89 #endif /* GRPC_CORE_LIB_BACKOFF_BACKOFF_H */
int64_t grpc_millis
Definition: exec_ctx.h:35
Definition: backoff.h:46
void SetRandomSeed(unsigned int seed)
Definition: backoff.cc:76
double multiplier() const
factor with which to multiply backoff after a failed retry
Definition: backoff.h:67
Implementation of the backoff mechanism described in doc/connection-backoff.md.
Definition: backoff.h:30
grpc_millis NextAttemptTime()
Returns the time at which the next attempt should start.
Definition: backoff.cc:55
grpc_millis max_backoff() const
maximum time between retries
Definition: backoff.h:71
Options & set_initial_backoff(grpc_millis initial_backoff)
Definition: backoff.h:48
Round Robin Policy.
Definition: backend_metric.cc:24
grpc_millis initial_backoff() const
how long to wait after the first failure before retrying
Definition: backoff.h:65
double jitter() const
amount to randomize backoffs
Definition: backoff.h:69
void Reset()
Reset the backoff, so the next value returned by NextAttemptTime() will be the time of the second att...
Definition: backoff.cc:71
BackOff(const Options &options)
Initialize backoff machinery - does not need to be destroyed.
Definition: backoff.cc:49
Options & set_jitter(double jitter)
Definition: backoff.h:56
Options & set_max_backoff(grpc_millis max_backoff)
Definition: backoff.h:60
Options & set_multiplier(double multiplier)
Definition: backoff.h:52