From cf284e49d1853f156460a950cc2b99c681ea4866 Mon Sep 17 00:00:00 2001 From: donnadionne Date: Tue, 6 Apr 2021 19:37:09 -0700 Subject: [PATCH] Making C++ implementation of circuit breaking consistent with other (#25900) languages. --- .../client_channel/lb_policy/xds/xds_cluster_impl.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc index 90e4073aef3..d7ee6619b04 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc @@ -31,6 +31,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/gprpp/atomic.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -56,6 +57,7 @@ class CircuitBreakerCallCounterMap { explicit CallCounter(Key key) : key_(std::move(key)) {} ~CallCounter() override; + uint32_t Load() { return concurrent_requests_.Load(MemoryOrder::SEQ_CST); } uint32_t Increment() { return concurrent_requests_.FetchAdd(1); } void Decrement() { concurrent_requests_.FetchSub(1); } @@ -287,15 +289,15 @@ LoadBalancingPolicy::PickResult XdsClusterImplLb::Picker::Pick( return result; } // Handle circuit breaking. - uint32_t current = call_counter_->Increment(); + uint32_t current = call_counter_->Load(); // Check and see if we exceeded the max concurrent requests count. if (current >= max_concurrent_requests_) { - call_counter_->Decrement(); if (drop_stats_ != nullptr) drop_stats_->AddUncategorizedDrops(); PickResult result; result.type = PickResult::PICK_COMPLETE; return result; } + call_counter_->Increment(); // If we're not dropping the call, we should always have a child picker. if (picker_ == nullptr) { // Should never happen. PickResult result;