grpc 1.1.2 → 1.2.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -0,0 +1,56 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #ifndef GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H
35
+ #define GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H
36
+
37
+ #include "src/core/ext/client_channel/lb_policy_factory.h"
38
+ #include "src/core/lib/slice/slice_hash_table.h"
39
+
40
+ /** Create the channel used for communicating with an LB service.
41
+ * Note that an LB *service* may be comprised of several LB *servers*.
42
+ *
43
+ * \a lb_service_target_addresses is the target URI containing the addresses
44
+ * from resolving the LB service's name (eg, ipv4:10.0.0.1:1234,10.2.3.4:9876).
45
+ * \a client_channel_factory will be used for the creation of the LB channel,
46
+ * alongside the channel args passed in \a args. */
47
+ grpc_channel *grpc_lb_policy_grpclb_create_lb_channel(
48
+ grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses,
49
+ grpc_client_channel_factory *client_channel_factory,
50
+ grpc_channel_args *args);
51
+
52
+ grpc_channel_args *get_lb_channel_args(grpc_exec_ctx *exec_ctx,
53
+ grpc_slice_hash_table *targets_info,
54
+ const grpc_channel_args *args);
55
+
56
+ #endif /* GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H */
@@ -0,0 +1,107 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include <grpc/support/alloc.h>
35
+ #include <grpc/support/string_util.h>
36
+
37
+ #include "src/core/ext/client_channel/client_channel.h"
38
+ #include "src/core/ext/lb_policy/grpclb/grpclb_channel.h"
39
+ #include "src/core/lib/channel/channel_args.h"
40
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
41
+ #include "src/core/lib/security/credentials/credentials.h"
42
+ #include "src/core/lib/security/transport/lb_targets_info.h"
43
+ #include "src/core/lib/slice/slice_internal.h"
44
+ #include "src/core/lib/support/string.h"
45
+
46
+ grpc_channel *grpc_lb_policy_grpclb_create_lb_channel(
47
+ grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses,
48
+ grpc_client_channel_factory *client_channel_factory,
49
+ grpc_channel_args *args) {
50
+ grpc_channel_args *new_args = args;
51
+ grpc_channel_credentials *channel_credentials =
52
+ grpc_channel_credentials_find_in_args(args);
53
+ if (channel_credentials != NULL) {
54
+ /* Substitute the channel credentials with a version without call
55
+ * credentials: the load balancer is not necessarily trusted to handle
56
+ * bearer token credentials */
57
+ static const char *keys_to_remove[] = {GRPC_ARG_CHANNEL_CREDENTIALS};
58
+ grpc_channel_credentials *creds_sans_call_creds =
59
+ grpc_channel_credentials_duplicate_without_call_credentials(
60
+ channel_credentials);
61
+ GPR_ASSERT(creds_sans_call_creds != NULL);
62
+ grpc_arg args_to_add[] = {
63
+ grpc_channel_credentials_to_arg(creds_sans_call_creds)};
64
+ /* Create the new set of channel args */
65
+ new_args = grpc_channel_args_copy_and_add_and_remove(
66
+ args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add,
67
+ GPR_ARRAY_SIZE(args_to_add));
68
+ grpc_channel_credentials_unref(exec_ctx, creds_sans_call_creds);
69
+ }
70
+ grpc_channel *lb_channel = grpc_client_channel_factory_create_channel(
71
+ exec_ctx, client_channel_factory, lb_service_target_addresses,
72
+ GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args);
73
+ if (channel_credentials != NULL) {
74
+ grpc_channel_args_destroy(exec_ctx, new_args);
75
+ }
76
+ return lb_channel;
77
+ }
78
+
79
+ grpc_channel_args *get_lb_channel_args(grpc_exec_ctx *exec_ctx,
80
+ grpc_slice_hash_table *targets_info,
81
+ const grpc_channel_args *args) {
82
+ const grpc_arg targets_info_arg =
83
+ grpc_lb_targets_info_create_channel_arg(targets_info);
84
+ /* We strip out the channel arg for the LB policy name, since we want
85
+ * to use the default (pick_first) in this case.
86
+ *
87
+ * We also strip out the channel arg for the resolved addresses, since
88
+ * that will be generated by the name resolver used in the LB channel.
89
+ * Note that the LB channel will use the sockaddr resolver, so this
90
+ * won't actually generate a query to DNS (or some other name service).
91
+ * However, the addresses returned by the sockaddr resolver will have
92
+ * is_balancer=false, whereas our own addresses have is_balancer=true.
93
+ * We need the LB channel to return addresses with is_balancer=false
94
+ * so that it does not wind up recursively using the grpclb LB policy,
95
+ * as per the special case logic in client_channel.c.
96
+ *
97
+ * Lastly, we also strip out the channel arg for the server URI,
98
+ * since that will be different for the LB channel than for the parent
99
+ * channel (the client channel factory will re-add this arg with
100
+ * the right value). */
101
+ static const char *keys_to_remove[] = {
102
+ GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES, GRPC_ARG_SERVER_URI};
103
+ /* Add the targets info table to be used for secure naming */
104
+ return grpc_channel_args_copy_and_add_and_remove(
105
+ args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &targets_info_arg,
106
+ 1);
107
+ }
@@ -62,8 +62,7 @@ static bool decode_serverlist(pb_istream_t *stream, const pb_field_t *field,
62
62
  }
63
63
  dec_arg->num_servers++;
64
64
  } else { /* second pass. Actually decode. */
65
- grpc_grpclb_server *server = gpr_malloc(sizeof(grpc_grpclb_server));
66
- memset(server, 0, sizeof(grpc_grpclb_server));
65
+ grpc_grpclb_server *server = gpr_zalloc(sizeof(grpc_grpclb_server));
67
66
  GPR_ASSERT(dec_arg->num_servers > 0);
68
67
  if (dec_arg->decoding_idx == 0) { /* first iteration of second pass */
69
68
  dec_arg->servers =
@@ -160,8 +159,7 @@ grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist(
160
159
  return NULL;
161
160
  }
162
161
 
163
- grpc_grpclb_serverlist *sl = gpr_malloc(sizeof(grpc_grpclb_serverlist));
164
- memset(sl, 0, sizeof(*sl));
162
+ grpc_grpclb_serverlist *sl = gpr_zalloc(sizeof(grpc_grpclb_serverlist));
165
163
  sl->num_servers = arg.num_servers;
166
164
  sl->servers = arg.servers;
167
165
  if (res.server_list.has_expiration_interval) {
@@ -183,8 +181,7 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist *serverlist) {
183
181
 
184
182
  grpc_grpclb_serverlist *grpc_grpclb_serverlist_copy(
185
183
  const grpc_grpclb_serverlist *sl) {
186
- grpc_grpclb_serverlist *copy = gpr_malloc(sizeof(grpc_grpclb_serverlist));
187
- memset(copy, 0, sizeof(grpc_grpclb_serverlist));
184
+ grpc_grpclb_serverlist *copy = gpr_zalloc(sizeof(grpc_grpclb_serverlist));
188
185
  copy->num_servers = sl->num_servers;
189
186
  memcpy(&copy->expiration_interval, &sl->expiration_interval,
190
187
  sizeof(grpc_grpclb_duration));
@@ -38,6 +38,7 @@
38
38
  #include "src/core/ext/client_channel/lb_policy_registry.h"
39
39
  #include "src/core/ext/client_channel/subchannel.h"
40
40
  #include "src/core/lib/channel/channel_args.h"
41
+ #include "src/core/lib/iomgr/combiner.h"
41
42
  #include "src/core/lib/iomgr/sockaddr_utils.h"
42
43
  #include "src/core/lib/transport/connectivity_state.h"
43
44
 
@@ -57,11 +58,11 @@ typedef struct {
57
58
 
58
59
  grpc_closure connectivity_changed;
59
60
 
60
- /** the selected channel (a grpc_connected_subchannel) */
61
- gpr_atm selected;
61
+ /** remaining members are protected by the combiner */
62
+
63
+ /** the selected channel */
64
+ grpc_connected_subchannel *selected;
62
65
 
63
- /** mutex protecting remaining members */
64
- gpr_mu mu;
65
66
  /** have we started picking? */
66
67
  int started_picking;
67
68
  /** are we shut down? */
@@ -77,32 +78,24 @@ typedef struct {
77
78
  grpc_connectivity_state_tracker state_tracker;
78
79
  } pick_first_lb_policy;
79
80
 
80
- #define GET_SELECTED(p) \
81
- ((grpc_connected_subchannel *)gpr_atm_acq_load(&(p)->selected))
82
-
83
81
  static void pf_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
84
82
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
85
- grpc_connected_subchannel *selected = GET_SELECTED(p);
86
83
  size_t i;
87
84
  GPR_ASSERT(p->pending_picks == NULL);
88
85
  for (i = 0; i < p->num_subchannels; i++) {
89
86
  GRPC_SUBCHANNEL_UNREF(exec_ctx, p->subchannels[i], "pick_first");
90
87
  }
91
- if (selected != NULL) {
92
- GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, selected, "picked_first");
88
+ if (p->selected != NULL) {
89
+ GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, p->selected, "picked_first");
93
90
  }
94
91
  grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker);
95
92
  gpr_free(p->subchannels);
96
- gpr_mu_destroy(&p->mu);
97
93
  gpr_free(p);
98
94
  }
99
95
 
100
- static void pf_shutdown(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
96
+ static void pf_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
101
97
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
102
98
  pending_pick *pp;
103
- grpc_connected_subchannel *selected;
104
- gpr_mu_lock(&p->mu);
105
- selected = GET_SELECTED(p);
106
99
  p->shutdown = 1;
107
100
  pp = p->pending_picks;
108
101
  p->pending_picks = NULL;
@@ -110,15 +103,14 @@ static void pf_shutdown(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
110
103
  exec_ctx, &p->state_tracker, GRPC_CHANNEL_SHUTDOWN,
111
104
  GRPC_ERROR_CREATE("Channel shutdown"), "shutdown");
112
105
  /* cancel subscription */
113
- if (selected != NULL) {
106
+ if (p->selected != NULL) {
114
107
  grpc_connected_subchannel_notify_on_state_change(
115
- exec_ctx, selected, NULL, NULL, &p->connectivity_changed);
108
+ exec_ctx, p->selected, NULL, NULL, &p->connectivity_changed);
116
109
  } else if (p->num_subchannels > 0) {
117
110
  grpc_subchannel_notify_on_state_change(
118
111
  exec_ctx, p->subchannels[p->checking_subchannel], NULL, NULL,
119
112
  &p->connectivity_changed);
120
113
  }
121
- gpr_mu_unlock(&p->mu);
122
114
  while (pp != NULL) {
123
115
  pending_pick *next = pp->next;
124
116
  *pp->target = NULL;
@@ -128,12 +120,11 @@ static void pf_shutdown(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
128
120
  }
129
121
  }
130
122
 
131
- static void pf_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
132
- grpc_connected_subchannel **target,
133
- grpc_error *error) {
123
+ static void pf_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
124
+ grpc_connected_subchannel **target,
125
+ grpc_error *error) {
134
126
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
135
127
  pending_pick *pp;
136
- gpr_mu_lock(&p->mu);
137
128
  pp = p->pending_picks;
138
129
  p->pending_picks = NULL;
139
130
  while (pp != NULL) {
@@ -150,17 +141,15 @@ static void pf_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
150
141
  }
151
142
  pp = next;
152
143
  }
153
- gpr_mu_unlock(&p->mu);
154
144
  GRPC_ERROR_UNREF(error);
155
145
  }
156
146
 
157
- static void pf_cancel_picks(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
158
- uint32_t initial_metadata_flags_mask,
159
- uint32_t initial_metadata_flags_eq,
160
- grpc_error *error) {
147
+ static void pf_cancel_picks_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
148
+ uint32_t initial_metadata_flags_mask,
149
+ uint32_t initial_metadata_flags_eq,
150
+ grpc_error *error) {
161
151
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
162
152
  pending_pick *pp;
163
- gpr_mu_lock(&p->mu);
164
153
  pp = p->pending_picks;
165
154
  p->pending_picks = NULL;
166
155
  while (pp != NULL) {
@@ -177,7 +166,6 @@ static void pf_cancel_picks(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
177
166
  }
178
167
  pp = next;
179
168
  }
180
- gpr_mu_unlock(&p->mu);
181
169
  GRPC_ERROR_UNREF(error);
182
170
  }
183
171
 
@@ -192,63 +180,48 @@ static void start_picking(grpc_exec_ctx *exec_ctx, pick_first_lb_policy *p) {
192
180
  &p->connectivity_changed);
193
181
  }
194
182
 
195
- static void pf_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
183
+ static void pf_exit_idle_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
196
184
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
197
- gpr_mu_lock(&p->mu);
198
185
  if (!p->started_picking) {
199
186
  start_picking(exec_ctx, p);
200
187
  }
201
- gpr_mu_unlock(&p->mu);
202
188
  }
203
189
 
204
- static int pf_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
205
- const grpc_lb_policy_pick_args *pick_args,
206
- grpc_connected_subchannel **target, void **user_data,
207
- grpc_closure *on_complete) {
190
+ static int pf_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
191
+ const grpc_lb_policy_pick_args *pick_args,
192
+ grpc_connected_subchannel **target, void **user_data,
193
+ grpc_closure *on_complete) {
208
194
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
209
195
  pending_pick *pp;
210
196
 
211
197
  /* Check atomically for a selected channel */
212
- grpc_connected_subchannel *selected = GET_SELECTED(p);
213
- if (selected != NULL) {
214
- *target = GRPC_CONNECTED_SUBCHANNEL_REF(selected, "picked");
198
+ if (p->selected != NULL) {
199
+ *target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected, "picked");
215
200
  return 1;
216
201
  }
217
202
 
218
- /* No subchannel selected yet, so acquire lock and then attempt again */
219
- gpr_mu_lock(&p->mu);
220
- selected = GET_SELECTED(p);
221
- if (selected) {
222
- gpr_mu_unlock(&p->mu);
223
- *target = GRPC_CONNECTED_SUBCHANNEL_REF(selected, "picked");
224
- return 1;
225
- } else {
226
- if (!p->started_picking) {
227
- start_picking(exec_ctx, p);
228
- }
229
- pp = gpr_malloc(sizeof(*pp));
230
- pp->next = p->pending_picks;
231
- pp->target = target;
232
- pp->initial_metadata_flags = pick_args->initial_metadata_flags;
233
- pp->on_complete = on_complete;
234
- p->pending_picks = pp;
235
- gpr_mu_unlock(&p->mu);
236
- return 0;
203
+ /* No subchannel selected yet, so try again */
204
+ if (!p->started_picking) {
205
+ start_picking(exec_ctx, p);
237
206
  }
207
+ pp = gpr_malloc(sizeof(*pp));
208
+ pp->next = p->pending_picks;
209
+ pp->target = target;
210
+ pp->initial_metadata_flags = pick_args->initial_metadata_flags;
211
+ pp->on_complete = on_complete;
212
+ p->pending_picks = pp;
213
+ return 0;
238
214
  }
239
215
 
240
- static void destroy_subchannels(grpc_exec_ctx *exec_ctx, void *arg,
241
- grpc_error *error) {
242
- pick_first_lb_policy *p = arg;
216
+ static void destroy_subchannels_locked(grpc_exec_ctx *exec_ctx,
217
+ pick_first_lb_policy *p) {
243
218
  size_t i;
244
219
  size_t num_subchannels = p->num_subchannels;
245
220
  grpc_subchannel **subchannels;
246
221
 
247
- gpr_mu_lock(&p->mu);
248
222
  subchannels = p->subchannels;
249
223
  p->num_subchannels = 0;
250
224
  p->subchannels = NULL;
251
- gpr_mu_unlock(&p->mu);
252
225
  GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &p->base, "destroy_subchannels");
253
226
 
254
227
  for (i = 0; i < num_subchannels; i++) {
@@ -258,25 +231,19 @@ static void destroy_subchannels(grpc_exec_ctx *exec_ctx, void *arg,
258
231
  gpr_free(subchannels);
259
232
  }
260
233
 
261
- static void pf_connectivity_changed(grpc_exec_ctx *exec_ctx, void *arg,
262
- grpc_error *error) {
234
+ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
235
+ grpc_error *error) {
263
236
  pick_first_lb_policy *p = arg;
264
237
  grpc_subchannel *selected_subchannel;
265
238
  pending_pick *pp;
266
- grpc_connected_subchannel *selected;
267
239
 
268
240
  GRPC_ERROR_REF(error);
269
241
 
270
- gpr_mu_lock(&p->mu);
271
-
272
- selected = GET_SELECTED(p);
273
-
274
242
  if (p->shutdown) {
275
- gpr_mu_unlock(&p->mu);
276
243
  GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &p->base, "pick_first_connectivity");
277
244
  GRPC_ERROR_UNREF(error);
278
245
  return;
279
- } else if (selected != NULL) {
246
+ } else if (p->selected != NULL) {
280
247
  if (p->checking_connectivity == GRPC_CHANNEL_TRANSIENT_FAILURE) {
281
248
  /* if the selected channel goes bad, we're done */
282
249
  p->checking_connectivity = GRPC_CHANNEL_SHUTDOWN;
@@ -286,7 +253,7 @@ static void pf_connectivity_changed(grpc_exec_ctx *exec_ctx, void *arg,
286
253
  "selected_changed");
287
254
  if (p->checking_connectivity != GRPC_CHANNEL_SHUTDOWN) {
288
255
  grpc_connected_subchannel_notify_on_state_change(
289
- exec_ctx, selected, p->base.interested_parties,
256
+ exec_ctx, p->selected, p->base.interested_parties,
290
257
  &p->checking_connectivity, &p->connectivity_changed);
291
258
  } else {
292
259
  GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &p->base, "pick_first_connectivity");
@@ -301,26 +268,21 @@ static void pf_connectivity_changed(grpc_exec_ctx *exec_ctx, void *arg,
301
268
  GRPC_CHANNEL_READY, GRPC_ERROR_NONE,
302
269
  "connecting_ready");
303
270
  selected_subchannel = p->subchannels[p->checking_subchannel];
304
- selected =
305
- grpc_subchannel_get_connected_subchannel(selected_subchannel);
306
- GPR_ASSERT(selected != NULL);
307
- GRPC_CONNECTED_SUBCHANNEL_REF(selected, "picked_first");
271
+ p->selected = GRPC_CONNECTED_SUBCHANNEL_REF(
272
+ grpc_subchannel_get_connected_subchannel(selected_subchannel),
273
+ "picked_first");
308
274
  /* drop the pick list: we are connected now */
309
275
  GRPC_LB_POLICY_WEAK_REF(&p->base, "destroy_subchannels");
310
- gpr_atm_rel_store(&p->selected, (gpr_atm)selected);
311
- grpc_closure_sched(exec_ctx,
312
- grpc_closure_create(destroy_subchannels, p,
313
- grpc_schedule_on_exec_ctx),
314
- GRPC_ERROR_NONE);
276
+ destroy_subchannels_locked(exec_ctx, p);
315
277
  /* update any calls that were waiting for a pick */
316
278
  while ((pp = p->pending_picks)) {
317
279
  p->pending_picks = pp->next;
318
- *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF(selected, "picked");
280
+ *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected, "picked");
319
281
  grpc_closure_sched(exec_ctx, pp->on_complete, GRPC_ERROR_NONE);
320
282
  gpr_free(pp);
321
283
  }
322
284
  grpc_connected_subchannel_notify_on_state_change(
323
- exec_ctx, selected, p->base.interested_parties,
285
+ exec_ctx, p->selected, p->base.interested_parties,
324
286
  &p->checking_connectivity, &p->connectivity_changed);
325
287
  break;
326
288
  case GRPC_CHANNEL_TRANSIENT_FAILURE:
@@ -387,48 +349,44 @@ static void pf_connectivity_changed(grpc_exec_ctx *exec_ctx, void *arg,
387
349
  }
388
350
  }
389
351
 
390
- gpr_mu_unlock(&p->mu);
391
-
392
352
  GRPC_ERROR_UNREF(error);
393
353
  }
394
354
 
395
- static grpc_connectivity_state pf_check_connectivity(grpc_exec_ctx *exec_ctx,
396
- grpc_lb_policy *pol,
397
- grpc_error **error) {
355
+ static grpc_connectivity_state pf_check_connectivity_locked(
356
+ grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, grpc_error **error) {
398
357
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
399
- grpc_connectivity_state st;
400
- gpr_mu_lock(&p->mu);
401
- st = grpc_connectivity_state_check(&p->state_tracker, error);
402
- gpr_mu_unlock(&p->mu);
403
- return st;
358
+ return grpc_connectivity_state_get(&p->state_tracker, error);
404
359
  }
405
360
 
406
- static void pf_notify_on_state_change(grpc_exec_ctx *exec_ctx,
407
- grpc_lb_policy *pol,
408
- grpc_connectivity_state *current,
409
- grpc_closure *notify) {
361
+ static void pf_notify_on_state_change_locked(grpc_exec_ctx *exec_ctx,
362
+ grpc_lb_policy *pol,
363
+ grpc_connectivity_state *current,
364
+ grpc_closure *notify) {
410
365
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
411
- gpr_mu_lock(&p->mu);
412
366
  grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker,
413
367
  current, notify);
414
- gpr_mu_unlock(&p->mu);
415
368
  }
416
369
 
417
- static void pf_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
418
- grpc_closure *closure) {
370
+ static void pf_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
371
+ grpc_closure *closure) {
419
372
  pick_first_lb_policy *p = (pick_first_lb_policy *)pol;
420
- grpc_connected_subchannel *selected = GET_SELECTED(p);
421
- if (selected) {
422
- grpc_connected_subchannel_ping(exec_ctx, selected, closure);
373
+ if (p->selected) {
374
+ grpc_connected_subchannel_ping(exec_ctx, p->selected, closure);
423
375
  } else {
424
376
  grpc_closure_sched(exec_ctx, closure, GRPC_ERROR_CREATE("Not connected"));
425
377
  }
426
378
  }
427
379
 
428
380
  static const grpc_lb_policy_vtable pick_first_lb_policy_vtable = {
429
- pf_destroy, pf_shutdown, pf_pick,
430
- pf_cancel_pick, pf_cancel_picks, pf_ping_one,
431
- pf_exit_idle, pf_check_connectivity, pf_notify_on_state_change};
381
+ pf_destroy,
382
+ pf_shutdown_locked,
383
+ pf_pick_locked,
384
+ pf_cancel_pick_locked,
385
+ pf_cancel_picks_locked,
386
+ pf_ping_one_locked,
387
+ pf_exit_idle_locked,
388
+ pf_check_connectivity_locked,
389
+ pf_notify_on_state_change_locked};
432
390
 
433
391
  static void pick_first_factory_ref(grpc_lb_policy_factory *factory) {}
434
392
 
@@ -451,11 +409,9 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx,
451
409
  }
452
410
  if (num_addrs == 0) return NULL;
453
411
 
454
- pick_first_lb_policy *p = gpr_malloc(sizeof(*p));
455
- memset(p, 0, sizeof(*p));
412
+ pick_first_lb_policy *p = gpr_zalloc(sizeof(*p));
456
413
 
457
- p->subchannels = gpr_malloc(sizeof(grpc_subchannel *) * num_addrs);
458
- memset(p->subchannels, 0, sizeof(*p->subchannels) * num_addrs);
414
+ p->subchannels = gpr_zalloc(sizeof(grpc_subchannel *) * num_addrs);
459
415
  grpc_subchannel_args sc_args;
460
416
  size_t subchannel_idx = 0;
461
417
  for (size_t i = 0; i < addresses->num_addresses; i++) {
@@ -489,10 +445,9 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx,
489
445
  }
490
446
  p->num_subchannels = subchannel_idx;
491
447
 
492
- grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable);
493
- grpc_closure_init(&p->connectivity_changed, pf_connectivity_changed, p,
494
- grpc_schedule_on_exec_ctx);
495
- gpr_mu_init(&p->mu);
448
+ grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable, args->combiner);
449
+ grpc_closure_init(&p->connectivity_changed, pf_connectivity_changed_locked, p,
450
+ grpc_combiner_scheduler(args->combiner, false));
496
451
  return &p->base;
497
452
  }
498
453