grpc 1.28.0.pre2 → 1.28.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 +8 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +27 -3
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +291 -0
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +83 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +37 -178
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +242 -396
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +27 -5
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +27 -165
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +2 -4
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +679 -56
- data/src/core/ext/filters/client_channel/xds/xds_api.h +30 -9
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +82 -5
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +5 -1
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +273 -137
- data/src/core/ext/filters/client_channel/xds/xds_client.h +28 -12
- data/src/core/lib/gprpp/sync.h +9 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +32 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c6f5eeb248b7adaf5070f1ec2572609be8ea388f9d44bf401eca5652222227
|
4
|
+
data.tar.gz: c3ca948b522806854fd938317d77969cb73ac2f7bf2c935e58bc6421effaba11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6be5c5061065073d8898c29eeeedec50be26ae126e80e38340dbcf26708cce2f870888edfdde5e1633c66cff133dcee3707ccd7adde32635961eb36e7e5b8442
|
7
|
+
data.tar.gz: c9443ef252f58a0ff47ef6ed9a7eee391b367acf7c02a46712aa4b0eb6dcc615ff1933fe47a940e67ef17ebd9429a98c0d2802b4172df394f5ae87d016b2762f
|
data/Makefile
CHANGED
@@ -470,8 +470,8 @@ Q = @
|
|
470
470
|
endif
|
471
471
|
|
472
472
|
CORE_VERSION = 9.0.0
|
473
|
-
CPP_VERSION = 1.28.0
|
474
|
-
CSHARP_VERSION = 2.28.0
|
473
|
+
CPP_VERSION = 1.28.0
|
474
|
+
CSHARP_VERSION = 2.28.0
|
475
475
|
|
476
476
|
CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
|
477
477
|
CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
|
@@ -3690,6 +3690,7 @@ LIBALTS_TEST_UTIL_SRC = \
|
|
3690
3690
|
src/core/ext/filters/client_channel/http_connect_handshaker.cc \
|
3691
3691
|
src/core/ext/filters/client_channel/http_proxy.cc \
|
3692
3692
|
src/core/ext/filters/client_channel/lb_policy.cc \
|
3693
|
+
src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc \
|
3693
3694
|
src/core/ext/filters/client_channel/lb_policy_registry.cc \
|
3694
3695
|
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
|
3695
3696
|
src/core/ext/filters/client_channel/parse_address.cc \
|
@@ -4250,6 +4251,7 @@ LIBGRPC_SRC = \
|
|
4250
4251
|
src/core/ext/filters/client_channel/http_connect_handshaker.cc \
|
4251
4252
|
src/core/ext/filters/client_channel/http_proxy.cc \
|
4252
4253
|
src/core/ext/filters/client_channel/lb_policy.cc \
|
4254
|
+
src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc \
|
4253
4255
|
src/core/ext/filters/client_channel/lb_policy_registry.cc \
|
4254
4256
|
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
|
4255
4257
|
src/core/ext/filters/client_channel/parse_address.cc \
|
@@ -4673,6 +4675,7 @@ LIBGRPC_CRONET_SRC = \
|
|
4673
4675
|
src/core/ext/filters/client_channel/http_connect_handshaker.cc \
|
4674
4676
|
src/core/ext/filters/client_channel/http_proxy.cc \
|
4675
4677
|
src/core/ext/filters/client_channel/lb_policy.cc \
|
4678
|
+
src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc \
|
4676
4679
|
src/core/ext/filters/client_channel/lb_policy_registry.cc \
|
4677
4680
|
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
|
4678
4681
|
src/core/ext/filters/client_channel/parse_address.cc \
|
@@ -5061,6 +5064,7 @@ LIBGRPC_TEST_UTIL_SRC = \
|
|
5061
5064
|
src/core/ext/filters/client_channel/http_connect_handshaker.cc \
|
5062
5065
|
src/core/ext/filters/client_channel/http_proxy.cc \
|
5063
5066
|
src/core/ext/filters/client_channel/lb_policy.cc \
|
5067
|
+
src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc \
|
5064
5068
|
src/core/ext/filters/client_channel/lb_policy_registry.cc \
|
5065
5069
|
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
|
5066
5070
|
src/core/ext/filters/client_channel/parse_address.cc \
|
@@ -5391,6 +5395,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \
|
|
5391
5395
|
src/core/ext/filters/client_channel/http_connect_handshaker.cc \
|
5392
5396
|
src/core/ext/filters/client_channel/http_proxy.cc \
|
5393
5397
|
src/core/ext/filters/client_channel/lb_policy.cc \
|
5398
|
+
src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc \
|
5394
5399
|
src/core/ext/filters/client_channel/lb_policy_registry.cc \
|
5395
5400
|
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
|
5396
5401
|
src/core/ext/filters/client_channel/parse_address.cc \
|
@@ -5719,6 +5724,7 @@ LIBGRPC_UNSECURE_SRC = \
|
|
5719
5724
|
src/core/ext/filters/client_channel/http_connect_handshaker.cc \
|
5720
5725
|
src/core/ext/filters/client_channel/http_proxy.cc \
|
5721
5726
|
src/core/ext/filters/client_channel/lb_policy.cc \
|
5727
|
+
src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc \
|
5722
5728
|
src/core/ext/filters/client_channel/lb_policy_registry.cc \
|
5723
5729
|
src/core/ext/filters/client_channel/local_subchannel_pool.cc \
|
5724
5730
|
src/core/ext/filters/client_channel/parse_address.cc \
|
@@ -2283,10 +2283,32 @@ void CallData::FreeCachedSendOpDataForCompletedBatch(
|
|
2283
2283
|
void CallData::RecvTrailingMetadataReadyForLoadBalancingPolicy(
|
2284
2284
|
void* arg, grpc_error* error) {
|
2285
2285
|
CallData* calld = static_cast<CallData*>(arg);
|
2286
|
+
// Set error if call did not succeed.
|
2287
|
+
grpc_error* error_for_lb = GRPC_ERROR_NONE;
|
2288
|
+
if (error != GRPC_ERROR_NONE) {
|
2289
|
+
error_for_lb = error;
|
2290
|
+
} else {
|
2291
|
+
const auto& fields = calld->recv_trailing_metadata_->idx.named;
|
2292
|
+
GPR_ASSERT(fields.grpc_status != nullptr);
|
2293
|
+
grpc_status_code status =
|
2294
|
+
grpc_get_status_code_from_metadata(fields.grpc_status->md);
|
2295
|
+
std::string msg;
|
2296
|
+
if (status != GRPC_STATUS_OK) {
|
2297
|
+
error_for_lb = grpc_error_set_int(
|
2298
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("call failed"),
|
2299
|
+
GRPC_ERROR_INT_GRPC_STATUS, status);
|
2300
|
+
if (fields.grpc_message != nullptr) {
|
2301
|
+
error_for_lb = grpc_error_set_str(
|
2302
|
+
error_for_lb, GRPC_ERROR_STR_GRPC_MESSAGE,
|
2303
|
+
grpc_slice_ref_internal(GRPC_MDVALUE(fields.grpc_message->md)));
|
2304
|
+
}
|
2305
|
+
}
|
2306
|
+
}
|
2286
2307
|
// Invoke callback to LB policy.
|
2287
2308
|
Metadata trailing_metadata(calld, calld->recv_trailing_metadata_);
|
2288
|
-
calld->lb_recv_trailing_metadata_ready_(
|
2309
|
+
calld->lb_recv_trailing_metadata_ready_(error_for_lb, &trailing_metadata,
|
2289
2310
|
&calld->lb_call_state_);
|
2311
|
+
if (error == GRPC_ERROR_NONE) GRPC_ERROR_UNREF(error_for_lb);
|
2290
2312
|
// Chain to original callback.
|
2291
2313
|
Closure::Run(DEBUG_LOCATION, calld->original_recv_trailing_metadata_ready_,
|
2292
2314
|
GRPC_ERROR_REF(error));
|
@@ -3975,8 +3997,10 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem,
|
|
3975
3997
|
if (pick_queued_) RemoveCallFromQueuedPicksLocked(elem);
|
3976
3998
|
// Handle drops.
|
3977
3999
|
if (GPR_UNLIKELY(result.subchannel == nullptr)) {
|
3978
|
-
result.error =
|
3979
|
-
|
4000
|
+
result.error = grpc_error_set_int(
|
4001
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
4002
|
+
"Call dropped by load balancing policy"),
|
4003
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
|
3980
4004
|
} else {
|
3981
4005
|
// Grab a ref to the connected subchannel while we're still
|
3982
4006
|
// holding the data plane mutex.
|
@@ -0,0 +1,291 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2018 gRPC authors.
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
//
|
16
|
+
|
17
|
+
#include <grpc/support/port_platform.h>
|
18
|
+
|
19
|
+
#include <cstring>
|
20
|
+
|
21
|
+
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
|
22
|
+
|
23
|
+
#include "absl/strings/str_cat.h"
|
24
|
+
|
25
|
+
#include "src/core/ext/filters/client_channel/lb_policy_registry.h"
|
26
|
+
|
27
|
+
namespace grpc_core {
|
28
|
+
|
29
|
+
//
|
30
|
+
// ChildPolicyHandler::Helper
|
31
|
+
//
|
32
|
+
|
33
|
+
class ChildPolicyHandler::Helper
|
34
|
+
: public LoadBalancingPolicy::ChannelControlHelper {
|
35
|
+
public:
|
36
|
+
explicit Helper(RefCountedPtr<ChildPolicyHandler> parent)
|
37
|
+
: parent_(std::move(parent)) {}
|
38
|
+
|
39
|
+
~Helper() { parent_.reset(DEBUG_LOCATION, "Helper"); }
|
40
|
+
|
41
|
+
RefCountedPtr<SubchannelInterface> CreateSubchannel(
|
42
|
+
const grpc_channel_args& args) override {
|
43
|
+
if (parent_->shutting_down_) return nullptr;
|
44
|
+
if (!CalledByCurrentChild() && !CalledByPendingChild()) return nullptr;
|
45
|
+
return parent_->channel_control_helper()->CreateSubchannel(args);
|
46
|
+
}
|
47
|
+
|
48
|
+
void UpdateState(grpc_connectivity_state state,
|
49
|
+
std::unique_ptr<SubchannelPicker> picker) override {
|
50
|
+
if (parent_->shutting_down_) return;
|
51
|
+
// If this request is from the pending child policy, ignore it until
|
52
|
+
// it reports READY, at which point we swap it into place.
|
53
|
+
if (CalledByPendingChild()) {
|
54
|
+
if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
|
55
|
+
gpr_log(GPR_INFO,
|
56
|
+
"[child_policy_handler %p] helper %p: pending child policy %p "
|
57
|
+
"reports state=%s",
|
58
|
+
parent_.get(), this, child_, ConnectivityStateName(state));
|
59
|
+
}
|
60
|
+
if (state != GRPC_CHANNEL_READY) return;
|
61
|
+
grpc_pollset_set_del_pollset_set(
|
62
|
+
parent_->child_policy_->interested_parties(),
|
63
|
+
parent_->interested_parties());
|
64
|
+
parent_->child_policy_ = std::move(parent_->pending_child_policy_);
|
65
|
+
} else if (!CalledByCurrentChild()) {
|
66
|
+
// This request is from an outdated child, so ignore it.
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
parent_->channel_control_helper()->UpdateState(state, std::move(picker));
|
70
|
+
}
|
71
|
+
|
72
|
+
void RequestReresolution() override {
|
73
|
+
if (parent_->shutting_down_) return;
|
74
|
+
// Only forward re-resolution requests from the most recent child,
|
75
|
+
// since that's the one that will be receiving any update we receive
|
76
|
+
// from the resolver.
|
77
|
+
const LoadBalancingPolicy* latest_child_policy =
|
78
|
+
parent_->pending_child_policy_ != nullptr
|
79
|
+
? parent_->pending_child_policy_.get()
|
80
|
+
: parent_->child_policy_.get();
|
81
|
+
if (child_ != latest_child_policy) return;
|
82
|
+
if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
|
83
|
+
gpr_log(GPR_INFO, "[child_policy_handler %p] started name re-resolving",
|
84
|
+
parent_.get());
|
85
|
+
}
|
86
|
+
parent_->channel_control_helper()->RequestReresolution();
|
87
|
+
}
|
88
|
+
|
89
|
+
void AddTraceEvent(TraceSeverity severity, StringView message) override {
|
90
|
+
if (parent_->shutting_down_) return;
|
91
|
+
if (!CalledByPendingChild() && !CalledByCurrentChild()) return;
|
92
|
+
parent_->channel_control_helper()->AddTraceEvent(severity, message);
|
93
|
+
}
|
94
|
+
|
95
|
+
void set_child(LoadBalancingPolicy* child) { child_ = child; }
|
96
|
+
|
97
|
+
private:
|
98
|
+
bool CalledByPendingChild() const {
|
99
|
+
GPR_ASSERT(child_ != nullptr);
|
100
|
+
return child_ == parent_->pending_child_policy_.get();
|
101
|
+
}
|
102
|
+
|
103
|
+
bool CalledByCurrentChild() const {
|
104
|
+
GPR_ASSERT(child_ != nullptr);
|
105
|
+
return child_ == parent_->child_policy_.get();
|
106
|
+
};
|
107
|
+
|
108
|
+
RefCountedPtr<ChildPolicyHandler> parent_;
|
109
|
+
LoadBalancingPolicy* child_ = nullptr;
|
110
|
+
};
|
111
|
+
|
112
|
+
//
|
113
|
+
// ChildPolicyHandler
|
114
|
+
//
|
115
|
+
|
116
|
+
void ChildPolicyHandler::ShutdownLocked() {
|
117
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
118
|
+
gpr_log(GPR_INFO, "[child_policy_handler %p] shutting down", this);
|
119
|
+
}
|
120
|
+
shutting_down_ = true;
|
121
|
+
if (child_policy_ != nullptr) {
|
122
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
123
|
+
gpr_log(GPR_INFO, "[child_policy_handler %p] shutting down lb_policy %p",
|
124
|
+
this, child_policy_.get());
|
125
|
+
}
|
126
|
+
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
|
127
|
+
interested_parties());
|
128
|
+
child_policy_.reset();
|
129
|
+
}
|
130
|
+
if (pending_child_policy_ != nullptr) {
|
131
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
132
|
+
gpr_log(GPR_INFO,
|
133
|
+
"[child_policy_handler %p] shutting down pending lb_policy %p",
|
134
|
+
this, pending_child_policy_.get());
|
135
|
+
}
|
136
|
+
grpc_pollset_set_del_pollset_set(
|
137
|
+
pending_child_policy_->interested_parties(), interested_parties());
|
138
|
+
pending_child_policy_.reset();
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
void ChildPolicyHandler::UpdateLocked(UpdateArgs args) {
|
143
|
+
// If the child policy name changes, we need to create a new child
|
144
|
+
// policy. When this happens, we leave child_policy_ as-is and store
|
145
|
+
// the new child policy in pending_child_policy_. Once the new child
|
146
|
+
// policy transitions into state READY, we swap it into child_policy_,
|
147
|
+
// replacing the original child policy. So pending_child_policy_ is
|
148
|
+
// non-null only between when we apply an update that changes the child
|
149
|
+
// policy name and when the new child reports state READY.
|
150
|
+
//
|
151
|
+
// Updates can arrive at any point during this transition. We always
|
152
|
+
// apply updates relative to the most recently created child policy,
|
153
|
+
// even if the most recent one is still in pending_child_policy_. This
|
154
|
+
// is true both when applying the updates to an existing child policy
|
155
|
+
// and when determining whether we need to create a new policy.
|
156
|
+
//
|
157
|
+
// As a result of this, there are several cases to consider here:
|
158
|
+
//
|
159
|
+
// 1. We have no existing child policy (i.e., this is the first update
|
160
|
+
// we receive after being created; in this case, both child_policy_
|
161
|
+
// and pending_child_policy_ are null). In this case, we create a
|
162
|
+
// new child policy and store it in child_policy_.
|
163
|
+
//
|
164
|
+
// 2. We have an existing child policy and have no pending child policy
|
165
|
+
// from a previous update (i.e., either there has not been a
|
166
|
+
// previous update that changed the policy name, or we have already
|
167
|
+
// finished swapping in the new policy; in this case, child_policy_
|
168
|
+
// is non-null but pending_child_policy_ is null). In this case:
|
169
|
+
// a. If going from the current config to the new config does not
|
170
|
+
// require a new policy, then we update the existing child policy.
|
171
|
+
// b. If going from the current config to the new config does require a
|
172
|
+
// new policy, we create a new policy. The policy will be stored in
|
173
|
+
// pending_child_policy_ and will later be swapped into
|
174
|
+
// child_policy_ by the helper when the new child transitions
|
175
|
+
// into state READY.
|
176
|
+
//
|
177
|
+
// 3. We have an existing child policy and have a pending child policy
|
178
|
+
// from a previous update (i.e., a previous update set
|
179
|
+
// pending_child_policy_ as per case 2b above and that policy has
|
180
|
+
// not yet transitioned into state READY and been swapped into
|
181
|
+
// child_policy_; in this case, both child_policy_ and
|
182
|
+
// pending_child_policy_ are non-null). In this case:
|
183
|
+
// a. If going from the current config to the new config does not
|
184
|
+
// require a new policy, then we update the existing pending
|
185
|
+
// child policy.
|
186
|
+
// b. If going from the current config to the new config does require a
|
187
|
+
// new child policy, then we create a new policy. The new
|
188
|
+
// policy is stored in pending_child_policy_ (replacing the one
|
189
|
+
// that was there before, which will be immediately shut down)
|
190
|
+
// and will later be swapped into child_policy_ by the helper
|
191
|
+
// when the new child transitions into state READY.
|
192
|
+
const bool create_policy =
|
193
|
+
// case 1
|
194
|
+
child_policy_ == nullptr ||
|
195
|
+
// cases 2b and 3b
|
196
|
+
ConfigChangeRequiresNewPolicyInstance(current_config_.get(),
|
197
|
+
args.config.get());
|
198
|
+
current_config_ = args.config;
|
199
|
+
LoadBalancingPolicy* policy_to_update = nullptr;
|
200
|
+
if (create_policy) {
|
201
|
+
// Cases 1, 2b, and 3b: create a new child policy.
|
202
|
+
// If child_policy_ is null, we set it (case 1), else we set
|
203
|
+
// pending_child_policy_ (cases 2b and 3b).
|
204
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
205
|
+
gpr_log(GPR_INFO,
|
206
|
+
"[child_policy_handler %p] creating new %schild policy %s", this,
|
207
|
+
child_policy_ == nullptr ? "" : "pending ", args.config->name());
|
208
|
+
}
|
209
|
+
auto& lb_policy =
|
210
|
+
child_policy_ == nullptr ? child_policy_ : pending_child_policy_;
|
211
|
+
lb_policy = CreateChildPolicy(args.config->name(), *args.args);
|
212
|
+
policy_to_update = lb_policy.get();
|
213
|
+
} else {
|
214
|
+
// Cases 2a and 3a: update an existing policy.
|
215
|
+
// If we have a pending child policy, send the update to the pending
|
216
|
+
// policy (case 3a), else send it to the current policy (case 2a).
|
217
|
+
policy_to_update = pending_child_policy_ != nullptr
|
218
|
+
? pending_child_policy_.get()
|
219
|
+
: child_policy_.get();
|
220
|
+
}
|
221
|
+
GPR_ASSERT(policy_to_update != nullptr);
|
222
|
+
// Update the policy.
|
223
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
224
|
+
gpr_log(GPR_INFO, "[child_policy_handler %p] updating %schild policy %p",
|
225
|
+
this,
|
226
|
+
policy_to_update == pending_child_policy_.get() ? "pending " : "",
|
227
|
+
policy_to_update);
|
228
|
+
}
|
229
|
+
policy_to_update->UpdateLocked(std::move(args));
|
230
|
+
}
|
231
|
+
|
232
|
+
void ChildPolicyHandler::ExitIdleLocked() {
|
233
|
+
if (child_policy_ != nullptr) {
|
234
|
+
child_policy_->ExitIdleLocked();
|
235
|
+
if (pending_child_policy_ != nullptr) {
|
236
|
+
pending_child_policy_->ExitIdleLocked();
|
237
|
+
}
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
void ChildPolicyHandler::ResetBackoffLocked() {
|
242
|
+
if (child_policy_ != nullptr) {
|
243
|
+
child_policy_->ResetBackoffLocked();
|
244
|
+
if (pending_child_policy_ != nullptr) {
|
245
|
+
pending_child_policy_->ResetBackoffLocked();
|
246
|
+
}
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
OrphanablePtr<LoadBalancingPolicy> ChildPolicyHandler::CreateChildPolicy(
|
251
|
+
const char* child_policy_name, const grpc_channel_args& args) {
|
252
|
+
Helper* helper = new Helper(Ref(DEBUG_LOCATION, "Helper"));
|
253
|
+
LoadBalancingPolicy::Args lb_policy_args;
|
254
|
+
lb_policy_args.combiner = combiner();
|
255
|
+
lb_policy_args.channel_control_helper =
|
256
|
+
std::unique_ptr<ChannelControlHelper>(helper);
|
257
|
+
lb_policy_args.args = &args;
|
258
|
+
OrphanablePtr<LoadBalancingPolicy> lb_policy =
|
259
|
+
CreateLoadBalancingPolicy(child_policy_name, std::move(lb_policy_args));
|
260
|
+
if (GPR_UNLIKELY(lb_policy == nullptr)) {
|
261
|
+
gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", child_policy_name);
|
262
|
+
return nullptr;
|
263
|
+
}
|
264
|
+
helper->set_child(lb_policy.get());
|
265
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
|
266
|
+
gpr_log(GPR_INFO,
|
267
|
+
"[child_policy_handler %p] created new LB policy \"%s\" (%p)", this,
|
268
|
+
child_policy_name, lb_policy.get());
|
269
|
+
}
|
270
|
+
channel_control_helper()->AddTraceEvent(
|
271
|
+
ChannelControlHelper::TRACE_INFO,
|
272
|
+
absl::StrCat("Created new LB policy \"", child_policy_name, "\""));
|
273
|
+
grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
|
274
|
+
interested_parties());
|
275
|
+
return lb_policy;
|
276
|
+
}
|
277
|
+
|
278
|
+
bool ChildPolicyHandler::ConfigChangeRequiresNewPolicyInstance(
|
279
|
+
LoadBalancingPolicy::Config* old_config,
|
280
|
+
LoadBalancingPolicy::Config* new_config) const {
|
281
|
+
return strcmp(old_config->name(), new_config->name()) != 0;
|
282
|
+
}
|
283
|
+
|
284
|
+
OrphanablePtr<LoadBalancingPolicy>
|
285
|
+
ChildPolicyHandler::CreateLoadBalancingPolicy(
|
286
|
+
const char* name, LoadBalancingPolicy::Args args) const {
|
287
|
+
return LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
|
288
|
+
name, std::move(args));
|
289
|
+
}
|
290
|
+
|
291
|
+
} // namespace grpc_core
|
@@ -0,0 +1,83 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2018 gRPC authors.
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
//
|
16
|
+
|
17
|
+
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H
|
18
|
+
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H
|
19
|
+
|
20
|
+
#include <grpc/support/port_platform.h>
|
21
|
+
|
22
|
+
#include "src/core/ext/filters/client_channel/lb_policy.h"
|
23
|
+
#include "src/core/lib/debug/trace.h"
|
24
|
+
#include "src/core/lib/gprpp/orphanable.h"
|
25
|
+
|
26
|
+
namespace grpc_core {
|
27
|
+
|
28
|
+
// A class that makes it easy to gracefully switch child policies.
|
29
|
+
//
|
30
|
+
// Callers should instantiate this instead of using
|
31
|
+
// LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(). Once
|
32
|
+
// instantiated, this object will automatically take care of
|
33
|
+
// constructing the child policy as needed upon receiving an update.
|
34
|
+
class ChildPolicyHandler : public LoadBalancingPolicy {
|
35
|
+
public:
|
36
|
+
ChildPolicyHandler(Args args, TraceFlag* tracer)
|
37
|
+
: LoadBalancingPolicy(std::move(args)), tracer_(tracer) {}
|
38
|
+
|
39
|
+
virtual const char* name() const override { return "child_policy_handler"; }
|
40
|
+
|
41
|
+
void UpdateLocked(UpdateArgs args) override;
|
42
|
+
void ExitIdleLocked() override;
|
43
|
+
void ResetBackoffLocked() override;
|
44
|
+
|
45
|
+
// Returns true if transitioning from the old config to the new config
|
46
|
+
// requires instantiating a new policy object.
|
47
|
+
virtual bool ConfigChangeRequiresNewPolicyInstance(
|
48
|
+
LoadBalancingPolicy::Config* old_config,
|
49
|
+
LoadBalancingPolicy::Config* new_config) const;
|
50
|
+
|
51
|
+
// Instantiates a new policy of the specified name.
|
52
|
+
// May be overridden by subclasses to avoid recursion when an LB
|
53
|
+
// policy factory returns a ChildPolicyHandler.
|
54
|
+
virtual OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
|
55
|
+
const char* name, LoadBalancingPolicy::Args args) const;
|
56
|
+
|
57
|
+
private:
|
58
|
+
class Helper;
|
59
|
+
|
60
|
+
void ShutdownLocked() override;
|
61
|
+
|
62
|
+
OrphanablePtr<LoadBalancingPolicy> CreateChildPolicy(
|
63
|
+
const char* child_policy_name, const grpc_channel_args& args);
|
64
|
+
|
65
|
+
// Passed in from caller at construction time.
|
66
|
+
TraceFlag* tracer_;
|
67
|
+
|
68
|
+
bool shutting_down_ = false;
|
69
|
+
|
70
|
+
// The most recent config passed to UpdateLocked().
|
71
|
+
// If pending_child_policy_ is non-null, this is the config passed to
|
72
|
+
// pending_child_policy_; otherwise, it's the config passed to child_policy_.
|
73
|
+
RefCountedPtr<LoadBalancingPolicy::Config> current_config_;
|
74
|
+
|
75
|
+
// Child LB policy.
|
76
|
+
OrphanablePtr<LoadBalancingPolicy> child_policy_;
|
77
|
+
OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
|
78
|
+
};
|
79
|
+
|
80
|
+
} // namespace grpc_core
|
81
|
+
|
82
|
+
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_CHILD_POLICY_HANDLER_H \
|
83
|
+
*/
|