GRPC Core  9.0.0
retry_throttle.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 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_EXT_FILTERS_CLIENT_CHANNEL_RETRY_THROTTLE_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_THROTTLE_H
21 
23 
26 
27 namespace grpc_core {
28 namespace internal {
29 
31 class ServerRetryThrottleData : public RefCounted<ServerRetryThrottleData> {
32  public:
34  ServerRetryThrottleData* old_throttle_data);
36 
38  bool RecordFailure();
39 
41  void RecordSuccess();
42 
43  intptr_t max_milli_tokens() const { return max_milli_tokens_; }
44  intptr_t milli_token_ratio() const { return milli_token_ratio_; }
45 
46  private:
47  void GetReplacementThrottleDataIfNeeded(
48  ServerRetryThrottleData** throttle_data);
49 
50  const intptr_t max_milli_tokens_;
51  const intptr_t milli_token_ratio_;
52  gpr_atm milli_tokens_;
53  // A pointer to the replacement for this ServerRetryThrottleData entry.
54  // If non-nullptr, then this entry is stale and must not be used.
55  // We hold a reference to the replacement.
56  gpr_atm replacement_ = 0;
57 };
58 
61  public:
63  static void Init();
65  static void Shutdown();
66 
70  const char* server_name, intptr_t max_milli_tokens,
71  intptr_t milli_token_ratio);
72 };
73 
74 } // namespace internal
75 } // namespace grpc_core
76 
77 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_THROTTLE_H */
Definition: ref_counted.h:248
Definition: ref_counted_ptr.h:35
Tracks retry throttling data for an individual server name.
Definition: retry_throttle.h:31
intptr_t max_milli_tokens() const
Definition: retry_throttle.h:43
intptr_t milli_token_ratio() const
Definition: retry_throttle.h:44
ServerRetryThrottleData(intptr_t max_milli_tokens, intptr_t milli_token_ratio, ServerRetryThrottleData *old_throttle_data)
Definition: retry_throttle.cc:40
void RecordSuccess()
Records a success.
Definition: retry_throttle.cc:103
bool RecordFailure()
Records a failure. Returns true if it's okay to send a retry.
Definition: retry_throttle.cc:88
~ServerRetryThrottleData()
Definition: retry_throttle.cc:68
Global map of server name to retry throttle data.
Definition: retry_throttle.h:60
static RefCountedPtr< ServerRetryThrottleData > GetDataForServer(const char *server_name, intptr_t max_milli_tokens, intptr_t milli_token_ratio)
Returns the failure data for server_name, creating a new entry if needed.
Definition: retry_throttle.cc:166
static void Init()
Initializes global map of failure data for each server name.
Definition: retry_throttle.cc:156
static void Shutdown()
Shuts down global map of failure data for each server name.
Definition: retry_throttle.cc:161
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
Round Robin Policy.
Definition: backend_metric.cc:24