grpc 1.17.1 → 1.18.0.pre1

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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -79,6 +79,7 @@
79
79
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
80
80
  #include "src/core/ext/filters/client_channel/parse_address.h"
81
81
  #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
82
+ #include "src/core/ext/filters/client_channel/server_address.h"
82
83
  #include "src/core/ext/filters/client_channel/subchannel_index.h"
83
84
  #include "src/core/lib/backoff/backoff.h"
84
85
  #include "src/core/lib/channel/channel_args.h"
@@ -114,9 +115,13 @@ TraceFlag grpc_lb_xds_trace(false, "xds");
114
115
 
115
116
  namespace {
116
117
 
118
+ constexpr char kXds[] = "xds_experimental";
119
+
117
120
  class XdsLb : public LoadBalancingPolicy {
118
121
  public:
119
- XdsLb(const grpc_lb_addresses* addresses, const Args& args);
122
+ explicit XdsLb(const Args& args);
123
+
124
+ const char* name() const override { return kXds; }
120
125
 
121
126
  void UpdateLocked(const grpc_channel_args& args,
122
127
  grpc_json* lb_config) override;
@@ -156,9 +161,6 @@ class XdsLb : public LoadBalancingPolicy {
156
161
  // Our on_complete closure and the original one.
157
162
  grpc_closure on_complete;
158
163
  grpc_closure* original_on_complete;
159
- // The LB token associated with the pick. This is set via user_data in
160
- // the pick.
161
- grpc_mdelem lb_token;
162
164
  // Stats for client-side load reporting.
163
165
  RefCountedPtr<XdsLbClientStats> client_stats;
164
166
  // Next pending pick.
@@ -166,8 +168,7 @@ class XdsLb : public LoadBalancingPolicy {
166
168
  };
167
169
 
168
170
  /// Contains a call to the LB server and all the data related to the call.
169
- class BalancerCallState
170
- : public InternallyRefCountedWithTracing<BalancerCallState> {
171
+ class BalancerCallState : public InternallyRefCounted<BalancerCallState> {
171
172
  public:
172
173
  explicit BalancerCallState(
173
174
  RefCountedPtr<LoadBalancingPolicy> parent_xdslb_policy);
@@ -199,7 +200,6 @@ class XdsLb : public LoadBalancingPolicy {
199
200
  static bool LoadReportCountersAreZero(xds_grpclb_request* request);
200
201
 
201
202
  static void MaybeSendClientLoadReportLocked(void* arg, grpc_error* error);
202
- static void ClientLoadReportDoneLocked(void* arg, grpc_error* error);
203
203
  static void OnInitialRequestSentLocked(void* arg, grpc_error* error);
204
204
  static void OnBalancerMessageReceivedLocked(void* arg, grpc_error* error);
205
205
  static void OnBalancerStatusReceivedLocked(void* arg, grpc_error* error);
@@ -258,7 +258,7 @@ class XdsLb : public LoadBalancingPolicy {
258
258
  grpc_error* error);
259
259
 
260
260
  // Pending pick methods.
261
- static void PendingPickSetMetadataAndContext(PendingPick* pp);
261
+ static void PendingPickCleanup(PendingPick* pp);
262
262
  PendingPick* PendingPickCreate(PickState* pick);
263
263
  void AddPendingPick(PendingPick* pp);
264
264
  static void OnPendingPickComplete(void* arg, grpc_error* error);
@@ -321,7 +321,7 @@ class XdsLb : public LoadBalancingPolicy {
321
321
  // 0 means not using fallback.
322
322
  int lb_fallback_timeout_ms_ = 0;
323
323
  // The backend addresses from the resolver.
324
- grpc_lb_addresses* fallback_backend_addresses_ = nullptr;
324
+ UniquePtr<ServerAddressList> fallback_backend_addresses_;
325
325
  // Fallback timer.
326
326
  bool fallback_timer_callback_pending_ = false;
327
327
  grpc_timer lb_fallback_timer_;
@@ -341,47 +341,15 @@ class XdsLb : public LoadBalancingPolicy {
341
341
  // serverlist parsing code
342
342
  //
343
343
 
344
- // vtable for LB tokens in grpc_lb_addresses
345
- void* lb_token_copy(void* token) {
346
- return token == nullptr
347
- ? nullptr
348
- : (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload;
349
- }
350
- void lb_token_destroy(void* token) {
351
- if (token != nullptr) {
352
- GRPC_MDELEM_UNREF(grpc_mdelem{(uintptr_t)token});
353
- }
354
- }
355
- int lb_token_cmp(void* token1, void* token2) {
356
- if (token1 > token2) return 1;
357
- if (token1 < token2) return -1;
358
- return 0;
359
- }
360
- const grpc_lb_user_data_vtable lb_token_vtable = {
361
- lb_token_copy, lb_token_destroy, lb_token_cmp};
362
-
363
344
  // Returns the backend addresses extracted from the given addresses.
364
- grpc_lb_addresses* ExtractBackendAddresses(const grpc_lb_addresses* addresses) {
365
- // First pass: count the number of backend addresses.
366
- size_t num_backends = 0;
367
- for (size_t i = 0; i < addresses->num_addresses; ++i) {
368
- if (!addresses->addresses[i].is_balancer) {
369
- ++num_backends;
345
+ UniquePtr<ServerAddressList> ExtractBackendAddresses(
346
+ const ServerAddressList& addresses) {
347
+ auto backend_addresses = MakeUnique<ServerAddressList>();
348
+ for (size_t i = 0; i < addresses.size(); ++i) {
349
+ if (!addresses[i].IsBalancer()) {
350
+ backend_addresses->emplace_back(addresses[i]);
370
351
  }
371
352
  }
372
- // Second pass: actually populate the addresses and (empty) LB tokens.
373
- grpc_lb_addresses* backend_addresses =
374
- grpc_lb_addresses_create(num_backends, &lb_token_vtable);
375
- size_t num_copied = 0;
376
- for (size_t i = 0; i < addresses->num_addresses; ++i) {
377
- if (addresses->addresses[i].is_balancer) continue;
378
- const grpc_resolved_address* addr = &addresses->addresses[i].address;
379
- grpc_lb_addresses_set_address(backend_addresses, num_copied, &addr->addr,
380
- addr->len, false /* is_balancer */,
381
- nullptr /* balancer_name */,
382
- (void*)GRPC_MDELEM_LB_TOKEN_EMPTY.payload);
383
- ++num_copied;
384
- }
385
353
  return backend_addresses;
386
354
  }
387
355
 
@@ -431,56 +399,17 @@ void ParseServer(const xds_grpclb_server* server, grpc_resolved_address* addr) {
431
399
  }
432
400
 
433
401
  // Returns addresses extracted from \a serverlist.
434
- grpc_lb_addresses* ProcessServerlist(const xds_grpclb_serverlist* serverlist) {
435
- size_t num_valid = 0;
436
- /* first pass: count how many are valid in order to allocate the necessary
437
- * memory in a single block */
402
+ UniquePtr<ServerAddressList> ProcessServerlist(
403
+ const xds_grpclb_serverlist* serverlist) {
404
+ auto addresses = MakeUnique<ServerAddressList>();
438
405
  for (size_t i = 0; i < serverlist->num_servers; ++i) {
439
- if (IsServerValid(serverlist->servers[i], i, true)) ++num_valid;
440
- }
441
- grpc_lb_addresses* lb_addresses =
442
- grpc_lb_addresses_create(num_valid, &lb_token_vtable);
443
- /* second pass: actually populate the addresses and LB tokens (aka user data
444
- * to the outside world) to be read by the child policy during its creation.
445
- * Given that the validity tests are very cheap, they are performed again
446
- * instead of marking the valid ones during the first pass, as this would
447
- * incurr in an allocation due to the arbitrary number of server */
448
- size_t addr_idx = 0;
449
- for (size_t sl_idx = 0; sl_idx < serverlist->num_servers; ++sl_idx) {
450
- const xds_grpclb_server* server = serverlist->servers[sl_idx];
451
- if (!IsServerValid(serverlist->servers[sl_idx], sl_idx, false)) continue;
452
- GPR_ASSERT(addr_idx < num_valid);
453
- /* address processing */
406
+ const xds_grpclb_server* server = serverlist->servers[i];
407
+ if (!IsServerValid(serverlist->servers[i], i, false)) continue;
454
408
  grpc_resolved_address addr;
455
409
  ParseServer(server, &addr);
456
- /* lb token processing */
457
- void* user_data;
458
- if (server->has_load_balance_token) {
459
- const size_t lb_token_max_length =
460
- GPR_ARRAY_SIZE(server->load_balance_token);
461
- const size_t lb_token_length =
462
- strnlen(server->load_balance_token, lb_token_max_length);
463
- grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer(
464
- server->load_balance_token, lb_token_length);
465
- user_data =
466
- (void*)grpc_mdelem_from_slices(GRPC_MDSTR_LB_TOKEN, lb_token_mdstr)
467
- .payload;
468
- } else {
469
- char* uri = grpc_sockaddr_to_uri(&addr);
470
- gpr_log(GPR_INFO,
471
- "Missing LB token for backend address '%s'. The empty token will "
472
- "be used instead",
473
- uri);
474
- gpr_free(uri);
475
- user_data = (void*)GRPC_MDELEM_LB_TOKEN_EMPTY.payload;
476
- }
477
- grpc_lb_addresses_set_address(lb_addresses, addr_idx, &addr.addr, addr.len,
478
- false /* is_balancer */,
479
- nullptr /* balancer_name */, user_data);
480
- ++addr_idx;
410
+ addresses->emplace_back(addr, nullptr);
481
411
  }
482
- GPR_ASSERT(addr_idx == num_valid);
483
- return lb_addresses;
412
+ return addresses;
484
413
  }
485
414
 
486
415
  //
@@ -489,7 +418,7 @@ grpc_lb_addresses* ProcessServerlist(const xds_grpclb_serverlist* serverlist) {
489
418
 
490
419
  XdsLb::BalancerCallState::BalancerCallState(
491
420
  RefCountedPtr<LoadBalancingPolicy> parent_xdslb_policy)
492
- : InternallyRefCountedWithTracing<BalancerCallState>(&grpc_lb_xds_trace),
421
+ : InternallyRefCounted<BalancerCallState>(&grpc_lb_xds_trace),
493
422
  xdslb_policy_(std::move(parent_xdslb_policy)) {
494
423
  GPR_ASSERT(xdslb_policy_ != nullptr);
495
424
  GPR_ASSERT(!xdslb_policy()->shutting_down_);
@@ -668,6 +597,7 @@ bool XdsLb::BalancerCallState::LoadReportCountersAreZero(
668
597
  (drop_entries == nullptr || drop_entries->empty());
669
598
  }
670
599
 
600
+ // TODO(vpowar): Use LRS to send the client Load Report.
671
601
  void XdsLb::BalancerCallState::SendClientLoadReportLocked() {
672
602
  // Construct message payload.
673
603
  GPR_ASSERT(send_message_payload_ == nullptr);
@@ -685,38 +615,8 @@ void XdsLb::BalancerCallState::SendClientLoadReportLocked() {
685
615
  } else {
686
616
  last_client_load_report_counters_were_zero_ = false;
687
617
  }
688
- grpc_slice request_payload_slice = xds_grpclb_request_encode(request);
689
- send_message_payload_ =
690
- grpc_raw_byte_buffer_create(&request_payload_slice, 1);
691
- grpc_slice_unref_internal(request_payload_slice);
618
+ // TODO(vpowar): Send the report on LRS stream.
692
619
  xds_grpclb_request_destroy(request);
693
- // Send the report.
694
- grpc_op op;
695
- memset(&op, 0, sizeof(op));
696
- op.op = GRPC_OP_SEND_MESSAGE;
697
- op.data.send_message.send_message = send_message_payload_;
698
- GRPC_CLOSURE_INIT(&client_load_report_closure_, ClientLoadReportDoneLocked,
699
- this, grpc_combiner_scheduler(xdslb_policy()->combiner()));
700
- grpc_call_error call_error = grpc_call_start_batch_and_execute(
701
- lb_call_, &op, 1, &client_load_report_closure_);
702
- if (GPR_UNLIKELY(call_error != GRPC_CALL_OK)) {
703
- gpr_log(GPR_ERROR, "[xdslb %p] call_error=%d", xdslb_policy_.get(),
704
- call_error);
705
- GPR_ASSERT(GRPC_CALL_OK == call_error);
706
- }
707
- }
708
-
709
- void XdsLb::BalancerCallState::ClientLoadReportDoneLocked(void* arg,
710
- grpc_error* error) {
711
- BalancerCallState* lb_calld = static_cast<BalancerCallState*>(arg);
712
- XdsLb* xdslb_policy = lb_calld->xdslb_policy();
713
- grpc_byte_buffer_destroy(lb_calld->send_message_payload_);
714
- lb_calld->send_message_payload_ = nullptr;
715
- if (error != GRPC_ERROR_NONE || lb_calld != xdslb_policy->lb_calld_.get()) {
716
- lb_calld->Unref(DEBUG_LOCATION, "client_load_report");
717
- return;
718
- }
719
- lb_calld->ScheduleNextClientLoadReportLocked();
720
620
  }
721
621
 
722
622
  void XdsLb::BalancerCallState::OnInitialRequestSentLocked(void* arg,
@@ -820,8 +720,7 @@ void XdsLb::BalancerCallState::OnBalancerMessageReceivedLocked(
820
720
  xds_grpclb_destroy_serverlist(xdslb_policy->serverlist_);
821
721
  } else {
822
722
  /* or dispose of the fallback */
823
- grpc_lb_addresses_destroy(xdslb_policy->fallback_backend_addresses_);
824
- xdslb_policy->fallback_backend_addresses_ = nullptr;
723
+ xdslb_policy->fallback_backend_addresses_.reset();
825
724
  if (xdslb_policy->fallback_timer_callback_pending_) {
826
725
  grpc_timer_cancel(&xdslb_policy->lb_fallback_timer_);
827
726
  }
@@ -907,31 +806,15 @@ void XdsLb::BalancerCallState::OnBalancerStatusReceivedLocked(
907
806
  // helper code for creating balancer channel
908
807
  //
909
808
 
910
- grpc_lb_addresses* ExtractBalancerAddresses(
911
- const grpc_lb_addresses* addresses) {
912
- size_t num_grpclb_addrs = 0;
913
- for (size_t i = 0; i < addresses->num_addresses; ++i) {
914
- if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs;
915
- }
916
- // There must be at least one balancer address, or else the
917
- // client_channel would not have chosen this LB policy.
918
- GPR_ASSERT(num_grpclb_addrs > 0);
919
- grpc_lb_addresses* lb_addresses =
920
- grpc_lb_addresses_create(num_grpclb_addrs, nullptr);
921
- size_t lb_addresses_idx = 0;
922
- for (size_t i = 0; i < addresses->num_addresses; ++i) {
923
- if (!addresses->addresses[i].is_balancer) continue;
924
- if (GPR_UNLIKELY(addresses->addresses[i].user_data != nullptr)) {
925
- gpr_log(GPR_ERROR,
926
- "This LB policy doesn't support user data. It will be ignored");
809
+ UniquePtr<ServerAddressList> ExtractBalancerAddresses(
810
+ const ServerAddressList& addresses) {
811
+ auto balancer_addresses = MakeUnique<ServerAddressList>();
812
+ for (size_t i = 0; i < addresses.size(); ++i) {
813
+ if (addresses[i].IsBalancer()) {
814
+ balancer_addresses->emplace_back(addresses[i]);
927
815
  }
928
- grpc_lb_addresses_set_address(
929
- lb_addresses, lb_addresses_idx++, addresses->addresses[i].address.addr,
930
- addresses->addresses[i].address.len, false /* is balancer */,
931
- addresses->addresses[i].balancer_name, nullptr /* user data */);
932
816
  }
933
- GPR_ASSERT(num_grpclb_addrs == lb_addresses_idx);
934
- return lb_addresses;
817
+ return balancer_addresses;
935
818
  }
936
819
 
937
820
  /* Returns the channel args for the LB channel, used to create a bidirectional
@@ -943,10 +826,11 @@ grpc_lb_addresses* ExtractBalancerAddresses(
943
826
  * above the grpclb policy.
944
827
  * - \a args: other args inherited from the xds policy. */
945
828
  grpc_channel_args* BuildBalancerChannelArgs(
946
- const grpc_lb_addresses* addresses,
829
+ const ServerAddressList& addresses,
947
830
  FakeResolverResponseGenerator* response_generator,
948
831
  const grpc_channel_args* args) {
949
- grpc_lb_addresses* lb_addresses = ExtractBalancerAddresses(addresses);
832
+ UniquePtr<ServerAddressList> balancer_addresses =
833
+ ExtractBalancerAddresses(addresses);
950
834
  // Channel args to remove.
951
835
  static const char* args_to_remove[] = {
952
836
  // LB policy name, since we want to use the default (pick_first) in
@@ -964,7 +848,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
964
848
  // is_balancer=true. We need the LB channel to return addresses with
965
849
  // is_balancer=false so that it does not wind up recursively using the
966
850
  // xds LB policy, as per the special case logic in client_channel.c.
967
- GRPC_ARG_LB_ADDRESSES,
851
+ GRPC_ARG_SERVER_ADDRESS_LIST,
968
852
  // The fake resolver response generator, because we are replacing it
969
853
  // with the one from the xds policy, used to propagate updates to
970
854
  // the LB channel.
@@ -980,10 +864,10 @@ grpc_channel_args* BuildBalancerChannelArgs(
980
864
  };
981
865
  // Channel args to add.
982
866
  const grpc_arg args_to_add[] = {
983
- // New LB addresses.
867
+ // New server address list.
984
868
  // Note that we pass these in both when creating the LB channel
985
869
  // and via the fake resolver. The latter is what actually gets used.
986
- grpc_lb_addresses_create_channel_arg(lb_addresses),
870
+ CreateServerAddressListChannelArg(balancer_addresses.get()),
987
871
  // The fake resolver response generator, which we use to inject
988
872
  // address updates into the LB channel.
989
873
  grpc_core::FakeResolverResponseGenerator::MakeChannelArg(
@@ -1001,10 +885,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
1001
885
  args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add,
1002
886
  GPR_ARRAY_SIZE(args_to_add));
1003
887
  // Make any necessary modifications for security.
1004
- new_args = grpc_lb_policy_xds_modify_lb_channel_args(new_args);
1005
- // Clean up.
1006
- grpc_lb_addresses_destroy(lb_addresses);
1007
- return new_args;
888
+ return grpc_lb_policy_xds_modify_lb_channel_args(new_args);
1008
889
  }
1009
890
 
1010
891
  //
@@ -1012,8 +893,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
1012
893
  //
1013
894
 
1014
895
  // TODO(vishalpowar): Use lb_config in args to configure LB policy.
1015
- XdsLb::XdsLb(const grpc_lb_addresses* addresses,
1016
- const LoadBalancingPolicy::Args& args)
896
+ XdsLb::XdsLb(const LoadBalancingPolicy::Args& args)
1017
897
  : LoadBalancingPolicy(args),
1018
898
  response_generator_(MakeRefCounted<FakeResolverResponseGenerator>()),
1019
899
  lb_call_backoff_(
@@ -1069,9 +949,6 @@ XdsLb::~XdsLb() {
1069
949
  if (serverlist_ != nullptr) {
1070
950
  xds_grpclb_destroy_serverlist(serverlist_);
1071
951
  }
1072
- if (fallback_backend_addresses_ != nullptr) {
1073
- grpc_lb_addresses_destroy(fallback_backend_addresses_);
1074
- }
1075
952
  grpc_subchannel_index_unref();
1076
953
  }
1077
954
 
@@ -1119,7 +996,6 @@ void XdsLb::HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) {
1119
996
  while ((pp = pending_picks_) != nullptr) {
1120
997
  pending_picks_ = pp->next;
1121
998
  pp->pick->on_complete = pp->original_on_complete;
1122
- pp->pick->user_data = nullptr;
1123
999
  grpc_error* error = GRPC_ERROR_NONE;
1124
1000
  if (new_policy->PickLocked(pp->pick, &error)) {
1125
1001
  // Synchronous return; schedule closure.
@@ -1181,7 +1057,7 @@ void XdsLb::CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
1181
1057
  pending_picks_ = nullptr;
1182
1058
  while (pp != nullptr) {
1183
1059
  PendingPick* next = pp->next;
1184
- if ((pp->pick->initial_metadata_flags & initial_metadata_flags_mask) ==
1060
+ if ((*pp->pick->initial_metadata_flags & initial_metadata_flags_mask) ==
1185
1061
  initial_metadata_flags_eq) {
1186
1062
  // Note: pp is deleted in this callback.
1187
1063
  GRPC_CLOSURE_SCHED(&pp->on_complete,
@@ -1272,21 +1148,16 @@ void XdsLb::NotifyOnStateChangeLocked(grpc_connectivity_state* current,
1272
1148
  }
1273
1149
 
1274
1150
  void XdsLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
1275
- const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
1276
- if (GPR_UNLIKELY(arg == nullptr || arg->type != GRPC_ARG_POINTER)) {
1151
+ const ServerAddressList* addresses = FindServerAddressListChannelArg(&args);
1152
+ if (addresses == nullptr) {
1277
1153
  // Ignore this update.
1278
1154
  gpr_log(GPR_ERROR,
1279
1155
  "[xdslb %p] No valid LB addresses channel arg in update, ignoring.",
1280
1156
  this);
1281
1157
  return;
1282
1158
  }
1283
- const grpc_lb_addresses* addresses =
1284
- static_cast<const grpc_lb_addresses*>(arg->value.pointer.p);
1285
1159
  // Update fallback address list.
1286
- if (fallback_backend_addresses_ != nullptr) {
1287
- grpc_lb_addresses_destroy(fallback_backend_addresses_);
1288
- }
1289
- fallback_backend_addresses_ = ExtractBackendAddresses(addresses);
1160
+ fallback_backend_addresses_ = ExtractBackendAddresses(*addresses);
1290
1161
  // Make sure that GRPC_ARG_LB_POLICY_NAME is set in channel args,
1291
1162
  // since we use this to trigger the client_load_reporting filter.
1292
1163
  static const char* args_to_remove[] = {GRPC_ARG_LB_POLICY_NAME};
@@ -1297,7 +1168,7 @@ void XdsLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
1297
1168
  &args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), &new_arg, 1);
1298
1169
  // Construct args for balancer channel.
1299
1170
  grpc_channel_args* lb_channel_args =
1300
- BuildBalancerChannelArgs(addresses, response_generator_.get(), &args);
1171
+ BuildBalancerChannelArgs(*addresses, response_generator_.get(), &args);
1301
1172
  // Create balancer channel if needed.
1302
1173
  if (lb_channel_ == nullptr) {
1303
1174
  char* uri_str;
@@ -1488,37 +1359,15 @@ void XdsLb::OnBalancerChannelConnectivityChangedLocked(void* arg,
1488
1359
  // PendingPick
1489
1360
  //
1490
1361
 
1491
- // Adds lb_token of selected subchannel (address) to the call's initial
1492
- // metadata.
1493
- grpc_error* AddLbTokenToInitialMetadata(
1494
- grpc_mdelem lb_token, grpc_linked_mdelem* lb_token_mdelem_storage,
1495
- grpc_metadata_batch* initial_metadata) {
1496
- GPR_ASSERT(lb_token_mdelem_storage != nullptr);
1497
- GPR_ASSERT(!GRPC_MDISNULL(lb_token));
1498
- return grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage,
1499
- lb_token);
1500
- }
1501
-
1502
1362
  // Destroy function used when embedding client stats in call context.
1503
1363
  void DestroyClientStats(void* arg) {
1504
1364
  static_cast<XdsLbClientStats*>(arg)->Unref();
1505
1365
  }
1506
1366
 
1507
- void XdsLb::PendingPickSetMetadataAndContext(PendingPick* pp) {
1508
- /* if connected_subchannel is nullptr, no pick has been made by the
1509
- * child policy (e.g., all addresses failed to connect). There won't be any
1510
- * user_data/token available */
1367
+ void XdsLb::PendingPickCleanup(PendingPick* pp) {
1368
+ // If connected_subchannel is nullptr, no pick has been made by the
1369
+ // child policy (e.g., all addresses failed to connect).
1511
1370
  if (pp->pick->connected_subchannel != nullptr) {
1512
- if (GPR_LIKELY(!GRPC_MDISNULL(pp->lb_token))) {
1513
- AddLbTokenToInitialMetadata(GRPC_MDELEM_REF(pp->lb_token),
1514
- &pp->pick->lb_token_mdelem_storage,
1515
- pp->pick->initial_metadata);
1516
- } else {
1517
- gpr_log(GPR_ERROR,
1518
- "[xdslb %p] No LB token for connected subchannel pick %p",
1519
- pp->xdslb_policy, pp->pick);
1520
- abort();
1521
- }
1522
1371
  // Pass on client stats via context. Passes ownership of the reference.
1523
1372
  if (pp->client_stats != nullptr) {
1524
1373
  pp->pick->subchannel_call_context[GRPC_GRPCLB_CLIENT_STATS].value =
@@ -1536,7 +1385,7 @@ void XdsLb::PendingPickSetMetadataAndContext(PendingPick* pp) {
1536
1385
  * order to unref the child policy instance upon its invocation */
1537
1386
  void XdsLb::OnPendingPickComplete(void* arg, grpc_error* error) {
1538
1387
  PendingPick* pp = static_cast<PendingPick*>(arg);
1539
- PendingPickSetMetadataAndContext(pp);
1388
+ PendingPickCleanup(pp);
1540
1389
  GRPC_CLOSURE_SCHED(pp->original_on_complete, GRPC_ERROR_REF(error));
1541
1390
  Delete(pp);
1542
1391
  }
@@ -1568,16 +1417,14 @@ void XdsLb::AddPendingPick(PendingPick* pp) {
1568
1417
  // completion callback even if the pick is available immediately.
1569
1418
  bool XdsLb::PickFromChildPolicyLocked(bool force_async, PendingPick* pp,
1570
1419
  grpc_error** error) {
1571
- // Set client_stats and user_data.
1420
+ // Set client_stats.
1572
1421
  if (lb_calld_ != nullptr && lb_calld_->client_stats() != nullptr) {
1573
1422
  pp->client_stats = lb_calld_->client_stats()->Ref();
1574
1423
  }
1575
- GPR_ASSERT(pp->pick->user_data == nullptr);
1576
- pp->pick->user_data = (void**)&pp->lb_token;
1577
1424
  // Pick via the child policy.
1578
1425
  bool pick_done = child_policy_->PickLocked(pp->pick, error);
1579
1426
  if (pick_done) {
1580
- PendingPickSetMetadataAndContext(pp);
1427
+ PendingPickCleanup(pp);
1581
1428
  if (force_async) {
1582
1429
  GRPC_CLOSURE_SCHED(pp->original_on_complete, *error);
1583
1430
  *error = GRPC_ERROR_NONE;
@@ -1639,20 +1486,19 @@ void XdsLb::CreateChildPolicyLocked(const Args& args) {
1639
1486
  }
1640
1487
 
1641
1488
  grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
1642
- grpc_lb_addresses* addresses;
1643
1489
  bool is_backend_from_grpclb_load_balancer = false;
1644
1490
  // This should never be invoked if we do not have serverlist_, as fallback
1645
1491
  // mode is disabled for xDS plugin.
1646
1492
  GPR_ASSERT(serverlist_ != nullptr);
1647
1493
  GPR_ASSERT(serverlist_->num_servers > 0);
1648
- addresses = ProcessServerlist(serverlist_);
1649
- is_backend_from_grpclb_load_balancer = true;
1494
+ UniquePtr<ServerAddressList> addresses = ProcessServerlist(serverlist_);
1650
1495
  GPR_ASSERT(addresses != nullptr);
1651
- // Replace the LB addresses in the channel args that we pass down to
1496
+ is_backend_from_grpclb_load_balancer = true;
1497
+ // Replace the server address list in the channel args that we pass down to
1652
1498
  // the subchannel.
1653
- static const char* keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES};
1499
+ static const char* keys_to_remove[] = {GRPC_ARG_SERVER_ADDRESS_LIST};
1654
1500
  const grpc_arg args_to_add[] = {
1655
- grpc_lb_addresses_create_channel_arg(addresses),
1501
+ CreateServerAddressListChannelArg(addresses.get()),
1656
1502
  // A channel arg indicating if the target is a backend inferred from a
1657
1503
  // grpclb load balancer.
1658
1504
  grpc_channel_arg_integer_create(
@@ -1662,7 +1508,6 @@ grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
1662
1508
  grpc_channel_args* args = grpc_channel_args_copy_and_add_and_remove(
1663
1509
  args_, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add,
1664
1510
  GPR_ARRAY_SIZE(args_to_add));
1665
- grpc_lb_addresses_destroy(addresses);
1666
1511
  return args;
1667
1512
  }
1668
1513
 
@@ -1796,22 +1641,21 @@ class XdsFactory : public LoadBalancingPolicyFactory {
1796
1641
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
1797
1642
  const LoadBalancingPolicy::Args& args) const override {
1798
1643
  /* Count the number of gRPC-LB addresses. There must be at least one. */
1799
- const grpc_arg* arg =
1800
- grpc_channel_args_find(args.args, GRPC_ARG_LB_ADDRESSES);
1801
- if (arg == nullptr || arg->type != GRPC_ARG_POINTER) {
1802
- return nullptr;
1803
- }
1804
- grpc_lb_addresses* addresses =
1805
- static_cast<grpc_lb_addresses*>(arg->value.pointer.p);
1806
- size_t num_grpclb_addrs = 0;
1807
- for (size_t i = 0; i < addresses->num_addresses; ++i) {
1808
- if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs;
1644
+ const ServerAddressList* addresses =
1645
+ FindServerAddressListChannelArg(args.args);
1646
+ if (addresses == nullptr) return nullptr;
1647
+ bool found_balancer_address = false;
1648
+ for (size_t i = 0; i < addresses->size(); ++i) {
1649
+ if ((*addresses)[i].IsBalancer()) {
1650
+ found_balancer_address = true;
1651
+ break;
1652
+ }
1809
1653
  }
1810
- if (num_grpclb_addrs == 0) return nullptr;
1811
- return OrphanablePtr<LoadBalancingPolicy>(New<XdsLb>(addresses, args));
1654
+ if (!found_balancer_address) return nullptr;
1655
+ return OrphanablePtr<LoadBalancingPolicy>(New<XdsLb>(args));
1812
1656
  }
1813
1657
 
1814
- const char* name() const override { return "xds_experimental"; }
1658
+ const char* name() const override { return kXds; }
1815
1659
  };
1816
1660
 
1817
1661
  } // namespace