@@ -35,6 +35,26 @@ SubsetLoadBalancer::SubsetLoadBalancer(
3535 scale_locality_weight_(subsets.scaleLocalityWeight()) {
3636 ASSERT (subsets.isEnabled ());
3737
38+ if (fallback_policy_ != envoy::api::v2::Cluster::LbSubsetConfig::NO_FALLBACK) {
39+ HostPredicate predicate;
40+ if (fallback_policy_ == envoy::api::v2::Cluster::LbSubsetConfig::ANY_ENDPOINT) {
41+ predicate = [](const Host&) -> bool { return true ; };
42+
43+ ENVOY_LOG (debug, " subset lb: creating any-endpoint fallback load balancer" );
44+ } else {
45+ predicate = [this ](const Host& host) -> bool {
46+ return hostMatches (default_subset_metadata_, host);
47+ };
48+
49+ ENVOY_LOG (debug, " subset lb: creating fallback load balancer for {}" ,
50+ describeMetadata (default_subset_metadata_));
51+ }
52+
53+ fallback_subset_ = std::make_unique<LbSubsetEntry>();
54+ fallback_subset_->priority_subset_ = std::make_unique<PrioritySubsetImpl>(
55+ *this , predicate, locality_weight_aware_, scale_locality_weight_);
56+ }
57+
3858 if (subsets.panicModeAny ()) {
3959 HostPredicate predicate = [](const Host&) -> bool { return true ; };
4060
@@ -186,34 +206,18 @@ SubsetLoadBalancer::LbSubsetEntryPtr SubsetLoadBalancer::findSubset(
186206
187207void SubsetLoadBalancer::updateFallbackSubset (uint32_t priority, const HostVector& hosts_added,
188208 const HostVector& hosts_removed) {
189- if (fallback_policy_ == envoy::api::v2::Cluster::LbSubsetConfig::NO_FALLBACK ) {
209+ if (fallback_subset_ == nullptr ) {
190210 ENVOY_LOG (debug, " subset lb: fallback load balancer disabled" );
191211 return ;
192212 }
193213
194- if (fallback_subset_ == nullptr ) {
195- // First update: create the default host subset.
196- HostPredicate predicate;
197- if (fallback_policy_ == envoy::api::v2::Cluster::LbSubsetConfig::ANY_ENDPOINT) {
198- predicate = [](const Host&) -> bool { return true ; };
199-
200- ENVOY_LOG (debug, " subset lb: creating any-endpoint fallback load balancer" );
201- } else {
202- predicate = std::bind (&SubsetLoadBalancer::hostMatches, this , default_subset_metadata_,
203- std::placeholders::_1);
204-
205- ENVOY_LOG (debug, " subset lb: creating fallback load balancer for {}" ,
206- describeMetadata (default_subset_metadata_));
207- }
214+ // Add/remove hosts.
215+ fallback_subset_->priority_subset_ ->update (priority, hosts_added, hosts_removed);
208216
209- fallback_subset_.reset (new LbSubsetEntry ());
210- fallback_subset_->priority_subset_ .reset (
211- new PrioritySubsetImpl (*this , predicate, locality_weight_aware_, scale_locality_weight_));
212- return ;
217+ // Same thing for the panic mode subset.
218+ if (panic_mode_subset_ != nullptr ) {
219+ panic_mode_subset_->priority_subset_ ->update (priority, hosts_added, hosts_removed);
213220 }
214-
215- // Subsequent updates: add/remove hosts.
216- fallback_subset_->priority_subset_ ->update (priority, hosts_added, hosts_removed);
217221}
218222
219223// Iterates over the added and removed hosts, looking up an LbSubsetEntryPtr for each. For every
@@ -249,9 +253,9 @@ void SubsetLoadBalancer::processSubsets(
249253 if (entry->initialized ()) {
250254 update_cb (entry);
251255 } else {
252- HostPredicate predicate =
253- std::bind (&SubsetLoadBalancer:: hostMatches, this , kvs, std::placeholders::_1 );
254-
256+ HostPredicate predicate = [ this , kvs]( const Host& host) -> bool {
257+ return hostMatches ( kvs, host );
258+ };
255259 new_cb (entry, predicate, kvs, adding_hosts);
256260 }
257261 }
0 commit comments