grpc 1.21.0 → 1.22.0

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

Potentially problematic release.


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

Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +422 -62
  3. data/include/grpc/grpc_security.h +61 -5
  4. data/include/grpc/grpc_security_constants.h +1 -1
  5. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  6. data/include/grpc/slice.h +2 -2
  7. data/src/core/ext/filters/client_channel/backup_poller.cc +2 -3
  8. data/src/core/ext/filters/client_channel/backup_poller.h +5 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +260 -122
  10. data/src/core/ext/filters/client_channel/client_channel.h +0 -8
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -84
  12. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -28
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -8
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +5 -4
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +16 -2
  16. data/src/core/ext/filters/client_channel/lb_policy.h +92 -98
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +63 -87
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +6 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +35 -87
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +18 -74
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +167 -217
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +216 -190
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +1 -1
  26. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  27. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +6 -3
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -1
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -0
  31. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -8
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +7 -7
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +28 -64
  34. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -12
  35. data/src/core/ext/filters/client_channel/server_address.cc +4 -6
  36. data/src/core/ext/filters/client_channel/server_address.h +1 -3
  37. data/src/core/ext/filters/client_channel/service_config.cc +20 -22
  38. data/src/core/ext/filters/client_channel/service_config.h +26 -28
  39. data/src/core/ext/filters/client_channel/subchannel.cc +261 -160
  40. data/src/core/ext/filters/client_channel/subchannel.h +97 -23
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +12 -12
  43. data/src/core/ext/filters/message_size/message_size_filter.h +2 -2
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -2
  45. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  46. data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -36
  47. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -2
  48. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +71 -52
  49. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +18 -3
  50. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +5 -12
  51. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  52. data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
  53. data/src/core/ext/transport/chttp2/transport/parsing.cc +39 -57
  54. data/src/core/lib/channel/channelz.cc +136 -19
  55. data/src/core/lib/channel/channelz.h +36 -40
  56. data/src/core/lib/channel/channelz_registry.cc +74 -106
  57. data/src/core/lib/channel/channelz_registry.h +10 -28
  58. data/src/core/lib/channel/context.h +1 -1
  59. data/src/core/lib/channel/handshaker.cc +6 -0
  60. data/src/core/lib/compression/compression.cc +13 -8
  61. data/src/core/lib/compression/compression_internal.cc +14 -10
  62. data/src/core/lib/compression/compression_internal.h +1 -1
  63. data/src/core/lib/compression/stream_compression.cc +3 -2
  64. data/src/core/lib/compression/stream_compression.h +2 -2
  65. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  66. data/src/core/lib/gpr/env.h +1 -1
  67. data/src/core/lib/gpr/string.cc +8 -1
  68. data/src/core/lib/gpr/string.h +6 -1
  69. data/src/core/lib/gprpp/fork.cc +1 -1
  70. data/src/core/lib/gprpp/fork.h +5 -1
  71. data/src/core/lib/gprpp/global_config.h +9 -0
  72. data/src/core/lib/gprpp/global_config_custom.h +1 -1
  73. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  74. data/src/core/lib/gprpp/map.h +38 -21
  75. data/src/core/lib/gprpp/memory.h +2 -2
  76. data/src/core/lib/gprpp/orphanable.h +1 -1
  77. data/src/core/lib/gprpp/ref_counted.h +9 -4
  78. data/src/core/lib/http/httpcli.cc +3 -3
  79. data/src/core/lib/iomgr/buffer_list.h +1 -1
  80. data/src/core/lib/iomgr/call_combiner.cc +1 -1
  81. data/src/core/lib/iomgr/call_combiner.h +1 -1
  82. data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
  83. data/src/core/lib/iomgr/cfstream_handle.h +4 -0
  84. data/src/core/lib/iomgr/error.cc +3 -3
  85. data/src/core/lib/iomgr/error.h +9 -3
  86. data/src/core/lib/iomgr/error_internal.h +1 -1
  87. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -1
  88. data/src/core/lib/iomgr/ev_posix.cc +3 -3
  89. data/src/core/lib/iomgr/ev_posix.h +3 -2
  90. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  91. data/src/core/lib/iomgr/iomgr.cc +4 -4
  92. data/src/core/lib/iomgr/lockfree_event.cc +1 -1
  93. data/src/core/lib/iomgr/port.h +5 -1
  94. data/src/core/lib/iomgr/tcp_posix.cc +1 -3
  95. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  96. data/src/core/lib/iomgr/tcp_server.h +24 -0
  97. data/src/core/lib/iomgr/tcp_server_custom.cc +11 -9
  98. data/src/core/lib/iomgr/tcp_server_posix.cc +72 -11
  99. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  100. data/src/core/lib/iomgr/tcp_server_windows.cc +11 -9
  101. data/src/core/lib/iomgr/tcp_uv.cc +5 -6
  102. data/src/core/lib/iomgr/timer.h +2 -1
  103. data/src/core/lib/iomgr/udp_server.cc +2 -2
  104. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  105. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  106. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  107. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  108. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +1 -1
  109. data/src/core/lib/security/transport/auth_filters.h +3 -0
  110. data/src/core/lib/security/transport/client_auth_filter.cc +13 -0
  111. data/src/core/lib/security/transport/security_handshaker.cc +7 -7
  112. data/src/core/lib/slice/b64.h +2 -2
  113. data/src/core/lib/slice/slice.cc +82 -10
  114. data/src/core/lib/slice/slice_buffer.cc +49 -21
  115. data/src/core/lib/slice/slice_hash_table.h +2 -2
  116. data/src/core/lib/slice/slice_intern.cc +15 -16
  117. data/src/core/lib/slice/slice_internal.h +52 -0
  118. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  119. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  120. data/src/core/lib/slice/slice_utils.h +50 -0
  121. data/src/core/lib/slice/slice_weak_hash_table.h +2 -2
  122. data/src/core/lib/surface/call.cc +14 -8
  123. data/src/core/lib/surface/channel.cc +89 -97
  124. data/src/core/lib/surface/channel.h +60 -6
  125. data/src/core/lib/surface/completion_queue.cc +49 -36
  126. data/src/core/lib/surface/completion_queue.h +2 -1
  127. data/src/core/lib/surface/server.cc +8 -8
  128. data/src/core/lib/surface/validate_metadata.cc +14 -8
  129. data/src/core/lib/surface/validate_metadata.h +13 -2
  130. data/src/core/lib/surface/version.cc +1 -1
  131. data/src/core/lib/transport/metadata.cc +56 -26
  132. data/src/core/lib/transport/metadata.h +91 -75
  133. data/src/core/lib/transport/static_metadata.cc +262 -176
  134. data/src/core/lib/transport/static_metadata.h +272 -180
  135. data/src/core/lib/transport/transport.cc +1 -1
  136. data/src/core/lib/transport/transport.h +8 -2
  137. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  138. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +5 -2
  140. data/src/ruby/lib/grpc/version.rb +1 -1
  141. metadata +33 -31
@@ -40,14 +40,6 @@ extern grpc_core::TraceFlag grpc_client_channel_trace;
40
40
 
41
41
  extern const grpc_channel_filter grpc_client_channel_filter;
42
42
 
43
- void grpc_client_channel_set_channelz_node(
44
- grpc_channel_element* elem, grpc_core::channelz::ClientChannelNode* node);
45
-
46
- void grpc_client_channel_populate_child_refs(
47
- grpc_channel_element* elem,
48
- grpc_core::channelz::ChildRefsList* child_subchannels,
49
- grpc_core::channelz::ChildRefsList* child_channels);
50
-
51
43
  grpc_connectivity_state grpc_client_channel_check_connectivity_state(
52
44
  grpc_channel_element* elem, int try_to_connect);
53
45
 
@@ -29,89 +29,6 @@
29
29
 
30
30
  namespace grpc_core {
31
31
  namespace channelz {
32
- namespace {
33
-
34
- void* client_channel_channelz_copy(void* p) { return p; }
35
-
36
- void client_channel_channelz_destroy(void* p) {}
37
-
38
- int client_channel_channelz_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
39
-
40
- } // namespace
41
-
42
- static const grpc_arg_pointer_vtable client_channel_channelz_vtable = {
43
- client_channel_channelz_copy, client_channel_channelz_destroy,
44
- client_channel_channelz_cmp};
45
-
46
- ClientChannelNode::ClientChannelNode(grpc_channel* channel,
47
- size_t channel_tracer_max_nodes,
48
- bool is_top_level_channel)
49
- : ChannelNode(channel, channel_tracer_max_nodes, is_top_level_channel) {
50
- client_channel_ =
51
- grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel));
52
- GPR_ASSERT(client_channel_->filter == &grpc_client_channel_filter);
53
- grpc_client_channel_set_channelz_node(client_channel_, this);
54
- }
55
-
56
- void ClientChannelNode::PopulateConnectivityState(grpc_json* json) {
57
- grpc_connectivity_state state;
58
- if (ChannelIsDestroyed()) {
59
- state = GRPC_CHANNEL_SHUTDOWN;
60
- } else {
61
- state =
62
- grpc_client_channel_check_connectivity_state(client_channel_, false);
63
- }
64
- json = grpc_json_create_child(nullptr, json, "state", nullptr,
65
- GRPC_JSON_OBJECT, false);
66
- grpc_json_create_child(nullptr, json, "state",
67
- grpc_connectivity_state_name(state), GRPC_JSON_STRING,
68
- false);
69
- }
70
-
71
- void ClientChannelNode::PopulateChildRefs(grpc_json* json) {
72
- ChildRefsList child_subchannels;
73
- ChildRefsList child_channels;
74
- grpc_json* json_iterator = nullptr;
75
- grpc_client_channel_populate_child_refs(client_channel_, &child_subchannels,
76
- &child_channels);
77
- if (!child_subchannels.empty()) {
78
- grpc_json* array_parent = grpc_json_create_child(
79
- nullptr, json, "subchannelRef", nullptr, GRPC_JSON_ARRAY, false);
80
- for (size_t i = 0; i < child_subchannels.size(); ++i) {
81
- json_iterator =
82
- grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr,
83
- GRPC_JSON_OBJECT, false);
84
- grpc_json_add_number_string_child(json_iterator, nullptr, "subchannelId",
85
- child_subchannels[i]);
86
- }
87
- }
88
- if (!child_channels.empty()) {
89
- grpc_json* array_parent = grpc_json_create_child(
90
- nullptr, json, "channelRef", nullptr, GRPC_JSON_ARRAY, false);
91
- json_iterator = nullptr;
92
- for (size_t i = 0; i < child_channels.size(); ++i) {
93
- json_iterator =
94
- grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr,
95
- GRPC_JSON_OBJECT, false);
96
- grpc_json_add_number_string_child(json_iterator, nullptr, "channelId",
97
- child_channels[i]);
98
- }
99
- }
100
- }
101
-
102
- grpc_arg ClientChannelNode::CreateChannelArg() {
103
- return grpc_channel_arg_pointer_create(
104
- const_cast<char*>(GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC),
105
- reinterpret_cast<void*>(MakeClientChannelNode),
106
- &client_channel_channelz_vtable);
107
- }
108
-
109
- RefCountedPtr<ChannelNode> ClientChannelNode::MakeClientChannelNode(
110
- grpc_channel* channel, size_t channel_tracer_max_nodes,
111
- bool is_top_level_channel) {
112
- return MakeRefCounted<ClientChannelNode>(channel, channel_tracer_max_nodes,
113
- is_top_level_channel);
114
- }
115
32
 
116
33
  SubchannelNode::SubchannelNode(Subchannel* subchannel,
117
34
  size_t channel_tracer_max_nodes)
@@ -127,7 +44,9 @@ void SubchannelNode::PopulateConnectivityState(grpc_json* json) {
127
44
  if (subchannel_ == nullptr) {
128
45
  state = GRPC_CHANNEL_SHUTDOWN;
129
46
  } else {
130
- state = subchannel_->CheckConnectivity(true /* inhibit_health_checking */);
47
+ state = subchannel_->CheckConnectivityState(
48
+ nullptr /* health_check_service_name */,
49
+ nullptr /* connected_subchannel */);
131
50
  }
132
51
  json = grpc_json_create_child(nullptr, json, "state", nullptr,
133
52
  GRPC_JSON_OBJECT, false);
@@ -32,32 +32,6 @@ class Subchannel;
32
32
 
33
33
  namespace channelz {
34
34
 
35
- // Subtype of ChannelNode that overrides and provides client_channel specific
36
- // functionality like querying for connectivity_state and subchannel data.
37
- class ClientChannelNode : public ChannelNode {
38
- public:
39
- static RefCountedPtr<ChannelNode> MakeClientChannelNode(
40
- grpc_channel* channel, size_t channel_tracer_max_nodes,
41
- bool is_top_level_channel);
42
-
43
- ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes,
44
- bool is_top_level_channel);
45
- virtual ~ClientChannelNode() {}
46
-
47
- // Overriding template methods from ChannelNode to render information that
48
- // only ClientChannelNode knows about.
49
- void PopulateConnectivityState(grpc_json* json) override;
50
- void PopulateChildRefs(grpc_json* json) override;
51
-
52
- // Helper to create a channel arg to ensure this type of ChannelNode is
53
- // created.
54
- static grpc_arg CreateChannelArg();
55
-
56
- private:
57
- grpc_channel_element* client_channel_;
58
- };
59
-
60
- // Handles channelz bookkeeping for sockets
61
35
  class SubchannelNode : public BaseNode {
62
36
  public:
63
37
  SubchannelNode(Subchannel* subchannel, size_t channel_tracer_max_nodes);
@@ -85,12 +59,12 @@ class SubchannelNode : public BaseNode {
85
59
  void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
86
60
 
87
61
  private:
62
+ void PopulateConnectivityState(grpc_json* json);
63
+
88
64
  Subchannel* subchannel_;
89
65
  UniquePtr<char> target_;
90
66
  CallCountingHelper call_counter_;
91
67
  ChannelTrace trace_;
92
-
93
- void PopulateConnectivityState(grpc_json* json);
94
68
  };
95
69
 
96
70
  } // namespace channelz
@@ -24,6 +24,7 @@
24
24
 
25
25
  #include <grpc/support/alloc.h>
26
26
 
27
+ #include "src/core/ext/filters/client_channel/backup_poller.h"
27
28
  #include "src/core/ext/filters/client_channel/client_channel.h"
28
29
  #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
29
30
  #include "src/core/ext/filters/client_channel/global_subchannel_pool.h"
@@ -37,14 +38,6 @@
37
38
  #include "src/core/lib/surface/channel_init.h"
38
39
 
39
40
  static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
40
- const grpc_channel_args* args =
41
- grpc_channel_stack_builder_get_channel_arguments(builder);
42
- grpc_arg args_to_add[] = {
43
- grpc_core::channelz::ClientChannelNode::CreateChannelArg()};
44
- grpc_channel_args* new_args = grpc_channel_args_copy_and_add(
45
- args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
46
- grpc_channel_stack_builder_set_channel_arguments(builder, new_args);
47
- grpc_channel_args_destroy(new_args);
48
41
  return grpc_channel_stack_builder_append_filter(
49
42
  builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
50
43
  }
@@ -62,6 +55,7 @@ void grpc_client_channel_init(void) {
62
55
  GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
63
56
  (void*)&grpc_client_channel_filter);
64
57
  grpc_http_connect_register_handshaker_factory();
58
+ grpc_client_channel_global_init_backup_polling();
65
59
  }
66
60
 
67
61
  void grpc_client_channel_shutdown(void) {
@@ -323,6 +323,11 @@ void HealthCheckClient::CallState::StartCall() {
323
323
  grpc_error* error = GRPC_ERROR_NONE;
324
324
  call_ = health_check_client_->connected_subchannel_->CreateCall(args, &error)
325
325
  .release();
326
+ // Register after-destruction callback.
327
+ GRPC_CLOSURE_INIT(&after_call_stack_destruction_, AfterCallStackDestruction,
328
+ this, grpc_schedule_on_exec_ctx);
329
+ call_->SetAfterCallStackDestroy(&after_call_stack_destruction_);
330
+ // Check if creation failed.
326
331
  if (error != GRPC_ERROR_NONE) {
327
332
  gpr_log(GPR_ERROR,
328
333
  "HealthCheckClient %p CallState %p: error creating health "
@@ -338,10 +343,6 @@ void HealthCheckClient::CallState::StartCall() {
338
343
  GRPC_ERROR_NONE);
339
344
  return;
340
345
  }
341
- // Register after-destruction callback.
342
- GRPC_CLOSURE_INIT(&after_call_stack_destruction_, AfterCallStackDestruction,
343
- this, grpc_schedule_on_exec_ctx);
344
- call_->SetAfterCallStackDestroy(&after_call_stack_destruction_);
345
346
  // Initialize payload and batch.
346
347
  payload_.context = context_;
347
348
  batch_.payload = &payload_;
@@ -105,7 +105,7 @@ LoadBalancingPolicy::UpdateArgs& LoadBalancingPolicy::UpdateArgs::operator=(
105
105
  //
106
106
 
107
107
  LoadBalancingPolicy::PickResult LoadBalancingPolicy::QueuePicker::Pick(
108
- PickArgs* pick, grpc_error** error) {
108
+ PickArgs args) {
109
109
  // We invoke the parent's ExitIdleLocked() via a closure instead
110
110
  // of doing it directly here, for two reasons:
111
111
  // 1. ExitIdleLocked() may cause the policy's state to change and
@@ -125,7 +125,9 @@ LoadBalancingPolicy::PickResult LoadBalancingPolicy::QueuePicker::Pick(
125
125
  grpc_combiner_scheduler(parent_->combiner())),
126
126
  GRPC_ERROR_NONE);
127
127
  }
128
- return PICK_QUEUE;
128
+ PickResult result;
129
+ result.type = PickResult::PICK_QUEUE;
130
+ return result;
129
131
  }
130
132
 
131
133
  void LoadBalancingPolicy::QueuePicker::CallExitIdle(void* arg,
@@ -135,4 +137,16 @@ void LoadBalancingPolicy::QueuePicker::CallExitIdle(void* arg,
135
137
  parent->Unref();
136
138
  }
137
139
 
140
+ //
141
+ // LoadBalancingPolicy::TransientFailurePicker
142
+ //
143
+
144
+ LoadBalancingPolicy::PickResult
145
+ LoadBalancingPolicy::TransientFailurePicker::Pick(PickArgs args) {
146
+ PickResult result;
147
+ result.type = PickResult::PICK_TRANSIENT_FAILURE;
148
+ result.error = GRPC_ERROR_REF(error_);
149
+ return result;
150
+ }
151
+
138
152
  } // namespace grpc_core
@@ -21,32 +21,20 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
- #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
25
24
  #include "src/core/ext/filters/client_channel/server_address.h"
26
25
  #include "src/core/ext/filters/client_channel/service_config.h"
27
- #include "src/core/ext/filters/client_channel/subchannel.h"
26
+ #include "src/core/ext/filters/client_channel/subchannel_interface.h"
28
27
  #include "src/core/lib/gprpp/abstract.h"
29
28
  #include "src/core/lib/gprpp/orphanable.h"
30
29
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
31
30
  #include "src/core/lib/iomgr/combiner.h"
32
31
  #include "src/core/lib/iomgr/polling_entity.h"
33
32
  #include "src/core/lib/transport/connectivity_state.h"
34
-
35
- extern grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
33
+ #include "src/core/lib/transport/metadata_batch.h"
36
34
 
37
35
  namespace grpc_core {
38
36
 
39
- /// Interface for parsed forms of load balancing configs found in a service
40
- /// config.
41
- class ParsedLoadBalancingConfig : public RefCounted<ParsedLoadBalancingConfig> {
42
- public:
43
- virtual ~ParsedLoadBalancingConfig() = default;
44
-
45
- // Returns the load balancing policy name
46
- virtual const char* name() const GRPC_ABSTRACT;
47
-
48
- GRPC_ABSTRACT_BASE_CLASS;
49
- };
37
+ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
50
38
 
51
39
  /// Interface for load balancing policies.
52
40
  ///
@@ -89,66 +77,77 @@ class ParsedLoadBalancingConfig : public RefCounted<ParsedLoadBalancingConfig> {
89
77
  // interested_parties() hooks from the API.
90
78
  class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
91
79
  public:
80
+ /// Interface for accessing per-call state.
81
+ class CallState {
82
+ public:
83
+ CallState() = default;
84
+ virtual ~CallState() = default;
85
+
86
+ /// Allocates memory associated with the call, which will be
87
+ /// automatically freed when the call is complete.
88
+ /// It is more efficient to use this than to allocate memory directly
89
+ /// for allocations that need to be made on a per-call basis.
90
+ virtual void* Alloc(size_t size) GRPC_ABSTRACT;
91
+
92
+ GRPC_ABSTRACT_BASE_CLASS
93
+ };
94
+
92
95
  /// Arguments used when picking a subchannel for an RPC.
93
96
  struct PickArgs {
94
- ///
95
- /// Input parameters.
96
- ///
97
97
  /// Initial metadata associated with the picking call.
98
98
  /// The LB policy may use the existing metadata to influence its routing
99
99
  /// decision, and it may add new metadata elements to be sent with the
100
100
  /// call to the chosen backend.
101
101
  // TODO(roth): Provide a more generic metadata API here.
102
102
  grpc_metadata_batch* initial_metadata = nullptr;
103
- /// Storage for LB token in \a initial_metadata, or nullptr if not used.
104
- // TODO(roth): Remove this from the API. Maybe have the LB policy
105
- // allocate this on the arena instead?
106
- grpc_linked_mdelem lb_token_mdelem_storage;
107
- ///
108
- /// Output parameters.
109
- ///
110
- /// Will be set to the selected subchannel, or nullptr on failure or when
111
- /// the LB policy decides to drop the call.
112
- RefCountedPtr<ConnectedSubchannel> connected_subchannel;
113
- /// Callback set by lb policy to be notified of trailing metadata.
114
- /// The callback must be scheduled on grpc_schedule_on_exec_ctx.
115
- // TODO(roth): Provide a cleaner callback API.
116
- grpc_closure* recv_trailing_metadata_ready = nullptr;
117
- /// The address that will be set to point to the original
118
- /// recv_trailing_metadata_ready callback, to be invoked by the LB
119
- /// policy's recv_trailing_metadata_ready callback when complete.
120
- /// Must be non-null if recv_trailing_metadata_ready is non-null.
121
- // TODO(roth): Consider making the recv_trailing_metadata closure a
122
- // synchronous callback, in which case it is not responsible for
123
- // chaining to the next callback, so this can be removed from the API.
124
- grpc_closure** original_recv_trailing_metadata_ready = nullptr;
125
- /// If this is not nullptr, then the client channel will point it to the
126
- /// call's trailing metadata before invoking recv_trailing_metadata_ready.
127
- /// If this is nullptr, then the callback will still be called.
128
- /// The lb does not have ownership of the metadata.
129
- // TODO(roth): If we make this a synchronous callback, then this can
130
- // be passed to the callback as a parameter and can be removed from
131
- // the API here.
132
- grpc_metadata_batch** recv_trailing_metadata = nullptr;
103
+ /// An interface for accessing call state. Can be used to allocate
104
+ /// data associated with the call in an efficient way.
105
+ CallState* call_state;
133
106
  };
134
107
 
135
108
  /// The result of picking a subchannel for an RPC.
136
- enum PickResult {
137
- // Pick complete. If connected_subchannel is non-null, client channel
138
- // can immediately proceed with the call on connected_subchannel;
139
- // otherwise, call should be dropped.
140
- PICK_COMPLETE,
141
- // Pick cannot be completed until something changes on the control
142
- // plane. Client channel will queue the pick and try again the
143
- // next time the picker is updated.
144
- PICK_QUEUE,
145
- // LB policy is in transient failure. If the pick is wait_for_ready,
146
- // client channel will wait for the next picker and try again;
147
- // otherwise, the call will be failed immediately (although it may
148
- // be retried if the client channel is configured to do so).
149
- // The Pick() method will set its error parameter if this value is
150
- // returned.
151
- PICK_TRANSIENT_FAILURE,
109
+ struct PickResult {
110
+ enum ResultType {
111
+ /// Pick complete. If connected_subchannel is non-null, client channel
112
+ /// can immediately proceed with the call on connected_subchannel;
113
+ /// otherwise, call should be dropped.
114
+ PICK_COMPLETE,
115
+ /// Pick cannot be completed until something changes on the control
116
+ /// plane. Client channel will queue the pick and try again the
117
+ /// next time the picker is updated.
118
+ PICK_QUEUE,
119
+ /// LB policy is in transient failure. If the pick is wait_for_ready,
120
+ /// client channel will wait for the next picker and try again;
121
+ /// otherwise, the call will be failed immediately (although it may
122
+ /// be retried if the client channel is configured to do so).
123
+ /// The Pick() method will set its error parameter if this value is
124
+ /// returned.
125
+ PICK_TRANSIENT_FAILURE,
126
+ };
127
+ ResultType type;
128
+
129
+ /// Used only if type is PICK_COMPLETE. Will be set to the selected
130
+ /// subchannel, or nullptr if the LB policy decides to drop the call.
131
+ RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel;
132
+
133
+ /// Used only if type is PICK_TRANSIENT_FAILURE.
134
+ /// Error to be set when returning a transient failure.
135
+ // TODO(roth): Replace this with something similar to grpc::Status,
136
+ // so that we don't expose grpc_error to this API.
137
+ grpc_error* error = GRPC_ERROR_NONE;
138
+
139
+ /// Used only if type is PICK_COMPLETE.
140
+ /// Callback set by lb policy to be notified of trailing metadata.
141
+ /// The user_data argument will be set to the
142
+ /// recv_trailing_metadata_ready_user_data field.
143
+ /// recv_trailing_metadata will be set to the metadata, which may be
144
+ /// modified by the callback. The callback does not take ownership,
145
+ /// however, so any data that needs to be used after returning must
146
+ /// be copied.
147
+ void (*recv_trailing_metadata_ready)(
148
+ void* user_data, grpc_metadata_batch* recv_trailing_metadata,
149
+ CallState* call_state) = nullptr;
150
+ void* recv_trailing_metadata_ready_user_data = nullptr;
152
151
  };
153
152
 
154
153
  /// A subchannel picker is the object used to pick the subchannel to
@@ -162,17 +161,14 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
162
161
  /// live in the LB policy object itself.
163
162
  ///
164
163
  /// Currently, pickers are always accessed from within the
165
- /// client_channel combiner, so they do not have to be thread-safe.
166
- // TODO(roth): In a subsequent PR, split the data plane work (i.e.,
167
- // the interaction with the picker) and the control plane work (i.e.,
168
- // the interaction with the LB policy) into two different
169
- // synchronization mechanisms, to avoid lock contention between the two.
164
+ /// client_channel data plane combiner, so they do not have to be
165
+ /// thread-safe.
170
166
  class SubchannelPicker {
171
167
  public:
172
168
  SubchannelPicker() = default;
173
169
  virtual ~SubchannelPicker() = default;
174
170
 
175
- virtual PickResult Pick(PickArgs* pick, grpc_error** error) GRPC_ABSTRACT;
171
+ virtual PickResult Pick(PickArgs args) GRPC_ABSTRACT;
176
172
 
177
173
  GRPC_ABSTRACT_BASE_CLASS
178
174
  };
@@ -188,8 +184,8 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
188
184
  virtual ~ChannelControlHelper() = default;
189
185
 
190
186
  /// Creates a new subchannel with the specified channel args.
191
- virtual Subchannel* CreateSubchannel(const grpc_channel_args& args)
192
- GRPC_ABSTRACT;
187
+ virtual RefCountedPtr<SubchannelInterface> CreateSubchannel(
188
+ const grpc_channel_args& args) GRPC_ABSTRACT;
193
189
 
194
190
  /// Creates a channel with the specified target and channel args.
195
191
  /// This can be used in cases where the LB policy needs to create a
@@ -205,6 +201,25 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
205
201
  /// Requests that the resolver re-resolve.
206
202
  virtual void RequestReresolution() GRPC_ABSTRACT;
207
203
 
204
+ /// Adds a trace message associated with the channel.
205
+ /// Does NOT take ownership of \a message.
206
+ enum TraceSeverity { TRACE_INFO, TRACE_WARNING, TRACE_ERROR };
207
+ virtual void AddTraceEvent(TraceSeverity severity,
208
+ const char* message) GRPC_ABSTRACT;
209
+
210
+ GRPC_ABSTRACT_BASE_CLASS
211
+ };
212
+
213
+ /// Interface for configuration data used by an LB policy implementation.
214
+ /// Individual implementations will create a subclass that adds methods to
215
+ /// return the parameters they need.
216
+ class Config : public RefCounted<Config> {
217
+ public:
218
+ virtual ~Config() = default;
219
+
220
+ // Returns the load balancing policy name
221
+ virtual const char* name() const GRPC_ABSTRACT;
222
+
208
223
  GRPC_ABSTRACT_BASE_CLASS
209
224
  };
210
225
 
@@ -212,7 +227,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
212
227
  /// config are available.
213
228
  struct UpdateArgs {
214
229
  ServerAddressList addresses;
215
- RefCountedPtr<ParsedLoadBalancingConfig> config;
230
+ RefCountedPtr<Config> config;
216
231
  const grpc_channel_args* args = nullptr;
217
232
 
218
233
  // TODO(roth): Remove everything below once channel args is
@@ -265,20 +280,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
265
280
  /// Resets connection backoff.
266
281
  virtual void ResetBackoffLocked() GRPC_ABSTRACT;
267
282
 
268
- /// Populates child_subchannels and child_channels with the uuids of this
269
- /// LB policy's referenced children.
270
- ///
271
- /// This is not invoked from the client_channel's combiner. The
272
- /// implementation is responsible for providing its own synchronization.
273
- virtual void FillChildRefsForChannelz(
274
- channelz::ChildRefsList* child_subchannels,
275
- channelz::ChildRefsList* child_channels) GRPC_ABSTRACT;
276
-
277
- void set_channelz_node(
278
- RefCountedPtr<channelz::ClientChannelNode> channelz_node) {
279
- channelz_node_ = std::move(channelz_node);
280
- }
281
-
282
283
  grpc_pollset_set* interested_parties() const { return interested_parties_; }
283
284
 
284
285
  void Orphan() override;
@@ -291,7 +292,9 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
291
292
  explicit QueuePicker(RefCountedPtr<LoadBalancingPolicy> parent)
292
293
  : parent_(std::move(parent)) {}
293
294
 
294
- PickResult Pick(PickArgs* pick, grpc_error** error) override;
295
+ ~QueuePicker() { parent_.reset(DEBUG_LOCATION, "QueuePicker"); }
296
+
297
+ PickResult Pick(PickArgs args) override;
295
298
 
296
299
  private:
297
300
  static void CallExitIdle(void* arg, grpc_error* error);
@@ -306,10 +309,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
306
309
  explicit TransientFailurePicker(grpc_error* error) : error_(error) {}
307
310
  ~TransientFailurePicker() override { GRPC_ERROR_UNREF(error_); }
308
311
 
309
- PickResult Pick(PickArgs* pick, grpc_error** error) override {
310
- *error = GRPC_ERROR_REF(error_);
311
- return PICK_TRANSIENT_FAILURE;
312
- }
312
+ PickResult Pick(PickArgs args) override;
313
313
 
314
314
  private:
315
315
  grpc_error* error_;
@@ -327,10 +327,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
327
327
  return channel_control_helper_.get();
328
328
  }
329
329
 
330
- channelz::ClientChannelNode* channelz_node() const {
331
- return channelz_node_.get();
332
- }
333
-
334
330
  /// Shuts down the policy.
335
331
  virtual void ShutdownLocked() GRPC_ABSTRACT;
336
332
 
@@ -343,8 +339,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
343
339
  grpc_pollset_set* interested_parties_;
344
340
  /// Channel control helper.
345
341
  UniquePtr<ChannelControlHelper> channel_control_helper_;
346
- /// Channelz node.
347
- RefCountedPtr<channelz::ClientChannelNode> channelz_node_;
348
342
  };
349
343
 
350
344
  } // namespace grpc_core