Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream: avoid copies of all cluster endpoints for every resolve target #15013

Merged
merged 3 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions source/common/upstream/strict_dns_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ StrictDnsClusterImpl::StrictDnsClusterImpl(
Stats::ScopePtr&& stats_scope, bool added_via_api)
: BaseDynamicClusterImpl(cluster, runtime, factory_context, std::move(stats_scope),
added_via_api, factory_context.dispatcher().timeSource()),
load_assignment_{
cluster.has_load_assignment()
? cluster.load_assignment()
: Config::Utility::translateClusterHosts(cluster.hidden_envoy_deprecated_hosts())},
local_info_(factory_context.localInfo()), dns_resolver_(dns_resolver),
dns_refresh_rate_ms_(
std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))),
Expand All @@ -24,11 +28,7 @@ StrictDnsClusterImpl::StrictDnsClusterImpl(
cluster, dns_refresh_rate_ms_.count(), factory_context.api().randomGenerator());

std::list<ResolveTargetPtr> resolve_targets;
const envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment(
cluster.has_load_assignment()
? cluster.load_assignment()
: Config::Utility::translateClusterHosts(cluster.hidden_envoy_deprecated_hosts()));
const auto& locality_lb_endpoints = load_assignment.endpoints();
const auto& locality_lb_endpoints = load_assignment_.endpoints();
for (const auto& locality_lb_endpoint : locality_lb_endpoints) {
validateEndpointsForZoneAwareRouting(locality_lb_endpoint);

Expand All @@ -48,7 +48,7 @@ StrictDnsClusterImpl::StrictDnsClusterImpl(
dns_lookup_family_ = getDnsLookupFamilyFromCluster(cluster);

overprovisioning_factor_ = PROTOBUF_GET_WRAPPED_OR_DEFAULT(
load_assignment.policy(), overprovisioning_factor, kDefaultOverProvisioningFactor);
load_assignment_.policy(), overprovisioning_factor, kDefaultOverProvisioningFactor);
}

void StrictDnsClusterImpl::startPreInit() {
Expand Down
5 changes: 4 additions & 1 deletion source/common/upstream/strict_dns_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class StrictDnsClusterImpl : public BaseDynamicClusterImpl {
uint32_t port_;
Event::TimerPtr resolve_timer_;
HostVector hosts_;
const envoy::config::endpoint::v3::LocalityLbEndpoints locality_lb_endpoint_;
const envoy::config::endpoint::v3::LocalityLbEndpoints& locality_lb_endpoint_;
const envoy::config::endpoint::v3::LbEndpoint lb_endpoint_;
HostMap all_hosts_;
};
Expand All @@ -51,6 +51,9 @@ class StrictDnsClusterImpl : public BaseDynamicClusterImpl {
// ClusterImplBase
void startPreInit() override;

// Keep load assignment as a member to make sure its data referenced in
// resolve_targets_ outlives them.
const envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment_;
const LocalInfo::LocalInfo& local_info_;
Network::DnsResolverSharedPtr dns_resolver_;
std::list<ResolveTargetPtr> resolve_targets_;
Expand Down