diff --git a/BUILD b/BUILD
index aab73dbccbe..94bab543e83 100644
--- a/BUILD
+++ b/BUILD
@@ -552,6 +552,7 @@ GRPC_XDS_TARGETS = [
"grpc_lb_policy_xds_cluster_impl",
"grpc_lb_policy_xds_cluster_manager",
"grpc_lb_policy_xds_cluster_resolver",
+ "grpc_lb_policy_xds_wrr_locality",
"grpc_resolver_xds",
"grpc_resolver_c2p",
"grpc_xds_server_config_fetcher",
@@ -5023,15 +5024,20 @@ grpc_cc_library(
)
grpc_cc_library(
- name = "grpc_lb_xds_common",
+ name = "grpc_lb_xds_attributes",
+ srcs = [
+ "src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc",
+ ],
hdrs = [
- "src/core/ext/filters/client_channel/lb_policy/xds/xds.h",
+ "src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h",
],
+ external_deps = ["absl/strings"],
language = "c++",
deps = [
"gpr_platform",
"ref_counted_ptr",
"server_address",
+ "useful",
"xds_client",
],
)
@@ -5056,9 +5062,8 @@ grpc_cc_library(
"grpc_base",
"grpc_client_channel",
"grpc_lb_address_filtering",
- "grpc_lb_policy_ring_hash",
+ "grpc_lb_xds_attributes",
"grpc_lb_xds_channel_args",
- "grpc_lb_xds_common",
"grpc_public_hdrs",
"grpc_resolver",
"grpc_resolver_fake",
@@ -5102,8 +5107,8 @@ grpc_cc_library(
"gpr",
"grpc_base",
"grpc_client_channel",
+ "grpc_lb_xds_attributes",
"grpc_lb_xds_channel_args",
- "grpc_lb_xds_common",
"grpc_public_hdrs",
"grpc_trace",
"grpc_xds_client",
@@ -5166,6 +5171,42 @@ grpc_cc_library(
],
)
+grpc_cc_library(
+ name = "grpc_lb_policy_xds_wrr_locality",
+ srcs = [
+ "src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc",
+ ],
+ external_deps = [
+ "absl/status",
+ "absl/status:statusor",
+ "absl/strings",
+ ],
+ language = "c++",
+ deps = [
+ "channel_args",
+ "config",
+ "debug_location",
+ "gpr",
+ "grpc_base",
+ "grpc_lb_xds_attributes",
+ "grpc_public_hdrs",
+ "grpc_trace",
+ "json",
+ "json_args",
+ "json_object_loader",
+ "lb_policy",
+ "lb_policy_factory",
+ "lb_policy_registry",
+ "orphanable",
+ "pollset_set",
+ "ref_counted_ptr",
+ "server_address",
+ "subchannel_interface",
+ "validation_errors",
+ "xds_client",
+ ],
+)
+
grpc_cc_library(
name = "grpc_lb_address_filtering",
srcs = [
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 87bfa48d5c8..8a042cba728 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1716,9 +1716,11 @@ add_library(grpc
src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc
src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
+ src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
+ src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc
src/core/ext/filters/client_channel/local_subchannel_pool.cc
src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc
src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
diff --git a/Makefile b/Makefile
index 5e416f9ef87..42c94d8e2bb 100644
--- a/Makefile
+++ b/Makefile
@@ -989,9 +989,11 @@ LIBGRPC_SRC = \
src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc \
src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc \
src/core/ext/filters/client_channel/lb_policy/xds/cds.cc \
+ src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc \
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc \
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc \
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc \
+ src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc \
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc \
src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \
@@ -2793,9 +2795,11 @@ ifneq ($(OPENSSL_DEP),)
# installing headers to their final destination on the drive. We need this
# otherwise parallel compilation will fail if a source is compiled first.
src/core/ext/filters/client_channel/lb_policy/xds/cds.cc: $(OPENSSL_DEP)
+src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc: $(OPENSSL_DEP)
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc: $(OPENSSL_DEP)
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc: $(OPENSSL_DEP)
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc: $(OPENSSL_DEP)
+src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc: $(OPENSSL_DEP)
src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc: $(OPENSSL_DEP)
src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc: $(OPENSSL_DEP)
src/core/ext/filters/rbac/rbac_filter.cc: $(OPENSSL_DEP)
diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml
index b0970e4a3ab..3f55ecf428d 100644
--- a/build_autogenerated.yaml
+++ b/build_autogenerated.yaml
@@ -336,7 +336,7 @@ libs:
- src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h
- src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h
- src/core/ext/filters/client_channel/lb_policy/subchannel_list.h
- - src/core/ext/filters/client_channel/lb_policy/xds/xds.h
+ - src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h
- src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h
- src/core/ext/filters/client_channel/local_subchannel_pool.h
- src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h
@@ -1047,9 +1047,11 @@ libs:
- src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
- src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc
- src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
+ - src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc
- src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
- src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc
- src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
+ - src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc
- src/core/ext/filters/client_channel/local_subchannel_pool.cc
- src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc
- src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
diff --git a/config.m4 b/config.m4
index 2ea580cf2ca..713c8ac41e0 100644
--- a/config.m4
+++ b/config.m4
@@ -71,9 +71,11 @@ if test "$PHP_GRPC" != "no"; then
src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc \
src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc \
src/core/ext/filters/client_channel/lb_policy/xds/cds.cc \
+ src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc \
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc \
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc \
src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc \
+ src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc \
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc \
src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \
diff --git a/config.w32 b/config.w32
index eea9718381e..d6045ba1670 100644
--- a/config.w32
+++ b/config.w32
@@ -37,9 +37,11 @@ if (PHP_GRPC != "no") {
"src\\core\\ext\\filters\\client_channel\\lb_policy\\round_robin\\round_robin.cc " +
"src\\core\\ext\\filters\\client_channel\\lb_policy\\weighted_target\\weighted_target.cc " +
"src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\cds.cc " +
+ "src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_attributes.cc " +
"src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_cluster_impl.cc " +
"src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_cluster_manager.cc " +
"src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_cluster_resolver.cc " +
+ "src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_wrr_locality.cc " +
"src\\core\\ext\\filters\\client_channel\\local_subchannel_pool.cc " +
"src\\core\\ext\\filters\\client_channel\\resolver\\binder\\binder_resolver.cc " +
"src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\dns_resolver_ares.cc " +
diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec
index 4eb9d98e9e8..ff7e8e3ba9f 100644
--- a/gRPC-C++.podspec
+++ b/gRPC-C++.podspec
@@ -249,7 +249,7 @@ Pod::Spec.new do |s|
'src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h',
'src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h',
'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h',
- 'src/core/ext/filters/client_channel/lb_policy/xds/xds.h',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h',
'src/core/ext/filters/client_channel/local_subchannel_pool.h',
'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h',
@@ -1132,7 +1132,7 @@ Pod::Spec.new do |s|
'src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h',
'src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h',
'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h',
- 'src/core/ext/filters/client_channel/lb_policy/xds/xds.h',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h',
'src/core/ext/filters/client_channel/local_subchannel_pool.h',
'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h',
diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec
index 972c11ea77e..b327246f582 100644
--- a/gRPC-Core.podspec
+++ b/gRPC-Core.podspec
@@ -255,11 +255,13 @@ Pod::Spec.new do |s|
'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h',
'src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/cds.cc',
- 'src/core/ext/filters/client_channel/lb_policy/xds/xds.h',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc',
'src/core/ext/filters/client_channel/local_subchannel_pool.cc',
'src/core/ext/filters/client_channel/local_subchannel_pool.h',
'src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc',
@@ -1781,7 +1783,7 @@ Pod::Spec.new do |s|
'src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h',
'src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h',
'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h',
- 'src/core/ext/filters/client_channel/lb_policy/xds/xds.h',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h',
'src/core/ext/filters/client_channel/local_subchannel_pool.h',
'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h',
diff --git a/grpc.gemspec b/grpc.gemspec
index 6dc84c8a9d7..93e9e90e37e 100644
--- a/grpc.gemspec
+++ b/grpc.gemspec
@@ -166,11 +166,13 @@ Gem::Specification.new do |s|
s.files += %w( src/core/ext/filters/client_channel/lb_policy/subchannel_list.h )
s.files += %w( src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc )
s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/cds.cc )
- s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds.h )
+ s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc )
+ s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h )
s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h )
s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc )
s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc )
s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc )
+ s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc )
s.files += %w( src/core/ext/filters/client_channel/local_subchannel_pool.cc )
s.files += %w( src/core/ext/filters/client_channel/local_subchannel_pool.h )
s.files += %w( src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc )
diff --git a/grpc.gyp b/grpc.gyp
index 37e7226fe68..f496f3d1f1e 100644
--- a/grpc.gyp
+++ b/grpc.gyp
@@ -403,9 +403,11 @@
'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc',
'src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/cds.cc',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc',
'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc',
+ 'src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc',
'src/core/ext/filters/client_channel/local_subchannel_pool.cc',
'src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc',
'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc',
diff --git a/package.xml b/package.xml
index 5af3a17129d..95d29a830d0 100644
--- a/package.xml
+++ b/package.xml
@@ -148,11 +148,13 @@
-
+
+
+
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
index d86f66cb830..5bc13e7aece 100644
--- a/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
@@ -504,27 +504,15 @@ void CdsLb::OnClusterChanged(const std::string& name,
// underlying cluster that we may be processing an update for.
auto it = watchers_.find(config_->cluster());
GPR_ASSERT(it != watchers_.end());
- const std::string& lb_policy = it->second.update->lb_policy;
// Construct config for child policy.
- Json::Object xds_lb_policy;
- if (lb_policy == "RING_HASH") {
- xds_lb_policy["RING_HASH"] = Json::Object{
- {"min_ring_size", cluster_data.min_ring_size},
- {"max_ring_size", cluster_data.max_ring_size},
- };
- } else {
- xds_lb_policy["ROUND_ROBIN"] = Json::Object();
- }
- Json::Object child_config = {
- {"xdsLbPolicy",
- Json::Array{
- xds_lb_policy,
- }},
- {"discoveryMechanisms", std::move(discovery_mechanisms)},
- };
Json json = Json::Array{
Json::Object{
- {"xds_cluster_resolver_experimental", std::move(child_config)},
+ {"xds_cluster_resolver_experimental",
+ Json::Object{
+ {"xdsLbPolicy",
+ std::move(it->second.update->lb_policy_config)},
+ {"discoveryMechanisms", std::move(discovery_mechanisms)},
+ }},
},
};
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc
new file mode 100644
index 00000000000..e6918fa4d4e
--- /dev/null
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc
@@ -0,0 +1,42 @@
+//
+// Copyright 2018 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include
+
+#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h"
+
+#include "absl/strings/str_cat.h"
+
+#include "src/core/lib/gpr/useful.h"
+
+namespace grpc_core {
+
+const char* kXdsLocalityNameAttributeKey = "xds_locality_name";
+
+int XdsLocalityAttribute::Cmp(const AttributeInterface* other) const {
+ const auto* other_locality_attr =
+ static_cast(other);
+ int r = locality_name_->Compare(*other_locality_attr->locality_name_);
+ if (r != 0) return r;
+ return QsortCompare(weight_, other_locality_attr->weight_);
+}
+
+std::string XdsLocalityAttribute::ToString() const {
+ return absl::StrCat("{name=", locality_name_->AsHumanReadableString(),
+ ", weight=", weight_, "}");
+}
+
+} // namespace grpc_core
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.h b/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h
similarity index 65%
rename from src/core/ext/filters/client_channel/lb_policy/xds/xds.h
rename to src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h
index 0b2ea4e2f9a..17382c34d4e 100644
--- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.h
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h
@@ -14,11 +14,13 @@
// limitations under the License.
//
-#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_H
-#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_H
+#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_ATTRIBUTES_H
+#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_ATTRIBUTES_H
#include
+#include
+
#include
#include
#include
@@ -29,36 +31,34 @@
namespace grpc_core {
-// Defined in the EDS policy.
extern const char* kXdsLocalityNameAttributeKey;
class XdsLocalityAttribute : public ServerAddress::AttributeInterface {
public:
- explicit XdsLocalityAttribute(RefCountedPtr locality_name)
- : locality_name_(std::move(locality_name)) {}
+ XdsLocalityAttribute(RefCountedPtr locality_name,
+ uint32_t weight)
+ : locality_name_(std::move(locality_name)), weight_(weight) {}
RefCountedPtr locality_name() const {
return locality_name_;
}
+ uint32_t weight() const { return weight_; }
+
std::unique_ptr Copy() const override {
- return std::make_unique(locality_name_->Ref());
+ return std::make_unique(locality_name_->Ref(),
+ weight_);
}
- int Cmp(const AttributeInterface* other) const override {
- const auto* other_locality_attr =
- static_cast(other);
- return locality_name_->Compare(*other_locality_attr->locality_name_);
- }
+ int Cmp(const AttributeInterface* other) const override;
- std::string ToString() const override {
- return locality_name_->AsHumanReadableString();
- }
+ std::string ToString() const override;
private:
RefCountedPtr locality_name_;
+ uint32_t weight_;
};
} // namespace grpc_core
-#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_H */
+#endif // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_ATTRIBUTES_H
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
index e1d8f28c4de..fd1c72ba8ae 100644
--- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
@@ -38,7 +38,7 @@
#include
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
-#include "src/core/ext/filters/client_channel/lb_policy/xds/xds.h"
+#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h"
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h"
#include "src/core/ext/xds/xds_bootstrap.h"
#include "src/core/ext/xds/xds_bootstrap_grpc.h"
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
index ed7e740479e..5ebbcd8f9ef 100644
--- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
@@ -40,8 +40,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
-#include "src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h"
-#include "src/core/ext/filters/client_channel/lb_policy/xds/xds.h"
+#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h"
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/ext/xds/xds_bootstrap.h"
@@ -78,8 +77,6 @@ namespace grpc_core {
TraceFlag grpc_lb_xds_cluster_resolver_trace(false, "xds_cluster_resolver_lb");
-const char* kXdsLocalityNameAttributeKey = "xds_locality_name";
-
namespace {
constexpr absl::string_view kXdsClusterResolver =
@@ -147,7 +144,7 @@ class XdsClusterResolverLbConfig : public LoadBalancingPolicy::Config {
private:
std::vector discovery_mechanisms_;
- Json xds_lb_policy_ = Json::Object{{"ROUND_ROBIN", Json::Object()}};
+ Json xds_lb_policy_;
};
// Xds Cluster Resolver LB policy.
@@ -839,7 +836,7 @@ ServerAddressList XdsClusterResolverLb::CreateChildPolicyAddressesLocked() {
MakeHierarchicalPathAttribute(hierarchical_path))
.WithAttribute(kXdsLocalityNameAttributeKey,
std::make_unique(
- locality_name->Ref()))
+ locality_name->Ref(), locality.lb_weight))
.WithAttribute(
ServerAddressWeightAttribute::
kServerAddressWeightAttributeKey,
@@ -870,60 +867,13 @@ XdsClusterResolverLb::CreateChildPolicyConfigLocked() {
for (size_t priority = 0;
priority < discovery_entry.latest_update->priorities.size();
++priority) {
- const auto& priority_entry =
- discovery_entry.latest_update->priorities[priority];
Json child_policy;
if (!discovery_entry.discovery_mechanism->override_child_policy()
.empty()) {
child_policy =
discovery_entry.discovery_mechanism->override_child_policy();
} else {
- const auto& xds_lb_policy = config_->xds_lb_policy().object_value();
- if (xds_lb_policy.find("ROUND_ROBIN") != xds_lb_policy.end()) {
- const auto& localities = priority_entry.localities;
- Json::Object weighted_targets;
- for (const auto& p : localities) {
- XdsLocalityName* locality_name = p.first;
- const auto& locality = p.second;
- // Add weighted target entry.
- weighted_targets[locality_name->AsHumanReadableString()] =
- Json::Object{
- {"weight", locality.lb_weight},
- {"childPolicy",
- Json::Array{
- Json::Object{
- {"round_robin", Json::Object()},
- },
- }},
- };
- }
- // Construct locality-picking policy.
- // Start with field from our config and add the "targets" field.
- child_policy = Json::Array{
- Json::Object{
- {"weighted_target_experimental",
- Json::Object{
- {"targets", Json::Object()},
- }},
- },
- };
- Json::Object& config =
- *(*child_policy.mutable_array())[0].mutable_object();
- auto it = config.begin();
- GPR_ASSERT(it != config.end());
- (*it->second.mutable_object())["targets"] =
- std::move(weighted_targets);
- } else {
- auto it = xds_lb_policy.find("RING_HASH");
- GPR_ASSERT(it != xds_lb_policy.end());
- Json::Object ring_hash_experimental_policy =
- it->second.object_value();
- child_policy = Json::Array{
- Json::Object{
- {"ring_hash_experimental", ring_hash_experimental_policy},
- },
- };
- }
+ child_policy = config_->xds_lb_policy();
}
// Wrap it in the drop policy.
Json::Array drop_categories;
@@ -1128,8 +1078,7 @@ const JsonLoaderInterface* XdsClusterResolverLbConfig::JsonLoader(
return loader;
}
-void XdsClusterResolverLbConfig::JsonPostLoad(const Json& json,
- const JsonArgs& args,
+void XdsClusterResolverLbConfig::JsonPostLoad(const Json& json, const JsonArgs&,
ValidationErrors* errors) {
// Validate discoveryMechanisms.
{
@@ -1142,37 +1091,14 @@ void XdsClusterResolverLbConfig::JsonPostLoad(const Json& json,
{
ValidationErrors::ScopedField field(errors, ".xdsLbPolicy");
auto it = json.object_value().find("xdsLbPolicy");
- if (it != json.object_value().end()) {
- if (it->second.type() != Json::Type::ARRAY) {
- errors->AddError("is not an array");
- } else {
- const Json::Array& array = it->second.array_value();
- for (size_t i = 0; i < array.size(); ++i) {
- ValidationErrors::ScopedField field(errors,
- absl::StrCat("[", i, "]"));
- if (array[i].type() != Json::Type::OBJECT) {
- errors->AddError("is not an object");
- continue;
- }
- const Json::Object& policy = array[i].object_value();
- auto policy_it = policy.find("ROUND_ROBIN");
- if (policy_it != policy.end()) {
- ValidationErrors::ScopedField field(errors, "[\"ROUND_ROBIN\"]");
- if (policy_it->second.type() != Json::Type::OBJECT) {
- errors->AddError("is not an object");
- }
- break;
- }
- {
- ValidationErrors::ScopedField field(errors, "[\"RING_HASH\"]");
- policy_it = policy.find("RING_HASH");
- if (policy_it != policy.end()) {
- LoadFromJson(policy_it->second, args, errors);
- xds_lb_policy_ = array[i];
- }
- }
- }
- }
+ if (it == json.object_value().end()) {
+ errors->AddError("field not present");
+ } else {
+ auto lb_config = CoreConfiguration::Get()
+ .lb_policy_registry()
+ .ParseLoadBalancingConfig(it->second);
+ if (!lb_config.ok()) errors->AddError(lb_config.status().message());
+ xds_lb_policy_ = it->second;
}
}
}
diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc
new file mode 100644
index 00000000000..1f7d1c83936
--- /dev/null
+++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc
@@ -0,0 +1,357 @@
+//
+// Copyright 2022 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include
+
+#include
+#include