clang-format

reviewable/pr14886/r3
Mark D. Roth 7 years ago
parent eef0cf6416
commit 5dd42ab4bb
  1. 15
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  2. 38
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  3. 55
      src/core/ext/filters/client_channel/lb_policy/subchannel_list.h

@ -73,8 +73,8 @@ class PickFirst : public LoadBalancingPolicy {
const grpc_lb_address& address, const grpc_lb_address& address,
grpc_subchannel* subchannel, grpc_subchannel* subchannel,
grpc_combiner* combiner) grpc_combiner* combiner)
: SubchannelData(subchannel_list, user_data_vtable, address, : SubchannelData(subchannel_list, user_data_vtable, address, subchannel,
subchannel, combiner) {} combiner) {}
void ProcessConnectivityChangeLocked(grpc_error* error) override; void ProcessConnectivityChangeLocked(grpc_error* error) override;
}; };
@ -83,9 +83,9 @@ class PickFirst : public LoadBalancingPolicy {
: public SubchannelList<PickFirstSubchannelList, : public SubchannelList<PickFirstSubchannelList,
PickFirstSubchannelData> { PickFirstSubchannelData> {
public: public:
PickFirstSubchannelList( PickFirstSubchannelList(PickFirst* policy, TraceFlag* tracer,
PickFirst* policy, TraceFlag* tracer, const grpc_lb_addresses* addresses,
const grpc_lb_addresses* addresses, grpc_combiner* combiner, grpc_combiner* combiner,
grpc_client_channel_factory* client_channel_factory, grpc_client_channel_factory* client_channel_factory,
const grpc_channel_args& args) const grpc_channel_args& args)
: SubchannelList(policy, tracer, addresses, combiner, : SubchannelList(policy, tracer, addresses, combiner,
@ -430,9 +430,8 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
"sd->subchannel_list->shutting_down=%d error=%s", "sd->subchannel_list->shutting_down=%d error=%s",
p, subchannel(), Index(), subchannel_list()->num_subchannels(), p, subchannel(), Index(), subchannel_list()->num_subchannels(),
subchannel_list(), subchannel_list(),
grpc_connectivity_state_name(connectivity_state()), grpc_connectivity_state_name(connectivity_state()), p->shutdown_,
p->shutdown_, subchannel_list()->shutting_down(), subchannel_list()->shutting_down(), grpc_error_string(error));
grpc_error_string(error));
} }
// If the policy is shutting down, unref and return. // If the policy is shutting down, unref and return.
if (p->shutdown_) { if (p->shutdown_) {

@ -91,8 +91,8 @@ class RoundRobin : public LoadBalancingPolicy {
const grpc_lb_address& address, const grpc_lb_address& address,
grpc_subchannel* subchannel, grpc_subchannel* subchannel,
grpc_combiner* combiner) grpc_combiner* combiner)
: SubchannelData(subchannel_list, user_data_vtable, address, : SubchannelData(subchannel_list, user_data_vtable, address, subchannel,
subchannel, combiner), combiner),
user_data_vtable_(user_data_vtable), user_data_vtable_(user_data_vtable),
user_data_(user_data_vtable_ != nullptr user_data_(user_data_vtable_ != nullptr
? user_data_vtable_->copy(address.user_data) ? user_data_vtable_->copy(address.user_data)
@ -255,8 +255,8 @@ size_t RoundRobin::GetNextReadySubchannelIndexLocked() {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[RR %p] found next ready subchannel (%p) at index %" PRIuPTR "[RR %p] found next ready subchannel (%p) at index %" PRIuPTR
" of subchannel_list %p", " of subchannel_list %p",
this, subchannel_list_->subchannel(index)->subchannel(), this, subchannel_list_->subchannel(index)->subchannel(), index,
index, subchannel_list_.get()); subchannel_list_.get());
} }
return index; return index;
} }
@ -272,13 +272,13 @@ void RoundRobin::UpdateLastReadySubchannelIndexLocked(size_t last_ready_index) {
GPR_ASSERT(last_ready_index < subchannel_list_->num_subchannels()); GPR_ASSERT(last_ready_index < subchannel_list_->num_subchannels());
last_ready_subchannel_index_ = last_ready_index; last_ready_subchannel_index_ = last_ready_index;
if (grpc_lb_round_robin_trace.enabled()) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(
GPR_DEBUG,
"[RR %p] setting last_ready_subchannel_index=%" PRIuPTR "[RR %p] setting last_ready_subchannel_index=%" PRIuPTR
" (SC %p, CSC %p)", " (SC %p, CSC %p)",
this, last_ready_index, this, last_ready_index,
subchannel_list_->subchannel(last_ready_index)->subchannel(), subchannel_list_->subchannel(last_ready_index)->subchannel(),
subchannel_list_->subchannel(last_ready_index) subchannel_list_->subchannel(last_ready_index)->connected_subchannel());
->connected_subchannel());
} }
} }
@ -382,8 +382,7 @@ bool RoundRobin::DoPickLocked(PickState* pick) {
*pick->user_data = sd->user_data(); *pick->user_data = sd->user_data();
} }
if (grpc_lb_round_robin_trace.enabled()) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log( gpr_log(GPR_DEBUG,
GPR_DEBUG,
"[RR %p] Picked target <-- Subchannel %p (connected %p) (sl %p, " "[RR %p] Picked target <-- Subchannel %p (connected %p) (sl %p, "
"index %" PRIuPTR ")", "index %" PRIuPTR ")",
this, sd->subchannel(), pick->connected_subchannel.get(), this, sd->subchannel(), pick->connected_subchannel.get(),
@ -508,8 +507,8 @@ void RoundRobin::RoundRobinSubchannelList::UpdateStateCountersLocked(
// Sets the RR policy's connectivity state based on the current // Sets the RR policy's connectivity state based on the current
// subchannel list. // subchannel list.
void void RoundRobin::RoundRobinSubchannelList::
RoundRobin::RoundRobinSubchannelList::MaybeUpdateConnectivityStateLocked() { MaybeUpdateConnectivityStateLocked() {
RoundRobin* p = static_cast<RoundRobin*>(policy()); RoundRobin* p = static_cast<RoundRobin*>(policy());
// Only set connectivity state if this is the current subchannel list. // Only set connectivity state if this is the current subchannel list.
if (p->subchannel_list_ != this) return; if (p->subchannel_list_ != this) return;
@ -586,14 +585,14 @@ void RoundRobin::RoundRobinSubchannelData::ProcessConnectivityChangeLocked(
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"[RR %p] connectivity changed for subchannel %p, subchannel_list %p " "[RR %p] connectivity changed for subchannel %p, subchannel_list %p "
"(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s " "(index %" PRIuPTR " of %" PRIuPTR
"): prev_state=%s new_state=%s "
"p->shutdown=%d sd->subchannel_list->shutting_down=%d error=%s", "p->shutdown=%d sd->subchannel_list->shutting_down=%d error=%s",
p, subchannel(), subchannel_list(), Index(), p, subchannel(), subchannel_list(), Index(),
subchannel_list()->num_subchannels(), subchannel_list()->num_subchannels(),
grpc_connectivity_state_name(prev_connectivity_state_), grpc_connectivity_state_name(prev_connectivity_state_),
grpc_connectivity_state_name(connectivity_state()), grpc_connectivity_state_name(connectivity_state()), p->shutdown_,
p->shutdown_, subchannel_list()->shutting_down(), subchannel_list()->shutting_down(), grpc_error_string(error));
grpc_error_string(error));
} }
GPR_ASSERT(subchannel() != nullptr); GPR_ASSERT(subchannel() != nullptr);
// If the subchannel list is shutting down, stop watching. // If the subchannel list is shutting down, stop watching.
@ -633,9 +632,8 @@ void RoundRobin::RoundRobinSubchannelData::ProcessConnectivityChangeLocked(
case GRPC_CHANNEL_IDLE:; // fallthrough case GRPC_CHANNEL_IDLE:; // fallthrough
} }
// Update state counters. // Update state counters.
subchannel_list()->UpdateStateCountersLocked(prev_connectivity_state_, subchannel_list()->UpdateStateCountersLocked(
connectivity_state(), prev_connectivity_state_, connectivity_state(), GRPC_ERROR_REF(error));
GRPC_ERROR_REF(error));
prev_connectivity_state_ = connectivity_state(); prev_connectivity_state_ = connectivity_state();
// If we've started watching, update overall state and renew notification. // If we've started watching, update overall state and renew notification.
if (subchannel_list()->started_watching()) { if (subchannel_list()->started_watching()) {
@ -694,8 +692,8 @@ void RoundRobin::UpdateLocked(const grpc_channel_args& args) {
if (latest_pending_subchannel_list_ != nullptr) { if (latest_pending_subchannel_list_ != nullptr) {
if (grpc_lb_round_robin_trace.enabled()) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[RR %p] Shutting down previous pending subchannel list %p", "[RR %p] Shutting down previous pending subchannel list %p", this,
this, latest_pending_subchannel_list_.get()); latest_pending_subchannel_list_.get());
} }
latest_pending_subchannel_list_->ShutdownLocked("sl_outdated"); latest_pending_subchannel_list_->ShutdownLocked("sl_outdated");
} }

@ -154,8 +154,7 @@ class SubchannelData {
GRPC_ABSTRACT_BASE_CLASS GRPC_ABSTRACT_BASE_CLASS
protected: protected:
SubchannelData( SubchannelData(SubchannelListType* subchannel_list,
SubchannelListType* subchannel_list,
const grpc_lb_user_data_vtable* user_data_vtable, const grpc_lb_user_data_vtable* user_data_vtable,
const grpc_lb_address& address, grpc_subchannel* subchannel, const grpc_lb_address& address, grpc_subchannel* subchannel,
grpc_combiner* combiner); grpc_combiner* combiner);
@ -195,8 +194,7 @@ class SubchannelData {
// A list of subchannels. // A list of subchannels.
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
class SubchannelList class SubchannelList : public RefCountedWithTracing<SubchannelListType> {
: public RefCountedWithTracing<SubchannelListType> {
public: public:
typedef InlinedVector<SubchannelDataType, 10> SubchannelVector; typedef InlinedVector<SubchannelDataType, 10> SubchannelVector;
@ -278,17 +276,16 @@ SubchannelData<SubchannelListType, SubchannelDataType>::~SubchannelData() {
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, void SubchannelData<SubchannelListType, SubchannelDataType>::
SubchannelDataType>::UnrefSubchannelLocked( UnrefSubchannelLocked(const char* reason) {
const char* reason) {
if (subchannel_ != nullptr) { if (subchannel_ != nullptr) {
if (subchannel_list_->tracer()->enabled()) { if (subchannel_list_->tracer()->enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): unreffing subchannel", " (subchannel %p): unreffing subchannel",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_list_->num_subchannels(), subchannel_); subchannel_);
} }
GRPC_SUBCHANNEL_UNREF(subchannel_, reason); GRPC_SUBCHANNEL_UNREF(subchannel_, reason);
subchannel_ = nullptr; subchannel_ = nullptr;
@ -300,21 +297,19 @@ template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, void SubchannelData<SubchannelListType,
SubchannelDataType>::StartConnectivityWatchLocked() { SubchannelDataType>::StartConnectivityWatchLocked() {
if (subchannel_list_->tracer()->enabled()) { if (subchannel_list_->tracer()->enabled()) {
gpr_log( gpr_log(GPR_DEBUG,
GPR_DEBUG,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): requesting connectivity change " " (subchannel %p): requesting connectivity change "
"notification (from %s)", "notification (from %s)",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_list_->num_subchannels(), subchannel_, subchannel_,
grpc_connectivity_state_name(pending_connectivity_state_unsafe_)); grpc_connectivity_state_name(pending_connectivity_state_unsafe_));
} }
connectivity_notification_pending_ = true; connectivity_notification_pending_ = true;
grpc_subchannel_notify_on_state_change( grpc_subchannel_notify_on_state_change(
subchannel_, subchannel_list_->policy()->interested_parties(), subchannel_, subchannel_list_->policy()->interested_parties(),
&pending_connectivity_state_unsafe_, &pending_connectivity_state_unsafe_, &connectivity_changed_closure_);
&connectivity_changed_closure_);
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
@ -325,33 +320,31 @@ void SubchannelData<SubchannelListType,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): stopping connectivity watch", " (subchannel %p): stopping connectivity watch",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_list_->num_subchannels(), subchannel_); subchannel_);
} }
GPR_ASSERT(connectivity_notification_pending_); GPR_ASSERT(connectivity_notification_pending_);
connectivity_notification_pending_ = false; connectivity_notification_pending_ = false;
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, void SubchannelData<SubchannelListType, SubchannelDataType>::
SubchannelDataType>::CancelConnectivityWatchLocked( CancelConnectivityWatchLocked(const char* reason) {
const char* reason) {
if (subchannel_list_->tracer()->enabled()) { if (subchannel_list_->tracer()->enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): canceling connectivity watch (%s)", " (subchannel %p): canceling connectivity watch (%s)",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_list_->num_subchannels(), subchannel_, reason); subchannel_, reason);
} }
grpc_subchannel_notify_on_state_change(subchannel_, nullptr, nullptr, grpc_subchannel_notify_on_state_change(subchannel_, nullptr, nullptr,
&connectivity_changed_closure_); &connectivity_changed_closure_);
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, void SubchannelData<SubchannelListType, SubchannelDataType>::
SubchannelDataType>::OnConnectivityChangedLocked( OnConnectivityChangedLocked(void* arg, grpc_error* error) {
void* arg, grpc_error* error) {
SubchannelData* sd = static_cast<SubchannelData*>(arg); SubchannelData* sd = static_cast<SubchannelData*>(arg);
// Now that we're inside the combiner, copy the pending connectivity // Now that we're inside the combiner, copy the pending connectivity
// state (which was set by the connectivity state watcher) to // state (which was set by the connectivity state watcher) to
@ -365,8 +358,8 @@ void SubchannelData<SubchannelListType,
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, void SubchannelData<SubchannelListType, SubchannelDataType>::ShutdownLocked(
SubchannelDataType>::ShutdownLocked(const char* reason) { const char* reason) {
// If there's a pending notification for this subchannel, cancel it; // If there's a pending notification for this subchannel, cancel it;
// the callback is responsible for unreffing the subchannel. // the callback is responsible for unreffing the subchannel.
// Otherwise, unref the subchannel directly. // Otherwise, unref the subchannel directly.
@ -447,14 +440,14 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
SubchannelList<SubchannelListType, SubchannelDataType>::~SubchannelList() { SubchannelList<SubchannelListType, SubchannelDataType>::~SubchannelList() {
if (tracer_->enabled()) { if (tracer_->enabled()) {
gpr_log(GPR_DEBUG, "[%s %p] Destroying subchannel_list %p", gpr_log(GPR_DEBUG, "[%s %p] Destroying subchannel_list %p", tracer_->name(),
tracer_->name(), policy_, this); policy_, this);
} }
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelList<SubchannelListType, void SubchannelList<SubchannelListType, SubchannelDataType>::ShutdownLocked(
SubchannelDataType>::ShutdownLocked(const char* reason) { const char* reason) {
if (tracer_->enabled()) { if (tracer_->enabled()) {
gpr_log(GPR_DEBUG, "[%s %p] Shutting down subchannel_list %p (%s)", gpr_log(GPR_DEBUG, "[%s %p] Shutting down subchannel_list %p (%s)",
tracer_->name(), policy_, this, reason); tracer_->name(), policy_, this, reason);

Loading…
Cancel
Save