|
|
@ -42,6 +42,7 @@ |
|
|
|
#include <grpc/support/sync.h> |
|
|
|
#include <grpc/support/sync.h> |
|
|
|
#include <grpc/support/useful.h> |
|
|
|
#include <grpc/support/useful.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/ext/client_config/lb_policy_registry.h" |
|
|
|
#include "src/core/ext/client_config/subchannel.h" |
|
|
|
#include "src/core/ext/client_config/subchannel.h" |
|
|
|
#include "src/core/lib/channel/channel_args.h" |
|
|
|
#include "src/core/lib/channel/channel_args.h" |
|
|
|
#include "src/core/lib/channel/connected_channel.h" |
|
|
|
#include "src/core/lib/channel/connected_channel.h" |
|
|
@ -63,6 +64,8 @@ typedef struct client_channel_channel_data { |
|
|
|
grpc_resolver *resolver; |
|
|
|
grpc_resolver *resolver; |
|
|
|
/** have we started resolving this channel */ |
|
|
|
/** have we started resolving this channel */ |
|
|
|
bool started_resolving; |
|
|
|
bool started_resolving; |
|
|
|
|
|
|
|
/** client channel factory */ |
|
|
|
|
|
|
|
grpc_client_channel_factory *client_channel_factory; |
|
|
|
|
|
|
|
|
|
|
|
/** mutex protecting client configuration, including all
|
|
|
|
/** mutex protecting client configuration, including all
|
|
|
|
variables below in this data structure */ |
|
|
|
variables below in this data structure */ |
|
|
@ -173,19 +176,25 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); |
|
|
|
grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); |
|
|
|
|
|
|
|
|
|
|
|
if (chand->resolver_result != NULL) { |
|
|
|
if (chand->resolver_result != NULL) { |
|
|
|
lb_policy = grpc_resolver_result_get_lb_policy(chand->resolver_result); |
|
|
|
grpc_lb_policy_args lb_policy_args; |
|
|
|
|
|
|
|
lb_policy_args.addresses = |
|
|
|
|
|
|
|
grpc_resolver_result_get_addresses(chand->resolver_result); |
|
|
|
|
|
|
|
lb_policy_args.additional_args = |
|
|
|
|
|
|
|
grpc_resolver_result_get_lb_policy_args(chand->resolver_result); |
|
|
|
|
|
|
|
lb_policy_args.client_channel_factory = chand->client_channel_factory; |
|
|
|
|
|
|
|
lb_policy = grpc_lb_policy_create( |
|
|
|
|
|
|
|
exec_ctx, |
|
|
|
|
|
|
|
grpc_resolver_result_get_lb_policy_name(chand->resolver_result), |
|
|
|
|
|
|
|
&lb_policy_args); |
|
|
|
if (lb_policy != NULL) { |
|
|
|
if (lb_policy != NULL) { |
|
|
|
GRPC_LB_POLICY_REF(lb_policy, "channel"); |
|
|
|
|
|
|
|
GRPC_LB_POLICY_REF(lb_policy, "config_change"); |
|
|
|
GRPC_LB_POLICY_REF(lb_policy, "config_change"); |
|
|
|
GRPC_ERROR_UNREF(state_error); |
|
|
|
GRPC_ERROR_UNREF(state_error); |
|
|
|
state = |
|
|
|
state = |
|
|
|
grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); |
|
|
|
grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_resolver_result_unref(exec_ctx, chand->resolver_result); |
|
|
|
grpc_resolver_result_unref(exec_ctx, chand->resolver_result); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chand->resolver_result = NULL; |
|
|
|
chand->resolver_result = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (lb_policy != NULL) { |
|
|
|
if (lb_policy != NULL) { |
|
|
|
grpc_pollset_set_add_pollset_set(exec_ctx, lb_policy->interested_parties, |
|
|
|
grpc_pollset_set_add_pollset_set(exec_ctx, lb_policy->interested_parties, |
|
|
@ -346,6 +355,9 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, |
|
|
|
grpc_resolver_shutdown(exec_ctx, chand->resolver); |
|
|
|
grpc_resolver_shutdown(exec_ctx, chand->resolver); |
|
|
|
GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); |
|
|
|
GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (chand->client_channel_factory != NULL) { |
|
|
|
|
|
|
|
grpc_client_channel_factory_unref(exec_ctx, chand->client_channel_factory); |
|
|
|
|
|
|
|
} |
|
|
|
if (chand->lb_policy != NULL) { |
|
|
|
if (chand->lb_policy != NULL) { |
|
|
|
grpc_pollset_set_del_pollset_set(exec_ctx, |
|
|
|
grpc_pollset_set_del_pollset_set(exec_ctx, |
|
|
|
chand->lb_policy->interested_parties, |
|
|
|
chand->lb_policy->interested_parties, |
|
|
@ -767,10 +779,12 @@ const grpc_channel_filter grpc_client_channel_filter = { |
|
|
|
"client-channel", |
|
|
|
"client-channel", |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void grpc_client_channel_set_resolver(grpc_exec_ctx *exec_ctx, |
|
|
|
void grpc_client_channel_finish_initialization( |
|
|
|
grpc_channel_stack *channel_stack, |
|
|
|
grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, |
|
|
|
grpc_resolver *resolver) { |
|
|
|
grpc_resolver *resolver, |
|
|
|
|
|
|
|
grpc_client_channel_factory *client_channel_factory) { |
|
|
|
/* post construction initialization: set the transport setup pointer */ |
|
|
|
/* post construction initialization: set the transport setup pointer */ |
|
|
|
|
|
|
|
GPR_ASSERT(client_channel_factory != NULL); |
|
|
|
grpc_channel_element *elem = grpc_channel_stack_last_element(channel_stack); |
|
|
|
grpc_channel_element *elem = grpc_channel_stack_last_element(channel_stack); |
|
|
|
channel_data *chand = elem->channel_data; |
|
|
|
channel_data *chand = elem->channel_data; |
|
|
|
gpr_mu_lock(&chand->mu); |
|
|
|
gpr_mu_lock(&chand->mu); |
|
|
@ -784,6 +798,8 @@ void grpc_client_channel_set_resolver(grpc_exec_ctx *exec_ctx, |
|
|
|
grpc_resolver_next(exec_ctx, resolver, &chand->resolver_result, |
|
|
|
grpc_resolver_next(exec_ctx, resolver, &chand->resolver_result, |
|
|
|
&chand->on_resolver_result_changed); |
|
|
|
&chand->on_resolver_result_changed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
chand->client_channel_factory = client_channel_factory; |
|
|
|
|
|
|
|
grpc_client_channel_factory_ref(client_channel_factory); |
|
|
|
gpr_mu_unlock(&chand->mu); |
|
|
|
gpr_mu_unlock(&chand->mu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|