From b572910677b8423e1acb4090daeed40346f7dc70 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 3 Apr 2018 10:49:48 -0700 Subject: [PATCH] Fix handling of connectivity state error in RR. --- .../lb_policy/round_robin/round_robin.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index dc504a5a399..6ed7201fbfd 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -122,13 +122,18 @@ class RoundRobin : public LoadBalancingPolicy { : SubchannelList(policy, tracer, addresses, combiner, client_channel_factory, args) {} + ~RoundRobinSubchannelList() { + GRPC_ERROR_UNREF(last_transient_failure_error_); + } + void RefForConnectivityWatch(const char* reason); void UnrefForConnectivityWatch(const char* reason); void StartWatchingLocked(); void UpdateStateCountersLocked(grpc_connectivity_state old_state, - grpc_connectivity_state new_state); + grpc_connectivity_state new_state, + grpc_error* transient_failure_error); void UpdateConnectivityStateLocked(); @@ -141,6 +146,7 @@ class RoundRobin : public LoadBalancingPolicy { size_t num_ready_ = 0; size_t num_connecting_ = 0; size_t num_transient_failure_ = 0; + grpc_error* last_transient_failure_error_ = GRPC_ERROR_NONE; }; void ShutdownLocked() override; @@ -437,7 +443,8 @@ gpr_log(GPR_INFO, "AFTER: CheckConnectivityStateLocked loop"); } void RoundRobin::RoundRobinSubchannelList::UpdateStateCountersLocked( - grpc_connectivity_state old_state, grpc_connectivity_state new_state) { + grpc_connectivity_state old_state, grpc_connectivity_state new_state, + grpc_error* transient_failure_error) { GPR_ASSERT(old_state != GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(new_state != GRPC_CHANNEL_SHUTDOWN); if (old_state == GRPC_CHANNEL_READY) { @@ -457,6 +464,8 @@ void RoundRobin::RoundRobinSubchannelList::UpdateStateCountersLocked( } else if (new_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { ++num_transient_failure_; } + GRPC_ERROR_UNREF(last_transient_failure_error_); + last_transient_failure_error_ = transient_failure_error; } /** Sets the policy's connectivity status based on that of the passed-in \a sd @@ -492,10 +501,9 @@ void RoundRobin::RoundRobinSubchannelList::UpdateConnectivityStateLocked() { /* 3) TRANSIENT_FAILURE */ grpc_connectivity_state_set(&p->state_tracker_, GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_ERROR_NONE, // FIXME: GRPC_ERROR_REF(error), + GRPC_ERROR_REF(last_transient_failure_error_), "rr_exhausted_subchannels"); } -// FIXME: GRPC_ERROR_UNREF(error); } void RoundRobin::RoundRobinSubchannelList::UpdateOverallStateLocked() { @@ -598,7 +606,8 @@ void RoundRobin::RoundRobinSubchannelData::ProcessConnectivityChangeLocked( } // Update state counters. subchannel_list()->UpdateStateCountersLocked(prev_connectivity_state_, - connectivity_state()); + connectivity_state(), + GRPC_ERROR_REF(error)); prev_connectivity_state_ = connectivity_state(); // If not initializing, update overall state and renew notification. if (subchannel_list()->initialized()) {