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.
- checksums.yaml +4 -4
- data/Makefile +422 -62
- data/include/grpc/grpc_security.h +61 -5
- data/include/grpc/grpc_security_constants.h +1 -1
- data/include/grpc/impl/codegen/gpr_types.h +1 -1
- data/include/grpc/slice.h +2 -2
- data/src/core/ext/filters/client_channel/backup_poller.cc +2 -3
- data/src/core/ext/filters/client_channel/backup_poller.h +5 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +260 -122
- data/src/core/ext/filters/client_channel/client_channel.h +0 -8
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -84
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -28
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -8
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +5 -4
- data/src/core/ext/filters/client_channel/lb_policy.cc +16 -2
- data/src/core/ext/filters/client_channel/lb_policy.h +92 -98
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +63 -87
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +35 -87
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +18 -74
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +167 -217
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +216 -190
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +6 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -0
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -8
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +7 -7
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +28 -64
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -12
- data/src/core/ext/filters/client_channel/server_address.cc +4 -6
- data/src/core/ext/filters/client_channel/server_address.h +1 -3
- data/src/core/ext/filters/client_channel/service_config.cc +20 -22
- data/src/core/ext/filters/client_channel/service_config.h +26 -28
- data/src/core/ext/filters/client_channel/subchannel.cc +261 -160
- data/src/core/ext/filters/client_channel/subchannel.h +97 -23
- data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
- data/src/core/ext/filters/message_size/message_size_filter.cc +12 -12
- data/src/core/ext/filters/message_size/message_size_filter.h +2 -2
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -36
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +71 -52
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +18 -3
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +5 -12
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
- data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
- data/src/core/ext/transport/chttp2/transport/parsing.cc +39 -57
- data/src/core/lib/channel/channelz.cc +136 -19
- data/src/core/lib/channel/channelz.h +36 -40
- data/src/core/lib/channel/channelz_registry.cc +74 -106
- data/src/core/lib/channel/channelz_registry.h +10 -28
- data/src/core/lib/channel/context.h +1 -1
- data/src/core/lib/channel/handshaker.cc +6 -0
- data/src/core/lib/compression/compression.cc +13 -8
- data/src/core/lib/compression/compression_internal.cc +14 -10
- data/src/core/lib/compression/compression_internal.h +1 -1
- data/src/core/lib/compression/stream_compression.cc +3 -2
- data/src/core/lib/compression/stream_compression.h +2 -2
- data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
- data/src/core/lib/gpr/env.h +1 -1
- data/src/core/lib/gpr/string.cc +8 -1
- data/src/core/lib/gpr/string.h +6 -1
- data/src/core/lib/gprpp/fork.cc +1 -1
- data/src/core/lib/gprpp/fork.h +5 -1
- data/src/core/lib/gprpp/global_config.h +9 -0
- data/src/core/lib/gprpp/global_config_custom.h +1 -1
- data/src/core/lib/gprpp/inlined_vector.h +8 -0
- data/src/core/lib/gprpp/map.h +38 -21
- data/src/core/lib/gprpp/memory.h +2 -2
- data/src/core/lib/gprpp/orphanable.h +1 -1
- data/src/core/lib/gprpp/ref_counted.h +9 -4
- data/src/core/lib/http/httpcli.cc +3 -3
- data/src/core/lib/iomgr/buffer_list.h +1 -1
- data/src/core/lib/iomgr/call_combiner.cc +1 -1
- data/src/core/lib/iomgr/call_combiner.h +1 -1
- data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
- data/src/core/lib/iomgr/cfstream_handle.h +4 -0
- data/src/core/lib/iomgr/error.cc +3 -3
- data/src/core/lib/iomgr/error.h +9 -3
- data/src/core/lib/iomgr/error_internal.h +1 -1
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -1
- data/src/core/lib/iomgr/ev_posix.cc +3 -3
- data/src/core/lib/iomgr/ev_posix.h +3 -2
- data/src/core/lib/iomgr/ev_windows.cc +2 -2
- data/src/core/lib/iomgr/iomgr.cc +4 -4
- data/src/core/lib/iomgr/lockfree_event.cc +1 -1
- data/src/core/lib/iomgr/port.h +5 -1
- data/src/core/lib/iomgr/tcp_posix.cc +1 -3
- data/src/core/lib/iomgr/tcp_server.cc +5 -0
- data/src/core/lib/iomgr/tcp_server.h +24 -0
- data/src/core/lib/iomgr/tcp_server_custom.cc +11 -9
- data/src/core/lib/iomgr/tcp_server_posix.cc +72 -11
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
- data/src/core/lib/iomgr/tcp_server_windows.cc +11 -9
- data/src/core/lib/iomgr/tcp_uv.cc +5 -6
- data/src/core/lib/iomgr/timer.h +2 -1
- data/src/core/lib/iomgr/udp_server.cc +2 -2
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
- data/src/core/lib/security/security_connector/security_connector.h +1 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +1 -1
- data/src/core/lib/security/transport/auth_filters.h +3 -0
- data/src/core/lib/security/transport/client_auth_filter.cc +13 -0
- data/src/core/lib/security/transport/security_handshaker.cc +7 -7
- data/src/core/lib/slice/b64.h +2 -2
- data/src/core/lib/slice/slice.cc +82 -10
- data/src/core/lib/slice/slice_buffer.cc +49 -21
- data/src/core/lib/slice/slice_hash_table.h +2 -2
- data/src/core/lib/slice/slice_intern.cc +15 -16
- data/src/core/lib/slice/slice_internal.h +52 -0
- data/src/core/lib/slice/slice_string_helpers.cc +10 -1
- data/src/core/lib/slice/slice_string_helpers.h +3 -1
- data/src/core/lib/slice/slice_utils.h +50 -0
- data/src/core/lib/slice/slice_weak_hash_table.h +2 -2
- data/src/core/lib/surface/call.cc +14 -8
- data/src/core/lib/surface/channel.cc +89 -97
- data/src/core/lib/surface/channel.h +60 -6
- data/src/core/lib/surface/completion_queue.cc +49 -36
- data/src/core/lib/surface/completion_queue.h +2 -1
- data/src/core/lib/surface/server.cc +8 -8
- data/src/core/lib/surface/validate_metadata.cc +14 -8
- data/src/core/lib/surface/validate_metadata.h +13 -2
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/metadata.cc +56 -26
- data/src/core/lib/transport/metadata.h +91 -75
- data/src/core/lib/transport/static_metadata.cc +262 -176
- data/src/core/lib/transport/static_metadata.h +272 -180
- data/src/core/lib/transport/transport.cc +1 -1
- data/src/core/lib/transport/transport.h +8 -2
- data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +5 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +33 -31
@@ -118,19 +118,19 @@ namespace {
|
|
118
118
|
|
119
119
|
constexpr char kGrpclb[] = "grpclb";
|
120
120
|
|
121
|
-
class ParsedGrpcLbConfig : public
|
121
|
+
class ParsedGrpcLbConfig : public LoadBalancingPolicy::Config {
|
122
122
|
public:
|
123
123
|
explicit ParsedGrpcLbConfig(
|
124
|
-
RefCountedPtr<
|
124
|
+
RefCountedPtr<LoadBalancingPolicy::Config> child_policy)
|
125
125
|
: child_policy_(std::move(child_policy)) {}
|
126
126
|
const char* name() const override { return kGrpclb; }
|
127
127
|
|
128
|
-
RefCountedPtr<
|
128
|
+
RefCountedPtr<LoadBalancingPolicy::Config> child_policy() const {
|
129
129
|
return child_policy_;
|
130
130
|
}
|
131
131
|
|
132
132
|
private:
|
133
|
-
RefCountedPtr<
|
133
|
+
RefCountedPtr<LoadBalancingPolicy::Config> child_policy_;
|
134
134
|
};
|
135
135
|
|
136
136
|
class GrpcLb : public LoadBalancingPolicy {
|
@@ -141,9 +141,6 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
141
141
|
|
142
142
|
void UpdateLocked(UpdateArgs args) override;
|
143
143
|
void ResetBackoffLocked() override;
|
144
|
-
void FillChildRefsForChannelz(
|
145
|
-
channelz::ChildRefsList* child_subchannels,
|
146
|
-
channelz::ChildRefsList* child_channels) override;
|
147
144
|
|
148
145
|
private:
|
149
146
|
/// Contains a call to the LB server and all the data related to the call.
|
@@ -274,7 +271,7 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
274
271
|
child_picker_(std::move(child_picker)),
|
275
272
|
client_stats_(std::move(client_stats)) {}
|
276
273
|
|
277
|
-
PickResult Pick(PickArgs
|
274
|
+
PickResult Pick(PickArgs args) override;
|
278
275
|
|
279
276
|
private:
|
280
277
|
// Storing the address for logging, but not holding a ref.
|
@@ -293,12 +290,14 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
293
290
|
explicit Helper(RefCountedPtr<GrpcLb> parent)
|
294
291
|
: parent_(std::move(parent)) {}
|
295
292
|
|
296
|
-
|
293
|
+
RefCountedPtr<SubchannelInterface> CreateSubchannel(
|
294
|
+
const grpc_channel_args& args) override;
|
297
295
|
grpc_channel* CreateChannel(const char* target,
|
298
296
|
const grpc_channel_args& args) override;
|
299
297
|
void UpdateState(grpc_connectivity_state state,
|
300
298
|
UniquePtr<SubchannelPicker> picker) override;
|
301
299
|
void RequestReresolution() override;
|
300
|
+
void AddTraceEvent(TraceSeverity severity, const char* message) override;
|
302
301
|
|
303
302
|
void set_child(LoadBalancingPolicy* child) { child_ = child; }
|
304
303
|
|
@@ -348,8 +347,6 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
348
347
|
|
349
348
|
// The channel for communicating with the LB server.
|
350
349
|
grpc_channel* lb_channel_ = nullptr;
|
351
|
-
// Uuid of the lb channel. Used for channelz.
|
352
|
-
gpr_atm lb_channel_uuid_ = 0;
|
353
350
|
// Response generator to inject address updates into lb_channel_.
|
354
351
|
RefCountedPtr<FakeResolverResponseGenerator> response_generator_;
|
355
352
|
|
@@ -385,16 +382,13 @@ class GrpcLb : public LoadBalancingPolicy {
|
|
385
382
|
grpc_connectivity_state lb_channel_connectivity_ = GRPC_CHANNEL_IDLE;
|
386
383
|
grpc_closure lb_channel_on_connectivity_changed_;
|
387
384
|
|
388
|
-
// Lock held when modifying the value of child_policy_ or
|
389
|
-
// pending_child_policy_.
|
390
|
-
gpr_mu child_policy_mu_;
|
391
385
|
// The child policy to use for the backends.
|
392
386
|
OrphanablePtr<LoadBalancingPolicy> child_policy_;
|
393
387
|
// When switching child policies, the new policy will be stored here
|
394
388
|
// until it reports READY, at which point it will be moved to child_policy_.
|
395
389
|
OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
|
396
390
|
// The child policy config.
|
397
|
-
RefCountedPtr<
|
391
|
+
RefCountedPtr<LoadBalancingPolicy::Config> child_policy_config_;
|
398
392
|
// Child policy in state READY.
|
399
393
|
bool child_policy_ready_ = false;
|
400
394
|
};
|
@@ -561,7 +555,8 @@ const char* GrpcLb::Serverlist::ShouldDrop() {
|
|
561
555
|
// GrpcLb::Picker
|
562
556
|
//
|
563
557
|
|
564
|
-
GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs
|
558
|
+
GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs args) {
|
559
|
+
PickResult result;
|
565
560
|
// Check if we should drop the call.
|
566
561
|
const char* drop_token = serverlist_->ShouldDrop();
|
567
562
|
if (drop_token != nullptr) {
|
@@ -573,26 +568,28 @@ GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs* pick, grpc_error** error) {
|
|
573
568
|
if (client_stats_ != nullptr) {
|
574
569
|
client_stats_->AddCallDropped(drop_token);
|
575
570
|
}
|
576
|
-
|
571
|
+
result.type = PickResult::PICK_COMPLETE;
|
572
|
+
return result;
|
577
573
|
}
|
578
574
|
// Forward pick to child policy.
|
579
|
-
|
575
|
+
result = child_picker_->Pick(args);
|
580
576
|
// If pick succeeded, add LB token to initial metadata.
|
581
|
-
if (result == PickResult::PICK_COMPLETE &&
|
582
|
-
|
577
|
+
if (result.type == PickResult::PICK_COMPLETE &&
|
578
|
+
result.connected_subchannel != nullptr) {
|
583
579
|
const grpc_arg* arg = grpc_channel_args_find(
|
584
|
-
|
580
|
+
result.connected_subchannel->args(), GRPC_ARG_GRPCLB_ADDRESS_LB_TOKEN);
|
585
581
|
if (arg == nullptr) {
|
586
582
|
gpr_log(GPR_ERROR,
|
587
|
-
"[grpclb %p picker %p] No LB token for connected subchannel "
|
588
|
-
|
589
|
-
parent_, this, pick);
|
583
|
+
"[grpclb %p picker %p] No LB token for connected subchannel %p",
|
584
|
+
parent_, this, result.connected_subchannel.get());
|
590
585
|
abort();
|
591
586
|
}
|
592
587
|
grpc_mdelem lb_token = {reinterpret_cast<uintptr_t>(arg->value.pointer.p)};
|
593
588
|
GPR_ASSERT(!GRPC_MDISNULL(lb_token));
|
589
|
+
grpc_linked_mdelem* mdelem_storage = static_cast<grpc_linked_mdelem*>(
|
590
|
+
args.call_state->Alloc(sizeof(grpc_linked_mdelem)));
|
594
591
|
GPR_ASSERT(grpc_metadata_batch_add_tail(
|
595
|
-
|
592
|
+
args.initial_metadata, mdelem_storage,
|
596
593
|
GRPC_MDELEM_REF(lb_token)) == GRPC_ERROR_NONE);
|
597
594
|
GrpcLbClientStats* client_stats = static_cast<GrpcLbClientStats*>(
|
598
595
|
grpc_mdelem_get_user_data(lb_token, GrpcLbClientStats::Destroy));
|
@@ -617,7 +614,8 @@ bool GrpcLb::Helper::CalledByCurrentChild() const {
|
|
617
614
|
return child_ == parent_->child_policy_.get();
|
618
615
|
}
|
619
616
|
|
620
|
-
|
617
|
+
RefCountedPtr<SubchannelInterface> GrpcLb::Helper::CreateSubchannel(
|
618
|
+
const grpc_channel_args& args) {
|
621
619
|
if (parent_->shutting_down_ ||
|
622
620
|
(!CalledByPendingChild() && !CalledByCurrentChild())) {
|
623
621
|
return nullptr;
|
@@ -650,7 +648,6 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
|
|
650
648
|
grpc_pollset_set_del_pollset_set(
|
651
649
|
parent_->child_policy_->interested_parties(),
|
652
650
|
parent_->interested_parties());
|
653
|
-
MutexLock lock(&parent_->child_policy_mu_);
|
654
651
|
parent_->child_policy_ = std::move(parent_->pending_child_policy_);
|
655
652
|
} else if (!CalledByCurrentChild()) {
|
656
653
|
// This request is from an outdated child, so ignore it.
|
@@ -730,6 +727,15 @@ void GrpcLb::Helper::RequestReresolution() {
|
|
730
727
|
}
|
731
728
|
}
|
732
729
|
|
730
|
+
void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity,
|
731
|
+
const char* message) {
|
732
|
+
if (parent_->shutting_down_ ||
|
733
|
+
(!CalledByPendingChild() && !CalledByCurrentChild())) {
|
734
|
+
return;
|
735
|
+
}
|
736
|
+
parent_->channel_control_helper()->AddTraceEvent(severity, message);
|
737
|
+
}
|
738
|
+
|
733
739
|
//
|
734
740
|
// GrpcLb::BalancerCallState
|
735
741
|
//
|
@@ -1239,25 +1245,34 @@ grpc_channel_args* BuildBalancerChannelArgs(
|
|
1239
1245
|
// treated as a stand-alone channel and not inherit this argument from the
|
1240
1246
|
// args of the parent channel.
|
1241
1247
|
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
|
1248
|
+
// Don't want to pass down channelz node from parent; the balancer
|
1249
|
+
// channel will get its own.
|
1250
|
+
GRPC_ARG_CHANNELZ_CHANNEL_NODE,
|
1242
1251
|
};
|
1243
1252
|
// Channel args to add.
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1253
|
+
InlinedVector<grpc_arg, 3> args_to_add;
|
1254
|
+
// The fake resolver response generator, which we use to inject
|
1255
|
+
// address updates into the LB channel.
|
1256
|
+
args_to_add.emplace_back(
|
1247
1257
|
grpc_core::FakeResolverResponseGenerator::MakeChannelArg(
|
1248
|
-
response_generator)
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1258
|
+
response_generator));
|
1259
|
+
// A channel arg indicating the target is a grpclb load balancer.
|
1260
|
+
args_to_add.emplace_back(grpc_channel_arg_integer_create(
|
1261
|
+
const_cast<char*>(GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER), 1));
|
1262
|
+
// The parent channel's channelz uuid.
|
1263
|
+
channelz::ChannelNode* channelz_node = nullptr;
|
1264
|
+
const grpc_arg* arg =
|
1265
|
+
grpc_channel_args_find(args, GRPC_ARG_CHANNELZ_CHANNEL_NODE);
|
1266
|
+
if (arg != nullptr && arg->type == GRPC_ARG_POINTER &&
|
1267
|
+
arg->value.pointer.p != nullptr) {
|
1268
|
+
channelz_node = static_cast<channelz::ChannelNode*>(arg->value.pointer.p);
|
1269
|
+
args_to_add.emplace_back(
|
1270
|
+
channelz::MakeParentUuidArg(channelz_node->uuid()));
|
1271
|
+
}
|
1257
1272
|
// Construct channel args.
|
1258
1273
|
grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(
|
1259
|
-
args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add,
|
1260
|
-
|
1274
|
+
args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add.data(),
|
1275
|
+
args_to_add.size());
|
1261
1276
|
// Make any necessary modifications for security.
|
1262
1277
|
return grpc_lb_policy_grpclb_modify_lb_channel_args(addresses, new_args);
|
1263
1278
|
}
|
@@ -1283,7 +1298,6 @@ GrpcLb::GrpcLb(Args args)
|
|
1283
1298
|
GRPC_CLOSURE_INIT(&lb_channel_on_connectivity_changed_,
|
1284
1299
|
&GrpcLb::OnBalancerChannelConnectivityChangedLocked, this,
|
1285
1300
|
grpc_combiner_scheduler(args.combiner));
|
1286
|
-
gpr_mu_init(&child_policy_mu_);
|
1287
1301
|
// Record server name.
|
1288
1302
|
const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
|
1289
1303
|
const char* server_uri = grpc_channel_arg_get_string(arg);
|
@@ -1309,7 +1323,6 @@ GrpcLb::GrpcLb(Args args)
|
|
1309
1323
|
GrpcLb::~GrpcLb() {
|
1310
1324
|
gpr_free((void*)server_name_);
|
1311
1325
|
grpc_channel_args_destroy(args_);
|
1312
|
-
gpr_mu_destroy(&child_policy_mu_);
|
1313
1326
|
}
|
1314
1327
|
|
1315
1328
|
void GrpcLb::ShutdownLocked() {
|
@@ -1330,11 +1343,8 @@ void GrpcLb::ShutdownLocked() {
|
|
1330
1343
|
grpc_pollset_set_del_pollset_set(
|
1331
1344
|
pending_child_policy_->interested_parties(), interested_parties());
|
1332
1345
|
}
|
1333
|
-
|
1334
|
-
|
1335
|
-
child_policy_.reset();
|
1336
|
-
pending_child_policy_.reset();
|
1337
|
-
}
|
1346
|
+
child_policy_.reset();
|
1347
|
+
pending_child_policy_.reset();
|
1338
1348
|
// We destroy the LB channel here instead of in our destructor because
|
1339
1349
|
// destroying the channel triggers a last callback to
|
1340
1350
|
// OnBalancerChannelConnectivityChangedLocked(), and we need to be
|
@@ -1342,7 +1352,6 @@ void GrpcLb::ShutdownLocked() {
|
|
1342
1352
|
if (lb_channel_ != nullptr) {
|
1343
1353
|
grpc_channel_destroy(lb_channel_);
|
1344
1354
|
lb_channel_ = nullptr;
|
1345
|
-
gpr_atm_no_barrier_store(&lb_channel_uuid_, 0);
|
1346
1355
|
}
|
1347
1356
|
}
|
1348
1357
|
|
@@ -1362,29 +1371,6 @@ void GrpcLb::ResetBackoffLocked() {
|
|
1362
1371
|
}
|
1363
1372
|
}
|
1364
1373
|
|
1365
|
-
void GrpcLb::FillChildRefsForChannelz(
|
1366
|
-
channelz::ChildRefsList* child_subchannels,
|
1367
|
-
channelz::ChildRefsList* child_channels) {
|
1368
|
-
{
|
1369
|
-
// Delegate to the child policy to fill the children subchannels.
|
1370
|
-
// This must be done holding child_policy_mu_, since this method
|
1371
|
-
// does not run in the combiner.
|
1372
|
-
MutexLock lock(&child_policy_mu_);
|
1373
|
-
if (child_policy_ != nullptr) {
|
1374
|
-
child_policy_->FillChildRefsForChannelz(child_subchannels,
|
1375
|
-
child_channels);
|
1376
|
-
}
|
1377
|
-
if (pending_child_policy_ != nullptr) {
|
1378
|
-
pending_child_policy_->FillChildRefsForChannelz(child_subchannels,
|
1379
|
-
child_channels);
|
1380
|
-
}
|
1381
|
-
}
|
1382
|
-
gpr_atm uuid = gpr_atm_no_barrier_load(&lb_channel_uuid_);
|
1383
|
-
if (uuid != 0) {
|
1384
|
-
child_channels->push_back(uuid);
|
1385
|
-
}
|
1386
|
-
}
|
1387
|
-
|
1388
1374
|
void GrpcLb::UpdateLocked(UpdateArgs args) {
|
1389
1375
|
const bool is_initial_update = lb_channel_ == nullptr;
|
1390
1376
|
auto* grpclb_config =
|
@@ -1467,11 +1453,6 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked(
|
|
1467
1453
|
lb_channel_ =
|
1468
1454
|
channel_control_helper()->CreateChannel(uri_str, *lb_channel_args);
|
1469
1455
|
GPR_ASSERT(lb_channel_ != nullptr);
|
1470
|
-
grpc_core::channelz::ChannelNode* channel_node =
|
1471
|
-
grpc_channel_get_channelz_node(lb_channel_);
|
1472
|
-
if (channel_node != nullptr) {
|
1473
|
-
gpr_atm_no_barrier_store(&lb_channel_uuid_, channel_node->uuid());
|
1474
|
-
}
|
1475
1456
|
gpr_free(uri_str);
|
1476
1457
|
}
|
1477
1458
|
// Propagate updates to the LB channel (pick_first) through the fake
|
@@ -1759,15 +1740,10 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
|
|
1759
1740
|
gpr_log(GPR_INFO, "[grpclb %p] Creating new %schild policy %s", this,
|
1760
1741
|
child_policy_ == nullptr ? "" : "pending ", child_policy_name);
|
1761
1742
|
}
|
1762
|
-
auto new_policy =
|
1763
|
-
CreateChildPolicyLocked(child_policy_name, update_args.args);
|
1764
1743
|
// Swap the policy into place.
|
1765
1744
|
auto& lb_policy =
|
1766
1745
|
child_policy_ == nullptr ? child_policy_ : pending_child_policy_;
|
1767
|
-
|
1768
|
-
MutexLock lock(&child_policy_mu_);
|
1769
|
-
lb_policy = std::move(new_policy);
|
1770
|
-
}
|
1746
|
+
lb_policy = CreateChildPolicyLocked(child_policy_name, update_args.args);
|
1771
1747
|
policy_to_update = lb_policy.get();
|
1772
1748
|
} else {
|
1773
1749
|
// Cases 2a and 3a: update an existing policy.
|
@@ -1800,15 +1776,15 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
|
|
1800
1776
|
|
1801
1777
|
const char* name() const override { return kGrpclb; }
|
1802
1778
|
|
1803
|
-
RefCountedPtr<
|
1779
|
+
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
|
1804
1780
|
const grpc_json* json, grpc_error** error) const override {
|
1805
1781
|
GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
|
1806
1782
|
if (json == nullptr) {
|
1807
|
-
return RefCountedPtr<
|
1783
|
+
return RefCountedPtr<LoadBalancingPolicy::Config>(
|
1808
1784
|
New<ParsedGrpcLbConfig>(nullptr));
|
1809
1785
|
}
|
1810
1786
|
InlinedVector<grpc_error*, 2> error_list;
|
1811
|
-
RefCountedPtr<
|
1787
|
+
RefCountedPtr<LoadBalancingPolicy::Config> child_policy;
|
1812
1788
|
for (const grpc_json* field = json->child; field != nullptr;
|
1813
1789
|
field = field->next) {
|
1814
1790
|
if (field->key == nullptr) continue;
|
@@ -1826,7 +1802,7 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
|
|
1826
1802
|
}
|
1827
1803
|
}
|
1828
1804
|
if (error_list.empty()) {
|
1829
|
-
return RefCountedPtr<
|
1805
|
+
return RefCountedPtr<LoadBalancingPolicy::Config>(
|
1830
1806
|
New<ParsedGrpcLbConfig>(std::move(child_policy)));
|
1831
1807
|
} else {
|
1832
1808
|
*error = GRPC_ERROR_CREATE_FROM_VECTOR("GrpcLb Parser", &error_list);
|
@@ -67,8 +67,12 @@ grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) {
|
|
67
67
|
req->has_client_stats = false;
|
68
68
|
req->has_initial_request = true;
|
69
69
|
req->initial_request.has_name = true;
|
70
|
-
|
71
|
-
|
70
|
+
// GCC warns (-Wstringop-truncation) because the destination
|
71
|
+
// buffer size is identical to max-size, leading to a potential
|
72
|
+
// char[] with no null terminator. nanopb can handle it fine,
|
73
|
+
// and parantheses around strncpy silence that compiler warning.
|
74
|
+
(strncpy(req->initial_request.name, lb_service_name,
|
75
|
+
GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH));
|
72
76
|
return req;
|
73
77
|
}
|
74
78
|
|
@@ -53,8 +53,6 @@ class PickFirst : public LoadBalancingPolicy {
|
|
53
53
|
void UpdateLocked(UpdateArgs args) override;
|
54
54
|
void ExitIdleLocked() override;
|
55
55
|
void ResetBackoffLocked() override;
|
56
|
-
void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
|
57
|
-
channelz::ChildRefsList* ignored) override;
|
58
56
|
|
59
57
|
private:
|
60
58
|
~PickFirst();
|
@@ -68,9 +66,9 @@ class PickFirst : public LoadBalancingPolicy {
|
|
68
66
|
PickFirstSubchannelData(
|
69
67
|
SubchannelList<PickFirstSubchannelList, PickFirstSubchannelData>*
|
70
68
|
subchannel_list,
|
71
|
-
const ServerAddress& address,
|
72
|
-
|
73
|
-
: SubchannelData(subchannel_list, address, subchannel
|
69
|
+
const ServerAddress& address,
|
70
|
+
RefCountedPtr<SubchannelInterface> subchannel)
|
71
|
+
: SubchannelData(subchannel_list, address, std::move(subchannel)) {}
|
74
72
|
|
75
73
|
void ProcessConnectivityChangeLocked(
|
76
74
|
grpc_connectivity_state connectivity_state) override;
|
@@ -113,34 +111,23 @@ class PickFirst : public LoadBalancingPolicy {
|
|
113
111
|
|
114
112
|
class Picker : public SubchannelPicker {
|
115
113
|
public:
|
116
|
-
explicit Picker(
|
114
|
+
explicit Picker(
|
115
|
+
RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel)
|
117
116
|
: connected_subchannel_(std::move(connected_subchannel)) {}
|
118
117
|
|
119
|
-
PickResult Pick(PickArgs
|
120
|
-
|
121
|
-
|
118
|
+
PickResult Pick(PickArgs args) override {
|
119
|
+
PickResult result;
|
120
|
+
result.type = PickResult::PICK_COMPLETE;
|
121
|
+
result.connected_subchannel = connected_subchannel_;
|
122
|
+
return result;
|
122
123
|
}
|
123
124
|
|
124
125
|
private:
|
125
|
-
RefCountedPtr<
|
126
|
-
};
|
127
|
-
|
128
|
-
// Helper class to ensure that any function that modifies the child refs
|
129
|
-
// data structures will update the channelz snapshot data structures before
|
130
|
-
// returning.
|
131
|
-
class AutoChildRefsUpdater {
|
132
|
-
public:
|
133
|
-
explicit AutoChildRefsUpdater(PickFirst* pf) : pf_(pf) {}
|
134
|
-
~AutoChildRefsUpdater() { pf_->UpdateChildRefsLocked(); }
|
135
|
-
|
136
|
-
private:
|
137
|
-
PickFirst* pf_;
|
126
|
+
RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel_;
|
138
127
|
};
|
139
128
|
|
140
129
|
void ShutdownLocked() override;
|
141
130
|
|
142
|
-
void UpdateChildRefsLocked();
|
143
|
-
|
144
131
|
// All our subchannels.
|
145
132
|
OrphanablePtr<PickFirstSubchannelList> subchannel_list_;
|
146
133
|
// Latest pending subchannel list.
|
@@ -151,12 +138,6 @@ class PickFirst : public LoadBalancingPolicy {
|
|
151
138
|
bool idle_ = false;
|
152
139
|
// Are we shut down?
|
153
140
|
bool shutdown_ = false;
|
154
|
-
|
155
|
-
/// Lock and data used to capture snapshots of this channels child
|
156
|
-
/// channels and subchannels. This data is consumed by channelz.
|
157
|
-
Mutex child_refs_mu_;
|
158
|
-
channelz::ChildRefsList child_subchannels_;
|
159
|
-
channelz::ChildRefsList child_channels_;
|
160
141
|
};
|
161
142
|
|
162
143
|
PickFirst::PickFirst(Args args) : LoadBalancingPolicy(std::move(args)) {
|
@@ -174,7 +155,6 @@ PickFirst::~PickFirst() {
|
|
174
155
|
}
|
175
156
|
|
176
157
|
void PickFirst::ShutdownLocked() {
|
177
|
-
AutoChildRefsUpdater guard(this);
|
178
158
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
|
179
159
|
gpr_log(GPR_INFO, "Pick First %p Shutting down", this);
|
180
160
|
}
|
@@ -209,42 +189,7 @@ void PickFirst::ResetBackoffLocked() {
|
|
209
189
|
}
|
210
190
|
}
|
211
191
|
|
212
|
-
void PickFirst::FillChildRefsForChannelz(
|
213
|
-
channelz::ChildRefsList* child_subchannels_to_fill,
|
214
|
-
channelz::ChildRefsList* ignored) {
|
215
|
-
MutexLock lock(&child_refs_mu_);
|
216
|
-
for (size_t i = 0; i < child_subchannels_.size(); ++i) {
|
217
|
-
// TODO(ncteisen): implement a de dup loop that is not O(n^2). Might
|
218
|
-
// have to implement lightweight set. For now, we don't care about
|
219
|
-
// performance when channelz requests are made.
|
220
|
-
bool found = false;
|
221
|
-
for (size_t j = 0; j < child_subchannels_to_fill->size(); ++j) {
|
222
|
-
if ((*child_subchannels_to_fill)[j] == child_subchannels_[i]) {
|
223
|
-
found = true;
|
224
|
-
break;
|
225
|
-
}
|
226
|
-
}
|
227
|
-
if (!found) {
|
228
|
-
child_subchannels_to_fill->push_back(child_subchannels_[i]);
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
void PickFirst::UpdateChildRefsLocked() {
|
234
|
-
channelz::ChildRefsList cs;
|
235
|
-
if (subchannel_list_ != nullptr) {
|
236
|
-
subchannel_list_->PopulateChildRefsList(&cs);
|
237
|
-
}
|
238
|
-
if (latest_pending_subchannel_list_ != nullptr) {
|
239
|
-
latest_pending_subchannel_list_->PopulateChildRefsList(&cs);
|
240
|
-
}
|
241
|
-
// atomically update the data that channelz will actually be looking at.
|
242
|
-
MutexLock lock(&child_refs_mu_);
|
243
|
-
child_subchannels_ = std::move(cs);
|
244
|
-
}
|
245
|
-
|
246
192
|
void PickFirst::UpdateLocked(UpdateArgs args) {
|
247
|
-
AutoChildRefsUpdater guard(this);
|
248
193
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
|
249
194
|
gpr_log(GPR_INFO,
|
250
195
|
"Pick First %p received update with %" PRIuPTR " addresses", this,
|
@@ -312,6 +257,7 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
|
|
312
257
|
// here, since we've already checked the initial connectivity
|
313
258
|
// state of all subchannels above.
|
314
259
|
subchannel_list_->subchannel(0)->StartConnectivityWatchLocked();
|
260
|
+
subchannel_list_->subchannel(0)->subchannel()->AttemptToConnect();
|
315
261
|
}
|
316
262
|
} else {
|
317
263
|
// We do have a selected subchannel (which means it's READY), so keep
|
@@ -334,6 +280,9 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
|
|
334
280
|
// state of all subchannels above.
|
335
281
|
latest_pending_subchannel_list_->subchannel(0)
|
336
282
|
->StartConnectivityWatchLocked();
|
283
|
+
latest_pending_subchannel_list_->subchannel(0)
|
284
|
+
->subchannel()
|
285
|
+
->AttemptToConnect();
|
337
286
|
}
|
338
287
|
}
|
339
288
|
}
|
@@ -341,7 +290,6 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
|
|
341
290
|
void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
342
291
|
grpc_connectivity_state connectivity_state) {
|
343
292
|
PickFirst* p = static_cast<PickFirst*>(subchannel_list()->policy());
|
344
|
-
AutoChildRefsUpdater guard(p);
|
345
293
|
// The notification must be for a subchannel in either the current or
|
346
294
|
// latest pending subchannel lists.
|
347
295
|
GPR_ASSERT(subchannel_list() == p->subchannel_list_.get() ||
|
@@ -366,7 +314,8 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
|
366
314
|
p->subchannel_list_.get());
|
367
315
|
}
|
368
316
|
p->selected_ = nullptr;
|
369
|
-
|
317
|
+
CancelConnectivityWatchLocked(
|
318
|
+
"selected subchannel failed; switching to pending update");
|
370
319
|
p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
|
371
320
|
// Set our state to that of the pending subchannel list.
|
372
321
|
if (p->subchannel_list_->in_transient_failure()) {
|
@@ -380,7 +329,8 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
|
380
329
|
} else {
|
381
330
|
p->channel_control_helper()->UpdateState(
|
382
331
|
GRPC_CHANNEL_CONNECTING,
|
383
|
-
UniquePtr<SubchannelPicker>(
|
332
|
+
UniquePtr<SubchannelPicker>(
|
333
|
+
New<QueuePicker>(p->Ref(DEBUG_LOCATION, "QueuePicker"))));
|
384
334
|
}
|
385
335
|
} else {
|
386
336
|
if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
|
@@ -391,10 +341,10 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
|
391
341
|
p->idle_ = true;
|
392
342
|
p->channel_control_helper()->RequestReresolution();
|
393
343
|
p->selected_ = nullptr;
|
394
|
-
|
344
|
+
CancelConnectivityWatchLocked("selected subchannel failed; going IDLE");
|
395
345
|
p->channel_control_helper()->UpdateState(
|
396
|
-
GRPC_CHANNEL_IDLE,
|
397
|
-
|
346
|
+
GRPC_CHANNEL_IDLE, UniquePtr<SubchannelPicker>(New<QueuePicker>(
|
347
|
+
p->Ref(DEBUG_LOCATION, "QueuePicker"))));
|
398
348
|
} else {
|
399
349
|
// This is unlikely but can happen when a subchannel has been asked
|
400
350
|
// to reconnect by a different channel and this channel has dropped
|
@@ -405,11 +355,9 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
|
405
355
|
connected_subchannel()->Ref())));
|
406
356
|
} else { // CONNECTING
|
407
357
|
p->channel_control_helper()->UpdateState(
|
408
|
-
connectivity_state,
|
409
|
-
|
358
|
+
connectivity_state, UniquePtr<SubchannelPicker>(New<QueuePicker>(
|
359
|
+
p->Ref(DEBUG_LOCATION, "QueuePicker"))));
|
410
360
|
}
|
411
|
-
// Renew notification.
|
412
|
-
RenewConnectivityWatchLocked();
|
413
361
|
}
|
414
362
|
}
|
415
363
|
return;
|
@@ -426,13 +374,11 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
|
426
374
|
subchannel_list()->set_in_transient_failure(false);
|
427
375
|
switch (connectivity_state) {
|
428
376
|
case GRPC_CHANNEL_READY: {
|
429
|
-
// Renew notification.
|
430
|
-
RenewConnectivityWatchLocked();
|
431
377
|
ProcessUnselectedReadyLocked();
|
432
378
|
break;
|
433
379
|
}
|
434
380
|
case GRPC_CHANNEL_TRANSIENT_FAILURE: {
|
435
|
-
|
381
|
+
CancelConnectivityWatchLocked("connection attempt failed");
|
436
382
|
PickFirstSubchannelData* sd = this;
|
437
383
|
size_t next_index =
|
438
384
|
(sd->Index() + 1) % subchannel_list()->num_subchannels();
|
@@ -466,10 +412,9 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
|
|
466
412
|
if (subchannel_list() == p->subchannel_list_.get()) {
|
467
413
|
p->channel_control_helper()->UpdateState(
|
468
414
|
GRPC_CHANNEL_CONNECTING,
|
469
|
-
UniquePtr<SubchannelPicker>(
|
415
|
+
UniquePtr<SubchannelPicker>(
|
416
|
+
New<QueuePicker>(p->Ref(DEBUG_LOCATION, "QueuePicker"))));
|
470
417
|
}
|
471
|
-
// Renew notification.
|
472
|
-
RenewConnectivityWatchLocked();
|
473
418
|
break;
|
474
419
|
}
|
475
420
|
case GRPC_CHANNEL_SHUTDOWN:
|
@@ -521,12 +466,15 @@ void PickFirst::PickFirstSubchannelData::
|
|
521
466
|
// If current state is READY, select the subchannel now, since we started
|
522
467
|
// watching from this state and will not get a notification of it
|
523
468
|
// transitioning into this state.
|
524
|
-
|
525
|
-
|
469
|
+
// If the current state is not READY, attempt to connect.
|
470
|
+
if (current_state == GRPC_CHANNEL_READY) {
|
471
|
+
if (p->selected_ != this) ProcessUnselectedReadyLocked();
|
472
|
+
} else {
|
473
|
+
subchannel()->AttemptToConnect();
|
526
474
|
}
|
527
475
|
}
|
528
476
|
|
529
|
-
class ParsedPickFirstConfig : public
|
477
|
+
class ParsedPickFirstConfig : public LoadBalancingPolicy::Config {
|
530
478
|
public:
|
531
479
|
const char* name() const override { return kPickFirst; }
|
532
480
|
};
|
@@ -544,12 +492,12 @@ class PickFirstFactory : public LoadBalancingPolicyFactory {
|
|
544
492
|
|
545
493
|
const char* name() const override { return kPickFirst; }
|
546
494
|
|
547
|
-
RefCountedPtr<
|
495
|
+
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
|
548
496
|
const grpc_json* json, grpc_error** error) const override {
|
549
497
|
if (json != nullptr) {
|
550
498
|
GPR_DEBUG_ASSERT(strcmp(json->key, name()) == 0);
|
551
499
|
}
|
552
|
-
return RefCountedPtr<
|
500
|
+
return RefCountedPtr<LoadBalancingPolicy::Config>(
|
553
501
|
New<ParsedPickFirstConfig>());
|
554
502
|
}
|
555
503
|
};
|