diff --git a/BUILD b/BUILD index 74af17760a9..0f3b426ff06 100644 --- a/BUILD +++ b/BUILD @@ -1226,15 +1226,12 @@ grpc_cc_library( "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h", ], - external_deps = [ - "nanopb", - ], language = "c++", deps = [ "grpc_base", "grpc_client_channel", "grpc_resolver_fake", - "grpclb_proto", + "grpc_lb_upb", ], ) @@ -1254,16 +1251,13 @@ grpc_cc_library( "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h", ], - external_deps = [ - "nanopb", - ], language = "c++", deps = [ "grpc_base", "grpc_client_channel", "grpc_resolver_fake", "grpc_secure", - "grpclb_proto", + "grpc_lb_upb", ], ) diff --git a/BUILD.gn b/BUILD.gn index 9b003465bc8..28a950c13cf 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -410,8 +410,24 @@ config("grpc_config") { "src/core/ext/transport/inproc/inproc_plugin.cc", "src/core/ext/transport/inproc/inproc_transport.cc", "src/core/ext/transport/inproc/inproc_transport.h", + "src/core/ext/upb-generated/google/protobuf/any.upb.c", + "src/core/ext/upb-generated/google/protobuf/any.upb.h", + "src/core/ext/upb-generated/google/protobuf/descriptor.upb.c", + "src/core/ext/upb-generated/google/protobuf/descriptor.upb.h", + "src/core/ext/upb-generated/google/protobuf/duration.upb.c", + "src/core/ext/upb-generated/google/protobuf/duration.upb.h", + "src/core/ext/upb-generated/google/protobuf/empty.upb.c", + "src/core/ext/upb-generated/google/protobuf/empty.upb.h", + "src/core/ext/upb-generated/google/protobuf/struct.upb.c", + "src/core/ext/upb-generated/google/protobuf/struct.upb.h", + "src/core/ext/upb-generated/google/protobuf/timestamp.upb.c", + "src/core/ext/upb-generated/google/protobuf/timestamp.upb.h", + "src/core/ext/upb-generated/google/protobuf/wrappers.upb.c", + "src/core/ext/upb-generated/google/protobuf/wrappers.upb.h", "src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c", "src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h", + "src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c", + "src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h", "src/core/lib/avl/avl.cc", "src/core/lib/avl/avl.h", "src/core/lib/backoff/backoff.cc", diff --git a/CMakeLists.txt b/CMakeLists.txt index 2034ec6c490..6c3c7d3feb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1322,14 +1322,22 @@ add_library(grpc src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc + src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c + src/core/ext/upb-generated/google/protobuf/any.upb.c + src/core/ext/upb-generated/google/protobuf/descriptor.upb.c + src/core/ext/upb-generated/google/protobuf/duration.upb.c + src/core/ext/upb-generated/google/protobuf/empty.upb.c + src/core/ext/upb-generated/google/protobuf/struct.upb.c + src/core/ext/upb-generated/google/protobuf/timestamp.upb.c + src/core/ext/upb-generated/google/protobuf/wrappers.upb.c src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c src/core/ext/filters/client_channel/lb_policy/xds/xds.cc src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -2795,16 +2803,24 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc + src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c + src/core/ext/upb-generated/google/protobuf/any.upb.c + src/core/ext/upb-generated/google/protobuf/descriptor.upb.c + src/core/ext/upb-generated/google/protobuf/duration.upb.c + src/core/ext/upb-generated/google/protobuf/empty.upb.c + src/core/ext/upb-generated/google/protobuf/struct.upb.c + src/core/ext/upb-generated/google/protobuf/timestamp.upb.c + src/core/ext/upb-generated/google/protobuf/wrappers.upb.c + src/core/ext/filters/client_channel/lb_policy/xds/xds.cc + src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc + src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc + src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c third_party/nanopb/pb_common.c third_party/nanopb/pb_decode.c third_party/nanopb/pb_encode.c - src/core/ext/filters/client_channel/lb_policy/xds/xds.cc - src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc - src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc - src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc src/core/ext/filters/census/grpc_context.cc diff --git a/Makefile b/Makefile index 97eb59912ec..4ea6acdb4bf 100644 --- a/Makefile +++ b/Makefile @@ -3813,14 +3813,22 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ + src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c \ + src/core/ext/upb-generated/google/protobuf/any.upb.c \ + src/core/ext/upb-generated/google/protobuf/descriptor.upb.c \ + src/core/ext/upb-generated/google/protobuf/duration.upb.c \ + src/core/ext/upb-generated/google/protobuf/empty.upb.c \ + src/core/ext/upb-generated/google/protobuf/struct.upb.c \ + src/core/ext/upb-generated/google/protobuf/timestamp.upb.c \ + src/core/ext/upb-generated/google/protobuf/wrappers.upb.c \ src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc \ - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c \ - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c \ - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ src/core/ext/filters/client_channel/lb_policy/xds/xds.cc \ src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc \ src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc \ + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c \ + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c \ + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ @@ -5210,16 +5218,24 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ + src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c \ + src/core/ext/upb-generated/google/protobuf/any.upb.c \ + src/core/ext/upb-generated/google/protobuf/descriptor.upb.c \ + src/core/ext/upb-generated/google/protobuf/duration.upb.c \ + src/core/ext/upb-generated/google/protobuf/empty.upb.c \ + src/core/ext/upb-generated/google/protobuf/struct.upb.c \ + src/core/ext/upb-generated/google/protobuf/timestamp.upb.c \ + src/core/ext/upb-generated/google/protobuf/wrappers.upb.c \ + src/core/ext/filters/client_channel/lb_policy/xds/xds.cc \ + src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc \ + src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc \ + src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ third_party/nanopb/pb_common.c \ third_party/nanopb/pb_decode.c \ third_party/nanopb/pb_encode.c \ - src/core/ext/filters/client_channel/lb_policy/xds/xds.cc \ - src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc \ - src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc \ - src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc \ src/core/ext/filters/census/grpc_context.cc \ diff --git a/build.yaml b/build.yaml index 0563f6558fb..24da28e2591 100644 --- a/build.yaml +++ b/build.yaml @@ -725,9 +725,8 @@ filegroups: uses: - grpc_base - grpc_client_channel + - grpc_lb_upb - grpc_resolver_fake - - grpclb_proto - - nanopb - upb - name: grpc_lb_policy_grpclb_secure headers: @@ -746,10 +745,9 @@ filegroups: uses: - grpc_base - grpc_client_channel + - grpc_lb_upb - grpc_resolver_fake - grpc_secure - - grpclb_proto - - nanopb - upb - name: grpc_lb_policy_pick_first src: @@ -785,7 +783,6 @@ filegroups: - grpc_resolver_fake - grpclb_proto - nanopb - - upb - name: grpc_lb_policy_xds_secure headers: - src/core/ext/filters/client_channel/lb_policy/xds/xds.h @@ -805,7 +802,6 @@ filegroups: - grpc_secure - grpclb_proto - nanopb - - upb - name: grpc_lb_subchannel_list headers: - src/core/ext/filters/client_channel/lb_policy/subchannel_list.h diff --git a/config.m4 b/config.m4 index 34974f18ac2..a23d65f8542 100644 --- a/config.m4 +++ b/config.m4 @@ -401,14 +401,22 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ + src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c \ + src/core/ext/upb-generated/google/protobuf/any.upb.c \ + src/core/ext/upb-generated/google/protobuf/descriptor.upb.c \ + src/core/ext/upb-generated/google/protobuf/duration.upb.c \ + src/core/ext/upb-generated/google/protobuf/empty.upb.c \ + src/core/ext/upb-generated/google/protobuf/struct.upb.c \ + src/core/ext/upb-generated/google/protobuf/timestamp.upb.c \ + src/core/ext/upb-generated/google/protobuf/wrappers.upb.c \ src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc \ - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c \ - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c \ - src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ src/core/ext/filters/client_channel/lb_policy/xds/xds.cc \ src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc \ src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc \ + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c \ + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c \ + src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ @@ -729,7 +737,9 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/transport/chttp2/server/secure) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/transport/chttp2/transport) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/transport/inproc) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/upb-generated/google/protobuf) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/upb-generated/src/proto/grpc/health/v1) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/upb-generated/src/proto/grpc/lb/v1) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/avl) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/backoff) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/channel) diff --git a/config.w32 b/config.w32 index db7f05c7aa5..27635b54544 100644 --- a/config.w32 +++ b/config.w32 @@ -374,14 +374,22 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\grpclb_channel_secure.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\grpclb_client_stats.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\load_balancer_api.cc " + + "src\\core\\ext\\upb-generated\\src\\proto\\grpc\\lb\\v1\\load_balancer.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\any.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\descriptor.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\duration.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\empty.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\struct.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\timestamp.upb.c " + + "src\\core\\ext\\upb-generated\\google\\protobuf\\wrappers.upb.c " + "src\\core\\ext\\filters\\client_channel\\resolver\\fake\\fake_resolver.cc " + - "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\google\\protobuf\\duration.pb.c " + - "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\google\\protobuf\\timestamp.pb.c " + - "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\load_balancer.pb.c " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_channel_secure.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_client_stats.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\xds\\xds_load_balancer_api.cc " + + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\google\\protobuf\\duration.pb.c " + + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\google\\protobuf\\timestamp.pb.c " + + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\load_balancer.pb.c " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\pick_first\\pick_first.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\round_robin\\round_robin.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\dns_resolver_ares.cc " + @@ -742,11 +750,15 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\transport\\chttp2\\transport"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\transport\\inproc"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\google"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\google\\protobuf"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src\\proto"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src\\proto\\grpc"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src\\proto\\grpc\\health"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src\\proto\\grpc\\health\\v1"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src\\proto\\grpc\\lb"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\upb-generated\\src\\proto\\grpc\\lb\\v1"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\avl"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\backoff"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 7e728026e68..b1a169207ac 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -578,13 +578,21 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h', + 'src/core/ext/upb-generated/google/protobuf/any.upb.h', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.h', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.h', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.h', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.h', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.h', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.h', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 1e2be599afb..6a449efed19 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -533,13 +533,21 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h', + 'src/core/ext/upb-generated/google/protobuf/any.upb.h', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.h', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.h', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.h', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.h', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.h', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.h', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h', @@ -861,14 +869,22 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c', + 'src/core/ext/upb-generated/google/protobuf/any.upb.c', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.c', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.c', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.c', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.c', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.c', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'src/core/ext/filters/client_channel/lb_policy/xds/xds.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', @@ -1198,13 +1214,21 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h', + 'src/core/ext/upb-generated/google/protobuf/any.upb.h', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.h', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.h', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.h', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.h', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.h', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.h', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h', diff --git a/grpc.gemspec b/grpc.gemspec index 45f4a759473..12fddb3252e 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -467,13 +467,21 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h ) + s.files += %w( src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/any.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/descriptor.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/duration.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/empty.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/struct.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/timestamp.upb.h ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/wrappers.upb.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h ) - s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h ) - s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h ) - s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/subchannel_list.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h ) @@ -798,14 +806,22 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc ) + s.files += %w( src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/any.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/descriptor.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/duration.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/empty.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/struct.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/timestamp.upb.c ) + s.files += %w( src/core/ext/upb-generated/google/protobuf/wrappers.upb.c ) s.files += %w( src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc ) - s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c ) - s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c ) - s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc ) diff --git a/grpc.gyp b/grpc.gyp index a5287a606ed..040831ec4f3 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -611,14 +611,22 @@ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c', + 'src/core/ext/upb-generated/google/protobuf/any.upb.c', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.c', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.c', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.c', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.c', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.c', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'src/core/ext/filters/client_channel/lb_policy/xds/xds.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', @@ -1416,16 +1424,24 @@ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c', + 'src/core/ext/upb-generated/google/protobuf/any.upb.c', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.c', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.c', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.c', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.c', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.c', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.c', + 'src/core/ext/filters/client_channel/lb_policy/xds/xds.cc', + 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc', + 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc', + 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'third_party/nanopb/pb_common.c', 'third_party/nanopb/pb_decode.c', 'third_party/nanopb/pb_encode.c', - 'src/core/ext/filters/client_channel/lb_policy/xds/xds.cc', - 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc', - 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc', - 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', 'src/core/ext/filters/census/grpc_context.cc', diff --git a/package.xml b/package.xml index fc68a9cdf12..5b85159a4f5 100644 --- a/package.xml +++ b/package.xml @@ -472,13 +472,21 @@ + + + + + + + + - - - + + + @@ -803,14 +811,22 @@ + + + + + + + + - - - + + + diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index bc4b63b74ec..6a565e057b9 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -409,18 +409,18 @@ void ParseServer(const grpc_grpclb_server* server, const uint16_t netorder_port = grpc_htons((uint16_t)server->port); /* the addresses are given in binary format (a in(6)_addr struct) in * server->ip_address.bytes. */ - const grpc_grpclb_ip_address* ip = &server->ip_address; - if (ip->size == 4) { + const grpc_grpclb_server_ip_address& ip = server->ip_address; + if (ip.size == 4) { addr->len = static_cast(sizeof(grpc_sockaddr_in)); grpc_sockaddr_in* addr4 = reinterpret_cast(&addr->addr); addr4->sin_family = GRPC_AF_INET; - memcpy(&addr4->sin_addr, ip->bytes, ip->size); + memcpy(&addr4->sin_addr, ip.data, ip.size); addr4->sin_port = netorder_port; - } else if (ip->size == 16) { + } else if (ip.size == 16) { addr->len = static_cast(sizeof(grpc_sockaddr_in6)); grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)&addr->addr; addr6->sin6_family = GRPC_AF_INET6; - memcpy(&addr6->sin6_addr, ip->bytes, ip->size); + memcpy(&addr6->sin6_addr, ip.data, ip.size); addr6->sin6_port = netorder_port; } } @@ -490,7 +490,7 @@ const grpc_arg_pointer_vtable client_stats_arg_vtable = { bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) { if (server->drop) return false; - const grpc_grpclb_ip_address* ip = &server->ip_address; + const grpc_grpclb_server_ip_address& ip = server->ip_address; if (GPR_UNLIKELY(server->port >> 16 != 0)) { if (log) { gpr_log(GPR_ERROR, @@ -499,12 +499,12 @@ bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) { } return false; } - if (GPR_UNLIKELY(ip->size != 4 && ip->size != 16)) { + if (GPR_UNLIKELY(ip.size != 4 && ip.size != 16)) { if (log) { gpr_log(GPR_ERROR, "Expected IP to be 4 or 16 bytes, got %d at index %lu of " "serverlist. Ignoring", - ip->size, (unsigned long)idx); + ip.size, (unsigned long)idx); } return false; } @@ -523,7 +523,7 @@ ServerAddressList GrpcLb::Serverlist::GetServerAddressList( ParseServer(server, &addr); // LB token processing. char lb_token[GPR_ARRAY_SIZE(server->load_balance_token) + 1]; - if (server->has_load_balance_token) { + if (server->load_balance_token[0] != 0) { const size_t lb_token_max_length = GPR_ARRAY_SIZE(server->load_balance_token); const size_t lb_token_length = @@ -790,13 +790,14 @@ GrpcLb::BalancerCallState::BalancerCallState( GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, nullptr, deadline, nullptr); // Init the LB call request payload. + upb::Arena arena; grpc_grpclb_request* request = - grpc_grpclb_request_create(grpclb_policy()->server_name_); - grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); + grpc_grpclb_request_create(grpclb_policy()->server_name_, arena.ptr()); + grpc_slice request_payload_slice = + grpc_grpclb_request_encode(request, arena.ptr()); send_message_payload_ = grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_slice_unref_internal(request_payload_slice); - grpc_grpclb_request_destroy(request); // Init other data associated with the LB call. grpc_metadata_array_init(&lb_initial_metadata_recv_); grpc_metadata_array_init(&lb_trailing_metadata_recv_); @@ -940,27 +941,32 @@ void GrpcLb::BalancerCallState::MaybeSendClientLoadReportLocked( bool GrpcLb::BalancerCallState::LoadReportCountersAreZero( grpc_grpclb_request* request) { - GrpcLbClientStats::DroppedCallCounts* drop_entries = - static_cast( - request->client_stats.calls_finished_with_drop.arg); - return request->client_stats.num_calls_started == 0 && - request->client_stats.num_calls_finished == 0 && - request->client_stats.num_calls_finished_with_client_failed_to_send == + const grpc_lb_v1_ClientStats* cstats = + grpc_lb_v1_LoadBalanceRequest_client_stats(request); + if (cstats == nullptr) { + return true; + } + size_t drop_count; + grpc_lb_v1_ClientStats_calls_finished_with_drop(cstats, &drop_count); + return grpc_lb_v1_ClientStats_num_calls_started(cstats) == 0 && + grpc_lb_v1_ClientStats_num_calls_finished(cstats) == 0 && + grpc_lb_v1_ClientStats_num_calls_finished_with_client_failed_to_send( + cstats) == 0 && + grpc_lb_v1_ClientStats_num_calls_finished_known_received(cstats) == 0 && - request->client_stats.num_calls_finished_known_received == 0 && - (drop_entries == nullptr || drop_entries->size() == 0); + drop_count == 0; } void GrpcLb::BalancerCallState::SendClientLoadReportLocked() { // Construct message payload. GPR_ASSERT(send_message_payload_ == nullptr); + upb::Arena arena; grpc_grpclb_request* request = - grpc_grpclb_load_report_request_create(client_stats_.get()); + grpc_grpclb_load_report_request_create(client_stats_.get(), arena.ptr()); // Skip client load report if the counters were all zero in the last // report and they are still zero in this one. if (LoadReportCountersAreZero(request)) { if (last_client_load_report_counters_were_zero_) { - grpc_grpclb_request_destroy(request); ScheduleNextClientLoadReportLocked(); return; } @@ -968,11 +974,11 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() { } else { last_client_load_report_counters_were_zero_ = false; } - grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); + grpc_slice request_payload_slice = + grpc_grpclb_request_encode(request, arena.ptr()); send_message_payload_ = grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_slice_unref_internal(request_payload_slice); - grpc_grpclb_request_destroy(request); // Send the report. grpc_op op; memset(&op, 0, sizeof(op)); @@ -1034,16 +1040,20 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked( grpc_byte_buffer_reader_destroy(&bbr); grpc_byte_buffer_destroy(lb_calld->recv_message_payload_); lb_calld->recv_message_payload_ = nullptr; - grpc_grpclb_initial_response* initial_response; + const grpc_grpclb_initial_response* initial_response; grpc_grpclb_serverlist* serverlist; + upb::Arena arena; if (!lb_calld->seen_initial_response_ && - (initial_response = grpc_grpclb_initial_response_parse(response_slice)) != - nullptr) { + (initial_response = grpc_grpclb_initial_response_parse( + response_slice, arena.ptr())) != nullptr) { // Have NOT seen initial response, look for initial response. - if (initial_response->has_client_stats_report_interval) { - lb_calld->client_stats_report_interval_ = GPR_MAX( - GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( - &initial_response->client_stats_report_interval)); + const google_protobuf_Duration* client_stats_report_interval = + grpc_lb_v1_InitialLoadBalanceResponse_client_stats_report_interval( + initial_response); + if (client_stats_report_interval != nullptr) { + lb_calld->client_stats_report_interval_ = + GPR_MAX(GPR_MS_PER_SEC, + grpc_grpclb_duration_to_millis(client_stats_report_interval)); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "[grpclb %p] lb_calld=%p: Received initial LB response " @@ -1058,7 +1068,6 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked( "client load reporting NOT enabled", grpclb_policy, lb_calld); } - grpc_grpclb_initial_response_destroy(initial_response); lb_calld->seen_initial_response_ = true; } else if ((serverlist = grpc_grpclb_response_parse_serverlist( response_slice)) != nullptr) { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc index 22cefc937b0..68097e14a4e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc @@ -18,213 +18,154 @@ #include -#include "pb_decode.h" -#include "pb_encode.h" #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" +#include "src/core/lib/gpr/useful.h" -#include - -/* invoked once for every Server in ServerList */ -static bool count_serverlist(pb_istream_t* stream, const pb_field_t* field, - void** arg) { - grpc_grpclb_serverlist* sl = static_cast(*arg); - grpc_grpclb_server server; - if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, &server))) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); - return false; - } - ++sl->num_servers; - return true; -} - -typedef struct decode_serverlist_arg { - /* The decoding callback is invoked once per server in serverlist. Remember - * which index of the serverlist are we currently decoding */ - size_t decoding_idx; - /* The decoded serverlist */ - grpc_grpclb_serverlist* serverlist; -} decode_serverlist_arg; +#include "google/protobuf/duration.upb.h" +#include "google/protobuf/timestamp.upb.h" -/* invoked once for every Server in ServerList */ -static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field, - void** arg) { - decode_serverlist_arg* dec_arg = static_cast(*arg); - GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx); - grpc_grpclb_server* server = - static_cast(gpr_zalloc(sizeof(grpc_grpclb_server))); - if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, server))) { - gpr_free(server); - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); - return false; - } - dec_arg->serverlist->servers[dec_arg->decoding_idx++] = server; - return true; -} +#include -grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) { - grpc_grpclb_request* req = static_cast( - gpr_malloc(sizeof(grpc_grpclb_request))); - req->has_client_stats = false; - req->has_initial_request = true; - req->initial_request.has_name = true; - // GCC warns (-Wstringop-truncation) because the destination - // buffer size is identical to max-size, leading to a potential - // char[] with no null terminator. nanopb can handle it fine, - // and parantheses around strncpy silence that compiler warning. - (strncpy(req->initial_request.name, lb_service_name, - GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH)); +namespace grpc_core { + +grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name, + upb_arena* arena) { + grpc_grpclb_request* req = grpc_lb_v1_LoadBalanceRequest_new(arena); + grpc_lb_v1_InitialLoadBalanceRequest* initial_request = + grpc_lb_v1_LoadBalanceRequest_mutable_initial_request(req, arena); + size_t name_len = + GPR_MIN(strlen(lb_service_name), GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH); + grpc_lb_v1_InitialLoadBalanceRequest_set_name( + initial_request, upb_strview_make(lb_service_name, name_len)); return req; } -static void populate_timestamp(gpr_timespec timestamp, - grpc_grpclb_timestamp* timestamp_pb) { - timestamp_pb->has_seconds = true; - timestamp_pb->seconds = timestamp.tv_sec; - timestamp_pb->has_nanos = true; - timestamp_pb->nanos = timestamp.tv_nsec; -} +namespace { -static bool encode_string(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg) { - char* str = static_cast(*arg); - if (!pb_encode_tag_for_field(stream, field)) return false; - return pb_encode_string(stream, reinterpret_cast(str), strlen(str)); +void google_protobuf_Timestamp_assign(google_protobuf_Timestamp* timestamp, + const gpr_timespec& value) { + google_protobuf_Timestamp_set_seconds(timestamp, value.tv_sec); + google_protobuf_Timestamp_set_nanos(timestamp, value.tv_nsec); } -static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg) { - grpc_core::GrpcLbClientStats::DroppedCallCounts* drop_entries = - static_cast(*arg); - if (drop_entries == nullptr) return true; - for (size_t i = 0; i < drop_entries->size(); ++i) { - if (!pb_encode_tag_for_field(stream, field)) return false; - grpc_lb_v1_ClientStatsPerToken drop_message; - drop_message.load_balance_token.funcs.encode = encode_string; - drop_message.load_balance_token.arg = (*drop_entries)[i].token.get(); - drop_message.has_num_calls = true; - drop_message.num_calls = (*drop_entries)[i].count; - if (!pb_encode_submessage(stream, grpc_lb_v1_ClientStatsPerToken_fields, - &drop_message)) { - return false; - } - } - return true; -} +} // namespace grpc_grpclb_request* grpc_grpclb_load_report_request_create( - grpc_core::GrpcLbClientStats* client_stats) { - grpc_grpclb_request* req = static_cast( - gpr_zalloc(sizeof(grpc_grpclb_request))); - req->has_client_stats = true; - req->client_stats.has_timestamp = true; - populate_timestamp(gpr_now(GPR_CLOCK_REALTIME), &req->client_stats.timestamp); - req->client_stats.has_num_calls_started = true; - req->client_stats.has_num_calls_finished = true; - req->client_stats.has_num_calls_finished_with_client_failed_to_send = true; - req->client_stats.has_num_calls_finished_with_client_failed_to_send = true; - req->client_stats.has_num_calls_finished_known_received = true; - req->client_stats.calls_finished_with_drop.funcs.encode = encode_drops; - grpc_core::UniquePtr - drop_counts; - client_stats->Get( - &req->client_stats.num_calls_started, - &req->client_stats.num_calls_finished, - &req->client_stats.num_calls_finished_with_client_failed_to_send, - &req->client_stats.num_calls_finished_known_received, &drop_counts); - // Will be deleted in grpc_grpclb_request_destroy(). - req->client_stats.calls_finished_with_drop.arg = drop_counts.release(); + GrpcLbClientStats* client_stats, upb_arena* arena) { + grpc_grpclb_request* req = grpc_lb_v1_LoadBalanceRequest_new(arena); + grpc_lb_v1_ClientStats* req_stats = + grpc_lb_v1_LoadBalanceRequest_mutable_client_stats(req, arena); + google_protobuf_Timestamp_assign( + grpc_lb_v1_ClientStats_mutable_timestamp(req_stats, arena), + gpr_now(GPR_CLOCK_REALTIME)); + + int64_t num_calls_started; + int64_t num_calls_finished; + int64_t num_calls_finished_with_client_failed_to_send; + int64_t num_calls_finished_known_received; + UniquePtr drop_token_counts; + client_stats->Get(&num_calls_started, &num_calls_finished, + &num_calls_finished_with_client_failed_to_send, + &num_calls_finished_known_received, &drop_token_counts); + grpc_lb_v1_ClientStats_set_num_calls_started(req_stats, num_calls_started); + grpc_lb_v1_ClientStats_set_num_calls_finished(req_stats, num_calls_finished); + grpc_lb_v1_ClientStats_set_num_calls_finished_with_client_failed_to_send( + req_stats, num_calls_finished_with_client_failed_to_send); + grpc_lb_v1_ClientStats_set_num_calls_finished_known_received( + req_stats, num_calls_finished_known_received); + if (drop_token_counts != nullptr) { + for (size_t i = 0; i < drop_token_counts->size(); ++i) { + GrpcLbClientStats::DropTokenCount& cur = (*drop_token_counts)[i]; + grpc_lb_v1_ClientStatsPerToken* cur_msg = + grpc_lb_v1_ClientStats_add_calls_finished_with_drop(req_stats, arena); + + const size_t token_len = strlen(cur.token.get()); + char* token = reinterpret_cast(upb_arena_malloc(arena, token_len)); + memcpy(token, cur.token.get(), token_len); + + grpc_lb_v1_ClientStatsPerToken_set_load_balance_token( + cur_msg, upb_strview_make(token, token_len)); + grpc_lb_v1_ClientStatsPerToken_set_num_calls(cur_msg, cur.count); + } + } return req; } -grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request) { - size_t encoded_length; - pb_ostream_t sizestream; - pb_ostream_t outputstream; - grpc_slice slice; - memset(&sizestream, 0, sizeof(pb_ostream_t)); - pb_encode(&sizestream, grpc_lb_v1_LoadBalanceRequest_fields, request); - encoded_length = sizestream.bytes_written; - - slice = GRPC_SLICE_MALLOC(encoded_length); - outputstream = - pb_ostream_from_buffer(GRPC_SLICE_START_PTR(slice), encoded_length); - GPR_ASSERT(pb_encode(&outputstream, grpc_lb_v1_LoadBalanceRequest_fields, - request) != 0); - return slice; -} - -void grpc_grpclb_request_destroy(grpc_grpclb_request* request) { - if (request->has_client_stats) { - grpc_core::GrpcLbClientStats::DroppedCallCounts* drop_entries = - static_cast( - request->client_stats.calls_finished_with_drop.arg); - grpc_core::Delete(drop_entries); - } - gpr_free(request); +grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request, + upb_arena* arena) { + size_t buf_length; + char* buf = + grpc_lb_v1_LoadBalanceRequest_serialize(request, arena, &buf_length); + return grpc_slice_from_copied_buffer(buf, buf_length); } -typedef grpc_lb_v1_LoadBalanceResponse grpc_grpclb_response; -grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( - const grpc_slice& encoded_grpc_grpclb_response) { - pb_istream_t stream = pb_istream_from_buffer( - const_cast(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)), - GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); - grpc_grpclb_response res; - memset(&res, 0, sizeof(grpc_grpclb_response)); - if (GPR_UNLIKELY( - !pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res))) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); +const grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( + const grpc_slice& encoded_grpc_grpclb_response, upb_arena* arena) { + grpc_lb_v1_LoadBalanceResponse* response = + grpc_lb_v1_LoadBalanceResponse_parse( + reinterpret_cast( + GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)), + GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena); + if (response == nullptr) { + gpr_log(GPR_ERROR, "grpc_lb_v1_LoadBalanceResponse parse error"); return nullptr; } - - if (!res.has_initial_response) return nullptr; - - grpc_grpclb_initial_response* initial_res = - static_cast( - gpr_malloc(sizeof(grpc_grpclb_initial_response))); - memcpy(initial_res, &res.initial_response, - sizeof(grpc_grpclb_initial_response)); - - return initial_res; + return grpc_lb_v1_LoadBalanceResponse_initial_response(response); } grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( const grpc_slice& encoded_grpc_grpclb_response) { - pb_istream_t stream = pb_istream_from_buffer( - const_cast(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)), - GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); - pb_istream_t stream_at_start = stream; - grpc_grpclb_serverlist* sl = static_cast( + upb::Arena arena; + grpc_lb_v1_LoadBalanceResponse* response = + grpc_lb_v1_LoadBalanceResponse_parse( + reinterpret_cast( + GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)), + GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena.ptr()); + if (response == nullptr) { + gpr_log(GPR_ERROR, "grpc_lb_v1_LoadBalanceResponse parse error"); + return nullptr; + } + grpc_grpclb_serverlist* server_list = static_cast( gpr_zalloc(sizeof(grpc_grpclb_serverlist))); - grpc_grpclb_response res; - memset(&res, 0, sizeof(grpc_grpclb_response)); // First pass: count number of servers. - res.server_list.servers.funcs.decode = count_serverlist; - res.server_list.servers.arg = sl; - bool status = pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res); - if (GPR_UNLIKELY(!status)) { - gpr_free(sl); - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return nullptr; + const grpc_lb_v1_ServerList* server_list_msg = + grpc_lb_v1_LoadBalanceResponse_server_list(response); + size_t server_count = 0; + const grpc_lb_v1_Server* const* servers = nullptr; + if (server_list_msg != nullptr) { + servers = grpc_lb_v1_ServerList_servers(server_list_msg, &server_count); } // Second pass: populate servers. - if (sl->num_servers > 0) { - sl->servers = static_cast( - gpr_zalloc(sizeof(grpc_grpclb_server*) * sl->num_servers)); - decode_serverlist_arg decode_arg; - memset(&decode_arg, 0, sizeof(decode_arg)); - decode_arg.serverlist = sl; - res.server_list.servers.funcs.decode = decode_serverlist; - res.server_list.servers.arg = &decode_arg; - status = pb_decode(&stream_at_start, grpc_lb_v1_LoadBalanceResponse_fields, - &res); - if (GPR_UNLIKELY(!status)) { - grpc_grpclb_destroy_serverlist(sl); - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return nullptr; + if (server_count > 0) { + server_list->servers = static_cast( + gpr_zalloc(sizeof(grpc_grpclb_server*) * server_count)); + server_list->num_servers = server_count; + for (size_t i = 0; i < server_count; ++i) { + grpc_grpclb_server* cur = server_list->servers[i] = + static_cast( + gpr_zalloc(sizeof(grpc_grpclb_server))); + upb_strview address = grpc_lb_v1_Server_ip_address(servers[i]); + if (address.size == 0) { + ; // Nothing to do because cur->ip_address is an empty string. + } else if (address.size <= GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE) { + cur->ip_address.size = static_cast(address.size); + memcpy(cur->ip_address.data, address.data, address.size); + } + cur->port = grpc_lb_v1_Server_port(servers[i]); + upb_strview token = grpc_lb_v1_Server_load_balance_token(servers[i]); + if (token.size == 0) { + ; // Nothing to do because cur->load_balance_token is an empty string. + } else if (token.size <= GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE) { + memcpy(cur->load_balance_token, token.data, token.size); + } else { + gpr_log(GPR_ERROR, + "grpc_lb_v1_LoadBalanceResponse has too long token. len=%zu", + token.size); + } + cur->drop = grpc_lb_v1_Server_drop(servers[i]); } } - return sl; + return server_list; } void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) { @@ -239,16 +180,17 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) { } grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( - const grpc_grpclb_serverlist* sl) { + const grpc_grpclb_serverlist* server_list) { grpc_grpclb_serverlist* copy = static_cast( gpr_zalloc(sizeof(grpc_grpclb_serverlist))); - copy->num_servers = sl->num_servers; + copy->num_servers = server_list->num_servers; copy->servers = static_cast( - gpr_malloc(sizeof(grpc_grpclb_server*) * sl->num_servers)); - for (size_t i = 0; i < sl->num_servers; i++) { + gpr_malloc(sizeof(grpc_grpclb_server*) * server_list->num_servers)); + for (size_t i = 0; i < server_list->num_servers; i++) { copy->servers[i] = static_cast( gpr_malloc(sizeof(grpc_grpclb_server))); - memcpy(copy->servers[i], sl->servers[i], sizeof(grpc_grpclb_server)); + memcpy(copy->servers[i], server_list->servers[i], + sizeof(grpc_grpclb_server)); } return copy; } @@ -274,38 +216,11 @@ bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs, return memcmp(lhs, rhs, sizeof(grpc_grpclb_server)) == 0; } -int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs, - const grpc_grpclb_duration* rhs) { - GPR_ASSERT(lhs && rhs); - if (lhs->has_seconds && rhs->has_seconds) { - if (lhs->seconds < rhs->seconds) return -1; - if (lhs->seconds > rhs->seconds) return 1; - } else if (lhs->has_seconds) { - return 1; - } else if (rhs->has_seconds) { - return -1; - } - - GPR_ASSERT(lhs->seconds == rhs->seconds); - if (lhs->has_nanos && rhs->has_nanos) { - if (lhs->nanos < rhs->nanos) return -1; - if (lhs->nanos > rhs->nanos) return 1; - } else if (lhs->has_nanos) { - return 1; - } else if (rhs->has_nanos) { - return -1; - } - - return 0; -} - -grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb) { +grpc_millis grpc_grpclb_duration_to_millis( + const grpc_grpclb_duration* duration_pb) { return static_cast( - (duration_pb->has_seconds ? duration_pb->seconds : 0) * GPR_MS_PER_SEC + - (duration_pb->has_nanos ? duration_pb->nanos : 0) / GPR_NS_PER_MS); + google_protobuf_Duration_seconds(duration_pb) * GPR_MS_PER_SEC + + google_protobuf_Duration_nanos(duration_pb) / GPR_NS_PER_MS); } -void grpc_grpclb_initial_response_destroy( - grpc_grpclb_initial_response* response) { - gpr_free(response); -} +} // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h index 8005f6fe301..3062e9526ae 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h @@ -24,38 +24,57 @@ #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h" -#include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/proto/grpc/lb/v1/load_balancer.upb.h" #define GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH 128 +#define GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE 16 +#define GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE 50 + +namespace grpc_core { -typedef grpc_lb_v1_Server_ip_address_t grpc_grpclb_ip_address; typedef grpc_lb_v1_LoadBalanceRequest grpc_grpclb_request; +typedef grpc_lb_v1_LoadBalanceResponse grpc_grpclb_response; typedef grpc_lb_v1_InitialLoadBalanceResponse grpc_grpclb_initial_response; -typedef grpc_lb_v1_Server grpc_grpclb_server; typedef google_protobuf_Duration grpc_grpclb_duration; typedef google_protobuf_Timestamp grpc_grpclb_timestamp; +typedef struct { + int32_t size; + char data[GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE]; +} grpc_grpclb_server_ip_address; + +// Contains server information. When the drop field is not true, use the other +// fields. +typedef struct { + grpc_grpclb_server_ip_address ip_address; + int32_t port; + char load_balance_token[GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE]; + bool drop; +} grpc_grpclb_server; + typedef struct { grpc_grpclb_server** servers; size_t num_servers; } grpc_grpclb_serverlist; -/** Create a request for a gRPC LB service under \a lb_service_name */ -grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name); +/** + * Create a request for a gRPC LB service under \a lb_service_name. + * \a lb_service_name should be alive when returned request is being used. + */ +grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name, + upb_arena* arena); grpc_grpclb_request* grpc_grpclb_load_report_request_create( - grpc_core::GrpcLbClientStats* client_stats); + grpc_core::GrpcLbClientStats* client_stats, upb_arena* arena); /** Protocol Buffers v3-encode \a request */ -grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request); - -/** Destroy \a request */ -void grpc_grpclb_request_destroy(grpc_grpclb_request* request); +grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request, + upb_arena* arena); /** Parse (ie, decode) the bytes in \a encoded_grpc_grpclb_response as a \a * grpc_grpclb_initial_response */ -grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( - const grpc_slice& encoded_grpc_grpclb_response); +const grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( + const grpc_slice& encoded_grpc_grpclb_response, upb_arena* arena); /** Parse the list of servers from an encoded \a grpc_grpclb_response */ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( @@ -75,16 +94,10 @@ bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs, /** Destroy \a serverlist */ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist); -/** Compare \a lhs against \a rhs and return 0 if \a lhs and \a rhs are equal, - * < 0 if \a lhs represents a duration shorter than \a rhs and > 0 otherwise */ -int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs, - const grpc_grpclb_duration* rhs); - -grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb); +grpc_millis grpc_grpclb_duration_to_millis( + const grpc_grpclb_duration* duration_pb); -/** Destroy \a initial_response */ -void grpc_grpclb_initial_response_destroy( - grpc_grpclb_initial_response* response); +} // namespace grpc_core #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H \ */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index ec5b79d965b..8138b2a6264 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -373,14 +373,22 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', + 'src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c', + 'src/core/ext/upb-generated/google/protobuf/any.upb.c', + 'src/core/ext/upb-generated/google/protobuf/descriptor.upb.c', + 'src/core/ext/upb-generated/google/protobuf/duration.upb.c', + 'src/core/ext/upb-generated/google/protobuf/empty.upb.c', + 'src/core/ext/upb-generated/google/protobuf/struct.upb.c', + 'src/core/ext/upb-generated/google/protobuf/timestamp.upb.c', + 'src/core/ext/upb-generated/google/protobuf/wrappers.upb.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', - 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'src/core/ext/filters/client_channel/lb_policy/xds/xds.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', diff --git a/test/core/nanopb/fuzzer_response.cc b/test/core/nanopb/fuzzer_response.cc index 3a70dea5e98..1f35eac8f64 100644 --- a/test/core/nanopb/fuzzer_response.cc +++ b/test/core/nanopb/fuzzer_response.cc @@ -33,10 +33,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); - grpc_grpclb_initial_response* response; - if ((response = grpc_grpclb_initial_response_parse(slice))) { - grpc_grpclb_initial_response_destroy(response); - } + upb::Arena arena; + grpc_core::grpc_grpclb_initial_response_parse(slice, arena.ptr()); grpc_slice_unref(slice); grpc_shutdown(); return 0; diff --git a/test/core/nanopb/fuzzer_serverlist.cc b/test/core/nanopb/fuzzer_serverlist.cc index d0af117ef96..079fbd34be1 100644 --- a/test/core/nanopb/fuzzer_serverlist.cc +++ b/test/core/nanopb/fuzzer_serverlist.cc @@ -33,8 +33,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); - grpc_grpclb_serverlist* serverlist; - if ((serverlist = grpc_grpclb_response_parse_serverlist(slice))) { + grpc_core::grpc_grpclb_serverlist* serverlist; + if ((serverlist = grpc_core::grpc_grpclb_response_parse_serverlist(slice))) { grpc_grpclb_destroy_serverlist(serverlist); } grpc_slice_unref(slice); diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index 0ace512c278..62e7c06bbb8 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -20,6 +20,7 @@ #include #include +#include "google/protobuf/duration.upb.h" #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" @@ -44,7 +45,8 @@ grpc::string Ip4ToPackedString(const char* ip_str) { return grpc::string(reinterpret_cast(&ip4), sizeof(ip4)); } -grpc::string PackedStringToIp(const grpc_grpclb_ip_address& pb_ip) { +grpc::string PackedStringToIp( + const grpc_core::grpc_grpclb_server_ip_address& pb_ip) { char ip_str[46] = {0}; int af = -1; if (pb_ip.size == 4) { @@ -54,21 +56,22 @@ grpc::string PackedStringToIp(const grpc_grpclb_ip_address& pb_ip) { } else { abort(); } - GPR_ASSERT(inet_ntop(af, (void*)pb_ip.bytes, ip_str, 46) != nullptr); + GPR_ASSERT(inet_ntop(af, (void*)pb_ip.data, ip_str, 46) != nullptr); return ip_str; } TEST_F(GrpclbTest, CreateRequest) { const grpc::string service_name = "AServiceName"; LoadBalanceRequest request; - grpc_grpclb_request* c_req = grpc_grpclb_request_create(service_name.c_str()); - grpc_slice slice = grpc_grpclb_request_encode(c_req); + upb::Arena arena; + grpc_core::grpc_grpclb_request* c_req = + grpc_core::grpc_grpclb_request_create(service_name.c_str(), arena.ptr()); + grpc_slice slice = grpc_core::grpc_grpclb_request_encode(c_req, arena.ptr()); const int num_bytes_written = GRPC_SLICE_LENGTH(slice); EXPECT_GT(num_bytes_written, 0); request.ParseFromArray(GRPC_SLICE_START_PTR(slice), num_bytes_written); EXPECT_EQ(request.initial_request().name(), service_name); grpc_slice_unref(slice); - grpc_grpclb_request_destroy(c_req); } TEST_F(GrpclbTest, ParseInitialResponse) { @@ -82,13 +85,21 @@ TEST_F(GrpclbTest, ParseInitialResponse) { grpc_slice encoded_slice = grpc_slice_from_copied_string(encoded_response.c_str()); - grpc_grpclb_initial_response* c_initial_response = - grpc_grpclb_initial_response_parse(encoded_slice); - EXPECT_FALSE(c_initial_response->has_load_balancer_delegate); - EXPECT_EQ(c_initial_response->client_stats_report_interval.seconds, 123); - EXPECT_EQ(c_initial_response->client_stats_report_interval.nanos, 456); + upb::Arena arena; + const grpc_core::grpc_grpclb_initial_response* c_initial_response = + grpc_core::grpc_grpclb_initial_response_parse(encoded_slice, arena.ptr()); + + upb_strview load_balancer_delegate = + grpc_lb_v1_InitialLoadBalanceResponse_load_balancer_delegate( + c_initial_response); + EXPECT_EQ(load_balancer_delegate.size, 0); + + const google_protobuf_Duration* report_interval = + grpc_lb_v1_InitialLoadBalanceResponse_client_stats_report_interval( + c_initial_response); + EXPECT_EQ(google_protobuf_Duration_seconds(report_interval), 123); + EXPECT_EQ(google_protobuf_Duration_nanos(report_interval), 456); grpc_slice_unref(encoded_slice); - grpc_grpclb_initial_response_destroy(c_initial_response); } TEST_F(GrpclbTest, ParseResponseServerList) { @@ -108,16 +119,14 @@ TEST_F(GrpclbTest, ParseResponseServerList) { const grpc::string encoded_response = response.SerializeAsString(); const grpc_slice encoded_slice = grpc_slice_from_copied_buffer( encoded_response.data(), encoded_response.size()); - grpc_grpclb_serverlist* c_serverlist = - grpc_grpclb_response_parse_serverlist(encoded_slice); + grpc_core::grpc_grpclb_serverlist* c_serverlist = + grpc_core::grpc_grpclb_response_parse_serverlist(encoded_slice); ASSERT_EQ(c_serverlist->num_servers, 2ul); - EXPECT_TRUE(c_serverlist->servers[0]->has_ip_address); EXPECT_EQ(PackedStringToIp(c_serverlist->servers[0]->ip_address), "127.0.0.1"); EXPECT_EQ(c_serverlist->servers[0]->port, 12345); EXPECT_STREQ(c_serverlist->servers[0]->load_balance_token, "rate_limting"); EXPECT_TRUE(c_serverlist->servers[0]->drop); - EXPECT_TRUE(c_serverlist->servers[1]->has_ip_address); EXPECT_EQ(PackedStringToIp(c_serverlist->servers[1]->ip_address), "10.0.0.1"); EXPECT_EQ(c_serverlist->servers[1]->port, 54321); diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 58d719c438e..e15778c276b 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1064,8 +1064,24 @@ src/core/ext/transport/chttp2/transport/writing.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ src/core/ext/transport/inproc/inproc_transport.h \ +src/core/ext/upb-generated/google/protobuf/any.upb.c \ +src/core/ext/upb-generated/google/protobuf/any.upb.h \ +src/core/ext/upb-generated/google/protobuf/descriptor.upb.c \ +src/core/ext/upb-generated/google/protobuf/descriptor.upb.h \ +src/core/ext/upb-generated/google/protobuf/duration.upb.c \ +src/core/ext/upb-generated/google/protobuf/duration.upb.h \ +src/core/ext/upb-generated/google/protobuf/empty.upb.c \ +src/core/ext/upb-generated/google/protobuf/empty.upb.h \ +src/core/ext/upb-generated/google/protobuf/struct.upb.c \ +src/core/ext/upb-generated/google/protobuf/struct.upb.h \ +src/core/ext/upb-generated/google/protobuf/timestamp.upb.c \ +src/core/ext/upb-generated/google/protobuf/timestamp.upb.h \ +src/core/ext/upb-generated/google/protobuf/wrappers.upb.c \ +src/core/ext/upb-generated/google/protobuf/wrappers.upb.h \ src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c \ src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h \ +src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c \ +src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h \ src/core/lib/README.md \ src/core/lib/avl/avl.cc \ src/core/lib/avl/avl.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 3278e997e6b..eea82fd730c 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9294,9 +9294,8 @@ "gpr", "grpc_base", "grpc_client_channel", + "grpc_lb_upb", "grpc_resolver_fake", - "grpclb_proto", - "nanopb", "upb" ], "headers": [ @@ -9329,10 +9328,9 @@ "gpr", "grpc_base", "grpc_client_channel", + "grpc_lb_upb", "grpc_resolver_fake", "grpc_secure", - "grpclb_proto", - "nanopb", "upb" ], "headers": [ @@ -9401,8 +9399,7 @@ "grpc_client_channel", "grpc_resolver_fake", "grpclb_proto", - "nanopb", - "upb" + "nanopb" ], "headers": [ "src/core/ext/filters/client_channel/lb_policy/xds/xds.h", @@ -9434,8 +9431,7 @@ "grpc_resolver_fake", "grpc_secure", "grpclb_proto", - "nanopb", - "upb" + "nanopb" ], "headers": [ "src/core/ext/filters/client_channel/lb_policy/xds/xds.h",