Skip to content

Commit

Permalink
fixup: ASAN error and API cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneo committed Jan 23, 2024
1 parent 518de93 commit 8c65836
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
42 changes: 20 additions & 22 deletions src/core/ext/xds/xds_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2032,32 +2032,30 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked(
return snapshot_map;
}

XdsApi::ResourceTypeMetadataMap XdsClient::BuildResourceTypeMetadataMap() {
MutexLock lock(&mu_);
XdsApi::ResourceTypeMetadataMap resource_type_metadata_map;
for (const auto& a : authority_state_map_) { // authority
const std::string& authority = a.first;
for (const auto& t : a.second.resource_map) { // type
const XdsResourceType* type = t.first;
auto& resource_metadata_map =
resource_type_metadata_map[type->type_url()];
for (const auto& r : t.second) { // resource id
const XdsResourceKey& resource_key = r.first;
const ResourceState& resource_state = r.second;
resource_metadata_map[ConstructFullXdsResourceName(
authority, type->type_url(), resource_key)] = &resource_state.meta;
}
}
}
return resource_type_metadata_map;
}

void XdsClient::DumpClientConfig(
envoy_service_status_v3_ClientConfig* client_config,
const XdsApi::ResourceTypeMetadataMap& resource_type_metadata_map,
XdsApi::ResourceTypeMetadataMap* resource_type_metadata_map,
std::vector<std::string>* strings_holder, upb_Arena* arena) {
{
MutexLock lock(&mu_);
for (const auto& a : authority_state_map_) { // authority
const std::string& authority = a.first;
for (const auto& t : a.second.resource_map) { // type
const XdsResourceType* type = t.first;
auto& resource_metadata_map =
(*resource_type_metadata_map)[type->type_url()];
for (const auto& r : t.second) { // resource id
const XdsResourceKey& resource_key = r.first;
const ResourceState& resource_state = r.second;
resource_metadata_map[ConstructFullXdsResourceName(
authority, type->type_url(), resource_key)] =
&resource_state.meta;
}
}
}
}
// Assemble config dump messages
api_.AssembleClientConfig(client_config, resource_type_metadata_map,
api_.AssembleClientConfig(client_config, *resource_type_metadata_map,
strings_holder, arena);
}

Expand Down
4 changes: 1 addition & 3 deletions src/core/ext/xds/xds_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ class XdsClient : public DualRefCounted<XdsClient> {
// implementation.
void DumpClientConfig(
envoy_service_status_v3_ClientConfig* client_config,
const XdsApi::ResourceTypeMetadataMap& resource_type_metadata_map,
XdsApi::ResourceTypeMetadataMap* resource_type_metadata_map,
std::vector<std::string>* strings_holder, upb_Arena* arena);

XdsApi::ResourceTypeMetadataMap BuildResourceTypeMetadataMap();

grpc_event_engine::experimental::EventEngine* engine() {
return engine_.get();
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ext/xds/xds_client_grpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ grpc_slice grpc_dump_xds_configs(void) {
// consistent with older gRPC implementation
auto client_config = envoy_service_status_v3_ClientStatusResponse_add_config(
response, arena.ptr());
grpc_core::XdsApi::ResourceTypeMetadataMap metadata_map;
if (xds_client.ok()) {
auto metadata_map = (*xds_client)->BuildResourceTypeMetadataMap();
(*xds_client)
->DumpClientConfig(client_config, metadata_map, &type_url_storage,
->DumpClientConfig(client_config, &metadata_map, &type_url_storage,
arena.ptr());
}
// Serialize the upb message to bytes
Expand Down

0 comments on commit 8c65836

Please sign in to comment.