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 <stdint.h>
25 
26 #include <map>
27 #include <string>
28 
29 #include "absl/base/thread_annotations.h"
30 
31 #include <grpc/support/atm.h>
32 
36 
37 namespace grpc_core {
38 namespace internal {
39 
41 class ServerRetryThrottleData : public RefCounted<ServerRetryThrottleData> {
42  public:
44  ServerRetryThrottleData* old_throttle_data);
45  ~ServerRetryThrottleData() override;
46 
48  bool RecordFailure();
49 
51  void RecordSuccess();
52 
55 
56  private:
58  ServerRetryThrottleData** throttle_data);
59 
63  // A pointer to the replacement for this ServerRetryThrottleData entry.
64  // If non-nullptr, then this entry is stale and must not be used.
65  // We hold a reference to the replacement.
67 };
68 
71  public:
72  static ServerRetryThrottleMap* Get();
73 
77  const std::string& server_name, intptr_t max_milli_tokens,
78  intptr_t milli_token_ratio);
79 
80  private:
81  using StringToDataMap =
82  std::map<std::string, RefCountedPtr<ServerRetryThrottleData>>;
83 
86 };
87 
88 } // namespace internal
89 } // namespace grpc_core
90 
91 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_THROTTLE_H */
grpc_core::internal::ServerRetryThrottleData::milli_token_ratio
intptr_t milli_token_ratio() const
Definition: retry_throttle.h:54
grpc_core::internal::ServerRetryThrottleData::ServerRetryThrottleData
ServerRetryThrottleData(intptr_t max_milli_tokens, intptr_t milli_token_ratio, ServerRetryThrottleData *old_throttle_data)
Definition: retry_throttle.cc:36
grpc_core
Definition: call_metric_recorder.h:31
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::internal::ServerRetryThrottleData::RecordFailure
bool RecordFailure()
Records a failure. Returns true if it's okay to send a retry.
Definition: retry_throttle.cc:84
grpc_core::internal::ServerRetryThrottleMap::mu_
Mutex mu_
Definition: retry_throttle.h:84
grpc_core::internal::ServerRetryThrottleData::replacement_
gpr_atm replacement_
Definition: retry_throttle.h:66
grpc_core::internal::ServerRetryThrottleMap::Get
static ServerRetryThrottleMap * Get()
Definition: retry_throttle.cc:115
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_core::internal::ServerRetryThrottleMap::ABSL_GUARDED_BY
StringToDataMap map_ ABSL_GUARDED_BY(mu_)
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
grpc_core::internal::ServerRetryThrottleData::milli_tokens_
gpr_atm milli_tokens_
Definition: retry_throttle.h:62
grpc_core::internal::ServerRetryThrottleMap::GetDataForServer
RefCountedPtr< ServerRetryThrottleData > GetDataForServer(const std::string &server_name, intptr_t max_milli_tokens, intptr_t milli_token_ratio)
Definition: retry_throttle.cc:120
grpc_core::internal::ServerRetryThrottleMap
Global map of server name to retry throttle data.
Definition: retry_throttle.h:70
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::internal::ServerRetryThrottleData::max_milli_tokens_
const intptr_t max_milli_tokens_
Definition: retry_throttle.h:60
stdint.h
grpc_core::internal::ServerRetryThrottleData
Tracks retry throttling data for an individual server name.
Definition: retry_throttle.h:41
grpc_core::internal::ServerRetryThrottleMap::StringToDataMap
std::map< std::string, RefCountedPtr< ServerRetryThrottleData > > StringToDataMap
Definition: retry_throttle.h:82
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_atomic.h:32
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_core::internal::ServerRetryThrottleData::milli_token_ratio_
const intptr_t milli_token_ratio_
Definition: retry_throttle.h:61
ref_counted.h
grpc_core::internal::ServerRetryThrottleData::RecordSuccess
void RecordSuccess()
Records a success.
Definition: retry_throttle.cc:99
ref_counted_ptr.h
internal
Definition: benchmark/test/output_test_helper.cc:20
grpc_core::internal::ServerRetryThrottleData::max_milli_tokens
intptr_t max_milli_tokens() const
Definition: retry_throttle.h:53
atm.h
grpc_core::internal::ServerRetryThrottleData::~ServerRetryThrottleData
~ServerRetryThrottleData() override
Definition: retry_throttle.cc:64
sync.h
run_interop_tests.server_name
server_name
Definition: run_interop_tests.py:1510
grpc_core::internal::ServerRetryThrottleData::GetReplacementThrottleDataIfNeeded
void GetReplacementThrottleDataIfNeeded(ServerRetryThrottleData **throttle_data)
Definition: retry_throttle.cc:73
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:11