-
Notifications
You must be signed in to change notification settings - Fork 5.3k
add all host map to priority set for fast host searching #17290
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0738957
a first commit for quick review
wbpcode ea819e5
minor udpate
wbpcode 0f36195
initial version for common host map
wbpcode 62a06c9
remove unused all host member in eds
wbpcode c4115c0
minor update of test
wbpcode 67438ee
minor update for test
wbpcode dbc35f4
update cross priority host map in the updateHosts
wbpcode 45b4817
some update according to reviewers' comments
wbpcode 5497817
fix mock
wbpcode 043dc35
Merge branch 'main' of https://github.com/envoyproxy/envoy into host_map
wbpcode d5f9c2f
Merge branch 'main' and resolve conflict
wbpcode 74b4b43
resolve conflict
wbpcode ae250b8
fix format
wbpcode eef4254
bump cluster memeory consumption limit
wbpcode d8dd287
make code more clean and reduce memory consumption
wbpcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,6 @@ EdsClusterImpl::EdsClusterImpl( | |
| void EdsClusterImpl::startPreInit() { subscription_->start({cluster_name_}); } | ||
|
|
||
| void EdsClusterImpl::BatchUpdateHelper::batchUpdate(PrioritySet::HostUpdateCb& host_update_cb) { | ||
| absl::flat_hash_map<std::string, HostSharedPtr> updated_hosts; | ||
| absl::flat_hash_set<std::string> all_new_hosts; | ||
| PriorityStateManager priority_state_manager(parent_, parent_.local_info_, &host_update_cb); | ||
| for (const auto& locality_lb_endpoint : cluster_load_assignment_.endpoints()) { | ||
|
|
@@ -56,6 +55,11 @@ void EdsClusterImpl::BatchUpdateHelper::batchUpdate(PrioritySet::HostUpdateCb& h | |
|
|
||
| for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) { | ||
| auto address = parent_.resolveProtoAddress(lb_endpoint.endpoint().address()); | ||
| // When the configuration contains duplicate hosts, only the first one will be retained. | ||
| if (all_new_hosts.count(address->asString()) > 0) { | ||
| continue; | ||
| } | ||
|
Comment on lines
+58
to
+61
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an unrelated bug fix? Or is this somehow required with this new code? |
||
|
|
||
| priority_state_manager.registerHostForPriority(lb_endpoint.endpoint().hostname(), address, | ||
| locality_lb_endpoint, lb_endpoint, | ||
| parent_.time_source_); | ||
|
|
@@ -66,6 +70,11 @@ void EdsClusterImpl::BatchUpdateHelper::batchUpdate(PrioritySet::HostUpdateCb& h | |
| // Track whether we rebuilt any LB structures. | ||
| bool cluster_rebuilt = false; | ||
|
|
||
| // Get the map of all the latest existing hosts, which is used to filter out the existing | ||
| // hosts in the process of updating cluster memberships. | ||
| HostMapConstSharedPtr all_hosts = parent_.prioritySet().crossPriorityHostMap(); | ||
| ASSERT(all_hosts != nullptr); | ||
|
|
||
| const uint32_t overprovisioning_factor = PROTOBUF_GET_WRAPPED_OR_DEFAULT( | ||
| cluster_load_assignment_.policy(), overprovisioning_factor, kDefaultOverProvisioningFactor); | ||
|
|
||
|
|
@@ -80,13 +89,13 @@ void EdsClusterImpl::BatchUpdateHelper::batchUpdate(PrioritySet::HostUpdateCb& h | |
| if (priority_state[i].first != nullptr) { | ||
| cluster_rebuilt |= parent_.updateHostsPerLocality( | ||
| i, overprovisioning_factor, *priority_state[i].first, parent_.locality_weights_map_[i], | ||
| priority_state[i].second, priority_state_manager, updated_hosts, all_new_hosts); | ||
| priority_state[i].second, priority_state_manager, *all_hosts, all_new_hosts); | ||
| } else { | ||
| // If the new update contains a priority with no hosts, call the update function with an empty | ||
| // set of hosts. | ||
| cluster_rebuilt |= parent_.updateHostsPerLocality( | ||
| i, overprovisioning_factor, {}, parent_.locality_weights_map_[i], empty_locality_map, | ||
| priority_state_manager, updated_hosts, all_new_hosts); | ||
| priority_state_manager, *all_hosts, all_new_hosts); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -99,11 +108,9 @@ void EdsClusterImpl::BatchUpdateHelper::batchUpdate(PrioritySet::HostUpdateCb& h | |
| } | ||
| cluster_rebuilt |= parent_.updateHostsPerLocality( | ||
| i, overprovisioning_factor, {}, parent_.locality_weights_map_[i], empty_locality_map, | ||
| priority_state_manager, updated_hosts, all_new_hosts); | ||
| priority_state_manager, *all_hosts, all_new_hosts); | ||
| } | ||
|
|
||
| parent_.all_hosts_ = std::move(updated_hosts); | ||
|
|
||
| if (!cluster_rebuilt) { | ||
| parent_.info_->stats().update_no_rebuild_.inc(); | ||
| } | ||
|
|
@@ -226,18 +233,12 @@ void EdsClusterImpl::reloadHealthyHostsHelper(const HostSharedPtr& host) { | |
| HostSetImpl::partitionHosts(hosts_copy, hosts_per_locality_copy), | ||
| host_set->localityWeights(), {}, hosts_to_remove, absl::nullopt); | ||
| } | ||
|
|
||
| if (host_to_exclude != nullptr) { | ||
| ASSERT(all_hosts_.find(host_to_exclude->address()->asString()) != all_hosts_.end()); | ||
| all_hosts_.erase(host_to_exclude->address()->asString()); | ||
| } | ||
| } | ||
|
|
||
| bool EdsClusterImpl::updateHostsPerLocality( | ||
| const uint32_t priority, const uint32_t overprovisioning_factor, const HostVector& new_hosts, | ||
| LocalityWeightsMap& locality_weights_map, LocalityWeightsMap& new_locality_weights_map, | ||
| PriorityStateManager& priority_state_manager, | ||
| absl::flat_hash_map<std::string, HostSharedPtr>& updated_hosts, | ||
| PriorityStateManager& priority_state_manager, const HostMap& all_hosts, | ||
| const absl::flat_hash_set<std::string>& all_new_hosts) { | ||
| const auto& host_set = priority_set_.getOrCreateHostSet(priority, overprovisioning_factor); | ||
| HostVectorSharedPtr current_hosts_copy(new HostVector(host_set.hosts())); | ||
|
|
@@ -254,9 +255,8 @@ bool EdsClusterImpl::updateHostsPerLocality( | |
| // performance implications, since this has the knock on effect that we rebuild the load balancers | ||
| // and locality scheduler. See the comment in BaseDynamicClusterImpl::updateDynamicHostList | ||
| // about this. In the future we may need to do better here. | ||
| const bool hosts_updated = | ||
| updateDynamicHostList(new_hosts, *current_hosts_copy, hosts_added, hosts_removed, | ||
| updated_hosts, all_hosts_, all_new_hosts); | ||
| const bool hosts_updated = updateDynamicHostList(new_hosts, *current_hosts_copy, hosts_added, | ||
| hosts_removed, all_hosts, all_new_hosts); | ||
| if (hosts_updated || host_set.overprovisioningFactor() != overprovisioning_factor || | ||
| locality_weights_map != new_locality_weights_map) { | ||
| ASSERT(std::all_of(current_hosts_copy->begin(), current_hosts_copy->end(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,6 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() { | |
| if (status == Network::DnsResolver::ResolutionStatus::Success) { | ||
| parent_.info_->stats().update_success_.inc(); | ||
|
|
||
| HostMap updated_hosts; | ||
| HostVector new_hosts; | ||
| std::chrono::seconds ttl_refresh_rate = std::chrono::seconds::max(); | ||
| absl::flat_hash_set<std::string> all_new_hosts; | ||
|
|
@@ -127,33 +126,44 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() { | |
| // potentially move port handling into the DNS interface itself, which would work better | ||
| // for SRV. | ||
| ASSERT(resp.address_ != nullptr); | ||
| auto address = Network::Utility::getAddressWithPort(*(resp.address_), port_); | ||
| if (all_new_hosts.count(address->asString()) > 0) { | ||
| continue; | ||
| } | ||
|
Comment on lines
+130
to
+132
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question? |
||
|
|
||
| new_hosts.emplace_back(new HostImpl( | ||
| parent_.info_, hostname_, | ||
| Network::Utility::getAddressWithPort(*(resp.address_), port_), | ||
| parent_.info_, hostname_, address, | ||
| // TODO(zyfjeff): Created through metadata shared pool | ||
| std::make_shared<const envoy::config::core::v3::Metadata>(lb_endpoint_.metadata()), | ||
| lb_endpoint_.load_balancing_weight().value(), locality_lb_endpoints_.locality(), | ||
| lb_endpoint_.endpoint().health_check_config(), locality_lb_endpoints_.priority(), | ||
| lb_endpoint_.health_status(), parent_.time_source_)); | ||
| all_new_hosts.emplace(new_hosts.back()->address()->asString()); | ||
| all_new_hosts.emplace(address->asString()); | ||
| ttl_refresh_rate = min(ttl_refresh_rate, resp.ttl_); | ||
| } | ||
|
|
||
| HostVector hosts_added; | ||
| HostVector hosts_removed; | ||
| if (parent_.updateDynamicHostList(new_hosts, hosts_, hosts_added, hosts_removed, | ||
| updated_hosts, all_hosts_, all_new_hosts)) { | ||
| all_hosts_, all_new_hosts)) { | ||
| ENVOY_LOG(debug, "DNS hosts have changed for {}", dns_address_); | ||
| ASSERT(std::all_of(hosts_.begin(), hosts_.end(), [&](const auto& host) { | ||
| return host->priority() == locality_lb_endpoints_.priority(); | ||
| })); | ||
|
|
||
| // Update host map for current resolve target. | ||
| for (const auto& host : hosts_removed) { | ||
| all_hosts_.erase(host->address()->asString()); | ||
| } | ||
| for (const auto& host : hosts_added) { | ||
| all_hosts_.insert({host->address()->asString(), host}); | ||
| } | ||
|
|
||
| parent_.updateAllHosts(hosts_added, hosts_removed, locality_lb_endpoints_.priority()); | ||
| } else { | ||
| parent_.info_->stats().update_no_rebuild_.inc(); | ||
| } | ||
|
|
||
| all_hosts_ = std::move(updated_hosts); | ||
|
|
||
| // reset failure backoff strategy because there was a success. | ||
| parent_.failure_backoff_strategy_->reset(); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Maybe call it host_map within the lambda as well?
mapseems a bit too genericThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get it.