grpc 1.39.0.pre1 → 1.40.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 (168) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +34 -18
  3. data/include/grpc/event_engine/event_engine.h +10 -14
  4. data/include/grpc/event_engine/slice_allocator.h +8 -33
  5. data/include/grpc/impl/codegen/grpc_types.h +18 -8
  6. data/include/grpc/impl/codegen/port_platform.h +24 -0
  7. data/src/core/ext/filters/client_channel/client_channel.cc +413 -247
  8. data/src/core/ext/filters/client_channel/client_channel.h +42 -18
  9. data/src/core/ext/filters/client_channel/config_selector.h +19 -6
  10. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +7 -8
  11. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -21
  12. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +3 -5
  13. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +17 -38
  14. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -15
  15. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -6
  16. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -12
  17. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -22
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +2 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +5 -8
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -15
  21. data/src/core/ext/filters/client_channel/lb_policy.h +70 -46
  22. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +101 -73
  23. data/src/core/ext/filters/client_channel/retry_filter.cc +392 -243
  24. data/src/core/ext/filters/client_channel/retry_service_config.cc +36 -26
  25. data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
  26. data/src/core/ext/filters/client_channel/service_config_call_data.h +45 -5
  27. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +0 -6
  28. data/src/core/ext/filters/http/client/http_client_filter.cc +5 -2
  29. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +5 -1
  30. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +1 -1
  31. data/src/core/{lib/event_engine/slice_allocator.cc → ext/transport/chttp2/transport/chttp2_slice_allocator.cc} +15 -38
  32. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +74 -0
  33. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -6
  34. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  35. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  36. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +8 -8
  37. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +5 -5
  38. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +639 -752
  39. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +190 -69
  40. data/src/core/ext/transport/chttp2/transport/internal.h +1 -1
  41. data/src/core/ext/transport/chttp2/transport/parsing.cc +70 -54
  42. data/src/core/ext/transport/chttp2/transport/varint.cc +6 -4
  43. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +56 -35
  44. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +180 -76
  45. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +35 -27
  46. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +97 -48
  47. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +45 -9
  48. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +67 -7
  49. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +66 -9
  50. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +227 -0
  51. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +46 -0
  52. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +121 -0
  53. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -0
  54. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +35 -0
  55. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +90 -0
  56. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +32 -24
  57. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +120 -73
  58. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +4 -2
  59. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +15 -0
  60. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +48 -0
  61. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +171 -0
  62. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +8 -6
  63. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +27 -19
  64. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +1 -0
  65. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +24 -7
  66. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +57 -0
  67. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +29 -17
  68. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +72 -0
  69. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +3 -2
  70. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +4 -0
  71. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +6 -5
  72. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +15 -11
  73. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +85 -43
  74. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +274 -91
  75. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +11 -8
  76. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +30 -13
  77. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +33 -5
  78. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +115 -0
  79. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +60 -0
  80. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +181 -0
  81. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +1 -0
  82. data/src/core/ext/upb-generated/validate/validate.upb.c +82 -66
  83. data/src/core/ext/upb-generated/validate/validate.upb.h +220 -124
  84. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +15 -7
  85. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +53 -52
  86. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +318 -277
  87. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +5 -0
  88. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +437 -410
  89. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +198 -170
  90. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +10 -0
  91. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +9 -8
  92. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +219 -163
  93. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +15 -0
  94. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.c +59 -0
  95. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.h +40 -0
  96. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +29 -25
  97. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.c +52 -0
  98. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.h +35 -0
  99. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +135 -125
  100. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +5 -0
  101. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +131 -123
  102. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.c +90 -0
  103. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.h +35 -0
  104. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +32 -24
  105. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +69 -55
  106. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +5 -0
  107. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +684 -664
  108. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  109. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +13 -10
  110. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +13 -10
  111. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +441 -375
  112. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +10 -0
  113. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +122 -114
  114. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +1 -1
  115. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c +112 -79
  116. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.h +5 -0
  117. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.c +64 -0
  118. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.h +50 -0
  119. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +35 -32
  120. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +4 -4
  121. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +182 -160
  122. data/src/core/ext/xds/certificate_provider_store.h +1 -1
  123. data/src/core/ext/xds/xds_api.cc +320 -121
  124. data/src/core/ext/xds/xds_api.h +31 -2
  125. data/src/core/ext/xds/xds_bootstrap.cc +4 -1
  126. data/src/core/ext/xds/xds_client.cc +66 -43
  127. data/src/core/ext/xds/xds_client.h +0 -4
  128. data/src/core/ext/xds/xds_http_filters.cc +3 -2
  129. data/src/core/ext/xds/xds_http_filters.h +3 -0
  130. data/src/core/lib/channel/call_tracer.h +85 -0
  131. data/src/core/lib/channel/channel_stack.h +1 -1
  132. data/src/core/lib/channel/context.h +3 -0
  133. data/src/core/lib/channel/status_util.h +4 -0
  134. data/src/core/lib/compression/stream_compression.h +1 -1
  135. data/src/core/lib/compression/stream_compression_gzip.h +1 -1
  136. data/src/core/lib/compression/stream_compression_identity.h +1 -1
  137. data/src/core/lib/debug/stats.h +1 -1
  138. data/src/core/lib/gpr/murmur_hash.cc +4 -2
  139. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  140. data/src/core/lib/gprpp/orphanable.h +3 -3
  141. data/src/core/lib/gprpp/sync.h +2 -30
  142. data/src/core/lib/iomgr/buffer_list.cc +1 -1
  143. data/src/core/lib/iomgr/ev_apple.h +1 -1
  144. data/src/core/lib/iomgr/event_engine/endpoint.cc +6 -8
  145. data/src/core/lib/iomgr/event_engine/tcp.cc +30 -10
  146. data/src/core/lib/iomgr/python_util.h +1 -1
  147. data/src/core/lib/iomgr/resource_quota.cc +2 -0
  148. data/src/core/lib/iomgr/tcp_client_windows.cc +2 -0
  149. data/src/core/lib/iomgr/tcp_server_posix.cc +1 -0
  150. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  151. data/src/core/lib/json/json_reader.cc +1 -2
  152. data/src/core/lib/matchers/matchers.cc +8 -20
  153. data/src/core/lib/matchers/matchers.h +2 -1
  154. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +49 -0
  155. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +7 -0
  156. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +6 -18
  157. data/src/core/lib/security/transport/security_handshaker.cc +12 -4
  158. data/src/core/lib/security/transport/server_auth_filter.cc +0 -7
  159. data/src/core/lib/slice/slice_internal.h +1 -0
  160. data/src/core/lib/surface/call.cc +5 -6
  161. data/src/core/lib/surface/server.cc +3 -1
  162. data/src/core/lib/surface/server.h +3 -3
  163. data/src/core/lib/surface/version.cc +2 -4
  164. data/src/ruby/ext/grpc/extconf.rb +1 -1
  165. data/src/ruby/lib/grpc/version.rb +1 -1
  166. data/third_party/xxhash/xxhash.h +77 -195
  167. metadata +57 -40
  168. data/src/core/lib/gpr/arena.h +0 -47
@@ -39,6 +39,7 @@
39
39
  #include "src/core/ext/filters/client_channel/service_config.h"
40
40
  #include "src/core/ext/filters/client_channel/subchannel.h"
41
41
  #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
42
+ #include "src/core/lib/channel/call_tracer.h"
42
43
  #include "src/core/lib/gprpp/sync.h"
43
44
  #include "src/core/lib/iomgr/error.h"
44
45
  #include "src/core/lib/iomgr/polling_entity.h"
@@ -132,9 +133,11 @@ class ClientChannel {
132
133
  void RemoveConnectivityWatcher(
133
134
  AsyncConnectivityStateWatcherInterface* watcher);
134
135
 
135
- RefCountedPtr<LoadBalancedCall> CreateLoadBalancedCall(
136
+ OrphanablePtr<LoadBalancedCall> CreateLoadBalancedCall(
136
137
  const grpc_call_element_args& args, grpc_polling_entity* pollent,
137
- grpc_closure* on_call_destruction_complete);
138
+ grpc_closure* on_call_destruction_complete,
139
+ ConfigSelector::CallDispatchController* call_dispatch_controller,
140
+ bool is_transparent_retry);
138
141
 
139
142
  private:
140
143
  class CallData;
@@ -273,7 +276,6 @@ class ClientChannel {
273
276
  // Fields set at construction and never modified.
274
277
  //
275
278
  const bool deadline_checking_enabled_;
276
- const bool enable_retries_;
277
279
  grpc_channel_stack* owning_stack_;
278
280
  ClientChannelFactory* client_channel_factory_;
279
281
  const grpc_channel_args* channel_args_;
@@ -369,12 +371,10 @@ class ClientChannel {
369
371
  // ClientChannel::LoadBalancedCall
370
372
  //
371
373
 
372
- // This object is ref-counted, but it cannot inherit from RefCounted<>,
373
- // because it is allocated on the arena and can't free its memory when
374
- // its refcount goes to zero. So instead, it manually implements the
375
- // same API as RefCounted<>, so that it can be used with RefCountedPtr<>.
374
+ // TODO(roth): As part of simplifying cancellation in the filter stack,
375
+ // this should no longer need to be ref-counted.
376
376
  class ClientChannel::LoadBalancedCall
377
- : public RefCounted<LoadBalancedCall, PolymorphicRefCount, kUnrefCallDtor> {
377
+ : public InternallyRefCounted<LoadBalancedCall, kUnrefCallDtor> {
378
378
  public:
379
379
  // If on_call_destruction_complete is non-null, then it will be
380
380
  // invoked once the LoadBalancedCall is completely destroyed.
@@ -382,11 +382,15 @@ class ClientChannel::LoadBalancedCall
382
382
  // the LB call has a subchannel call and ensuring that the
383
383
  // on_call_destruction_complete closure passed down from the surface
384
384
  // is not invoked until after the subchannel call stack is destroyed.
385
- LoadBalancedCall(ClientChannel* chand, const grpc_call_element_args& args,
386
- grpc_polling_entity* pollent,
387
- grpc_closure* on_call_destruction_complete);
385
+ LoadBalancedCall(
386
+ ClientChannel* chand, const grpc_call_element_args& args,
387
+ grpc_polling_entity* pollent, grpc_closure* on_call_destruction_complete,
388
+ ConfigSelector::CallDispatchController* call_dispatch_controller,
389
+ bool is_transparent_retry);
388
390
  ~LoadBalancedCall() override;
389
391
 
392
+ void Orphan() override;
393
+
390
394
  void StartTransportStreamOpBatch(grpc_transport_stream_op_batch* batch);
391
395
 
392
396
  // Invoked by channel for queued LB picks when the picker is updated.
@@ -438,10 +442,10 @@ class ClientChannel::LoadBalancedCall
438
442
  // Resumes all pending batches on subchannel_call_.
439
443
  void PendingBatchesResume();
440
444
 
441
- static void RecvTrailingMetadataReadyForLoadBalancingPolicy(
442
- void* arg, grpc_error_handle error);
443
- void InjectRecvTrailingMetadataReadyForLoadBalancingPolicy(
444
- grpc_transport_stream_op_batch* batch);
445
+ static void SendInitialMetadataOnComplete(void* arg, grpc_error_handle error);
446
+ static void RecvInitialMetadataReady(void* arg, grpc_error_handle error);
447
+ static void RecvMessageReady(void* arg, grpc_error_handle error);
448
+ static void RecvTrailingMetadataReady(void* arg, grpc_error_handle error);
445
449
 
446
450
  void CreateSubchannelCall();
447
451
  // Invoked when a pick is completed, on both success or failure.
@@ -459,7 +463,6 @@ class ClientChannel::LoadBalancedCall
459
463
  // that uses any one of them, we should store them in the call
460
464
  // context. This will save per-call memory overhead.
461
465
  grpc_slice path_; // Request path.
462
- gpr_cycle_counter call_start_time_;
463
466
  grpc_millis deadline_;
464
467
  Arena* arena_;
465
468
  grpc_call_stack* owning_call_;
@@ -467,6 +470,11 @@ class ClientChannel::LoadBalancedCall
467
470
  grpc_call_context_element* call_context_;
468
471
  grpc_polling_entity* pollent_;
469
472
  grpc_closure* on_call_destruction_complete_;
473
+ ConfigSelector::CallDispatchController* call_dispatch_controller_;
474
+
475
+ CallTracer::CallAttemptTracer* call_attempt_tracer_;
476
+
477
+ gpr_cycle_counter lb_call_start_time_ = gpr_get_cycle_counter();
470
478
 
471
479
  // Set when we get a cancel_stream op.
472
480
  grpc_error_handle cancel_error_ = GRPC_ERROR_NONE;
@@ -486,14 +494,30 @@ class ClientChannel::LoadBalancedCall
486
494
 
487
495
  RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
488
496
  const LoadBalancingPolicy::BackendMetricData* backend_metric_data_ = nullptr;
489
- std::function<void(grpc_error_handle, LoadBalancingPolicy::MetadataInterface*,
497
+ std::function<void(absl::Status, LoadBalancingPolicy::MetadataInterface*,
490
498
  LoadBalancingPolicy::CallState*)>
491
499
  lb_recv_trailing_metadata_ready_;
492
500
 
493
501
  RefCountedPtr<SubchannelCall> subchannel_call_;
494
502
 
495
- // For intercepting recv_trailing_metadata_ready for the LB policy.
503
+ // For intercepting send_initial_metadata on_complete.
504
+ gpr_atm* peer_string_ = nullptr;
505
+ grpc_closure send_initial_metadata_on_complete_;
506
+ grpc_closure* original_send_initial_metadata_on_complete_ = nullptr;
507
+
508
+ // For intercepting recv_initial_metadata_ready.
509
+ grpc_metadata_batch* recv_initial_metadata_ = nullptr;
510
+ grpc_closure recv_initial_metadata_ready_;
511
+ grpc_closure* original_recv_initial_metadata_ready_ = nullptr;
512
+
513
+ // For intercepting recv_message_ready.
514
+ OrphanablePtr<ByteStream>* recv_message_ = nullptr;
515
+ grpc_closure recv_message_ready_;
516
+ grpc_closure* original_recv_message_ready_ = nullptr;
517
+
518
+ // For intercepting recv_trailing_metadata_ready.
496
519
  grpc_metadata_batch* recv_trailing_metadata_ = nullptr;
520
+ grpc_transport_stream_stats* transport_stream_stats_ = nullptr;
497
521
  grpc_closure recv_trailing_metadata_ready_;
498
522
  grpc_closure* original_recv_trailing_metadata_ready_ = nullptr;
499
523
 
@@ -44,6 +44,22 @@ namespace grpc_core {
44
44
  // MethodConfig and provide input to LB policies on a per-call basis.
45
45
  class ConfigSelector : public RefCounted<ConfigSelector> {
46
46
  public:
47
+ using CallAttributes = std::map<const char*, absl::string_view>;
48
+
49
+ // An interface to be used by the channel when dispatching calls.
50
+ class CallDispatchController {
51
+ public:
52
+ virtual ~CallDispatchController() = default;
53
+
54
+ // Called by the channel to decide if it should retry the call upon a
55
+ // failure.
56
+ virtual bool ShouldRetry() = 0;
57
+
58
+ // Called by the channel when no more LB picks will be performed for
59
+ // the call.
60
+ virtual void Commit() = 0;
61
+ };
62
+
47
63
  struct GetCallConfigArgs {
48
64
  grpc_slice* path;
49
65
  grpc_metadata_batch* initial_metadata;
@@ -60,11 +76,9 @@ class ConfigSelector : public RefCounted<ConfigSelector> {
60
76
  // the call to ensure that method_configs lives long enough.
61
77
  RefCountedPtr<ServiceConfig> service_config;
62
78
  // Call attributes that will be accessible to LB policy implementations.
63
- std::map<const char*, absl::string_view> call_attributes;
64
- // A callback that, if set, will be invoked when the call is
65
- // committed (i.e., when we know that we will never again need to
66
- // ask the picker for a subchannel for this call).
67
- std::function<void()> on_call_committed;
79
+ CallAttributes call_attributes;
80
+ // Call dispatch controller.
81
+ CallDispatchController* call_dispatch_controller = nullptr;
68
82
  };
69
83
 
70
84
  ~ConfigSelector() override = default;
@@ -85,7 +99,6 @@ class ConfigSelector : public RefCounted<ConfigSelector> {
85
99
  // The channel will call this when the resolver returns a new ConfigSelector
86
100
  // to determine what set of dynamic filters will be configured.
87
101
  virtual std::vector<const grpc_channel_filter*> GetFilters() { return {}; }
88
-
89
102
  // Modifies channel args to be passed to the dynamic filter stack.
90
103
  // Takes ownership of argument. Caller takes ownership of result.
91
104
  virtual grpc_channel_args* ModifyChannelArgs(grpc_channel_args* args) {
@@ -606,7 +606,6 @@ const char* GrpcLb::Serverlist::ShouldDrop() {
606
606
  //
607
607
 
608
608
  GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs args) {
609
- PickResult result;
610
609
  // Check if we should drop the call.
611
610
  const char* drop_token =
612
611
  serverlist_ == nullptr ? nullptr : serverlist_->ShouldDrop();
@@ -619,16 +618,16 @@ GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs args) {
619
618
  if (client_stats_ != nullptr) {
620
619
  client_stats_->AddCallDropped(drop_token);
621
620
  }
622
- result.type = PickResult::PICK_COMPLETE;
623
- return result;
621
+ return PickResult::Drop(
622
+ absl::UnavailableError("drop directed by grpclb balancer"));
624
623
  }
625
624
  // Forward pick to child policy.
626
- result = child_picker_->Pick(args);
625
+ PickResult result = child_picker_->Pick(args);
627
626
  // If pick succeeded, add LB token to initial metadata.
628
- if (result.type == PickResult::PICK_COMPLETE &&
629
- result.subchannel != nullptr) {
627
+ auto* complete_pick = absl::get_if<PickResult::Complete>(&result.result);
628
+ if (complete_pick != nullptr) {
630
629
  const SubchannelWrapper* subchannel_wrapper =
631
- static_cast<SubchannelWrapper*>(result.subchannel.get());
630
+ static_cast<SubchannelWrapper*>(complete_pick->subchannel.get());
632
631
  // Encode client stats object into metadata for use by
633
632
  // client_load_reporting filter.
634
633
  GrpcLbClientStats* client_stats = subchannel_wrapper->client_stats();
@@ -654,7 +653,7 @@ GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs args) {
654
653
  args.initial_metadata->Add(kGrpcLbLbTokenMetadataKey, lb_token);
655
654
  }
656
655
  // Unwrap subchannel to pass up to the channel.
657
- result.subchannel = subchannel_wrapper->wrapped_subchannel();
656
+ complete_pick->subchannel = subchannel_wrapper->wrapped_subchannel();
658
657
  }
659
658
  return result;
660
659
  }
@@ -114,10 +114,7 @@ class PickFirst : public LoadBalancingPolicy {
114
114
  : subchannel_(std::move(subchannel)) {}
115
115
 
116
116
  PickResult Pick(PickArgs /*args*/) override {
117
- PickResult result;
118
- result.type = PickResult::PICK_COMPLETE;
119
- result.subchannel = subchannel_;
120
- return result;
117
+ return PickResult::Complete(subchannel_);
121
118
  }
122
119
 
123
120
  private:
@@ -197,12 +194,10 @@ void PickFirst::AttemptToConnectUsingLatestUpdateArgsLocked() {
197
194
  // (If we are idle, then this will happen in ExitIdleLocked() if we
198
195
  // haven't gotten a non-empty update by the time the application tries
199
196
  // to start a new call.)
200
- grpc_error_handle error =
201
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
202
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
197
+ absl::Status status = absl::UnavailableError("Empty update");
203
198
  channel_control_helper()->UpdateState(
204
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
205
- absl::make_unique<TransientFailurePicker>(error));
199
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
200
+ absl::make_unique<TransientFailurePicker>(status));
206
201
  return;
207
202
  }
208
203
  // If one of the subchannels in the new list is already in state
@@ -314,13 +309,11 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
314
309
  p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
315
310
  // Set our state to that of the pending subchannel list.
316
311
  if (p->subchannel_list_->in_transient_failure()) {
317
- grpc_error_handle error = grpc_error_set_int(
318
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
319
- "selected subchannel failed; switching to pending update"),
320
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
312
+ absl::Status status = absl::UnavailableError(
313
+ "selected subchannel failed; switching to pending update");
321
314
  p->channel_control_helper()->UpdateState(
322
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
323
- absl::make_unique<TransientFailurePicker>(error));
315
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
316
+ absl::make_unique<TransientFailurePicker>(status));
324
317
  } else {
325
318
  p->channel_control_helper()->UpdateState(
326
319
  GRPC_CHANNEL_CONNECTING, absl::Status(),
@@ -393,13 +386,11 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
393
386
  subchannel_list()->set_in_transient_failure(true);
394
387
  // Only report new state in case 1.
395
388
  if (subchannel_list() == p->subchannel_list_.get()) {
396
- grpc_error_handle error = grpc_error_set_int(
397
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
398
- "failed to connect to all addresses"),
399
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
389
+ absl::Status status =
390
+ absl::UnavailableError("failed to connect to all addresses");
400
391
  p->channel_control_helper()->UpdateState(
401
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
402
- absl::make_unique<TransientFailurePicker>(error));
392
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
393
+ absl::make_unique<TransientFailurePicker>(status));
403
394
  }
404
395
  }
405
396
  sd->CheckConnectivityStateAndStartWatchingLocked();
@@ -472,12 +472,10 @@ void PriorityLb::TryNextPriorityLocked(bool report_connecting) {
472
472
  this);
473
473
  }
474
474
  current_child_from_before_update_ = nullptr;
475
- grpc_error_handle error = grpc_error_set_int(
476
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("no ready priority"),
477
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
475
+ absl::Status status = absl::UnavailableError("no ready priority");
478
476
  channel_control_helper()->UpdateState(
479
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
480
- absl::make_unique<TransientFailurePicker>(error));
477
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
478
+ absl::make_unique<TransientFailurePicker>(status));
481
479
  }
482
480
 
483
481
  void PriorityLb::SelectPriorityLocked(uint32_t priority) {
@@ -380,18 +380,12 @@ RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
380
380
  }
381
381
 
382
382
  RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
383
- PickResult result;
384
- // Initialize to PICK_FAILED.
385
- result.type = PickResult::PICK_FAILED;
386
383
  auto hash =
387
384
  args.call_state->ExperimentalGetCallAttribute(kRequestRingHashAttribute);
388
385
  uint64_t h;
389
386
  if (!absl::SimpleAtoi(hash, &h)) {
390
- result.error = grpc_error_set_int(
391
- GRPC_ERROR_CREATE_FROM_COPIED_STRING(
392
- absl::StrCat("xds ring hash value is not a number").c_str()),
393
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL);
394
- return result;
387
+ return PickResult::Fail(
388
+ absl::InternalError("xds ring hash value is not a number"));
395
389
  }
396
390
  // Ported from https://github.com/RJ/ketama/blob/master/libketama/ketama.c
397
391
  // (ketama_get_server) NOTE: The algorithm depends on using signed integers
@@ -431,15 +425,12 @@ RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
431
425
  };
432
426
  switch (ring_[first_index].connectivity_state) {
433
427
  case GRPC_CHANNEL_READY:
434
- result.type = PickResult::PICK_COMPLETE;
435
- result.subchannel = ring_[first_index].subchannel;
436
- return result;
428
+ return PickResult::Complete(ring_[first_index].subchannel);
437
429
  case GRPC_CHANNEL_IDLE:
438
430
  ScheduleSubchannelConnectionAttempt(ring_[first_index].subchannel);
439
- // fallthrough
431
+ ABSL_FALLTHROUGH_INTENDED;
440
432
  case GRPC_CHANNEL_CONNECTING:
441
- result.type = PickResult::PICK_QUEUE;
442
- return result;
433
+ return PickResult::Queue();
443
434
  default: // GRPC_CHANNEL_TRANSIENT_FAILURE
444
435
  break;
445
436
  }
@@ -455,18 +446,15 @@ RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
455
446
  continue;
456
447
  }
457
448
  if (entry.connectivity_state == GRPC_CHANNEL_READY) {
458
- result.type = PickResult::PICK_COMPLETE;
459
- result.subchannel = entry.subchannel;
460
- return result;
449
+ return PickResult::Complete(entry.subchannel);
461
450
  }
462
451
  if (!found_second_subchannel) {
463
452
  switch (entry.connectivity_state) {
464
453
  case GRPC_CHANNEL_IDLE:
465
454
  ScheduleSubchannelConnectionAttempt(entry.subchannel);
466
- // fallthrough
455
+ ABSL_FALLTHROUGH_INTENDED;
467
456
  case GRPC_CHANNEL_CONNECTING:
468
- result.type = PickResult::PICK_QUEUE;
469
- return result;
457
+ return PickResult::Queue();
470
458
  default:
471
459
  break;
472
460
  }
@@ -483,13 +471,8 @@ RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
483
471
  }
484
472
  }
485
473
  }
486
- result.error =
487
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
488
- absl::StrCat("xds ring hash found a subchannel "
489
- "that is in TRANSIENT_FAILURE state")
490
- .c_str()),
491
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL);
492
- return result;
474
+ return PickResult::Fail(absl::UnavailableError(
475
+ "xds ring hash found a subchannel that is in TRANSIENT_FAILURE state"));
493
476
  }
494
477
 
495
478
  //
@@ -580,13 +563,11 @@ bool RingHash::RingHashSubchannelList::UpdateRingHashConnectivityStateLocked() {
580
563
  this));
581
564
  return false;
582
565
  }
583
- grpc_error* error =
584
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
585
- "connections to backend failing or idle"),
586
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
566
+ absl::Status status =
567
+ absl::UnavailableError("connections to backend failing or idle");
587
568
  p->channel_control_helper()->UpdateState(
588
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
589
- absl::make_unique<TransientFailurePicker>(error));
569
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
570
+ absl::make_unique<TransientFailurePicker>(status));
590
571
  return true;
591
572
  }
592
573
 
@@ -724,12 +705,10 @@ void RingHash::UpdateLocked(UpdateArgs args) {
724
705
  this, &grpc_lb_ring_hash_trace, std::move(addresses), *args.args);
725
706
  if (subchannel_list_->num_subchannels() == 0) {
726
707
  // If the new list is empty, immediately transition to TRANSIENT_FAILURE.
727
- grpc_error* error =
728
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
729
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
708
+ absl::Status status = absl::UnavailableError("Empty update");
730
709
  channel_control_helper()->UpdateState(
731
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
732
- absl::make_unique<TransientFailurePicker>(error));
710
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
711
+ absl::make_unique<TransientFailurePicker>(status));
733
712
  } else {
734
713
  // Start watching the new list.
735
714
  subchannel_list_->StartWatchingLocked();
@@ -213,10 +213,7 @@ RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs /*args*/) {
213
213
  parent_, this, last_picked_index_,
214
214
  subchannels_[last_picked_index_].get());
215
215
  }
216
- PickResult result;
217
- result.type = PickResult::PICK_COMPLETE;
218
- result.subchannel = subchannels_[last_picked_index_];
219
- return result;
216
+ return PickResult::Complete(subchannels_[last_picked_index_]);
220
217
  }
221
218
 
222
219
  //
@@ -331,13 +328,11 @@ void RoundRobin::RoundRobinSubchannelList::
331
328
  absl::make_unique<QueuePicker>(p->Ref(DEBUG_LOCATION, "QueuePicker")));
332
329
  } else if (num_transient_failure_ == num_subchannels()) {
333
330
  /* 3) TRANSIENT_FAILURE */
334
- grpc_error_handle error =
335
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
336
- "connections to all backends failing"),
337
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
331
+ absl::Status status =
332
+ absl::UnavailableError("connections to all backends failing");
338
333
  p->channel_control_helper()->UpdateState(
339
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
340
- absl::make_unique<TransientFailurePicker>(error));
334
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
335
+ absl::make_unique<TransientFailurePicker>(status));
341
336
  }
342
337
  }
343
338
 
@@ -449,12 +444,10 @@ void RoundRobin::UpdateLocked(UpdateArgs args) {
449
444
  if (latest_pending_subchannel_list_->num_subchannels() == 0) {
450
445
  // If the new list is empty, immediately promote the new list to the
451
446
  // current list and transition to TRANSIENT_FAILURE.
452
- grpc_error_handle error =
453
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
454
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
447
+ absl::Status status = absl::UnavailableError("Empty update");
455
448
  channel_control_helper()->UpdateState(
456
- GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_to_absl_status(error),
457
- absl::make_unique<TransientFailurePicker>(error));
449
+ GRPC_CHANNEL_TRANSIENT_FAILURE, status,
450
+ absl::make_unique<TransientFailurePicker>(status));
458
451
  subchannel_list_ = std::move(latest_pending_subchannel_list_);
459
452
  } else if (subchannel_list_ == nullptr) {
460
453
  // If there is no current list, immediately promote the new list to