grpc 1.22.0 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +487 -649
  3. data/include/grpc/grpc_security.h +25 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +11 -2
  5. data/include/grpc/impl/codegen/port_platform.h +12 -0
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +477 -182
  8. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +25 -16
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +11 -6
  10. data/src/core/ext/filters/client_channel/connector.h +10 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +3 -3
  12. data/src/core/ext/filters/client_channel/http_proxy.cc +9 -10
  13. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -17
  14. data/src/core/ext/filters/client_channel/lb_policy.h +36 -8
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +22 -8
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +86 -52
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +7 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +73 -72
  19. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -12
  20. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +25 -101
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +5 -5
  22. data/src/core/ext/filters/client_channel/parse_address.cc +29 -26
  23. data/src/core/ext/filters/client_channel/resolver.h +3 -11
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +405 -82
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -51
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -1
  29. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +11 -6
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +130 -65
  31. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +8 -3
  32. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +31 -14
  33. data/src/core/ext/filters/client_channel/resolver_factory.h +4 -0
  34. data/src/core/ext/filters/client_channel/resolver_registry.cc +11 -0
  35. data/src/core/ext/filters/client_channel/resolver_registry.h +3 -0
  36. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +10 -49
  37. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -14
  38. data/src/core/ext/filters/client_channel/retry_throttle.h +2 -3
  39. data/src/core/ext/filters/client_channel/subchannel.cc +65 -58
  40. data/src/core/ext/filters/client_channel/subchannel.h +65 -45
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +15 -30
  42. data/src/core/ext/filters/client_idle/client_idle_filter.cc +262 -0
  43. data/src/core/ext/filters/http/client/http_client_filter.cc +4 -5
  44. data/src/core/ext/filters/http/client_authority_filter.cc +2 -2
  45. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +140 -152
  46. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -3
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -4
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -6
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +63 -38
  50. data/src/core/ext/transport/chttp2/transport/context_list.cc +3 -1
  51. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  52. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +1 -1
  53. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -0
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +7 -0
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +1 -0
  57. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +37 -22
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +136 -81
  59. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -0
  60. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -166
  61. data/src/core/ext/transport/chttp2/transport/hpack_table.h +41 -15
  62. data/src/core/ext/transport/chttp2/transport/internal.h +13 -2
  63. data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -22
  64. data/src/core/ext/transport/chttp2/transport/stream_map.cc +28 -18
  65. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -0
  66. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  67. data/src/core/lib/channel/channelz.cc +80 -33
  68. data/src/core/lib/channel/channelz.h +28 -13
  69. data/src/core/lib/compression/compression.cc +1 -2
  70. data/src/core/lib/compression/compression_args.cc +13 -6
  71. data/src/core/lib/compression/compression_args.h +3 -2
  72. data/src/core/lib/compression/compression_internal.cc +1 -1
  73. data/src/core/lib/gpr/env_linux.cc +10 -21
  74. data/src/core/lib/gpr/env_posix.cc +0 -5
  75. data/src/core/lib/gpr/string.cc +7 -2
  76. data/src/core/lib/gpr/string.h +1 -0
  77. data/src/core/lib/gpr/sync_posix.cc +0 -129
  78. data/src/core/lib/gprpp/debug_location.h +3 -2
  79. data/src/core/lib/gprpp/fork.cc +14 -21
  80. data/src/core/lib/gprpp/fork.h +15 -4
  81. data/src/core/lib/gprpp/host_port.cc +118 -0
  82. data/src/core/lib/{gpr → gprpp}/host_port.h +27 -11
  83. data/src/core/lib/gprpp/map.h +25 -0
  84. data/src/core/lib/gprpp/memory.h +26 -9
  85. data/src/core/lib/gprpp/ref_counted.h +63 -21
  86. data/src/core/lib/gprpp/string_view.h +143 -0
  87. data/src/core/lib/gprpp/thd.h +10 -1
  88. data/src/core/lib/gprpp/thd_posix.cc +25 -0
  89. data/src/core/lib/gprpp/thd_windows.cc +9 -1
  90. data/src/core/lib/http/httpcli_security_connector.cc +3 -1
  91. data/src/core/lib/iomgr/cfstream_handle.cc +6 -1
  92. data/src/core/lib/iomgr/cfstream_handle.h +8 -2
  93. data/src/core/lib/iomgr/combiner.cc +4 -4
  94. data/src/core/lib/iomgr/error.cc +18 -8
  95. data/src/core/lib/iomgr/error.h +2 -0
  96. data/src/core/lib/iomgr/ev_posix.cc +4 -2
  97. data/src/core/lib/iomgr/executor.cc +4 -1
  98. data/src/core/lib/iomgr/executor/mpmcqueue.cc +183 -0
  99. data/src/core/lib/iomgr/executor/mpmcqueue.h +178 -0
  100. data/src/core/lib/iomgr/executor/threadpool.cc +138 -0
  101. data/src/core/lib/iomgr/executor/threadpool.h +153 -0
  102. data/src/core/lib/iomgr/fork_posix.cc +4 -2
  103. data/src/core/lib/iomgr/iocp_windows.cc +2 -2
  104. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +14 -0
  105. data/src/core/lib/iomgr/iomgr_uv.cc +3 -0
  106. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  107. data/src/core/lib/iomgr/resolve_address_custom.cc +16 -20
  108. data/src/core/lib/iomgr/resolve_address_posix.cc +8 -10
  109. data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
  110. data/src/core/lib/iomgr/sockaddr_utils.cc +5 -3
  111. data/src/core/lib/iomgr/socket_utils_common_posix.cc +0 -1
  112. data/src/core/lib/iomgr/socket_windows.h +1 -1
  113. data/src/core/lib/iomgr/tcp_client_cfstream.cc +7 -6
  114. data/src/core/lib/iomgr/tcp_client_custom.cc +1 -0
  115. data/src/core/lib/iomgr/tcp_custom.cc +4 -0
  116. data/src/core/lib/iomgr/tcp_posix.cc +8 -2
  117. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -0
  118. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
  119. data/src/core/lib/iomgr/tcp_windows.cc +7 -7
  120. data/src/core/lib/iomgr/timer_custom.cc +1 -0
  121. data/src/core/lib/iomgr/timer_manager.cc +0 -29
  122. data/src/core/lib/security/credentials/credentials.cc +84 -0
  123. data/src/core/lib/security/credentials/credentials.h +58 -2
  124. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -2
  125. data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +245 -24
  127. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +16 -0
  128. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +3 -2
  129. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +21 -25
  130. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -2
  131. data/src/core/lib/security/security_connector/security_connector.cc +1 -1
  132. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  133. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +19 -19
  134. data/src/core/lib/security/security_connector/ssl_utils.cc +26 -31
  135. data/src/core/lib/security/security_connector/ssl_utils.h +11 -8
  136. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +16 -20
  137. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -3
  138. data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
  139. data/src/core/lib/security/util/json_util.cc +19 -5
  140. data/src/core/lib/security/util/json_util.h +3 -1
  141. data/src/core/lib/slice/slice.cc +69 -50
  142. data/src/core/lib/slice/slice_buffer.cc +6 -5
  143. data/src/core/lib/slice/slice_hash_table.h +3 -7
  144. data/src/core/lib/slice/slice_intern.cc +130 -39
  145. data/src/core/lib/slice/slice_internal.h +8 -0
  146. data/src/core/lib/slice/slice_utils.h +120 -0
  147. data/src/core/lib/slice/slice_weak_hash_table.h +2 -7
  148. data/src/core/lib/surface/call.cc +8 -3
  149. data/src/core/lib/surface/channel.cc +31 -8
  150. data/src/core/lib/surface/completion_queue.cc +17 -7
  151. data/src/core/lib/surface/init_secure.cc +4 -1
  152. data/src/core/lib/surface/lame_client.cc +2 -2
  153. data/src/core/lib/surface/server.cc +34 -35
  154. data/src/core/lib/surface/server.h +8 -17
  155. data/src/core/lib/surface/version.cc +1 -1
  156. data/src/core/lib/transport/byte_stream.cc +3 -5
  157. data/src/core/lib/transport/byte_stream.h +1 -2
  158. data/src/core/lib/transport/error_utils.cc +10 -1
  159. data/src/core/lib/transport/metadata.cc +202 -35
  160. data/src/core/lib/transport/metadata.h +81 -6
  161. data/src/core/lib/transport/static_metadata.cc +1257 -465
  162. data/src/core/lib/transport/static_metadata.h +190 -347
  163. data/src/core/lib/transport/timeout_encoding.cc +7 -0
  164. data/src/core/lib/transport/timeout_encoding.h +3 -2
  165. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  166. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +0 -1
  167. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -7
  168. data/src/core/tsi/ssl_transport_security.cc +35 -43
  169. data/src/core/tsi/ssl_transport_security.h +2 -1
  170. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  171. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  172. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  173. data/src/ruby/lib/grpc/grpc.rb +1 -1
  174. data/src/ruby/lib/grpc/version.rb +1 -1
  175. metadata +39 -33
  176. data/src/core/lib/gpr/host_port.cc +0 -98
@@ -42,7 +42,8 @@ class FakeResolver;
42
42
  class FakeResolverResponseGenerator
43
43
  : public RefCounted<FakeResolverResponseGenerator> {
44
44
  public:
45
- FakeResolverResponseGenerator() {}
45
+ FakeResolverResponseGenerator();
46
+ ~FakeResolverResponseGenerator();
46
47
 
47
48
  // Instructs the fake resolver associated with the response generator
48
49
  // instance to trigger a new resolution with the specified result. If the
@@ -71,17 +72,21 @@ class FakeResolverResponseGenerator
71
72
  static grpc_arg MakeChannelArg(FakeResolverResponseGenerator* generator);
72
73
 
73
74
  // Returns the response generator in \a args, or null if not found.
74
- static FakeResolverResponseGenerator* GetFromArgs(
75
+ static RefCountedPtr<FakeResolverResponseGenerator> GetFromArgs(
75
76
  const grpc_channel_args* args);
76
77
 
77
78
  private:
78
79
  friend class FakeResolver;
80
+ // Set the corresponding FakeResolver to this generator.
81
+ void SetFakeResolver(RefCountedPtr<FakeResolver> resolver);
79
82
 
80
83
  static void SetResponseLocked(void* arg, grpc_error* error);
81
84
  static void SetReresolutionResponseLocked(void* arg, grpc_error* error);
82
85
  static void SetFailureLocked(void* arg, grpc_error* error);
83
86
 
84
- FakeResolver* resolver_ = nullptr; // Do not own.
87
+ // Mutex protecting the members below.
88
+ Mutex mu_;
89
+ RefCountedPtr<FakeResolver> resolver_;
85
90
  Resolver::Result result_;
86
91
  bool has_result_ = false;
87
92
  };
@@ -30,7 +30,6 @@
30
30
  #include "src/core/ext/filters/client_channel/resolver_registry.h"
31
31
  #include "src/core/ext/filters/client_channel/server_address.h"
32
32
  #include "src/core/lib/channel/channel_args.h"
33
- #include "src/core/lib/gpr/host_port.h"
34
33
  #include "src/core/lib/gpr/string.h"
35
34
  #include "src/core/lib/iomgr/combiner.h"
36
35
  #include "src/core/lib/iomgr/resolve_address.h"
@@ -81,24 +80,23 @@ void SockaddrResolver::StartLocked() {
81
80
 
82
81
  void DoNothing(void* ignored) {}
83
82
 
84
- OrphanablePtr<Resolver> CreateSockaddrResolver(
85
- ResolverArgs args,
86
- bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) {
87
- if (0 != strcmp(args.uri->authority, "")) {
83
+ bool ParseUri(const grpc_uri* uri,
84
+ bool parse(const grpc_uri* uri, grpc_resolved_address* dst),
85
+ ServerAddressList* addresses) {
86
+ if (0 != strcmp(uri->authority, "")) {
88
87
  gpr_log(GPR_ERROR, "authority-based URIs not supported by the %s scheme",
89
- args.uri->scheme);
90
- return nullptr;
88
+ uri->scheme);
89
+ return false;
91
90
  }
92
91
  // Construct addresses.
93
92
  grpc_slice path_slice =
94
- grpc_slice_new(args.uri->path, strlen(args.uri->path), DoNothing);
93
+ grpc_slice_new(uri->path, strlen(uri->path), DoNothing);
95
94
  grpc_slice_buffer path_parts;
96
95
  grpc_slice_buffer_init(&path_parts);
97
96
  grpc_slice_split(path_slice, ",", &path_parts);
98
- ServerAddressList addresses;
99
97
  bool errors_found = false;
100
98
  for (size_t i = 0; i < path_parts.count; i++) {
101
- grpc_uri ith_uri = *args.uri;
99
+ grpc_uri ith_uri = *uri;
102
100
  UniquePtr<char> part_str(grpc_slice_to_c_string(path_parts.slices[i]));
103
101
  ith_uri.path = part_str.get();
104
102
  grpc_resolved_address addr;
@@ -106,13 +104,20 @@ OrphanablePtr<Resolver> CreateSockaddrResolver(
106
104
  errors_found = true;
107
105
  break;
108
106
  }
109
- addresses.emplace_back(addr, nullptr /* args */);
107
+ if (addresses != nullptr) {
108
+ addresses->emplace_back(addr, nullptr /* args */);
109
+ }
110
110
  }
111
111
  grpc_slice_buffer_destroy_internal(&path_parts);
112
112
  grpc_slice_unref_internal(path_slice);
113
- if (errors_found) {
114
- return OrphanablePtr<Resolver>(nullptr);
115
- }
113
+ return !errors_found;
114
+ }
115
+
116
+ OrphanablePtr<Resolver> CreateSockaddrResolver(
117
+ ResolverArgs args,
118
+ bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) {
119
+ ServerAddressList addresses;
120
+ if (!ParseUri(args.uri, parse, &addresses)) return nullptr;
116
121
  // Instantiate resolver.
117
122
  return OrphanablePtr<Resolver>(
118
123
  New<SockaddrResolver>(std::move(addresses), std::move(args)));
@@ -120,6 +125,10 @@ OrphanablePtr<Resolver> CreateSockaddrResolver(
120
125
 
121
126
  class IPv4ResolverFactory : public ResolverFactory {
122
127
  public:
128
+ bool IsValidUri(const grpc_uri* uri) const override {
129
+ return ParseUri(uri, grpc_parse_ipv4, nullptr);
130
+ }
131
+
123
132
  OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
124
133
  return CreateSockaddrResolver(std::move(args), grpc_parse_ipv4);
125
134
  }
@@ -129,6 +138,10 @@ class IPv4ResolverFactory : public ResolverFactory {
129
138
 
130
139
  class IPv6ResolverFactory : public ResolverFactory {
131
140
  public:
141
+ bool IsValidUri(const grpc_uri* uri) const override {
142
+ return ParseUri(uri, grpc_parse_ipv6, nullptr);
143
+ }
144
+
132
145
  OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
133
146
  return CreateSockaddrResolver(std::move(args), grpc_parse_ipv6);
134
147
  }
@@ -139,6 +152,10 @@ class IPv6ResolverFactory : public ResolverFactory {
139
152
  #ifdef GRPC_HAVE_UNIX_SOCKET
140
153
  class UnixResolverFactory : public ResolverFactory {
141
154
  public:
155
+ bool IsValidUri(const grpc_uri* uri) const override {
156
+ return ParseUri(uri, grpc_parse_unix, nullptr);
157
+ }
158
+
142
159
  OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
143
160
  return CreateSockaddrResolver(std::move(args), grpc_parse_unix);
144
161
  }
@@ -47,6 +47,10 @@ struct ResolverArgs {
47
47
 
48
48
  class ResolverFactory {
49
49
  public:
50
+ /// Returns a bool indicating whether the input uri is valid to create a
51
+ /// resolver.
52
+ virtual bool IsValidUri(const grpc_uri* uri) const GRPC_ABSTRACT;
53
+
50
54
  /// Returns a new resolver instance.
51
55
  virtual OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const
52
56
  GRPC_ABSTRACT;
@@ -132,6 +132,17 @@ ResolverFactory* ResolverRegistry::LookupResolverFactory(const char* scheme) {
132
132
  return g_state->LookupResolverFactory(scheme);
133
133
  }
134
134
 
135
+ bool ResolverRegistry::IsValidTarget(const char* target) {
136
+ grpc_uri* uri = nullptr;
137
+ char* canonical_target = nullptr;
138
+ ResolverFactory* factory =
139
+ g_state->FindResolverFactory(target, &uri, &canonical_target);
140
+ bool result = factory == nullptr ? false : factory->IsValidUri(uri);
141
+ grpc_uri_destroy(uri);
142
+ gpr_free(canonical_target);
143
+ return result;
144
+ }
145
+
135
146
  OrphanablePtr<Resolver> ResolverRegistry::CreateResolver(
136
147
  const char* target, const grpc_channel_args* args,
137
148
  grpc_pollset_set* pollset_set, grpc_combiner* combiner,
@@ -50,6 +50,9 @@ class ResolverRegistry {
50
50
  static void RegisterResolverFactory(UniquePtr<ResolverFactory> factory);
51
51
  };
52
52
 
53
+ /// Checks whether the user input \a target is valid to create a resolver.
54
+ static bool IsValidTarget(const char* target);
55
+
53
56
  /// Creates a resolver given \a target.
54
57
  /// First tries to parse \a target as a URI. If this succeeds, tries
55
58
  /// to locate a registered resolver factory based on the URI scheme.
@@ -181,52 +181,29 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
181
181
  // ResolvingLoadBalancingPolicy
182
182
  //
183
183
 
184
- ResolvingLoadBalancingPolicy::ResolvingLoadBalancingPolicy(
185
- Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
186
- UniquePtr<char> child_policy_name,
187
- RefCountedPtr<LoadBalancingPolicy::Config> child_lb_config,
188
- grpc_error** error)
189
- : LoadBalancingPolicy(std::move(args)),
190
- tracer_(tracer),
191
- target_uri_(std::move(target_uri)),
192
- child_policy_name_(std::move(child_policy_name)),
193
- child_lb_config_(std::move(child_lb_config)) {
194
- GPR_ASSERT(child_policy_name_ != nullptr);
195
- // Don't fetch service config, since this ctor is for use in nested LB
196
- // policies, not at the top level, and we only fetch the service
197
- // config at the top level.
198
- grpc_arg arg = grpc_channel_arg_integer_create(
199
- const_cast<char*>(GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION), 0);
200
- grpc_channel_args* new_args =
201
- grpc_channel_args_copy_and_add(args.args, &arg, 1);
202
- *error = Init(*new_args);
203
- grpc_channel_args_destroy(new_args);
204
- }
205
-
206
184
  ResolvingLoadBalancingPolicy::ResolvingLoadBalancingPolicy(
207
185
  Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
208
186
  ProcessResolverResultCallback process_resolver_result,
209
- void* process_resolver_result_user_data, grpc_error** error)
187
+ void* process_resolver_result_user_data)
210
188
  : LoadBalancingPolicy(std::move(args)),
211
189
  tracer_(tracer),
212
190
  target_uri_(std::move(target_uri)),
213
191
  process_resolver_result_(process_resolver_result),
214
192
  process_resolver_result_user_data_(process_resolver_result_user_data) {
215
193
  GPR_ASSERT(process_resolver_result != nullptr);
216
- *error = Init(*args.args);
217
- }
218
-
219
- grpc_error* ResolvingLoadBalancingPolicy::Init(const grpc_channel_args& args) {
220
194
  resolver_ = ResolverRegistry::CreateResolver(
221
- target_uri_.get(), &args, interested_parties(), combiner(),
195
+ target_uri_.get(), args.args, interested_parties(), combiner(),
222
196
  UniquePtr<Resolver::ResultHandler>(New<ResolverResultHandler>(Ref())));
223
- if (resolver_ == nullptr) {
224
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("resolver creation failed");
197
+ // Since the validity of args has been checked when create the channel,
198
+ // CreateResolver() must return a non-null result.
199
+ GPR_ASSERT(resolver_ != nullptr);
200
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
201
+ gpr_log(GPR_INFO, "resolving_lb=%p: starting name resolution", this);
225
202
  }
226
- // Return our picker to the channel.
227
203
  channel_control_helper()->UpdateState(
228
- GRPC_CHANNEL_IDLE, UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
229
- return GRPC_ERROR_NONE;
204
+ GRPC_CHANNEL_CONNECTING,
205
+ UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
206
+ resolver_->StartLocked();
230
207
  }
231
208
 
232
209
  ResolvingLoadBalancingPolicy::~ResolvingLoadBalancingPolicy() {
@@ -262,10 +239,6 @@ void ResolvingLoadBalancingPolicy::ExitIdleLocked() {
262
239
  if (lb_policy_ != nullptr) {
263
240
  lb_policy_->ExitIdleLocked();
264
241
  if (pending_lb_policy_ != nullptr) pending_lb_policy_->ExitIdleLocked();
265
- } else {
266
- if (!started_resolving_ && resolver_ != nullptr) {
267
- StartResolvingLocked();
268
- }
269
242
  }
270
243
  }
271
244
 
@@ -278,18 +251,6 @@ void ResolvingLoadBalancingPolicy::ResetBackoffLocked() {
278
251
  if (pending_lb_policy_ != nullptr) pending_lb_policy_->ResetBackoffLocked();
279
252
  }
280
253
 
281
- void ResolvingLoadBalancingPolicy::StartResolvingLocked() {
282
- if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
283
- gpr_log(GPR_INFO, "resolving_lb=%p: starting name resolution", this);
284
- }
285
- GPR_ASSERT(!started_resolving_);
286
- started_resolving_ = true;
287
- channel_control_helper()->UpdateState(
288
- GRPC_CHANNEL_CONNECTING,
289
- UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
290
- resolver_->StartLocked();
291
- }
292
-
293
254
  void ResolvingLoadBalancingPolicy::OnResolverError(grpc_error* error) {
294
255
  if (resolver_ == nullptr) {
295
256
  GRPC_ERROR_UNREF(error);
@@ -51,16 +51,6 @@ namespace grpc_core {
51
51
  // child LB policy and config to use.
52
52
  class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
53
53
  public:
54
- // If error is set when this returns, then construction failed, and
55
- // the caller may not use the new object.
56
- ResolvingLoadBalancingPolicy(
57
- Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
58
- UniquePtr<char> child_policy_name,
59
- RefCountedPtr<LoadBalancingPolicy::Config> child_lb_config,
60
- grpc_error** error);
61
-
62
- // Private ctor, to be used by client_channel only!
63
- //
64
54
  // Synchronous callback that takes the resolver result and sets
65
55
  // lb_policy_name and lb_policy_config to point to the right data.
66
56
  // Returns true if the service config has changed since the last result.
@@ -77,7 +67,7 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
77
67
  ResolvingLoadBalancingPolicy(
78
68
  Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
79
69
  ProcessResolverResultCallback process_resolver_result,
80
- void* process_resolver_result_user_data, grpc_error** error);
70
+ void* process_resolver_result_user_data);
81
71
 
82
72
  virtual const char* name() const override { return "resolving_lb"; }
83
73
 
@@ -98,10 +88,8 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
98
88
 
99
89
  ~ResolvingLoadBalancingPolicy();
100
90
 
101
- grpc_error* Init(const grpc_channel_args& args);
102
91
  void ShutdownLocked() override;
103
92
 
104
- void StartResolvingLocked();
105
93
  void OnResolverError(grpc_error* error);
106
94
  void CreateOrUpdateLbPolicyLocked(
107
95
  const char* lb_policy_name,
@@ -126,7 +114,6 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
126
114
 
127
115
  // Resolver and associated state.
128
116
  OrphanablePtr<Resolver> resolver_;
129
- bool started_resolving_ = false;
130
117
  bool previous_resolution_contained_addresses_ = false;
131
118
 
132
119
  // Child LB policy.
@@ -21,6 +21,7 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include "src/core/lib/gprpp/memory.h"
24
25
  #include "src/core/lib/gprpp/ref_counted.h"
25
26
 
26
27
  namespace grpc_core {
@@ -42,9 +43,7 @@ class ServerRetryThrottleData : public RefCounted<ServerRetryThrottleData> {
42
43
  intptr_t milli_token_ratio() const { return milli_token_ratio_; }
43
44
 
44
45
  private:
45
- // So Delete() can call our private dtor.
46
- template <typename T>
47
- friend void grpc_core::Delete(T*);
46
+ GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
48
47
 
49
48
  ~ServerRetryThrottleData();
50
49
 
@@ -84,13 +84,11 @@ DebugOnlyTraceFlag grpc_trace_subchannel_refcount(false, "subchannel_refcount");
84
84
 
85
85
  ConnectedSubchannel::ConnectedSubchannel(
86
86
  grpc_channel_stack* channel_stack, const grpc_channel_args* args,
87
- RefCountedPtr<channelz::SubchannelNode> channelz_subchannel,
88
- intptr_t socket_uuid)
89
- : ConnectedSubchannelInterface(&grpc_trace_subchannel_refcount),
87
+ RefCountedPtr<channelz::SubchannelNode> channelz_subchannel)
88
+ : RefCounted<ConnectedSubchannel>(&grpc_trace_subchannel_refcount),
90
89
  channel_stack_(channel_stack),
91
90
  args_(grpc_channel_args_copy(args)),
92
- channelz_subchannel_(std::move(channelz_subchannel)),
93
- socket_uuid_(socket_uuid) {}
91
+ channelz_subchannel_(std::move(channelz_subchannel)) {}
94
92
 
95
93
  ConnectedSubchannel::~ConnectedSubchannel() {
96
94
  grpc_channel_args_destroy(args_);
@@ -119,14 +117,38 @@ void ConnectedSubchannel::Ping(grpc_closure* on_initiate,
119
117
  elem->filter->start_transport_op(elem, op);
120
118
  }
121
119
 
122
- RefCountedPtr<SubchannelCall> ConnectedSubchannel::CreateCall(
123
- const CallArgs& args, grpc_error** error) {
120
+ size_t ConnectedSubchannel::GetInitialCallSizeEstimate(
121
+ size_t parent_data_size) const {
122
+ size_t allocation_size =
123
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(SubchannelCall));
124
+ if (parent_data_size > 0) {
125
+ allocation_size +=
126
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(channel_stack_->call_stack_size) +
127
+ parent_data_size;
128
+ } else {
129
+ allocation_size += channel_stack_->call_stack_size;
130
+ }
131
+ return allocation_size;
132
+ }
133
+
134
+ //
135
+ // SubchannelCall
136
+ //
137
+
138
+ RefCountedPtr<SubchannelCall> SubchannelCall::Create(Args args,
139
+ grpc_error** error) {
124
140
  const size_t allocation_size =
125
- GetInitialCallSizeEstimate(args.parent_data_size);
126
- RefCountedPtr<SubchannelCall> call(
127
- new (args.arena->Alloc(allocation_size))
128
- SubchannelCall(Ref(DEBUG_LOCATION, "subchannel_call"), args));
129
- grpc_call_stack* callstk = SUBCHANNEL_CALL_TO_CALL_STACK(call.get());
141
+ args.connected_subchannel->GetInitialCallSizeEstimate(
142
+ args.parent_data_size);
143
+ Arena* arena = args.arena;
144
+ return RefCountedPtr<SubchannelCall>(new (
145
+ arena->Alloc(allocation_size)) SubchannelCall(std::move(args), error));
146
+ }
147
+
148
+ SubchannelCall::SubchannelCall(Args args, grpc_error** error)
149
+ : connected_subchannel_(std::move(args.connected_subchannel)),
150
+ deadline_(args.deadline) {
151
+ grpc_call_stack* callstk = SUBCHANNEL_CALL_TO_CALL_STACK(this);
130
152
  const grpc_call_element_args call_args = {
131
153
  callstk, /* call_stack */
132
154
  nullptr, /* server_transport_data */
@@ -137,38 +159,20 @@ RefCountedPtr<SubchannelCall> ConnectedSubchannel::CreateCall(
137
159
  args.arena, /* arena */
138
160
  args.call_combiner /* call_combiner */
139
161
  };
140
- *error = grpc_call_stack_init(channel_stack_, 1, SubchannelCall::Destroy,
141
- call.get(), &call_args);
162
+ *error = grpc_call_stack_init(connected_subchannel_->channel_stack(), 1,
163
+ SubchannelCall::Destroy, this, &call_args);
142
164
  if (GPR_UNLIKELY(*error != GRPC_ERROR_NONE)) {
143
165
  const char* error_string = grpc_error_string(*error);
144
166
  gpr_log(GPR_ERROR, "error: %s", error_string);
145
- return call;
167
+ return;
146
168
  }
147
169
  grpc_call_stack_set_pollset_or_pollset_set(callstk, args.pollent);
148
- if (channelz_subchannel_ != nullptr) {
149
- channelz_subchannel_->RecordCallStarted();
170
+ auto* channelz_node = connected_subchannel_->channelz_subchannel();
171
+ if (channelz_node != nullptr) {
172
+ channelz_node->RecordCallStarted();
150
173
  }
151
- return call;
152
174
  }
153
175
 
154
- size_t ConnectedSubchannel::GetInitialCallSizeEstimate(
155
- size_t parent_data_size) const {
156
- size_t allocation_size =
157
- GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(SubchannelCall));
158
- if (parent_data_size > 0) {
159
- allocation_size +=
160
- GPR_ROUND_UP_TO_ALIGNMENT_SIZE(channel_stack_->call_stack_size) +
161
- parent_data_size;
162
- } else {
163
- allocation_size += channel_stack_->call_stack_size;
164
- }
165
- return allocation_size;
166
- }
167
-
168
- //
169
- // SubchannelCall
170
- //
171
-
172
176
  void SubchannelCall::StartTransportStreamOpBatch(
173
177
  grpc_transport_stream_op_batch* batch) {
174
178
  GPR_TIMER_SCOPE("subchannel_call_process_op", 0);
@@ -344,6 +348,9 @@ class Subchannel::ConnectedSubchannelStateWatcher {
344
348
  self->pending_connectivity_state_));
345
349
  }
346
350
  c->connected_subchannel_.reset();
351
+ if (c->channelz_node() != nullptr) {
352
+ c->channelz_node()->SetChildSocket(nullptr);
353
+ }
347
354
  c->SetConnectivityStateLocked(GRPC_CHANNEL_TRANSIENT_FAILURE);
348
355
  c->backoff_begun_ = false;
349
356
  c->backoff_.Reset();
@@ -378,12 +385,12 @@ class Subchannel::ConnectedSubchannelStateWatcher {
378
385
  //
379
386
 
380
387
  void Subchannel::ConnectivityStateWatcherList::AddWatcherLocked(
381
- UniquePtr<ConnectivityStateWatcher> watcher) {
388
+ OrphanablePtr<ConnectivityStateWatcherInterface> watcher) {
382
389
  watchers_.insert(MakePair(watcher.get(), std::move(watcher)));
383
390
  }
384
391
 
385
392
  void Subchannel::ConnectivityStateWatcherList::RemoveWatcherLocked(
386
- ConnectivityStateWatcher* watcher) {
393
+ ConnectivityStateWatcherInterface* watcher) {
387
394
  watchers_.erase(watcher);
388
395
  }
389
396
 
@@ -438,8 +445,9 @@ class Subchannel::HealthWatcherMap::HealthWatcher
438
445
 
439
446
  grpc_connectivity_state state() const { return state_; }
440
447
 
441
- void AddWatcherLocked(grpc_connectivity_state initial_state,
442
- UniquePtr<ConnectivityStateWatcher> watcher) {
448
+ void AddWatcherLocked(
449
+ grpc_connectivity_state initial_state,
450
+ OrphanablePtr<ConnectivityStateWatcherInterface> watcher) {
443
451
  if (state_ != initial_state) {
444
452
  RefCountedPtr<ConnectedSubchannel> connected_subchannel;
445
453
  if (state_ == GRPC_CHANNEL_READY) {
@@ -451,7 +459,7 @@ class Subchannel::HealthWatcherMap::HealthWatcher
451
459
  watcher_list_.AddWatcherLocked(std::move(watcher));
452
460
  }
453
461
 
454
- void RemoveWatcherLocked(ConnectivityStateWatcher* watcher) {
462
+ void RemoveWatcherLocked(ConnectivityStateWatcherInterface* watcher) {
455
463
  watcher_list_.RemoveWatcherLocked(watcher);
456
464
  }
457
465
 
@@ -527,7 +535,7 @@ class Subchannel::HealthWatcherMap::HealthWatcher
527
535
  void Subchannel::HealthWatcherMap::AddWatcherLocked(
528
536
  Subchannel* subchannel, grpc_connectivity_state initial_state,
529
537
  UniquePtr<char> health_check_service_name,
530
- UniquePtr<ConnectivityStateWatcher> watcher) {
538
+ OrphanablePtr<ConnectivityStateWatcherInterface> watcher) {
531
539
  // If the health check service name is not already present in the map,
532
540
  // add it.
533
541
  auto it = map_.find(health_check_service_name.get());
@@ -546,7 +554,8 @@ void Subchannel::HealthWatcherMap::AddWatcherLocked(
546
554
  }
547
555
 
548
556
  void Subchannel::HealthWatcherMap::RemoveWatcherLocked(
549
- const char* health_check_service_name, ConnectivityStateWatcher* watcher) {
557
+ const char* health_check_service_name,
558
+ ConnectivityStateWatcherInterface* watcher) {
550
559
  auto it = map_.find(health_check_service_name);
551
560
  GPR_ASSERT(it != map_.end());
552
561
  it->second->RemoveWatcherLocked(watcher);
@@ -676,7 +685,7 @@ Subchannel::Subchannel(SubchannelKey* key, grpc_connector* connector,
676
685
  (size_t)grpc_channel_arg_get_integer(arg, options);
677
686
  if (channelz_enabled) {
678
687
  channelz_node_ = MakeRefCounted<channelz::SubchannelNode>(
679
- this, channel_tracer_max_memory);
688
+ GetTargetAddress(), channel_tracer_max_memory);
680
689
  channelz_node_->AddTraceEvent(
681
690
  channelz::ChannelTrace::Severity::Info,
682
691
  grpc_slice_from_static_string("subchannel created"));
@@ -688,7 +697,7 @@ Subchannel::~Subchannel() {
688
697
  channelz_node_->AddTraceEvent(
689
698
  channelz::ChannelTrace::Severity::Info,
690
699
  grpc_slice_from_static_string("Subchannel destroyed"));
691
- channelz_node_->MarkSubchannelDestroyed();
700
+ channelz_node_->UpdateConnectivityState(GRPC_CHANNEL_SHUTDOWN);
692
701
  }
693
702
  grpc_channel_args_destroy(args_);
694
703
  grpc_connector_unref(connector_);
@@ -778,14 +787,6 @@ Subchannel* Subchannel::RefFromWeakRef(GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
778
787
  }
779
788
  }
780
789
 
781
- intptr_t Subchannel::GetChildSocketUuid() {
782
- if (connected_subchannel_ != nullptr) {
783
- return connected_subchannel_->socket_uuid();
784
- } else {
785
- return 0;
786
- }
787
- }
788
-
789
790
  const char* Subchannel::GetTargetAddress() {
790
791
  const grpc_arg* addr_arg =
791
792
  grpc_channel_args_find(args_, GRPC_ARG_SUBCHANNEL_ADDRESS);
@@ -818,7 +819,7 @@ grpc_connectivity_state Subchannel::CheckConnectivityState(
818
819
  void Subchannel::WatchConnectivityState(
819
820
  grpc_connectivity_state initial_state,
820
821
  UniquePtr<char> health_check_service_name,
821
- UniquePtr<ConnectivityStateWatcher> watcher) {
822
+ OrphanablePtr<ConnectivityStateWatcherInterface> watcher) {
822
823
  MutexLock lock(&mu_);
823
824
  grpc_pollset_set* interested_parties = watcher->interested_parties();
824
825
  if (interested_parties != nullptr) {
@@ -837,7 +838,8 @@ void Subchannel::WatchConnectivityState(
837
838
  }
838
839
 
839
840
  void Subchannel::CancelConnectivityStateWatch(
840
- const char* health_check_service_name, ConnectivityStateWatcher* watcher) {
841
+ const char* health_check_service_name,
842
+ ConnectivityStateWatcherInterface* watcher) {
841
843
  MutexLock lock(&mu_);
842
844
  grpc_pollset_set* interested_parties = watcher->interested_parties();
843
845
  if (interested_parties != nullptr) {
@@ -930,6 +932,7 @@ const char* SubchannelConnectivityStateChangeString(
930
932
  void Subchannel::SetConnectivityStateLocked(grpc_connectivity_state state) {
931
933
  state_ = state;
932
934
  if (channelz_node_ != nullptr) {
935
+ channelz_node_->UpdateConnectivityState(state);
933
936
  channelz_node_->AddTraceEvent(
934
937
  channelz::ChannelTrace::Severity::Info,
935
938
  grpc_slice_from_static_string(
@@ -1069,8 +1072,9 @@ bool Subchannel::PublishTransportLocked() {
1069
1072
  GRPC_ERROR_UNREF(error);
1070
1073
  return false;
1071
1074
  }
1072
- intptr_t socket_uuid = connecting_result_.socket_uuid;
1073
- memset(&connecting_result_, 0, sizeof(connecting_result_));
1075
+ RefCountedPtr<channelz::SocketNode> socket =
1076
+ std::move(connecting_result_.socket);
1077
+ connecting_result_.reset();
1074
1078
  if (disconnected_) {
1075
1079
  grpc_channel_stack_destroy(stk);
1076
1080
  gpr_free(stk);
@@ -1078,9 +1082,12 @@ bool Subchannel::PublishTransportLocked() {
1078
1082
  }
1079
1083
  // Publish.
1080
1084
  connected_subchannel_.reset(
1081
- New<ConnectedSubchannel>(stk, args_, channelz_node_, socket_uuid));
1085
+ New<ConnectedSubchannel>(stk, args_, channelz_node_));
1082
1086
  gpr_log(GPR_INFO, "New connected subchannel at %p for subchannel %p",
1083
1087
  connected_subchannel_.get(), this);
1088
+ if (channelz_node_ != nullptr) {
1089
+ channelz_node_->SetChildSocket(std::move(socket));
1090
+ }
1084
1091
  // Instantiate state watcher. Will clean itself up.
1085
1092
  New<ConnectedSubchannelStateWatcher>(this);
1086
1093
  // Report initial state.