-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Wire up panic mode subset to receive updates #6221
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,26 @@ SubsetLoadBalancer::SubsetLoadBalancer( | |
| scale_locality_weight_(subsets.scaleLocalityWeight()) { | ||
| ASSERT(subsets.isEnabled()); | ||
|
|
||
| if (fallback_policy_ != envoy::api::v2::Cluster::LbSubsetConfig::NO_FALLBACK) { | ||
| HostPredicate predicate; | ||
| if (fallback_policy_ == envoy::api::v2::Cluster::LbSubsetConfig::ANY_ENDPOINT) { | ||
| predicate = [](const Host&) -> bool { return true; }; | ||
|
|
||
| ENVOY_LOG(debug, "subset lb: creating any-endpoint fallback load balancer"); | ||
| } else { | ||
| predicate = [this](const Host& host) -> bool { | ||
| return hostMatches(default_subset_metadata_, host); | ||
| }; | ||
|
|
||
| ENVOY_LOG(debug, "subset lb: creating fallback load balancer for {}", | ||
| describeMetadata(default_subset_metadata_)); | ||
| } | ||
|
|
||
| fallback_subset_ = std::make_unique<LbSubsetEntry>(); | ||
| fallback_subset_->priority_subset_ = std::make_unique<PrioritySubsetImpl>( | ||
| *this, predicate, locality_weight_aware_, scale_locality_weight_); | ||
| } | ||
|
|
||
| if (subsets.panicModeAny()) { | ||
| HostPredicate predicate = [](const Host&) -> bool { return true; }; | ||
|
|
||
|
|
@@ -186,34 +206,18 @@ SubsetLoadBalancer::LbSubsetEntryPtr SubsetLoadBalancer::findSubset( | |
|
|
||
| void SubsetLoadBalancer::updateFallbackSubset(uint32_t priority, const HostVector& hosts_added, | ||
|
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. update name? as this method now updates not only default subset
Member
Author
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. hmm the panic mode subset is tied to the fallback subset.. not sure what a better name would be. |
||
| const HostVector& hosts_removed) { | ||
| if (fallback_policy_ == envoy::api::v2::Cluster::LbSubsetConfig::NO_FALLBACK) { | ||
| if (fallback_subset_ == nullptr) { | ||
| ENVOY_LOG(debug, "subset lb: fallback load balancer disabled"); | ||
| return; | ||
| } | ||
|
|
||
| if (fallback_subset_ == nullptr) { | ||
| // First update: create the default host subset. | ||
| HostPredicate predicate; | ||
| if (fallback_policy_ == envoy::api::v2::Cluster::LbSubsetConfig::ANY_ENDPOINT) { | ||
| predicate = [](const Host&) -> bool { return true; }; | ||
|
|
||
| ENVOY_LOG(debug, "subset lb: creating any-endpoint fallback load balancer"); | ||
| } else { | ||
| predicate = std::bind(&SubsetLoadBalancer::hostMatches, this, default_subset_metadata_, | ||
| std::placeholders::_1); | ||
|
|
||
| ENVOY_LOG(debug, "subset lb: creating fallback load balancer for {}", | ||
| describeMetadata(default_subset_metadata_)); | ||
| } | ||
| // Add/remove hosts. | ||
| fallback_subset_->priority_subset_->update(priority, hosts_added, hosts_removed); | ||
|
|
||
| fallback_subset_.reset(new LbSubsetEntry()); | ||
| fallback_subset_->priority_subset_.reset( | ||
| new PrioritySubsetImpl(*this, predicate, locality_weight_aware_, scale_locality_weight_)); | ||
| return; | ||
| // Same thing for the panic mode subset. | ||
| if (panic_mode_subset_ != nullptr) { | ||
| panic_mode_subset_->priority_subset_->update(priority, hosts_added, hosts_removed); | ||
| } | ||
|
|
||
| // Subsequent updates: add/remove hosts. | ||
| fallback_subset_->priority_subset_->update(priority, hosts_added, hosts_removed); | ||
| } | ||
|
|
||
| // Iterates over the added and removed hosts, looking up an LbSubsetEntryPtr for each. For every | ||
|
|
@@ -249,9 +253,9 @@ void SubsetLoadBalancer::processSubsets( | |
| if (entry->initialized()) { | ||
| update_cb(entry); | ||
| } else { | ||
| HostPredicate predicate = | ||
| std::bind(&SubsetLoadBalancer::hostMatches, this, kvs, std::placeholders::_1); | ||
|
|
||
| HostPredicate predicate = [this, kvs](const Host& host) -> bool { | ||
| return hostMatches(kvs, host); | ||
| }; | ||
| new_cb(entry, predicate, kvs, adding_hosts); | ||
| } | ||
| } | ||
|
|
||
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.
could be just a personal preference, but would rather use deferred initialisation or private helper method not to make constructor code blow up