GRPC C++  1.39.1
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 
24 #include <string>
25 
28 
29 namespace grpc_core {
30 namespace internal {
31 
33 class ServerRetryThrottleData : public RefCounted<ServerRetryThrottleData> {
34  public:
36  ServerRetryThrottleData* old_throttle_data);
37  ~ServerRetryThrottleData() override;
38 
40  bool RecordFailure();
41 
43  void RecordSuccess();
44 
45  intptr_t max_milli_tokens() const { return max_milli_tokens_; }
46  intptr_t milli_token_ratio() const { return milli_token_ratio_; }
47 
48  private:
49  void GetReplacementThrottleDataIfNeeded(
50  ServerRetryThrottleData** throttle_data);
51 
52  const intptr_t max_milli_tokens_;
53  const intptr_t milli_token_ratio_;
54  gpr_atm milli_tokens_;
55  // A pointer to the replacement for this ServerRetryThrottleData entry.
56  // If non-nullptr, then this entry is stale and must not be used.
57  // We hold a reference to the replacement.
58  gpr_atm replacement_ = 0;
59 };
60 
63  public:
65  static void Init();
67  static void Shutdown();
68 
72  const std::string& server_name, intptr_t max_milli_tokens,
73  intptr_t milli_token_ratio);
74 };
75 
76 } // namespace internal
77 } // namespace grpc_core
78 
79 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_THROTTLE_H */
Definition: ref_counted.h:282
Definition: ref_counted_ptr.h:35
Tracks retry throttling data for an individual server name.
Definition: retry_throttle.h:33
intptr_t max_milli_tokens() const
Definition: retry_throttle.h:45
intptr_t milli_token_ratio() const
Definition: retry_throttle.h:46
ServerRetryThrottleData(intptr_t max_milli_tokens, intptr_t milli_token_ratio, ServerRetryThrottleData *old_throttle_data)
Definition: retry_throttle.cc:42
~ServerRetryThrottleData() override
Definition: retry_throttle.cc:70
void RecordSuccess()
Records a success.
Definition: retry_throttle.cc:105
bool RecordFailure()
Records a failure. Returns true if it's okay to send a retry.
Definition: retry_throttle.cc:90
Global map of server name to retry throttle data.
Definition: retry_throttle.h:62
static void Init()
Initializes global map of failure data for each server name.
Definition: retry_throttle.cc:158
static void Shutdown()
Shuts down global map of failure data for each server name.
Definition: retry_throttle.cc:163
static RefCountedPtr< ServerRetryThrottleData > GetDataForServer(const std::string &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:168
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
Round Robin Policy.
Definition: backend_metric.cc:26