From 4cc16f951c0909196a9ed62774adcbbaf9cc88c1 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Thu, 27 Sep 2018 09:45:59 -0500 Subject: Simplifiy transport querying function --- .../client_channel/client_channel_channelz.cc | 29 ++++++++-------------- .../client_channel/client_channel_channelz.h | 5 ++++ src/core/ext/filters/client_channel/subchannel.cc | 16 ++++++------ src/core/ext/filters/client_channel/subchannel.h | 4 +-- 4 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/core/ext/filters') diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc index 4fedcbcbb6..8d02304d19 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.cc +++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc @@ -136,23 +136,6 @@ void SubchannelNode::PopulateConnectivityState(grpc_json* json) { false); } -void SubchannelNode::PopulateChildSockets(grpc_json* json) { - ChildRefsList child_sockets; - grpc_json* json_iterator = nullptr; - grpc_subchannel_populate_child_sockets(subchannel_, &child_sockets); - if (!child_sockets.empty()) { - grpc_json* array_parent = grpc_json_create_child( - nullptr, json, "socketRef", nullptr, GRPC_JSON_ARRAY, false); - for (size_t i = 0; i < child_sockets.size(); ++i) { - json_iterator = - grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr, - GRPC_JSON_OBJECT, false); - grpc_json_add_number_string_child(json_iterator, nullptr, "socketId", - child_sockets[i]); - } - } -} - grpc_json* SubchannelNode::RenderJson() { grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT); grpc_json* json = top_level_json; @@ -184,7 +167,17 @@ grpc_json* SubchannelNode::RenderJson() { // ask CallCountingHelper to populate trace and call count data. call_counter_.PopulateCallCounts(json); json = top_level_json; - PopulateChildSockets(json); + // populate the child socket. + intptr_t socket_uuid = grpc_subchannel_get_child_socket_uuid(subchannel_); + if (socket_uuid != 0) { + grpc_json* array_parent = grpc_json_create_child( + nullptr, json, "socketRef", nullptr, GRPC_JSON_ARRAY, false); + json_iterator = + grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr, + GRPC_JSON_OBJECT, false); + grpc_json_add_number_string_child(json_iterator, nullptr, "socketId", + socket_uuid); + } return top_level_json; } diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.h b/src/core/ext/filters/client_channel/client_channel_channelz.h index a63df00f9f..a6dae16522 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.h +++ b/src/core/ext/filters/client_channel/client_channel_channelz.h @@ -31,6 +31,11 @@ typedef struct grpc_subchannel grpc_subchannel; namespace grpc_core { +// TODO(ncteisen), this only contains the uuids of the children for now, +// since that is all that is strictly needed. In a future enhancement we will +// add human readable names as in the channelz.proto +typedef InlinedVector ChildRefsList; + namespace channelz { // Subtype of ChannelNode that overrides and provides client_channel specific diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 29aeb06e7b..4c33636646 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -97,7 +97,9 @@ struct grpc_subchannel { /** set during connection */ grpc_connect_out_args connecting_result; - grpc_transport* transport; + /** uuid of this subchannel's socket. 0 if this subchannel is not + connected */ + intptr_t socket_uuid; /** callback for connection finishing */ grpc_closure on_connected; @@ -256,6 +258,7 @@ static void disconnect(grpc_subchannel* c) { c->disconnected = true; grpc_connector_shutdown(c->connector, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Subchannel disconnected")); + c->socket_uuid = 0; c->connected_subchannel.reset(); gpr_mu_unlock(&c->mu); } @@ -413,11 +416,9 @@ grpc_core::channelz::SubchannelNode* grpc_subchannel_get_channelz_node( return subchannel->channelz_subchannel.get(); } -void grpc_subchannel_populate_child_sockets( - grpc_subchannel* subchannel, grpc_core::ChildRefsList* child_sockets) { - if (subchannel->transport != nullptr) { - grpc_transport_populate_sockets(subchannel->transport, child_sockets); - } +intptr_t grpc_subchannel_get_child_socket_uuid( + grpc_subchannel* subchannel) { + return subchannel->socket_uuid; } static void continue_connect_locked(grpc_subchannel* c) { @@ -578,6 +579,7 @@ static void on_connected_subchannel_connectivity_changed(void* p, grpc_connectivity_state_name( connected_subchannel_watcher->connectivity_state)); } + c->socket_uuid = 0; c->connected_subchannel.reset(); grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, @@ -630,7 +632,7 @@ static bool publish_transport_locked(grpc_subchannel* c) { GRPC_ERROR_UNREF(error); return false; } - c->transport = c->connecting_result.transport; + c->socket_uuid = grpc_transport_get_socket_uuid(c->connecting_result.transport); memset(&c->connecting_result, 0, sizeof(c->connecting_result)); /* initialize state watcher */ diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 2cf5067fc2..67a2d49711 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -126,8 +126,8 @@ void grpc_subchannel_call_unref( grpc_core::channelz::SubchannelNode* grpc_subchannel_get_channelz_node( grpc_subchannel* subchannel); -void grpc_subchannel_populate_child_sockets( - grpc_subchannel* subchannel, grpc_core::ChildRefsList* child_sockets); +intptr_t grpc_subchannel_get_child_socket_uuid( + grpc_subchannel* subchannel); /** Returns a pointer to the parent data associated with \a subchannel_call. The data will be of the size specified in \a parent_data_size -- cgit v1.2.3