Skip to content
Snippets Groups Projects
Commit f75d2692 authored by Mark D. Roth's avatar Mark D. Roth
Browse files

Fix grpclb code.

parent c217e490
No related branches found
No related tags found
No related merge requests found
...@@ -818,9 +818,15 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, ...@@ -818,9 +818,15 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx,
* We need the LB channel to return addresses with is_balancer=false * We need the LB channel to return addresses with is_balancer=false
* so that it does not wind up recursively using the grpclb LB policy, * so that it does not wind up recursively using the grpclb LB policy,
* as per the special case logic in client_channel.c. * as per the special case logic in client_channel.c.
*
* Finally, we also strip out the channel arg for the server URI,
* since that will be different for the LB channel than for the parent
* channel. (The client channel factory will re-add this arg with
* the right value.)
*/ */
static const char *keys_to_remove[] = {GRPC_ARG_LB_POLICY_NAME, static const char *keys_to_remove[] = {GRPC_ARG_LB_POLICY_NAME,
GRPC_ARG_LB_ADDRESSES}; GRPC_ARG_LB_ADDRESSES,
GRPC_ARG_SERVER_URI};
grpc_channel_args *new_args = grpc_channel_args_copy_and_remove( grpc_channel_args *new_args = grpc_channel_args_copy_and_remove(
args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove)); args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove));
glb_policy->lb_channel = grpc_client_channel_factory_create_channel( glb_policy->lb_channel = grpc_client_channel_factory_create_channel(
......
...@@ -65,7 +65,16 @@ static grpc_channel *client_channel_factory_create_channel( ...@@ -65,7 +65,16 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const char *target, grpc_client_channel_type type, const char *target, grpc_client_channel_type type,
const grpc_channel_args *args) { const grpc_channel_args *args) {
return grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); // Add channel arg containing the server URI.
grpc_arg arg;
arg.type = GRPC_ARG_STRING;
arg.key = GRPC_ARG_SERVER_URI;
arg.value.string = (char *)target;
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
GRPC_CLIENT_CHANNEL, NULL);
grpc_channel_args_destroy(new_args);
return channel;
} }
static const grpc_client_channel_factory_vtable client_channel_factory_vtable = static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
...@@ -90,19 +99,14 @@ grpc_channel *grpc_insecure_channel_create(const char *target, ...@@ -90,19 +99,14 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
GPR_ASSERT(reserved == NULL); GPR_ASSERT(reserved == NULL);
grpc_client_channel_factory *factory = grpc_client_channel_factory *factory =
(grpc_client_channel_factory *)&client_channel_factory; (grpc_client_channel_factory *)&client_channel_factory;
// Add channel args containing the server name and client channel factory. // Add channel arg containing the client channel factory.
grpc_arg new_args[2]; grpc_arg arg = grpc_client_channel_factory_create_channel_arg(factory);
new_args[0].type = GRPC_ARG_STRING; grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
new_args[0].key = GRPC_ARG_SERVER_URI;
new_args[0].value.string = (char *)target;
new_args[1] = grpc_client_channel_factory_create_channel_arg(factory);
grpc_channel_args *args_copy =
grpc_channel_args_copy_and_add(args, new_args, GPR_ARRAY_SIZE(new_args));
// Create channel. // Create channel.
grpc_channel *channel = client_channel_factory_create_channel( grpc_channel *channel = client_channel_factory_create_channel(
&exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args_copy); &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
// Clean up. // Clean up.
grpc_channel_args_destroy(args_copy); grpc_channel_args_destroy(new_args);
grpc_client_channel_factory_unref(&exec_ctx, factory); grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
return channel != NULL ? channel : grpc_lame_client_channel_create( return channel != NULL ? channel : grpc_lame_client_channel_create(
......
...@@ -89,7 +89,16 @@ static grpc_channel *client_channel_factory_create_channel( ...@@ -89,7 +89,16 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const char *target, grpc_client_channel_type type, const char *target, grpc_client_channel_type type,
const grpc_channel_args *args) { const grpc_channel_args *args) {
return grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); // Add channel arg containing the server URI.
grpc_arg arg;
arg.type = GRPC_ARG_STRING;
arg.key = GRPC_ARG_SERVER_URI;
arg.value.string = (char *)target;
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
GRPC_CLIENT_CHANNEL, NULL);
grpc_channel_args_destroy(new_args);
return channel;
} }
static const grpc_client_channel_factory_vtable client_channel_factory_vtable = static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
...@@ -137,14 +146,11 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, ...@@ -137,14 +146,11 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
GRPC_SECURITY_CONNECTOR_REF(&security_connector->base, GRPC_SECURITY_CONNECTOR_REF(&security_connector->base,
"grpc_secure_channel_create"); "grpc_secure_channel_create");
f->security_connector = security_connector; f->security_connector = security_connector;
// Add channel args containing the server name, client channel // Add channel args containing the client channel factory and security
// factory, and security connector. // connector.
grpc_arg new_args[3]; grpc_arg new_args[2];
new_args[0].type = GRPC_ARG_STRING; new_args[0] = grpc_client_channel_factory_create_channel_arg(&f->base);
new_args[0].key = GRPC_ARG_SERVER_URI; new_args[1] = grpc_security_connector_to_arg(&security_connector->base);
new_args[0].value.string = (char *)target;
new_args[1] = grpc_client_channel_factory_create_channel_arg(&f->base);
new_args[2] = grpc_security_connector_to_arg(&security_connector->base);
grpc_channel_args *args_copy = grpc_channel_args_copy_and_add( grpc_channel_args *args_copy = grpc_channel_args_copy_and_add(
new_args_from_connector != NULL ? new_args_from_connector : args, new_args_from_connector != NULL ? new_args_from_connector : args,
new_args, GPR_ARRAY_SIZE(new_args)); new_args, GPR_ARRAY_SIZE(new_args));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment