From 98abfd3d64d6a887f56f3dd78eec6c32bde369df Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 21 Oct 2016 08:10:51 -0700 Subject: Pass channel args through resolver. --- src/core/ext/client_config/client_channel.c | 6 +- src/core/ext/client_config/lb_policy_factory.h | 3 +- src/core/ext/client_config/resolver_factory.h | 5 +- src/core/ext/client_config/resolver_registry.c | 12 ++-- src/core/ext/client_config/resolver_registry.h | 3 +- src/core/ext/client_config/resolver_result.c | 12 ++-- src/core/ext/client_config/resolver_result.h | 6 +- src/core/ext/lb_policy/grpclb/grpclb.c | 6 +- src/core/ext/lb_policy/pick_first/pick_first.c | 2 +- src/core/ext/lb_policy/round_robin/round_robin.c | 2 +- src/core/ext/resolver/dns/native/dns_resolver.c | 10 +++- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 6 +- .../chttp2/client/insecure/channel_create.c | 57 +++++++------------ .../chttp2/client/secure/secure_channel_create.c | 66 +++++++++------------- 14 files changed, 91 insertions(+), 105 deletions(-) diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index beaa9637c3..d02dd5aacf 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -188,8 +188,8 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_resolver_result_get_server_name(chand->resolver_result); 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.args = + grpc_resolver_result_get_channel_args(chand->resolver_result); lb_policy_args.client_channel_factory = chand->client_channel_factory; // Special case: If all of the addresses are balancer addresses, @@ -227,7 +227,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); } const grpc_arg *channel_arg = grpc_channel_args_find( - lb_policy_args.additional_args, GRPC_ARG_SERVICE_CONFIG); + lb_policy_args.args, GRPC_ARG_SERVICE_CONFIG); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); method_config_table = grpc_method_config_table_ref( diff --git a/src/core/ext/client_config/lb_policy_factory.h b/src/core/ext/client_config/lb_policy_factory.h index ade55704f2..4e11501e01 100644 --- a/src/core/ext/client_config/lb_policy_factory.h +++ b/src/core/ext/client_config/lb_policy_factory.h @@ -93,8 +93,7 @@ typedef struct grpc_lb_policy_args { const char *server_name; grpc_lb_addresses *addresses; grpc_client_channel_factory *client_channel_factory; - /* Can be used to pass implementation-specific parameters to the LB policy. */ - grpc_channel_args *additional_args; + grpc_channel_args *args; } grpc_lb_policy_args; struct grpc_lb_policy_factory_vtable { diff --git a/src/core/ext/client_config/resolver_factory.h b/src/core/ext/client_config/resolver_factory.h index 9ec5b9a70e..e70e056577 100644 --- a/src/core/ext/client_config/resolver_factory.h +++ b/src/core/ext/client_config/resolver_factory.h @@ -47,7 +47,10 @@ struct grpc_resolver_factory { const grpc_resolver_factory_vtable *vtable; }; -typedef struct grpc_resolver_args { grpc_uri *uri; } grpc_resolver_args; +typedef struct grpc_resolver_args { + grpc_uri *uri; + const grpc_channel_args *args; +} grpc_resolver_args; struct grpc_resolver_factory_vtable { void (*ref)(grpc_resolver_factory *factory); diff --git a/src/core/ext/client_config/resolver_registry.c b/src/core/ext/client_config/resolver_registry.c index bd5c683878..0a168efbc9 100644 --- a/src/core/ext/client_config/resolver_registry.c +++ b/src/core/ext/client_config/resolver_registry.c @@ -131,14 +131,16 @@ static grpc_resolver_factory *resolve_factory(const char *target, return factory; } -grpc_resolver *grpc_resolver_create(const char *target) { +grpc_resolver *grpc_resolver_create(const char *target, + const grpc_channel_args *args) { grpc_uri *uri = NULL; grpc_resolver_factory *factory = resolve_factory(target, &uri); grpc_resolver *resolver; - grpc_resolver_args args; - memset(&args, 0, sizeof(args)); - args.uri = uri; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + grpc_resolver_args resolver_args; + memset(&resolver_args, 0, sizeof(resolver_args)); + resolver_args.uri = uri; + resolver_args.args = args; + resolver = grpc_resolver_factory_create_resolver(factory, &resolver_args); grpc_uri_destroy(uri); return resolver; } diff --git a/src/core/ext/client_config/resolver_registry.h b/src/core/ext/client_config/resolver_registry.h index 4c6279b978..dfe95b4a11 100644 --- a/src/core/ext/client_config/resolver_registry.h +++ b/src/core/ext/client_config/resolver_registry.h @@ -58,7 +58,8 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory); If a resolver factory was found, use it to instantiate a resolver and return it. If a resolver factory was not found, return NULL. */ -grpc_resolver *grpc_resolver_create(const char *target); +grpc_resolver *grpc_resolver_create(const char *target, + const grpc_channel_args* args); /** Find a resolver factory given a name and return an (owned-by-the-caller) * reference to it */ diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c index 63480d152b..5f3600e7d9 100644 --- a/src/core/ext/client_config/resolver_result.c +++ b/src/core/ext/client_config/resolver_result.c @@ -43,19 +43,19 @@ struct grpc_resolver_result { char* server_name; grpc_lb_addresses* addresses; char* lb_policy_name; - grpc_channel_args* lb_policy_args; + grpc_channel_args* channel_args; }; grpc_resolver_result* grpc_resolver_result_create( const char* server_name, grpc_lb_addresses* addresses, - const char* lb_policy_name, grpc_channel_args* lb_policy_args) { + const char* lb_policy_name, grpc_channel_args* args) { grpc_resolver_result* result = gpr_malloc(sizeof(*result)); memset(result, 0, sizeof(*result)); gpr_ref_init(&result->refs, 1); result->server_name = gpr_strdup(server_name); result->addresses = addresses; result->lb_policy_name = gpr_strdup(lb_policy_name); - result->lb_policy_args = lb_policy_args; + result->channel_args = args; return result; } @@ -69,7 +69,7 @@ void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, gpr_free(result->server_name); grpc_lb_addresses_destroy(result->addresses, NULL /* user_data_destroy */); gpr_free(result->lb_policy_name); - grpc_channel_args_destroy(result->lb_policy_args); + grpc_channel_args_destroy(result->channel_args); gpr_free(result); } } @@ -88,7 +88,7 @@ const char* grpc_resolver_result_get_lb_policy_name( return result->lb_policy_name; } -grpc_channel_args* grpc_resolver_result_get_lb_policy_args( +grpc_channel_args* grpc_resolver_result_get_channel_args( grpc_resolver_result* result) { - return result->lb_policy_args; + return result->channel_args; } diff --git a/src/core/ext/client_config/resolver_result.h b/src/core/ext/client_config/resolver_result.h index a7ea7c0f4b..f081c0448a 100644 --- a/src/core/ext/client_config/resolver_result.h +++ b/src/core/ext/client_config/resolver_result.h @@ -48,10 +48,10 @@ /// Results reported from a grpc_resolver. typedef struct grpc_resolver_result grpc_resolver_result; -/// Takes ownership of \a addresses and \a lb_policy_args. +/// Takes ownership of \a addresses and \a args. grpc_resolver_result* grpc_resolver_result_create( const char* server_name, grpc_lb_addresses* addresses, - const char* lb_policy_name, grpc_channel_args* lb_policy_args); + const char* lb_policy_name, grpc_channel_args* args); void grpc_resolver_result_ref(grpc_resolver_result* result); void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, @@ -63,7 +63,7 @@ grpc_lb_addresses* grpc_resolver_result_get_addresses( grpc_resolver_result* result); const char* grpc_resolver_result_get_lb_policy_name( grpc_resolver_result* result); -grpc_channel_args* grpc_resolver_result_get_lb_policy_args( +grpc_channel_args* grpc_resolver_result_get_channel_args( grpc_resolver_result* result); #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index b24b522449..663f1d3300 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -459,7 +459,7 @@ static grpc_lb_policy *create_rr_locked( args.server_name = glb_policy->server_name; args.client_channel_factory = glb_policy->cc_factory; args.addresses = process_serverlist(serverlist); - args.additional_args = glb_policy->args; + args.args = glb_policy->args; grpc_lb_policy *rr = grpc_lb_policy_create(exec_ctx, "round_robin", &args); @@ -587,7 +587,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, * Create a client channel over them to communicate with a LB service */ glb_policy->server_name = gpr_strdup(args->server_name); glb_policy->cc_factory = args->client_channel_factory; - glb_policy->args = grpc_channel_args_copy(args->additional_args); + glb_policy->args = grpc_channel_args_copy(args->args); GPR_ASSERT(glb_policy->cc_factory != NULL); /* construct a target from the addresses in args, given in the form @@ -621,7 +621,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, /* will pick using pick_first */ glb_policy->lb_channel = grpc_client_channel_factory_create_channel( exec_ctx, glb_policy->cc_factory, target_uri_str, - GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, NULL); + GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, args->args); gpr_free(target_uri_str); for (size_t i = 0; i < num_grpclb_addrs; i++) { diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index da20b9281b..3683079cf4 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -466,7 +466,7 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, sc_args.addr = (struct sockaddr *)(&args->addresses->addresses[i].address.addr); sc_args.addr_len = args->addresses->addresses[i].address.len; - sc_args.args = args->additional_args; + sc_args.args = args->args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index b8f4f67aeb..00a18974df 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -629,7 +629,7 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, sc_args.addr = (struct sockaddr *)(&args->addresses->addresses[i].address.addr); sc_args.addr_len = args->addresses->addresses[i].address.len; - sc_args.args = args->additional_args; + sc_args.args = args->args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index fa33ffd7bd..a4f6ed8c4e 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -40,6 +40,7 @@ #include "src/core/ext/client_config/http_connect_handshaker.h" #include "src/core/ext/client_config/lb_policy_registry.h" #include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/support/backoff.h" @@ -59,6 +60,8 @@ typedef struct { char *name_to_resolve; /** default port to use */ char *default_port; + /** channel args. */ + grpc_channel_args *channel_args; /** mutex guarding the rest of the state */ gpr_mu mu; @@ -176,8 +179,9 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, NULL /* balancer_name */, NULL /* user_data */); } grpc_resolved_addresses_destroy(r->addresses); - result = grpc_resolver_result_create(r->target_name, addresses, - NULL /* lb_policy_name */, NULL); + result = grpc_resolver_result_create( + r->target_name, addresses, NULL /* lb_policy_name */, + grpc_channel_args_copy(r->channel_args)); } else { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); @@ -241,6 +245,7 @@ static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { gpr_free(r->target_name); gpr_free(r->name_to_resolve); gpr_free(r->default_port); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } @@ -263,6 +268,7 @@ static grpc_resolver *dns_create(grpc_resolver_args *args, r->target_name = gpr_strdup(path); r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name; r->default_port = gpr_strdup(default_port); + r->channel_args = grpc_channel_args_copy(args->args); gpr_backoff_init(&r->backoff_state, BACKOFF_MULTIPLIER, BACKOFF_JITTER, BACKOFF_MIN_SECONDS * 1000, BACKOFF_MAX_SECONDS * 1000); return &r->base; diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index 28dd2569e8..eaaa2e47c2 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -55,6 +55,8 @@ typedef struct { char *target_name; /** the addresses that we've 'resolved' */ grpc_lb_addresses *addresses; + /** channel args */ + grpc_channel_args *channel_args; /** mutex guarding the rest of the state */ gpr_mu mu; /** have we published? */ @@ -121,7 +123,7 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, *r->target_result = grpc_resolver_result_create( r->target_name, grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */), - NULL /* lb_policy_name */, NULL /* lb_policy_args */); + NULL /* lb_policy_name */, grpc_channel_args_copy(r->channel_args)); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } @@ -132,6 +134,7 @@ static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { gpr_mu_destroy(&r->mu); gpr_free(r->target_name); grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } @@ -201,6 +204,7 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, memset(r, 0, sizeof(*r)); r->target_name = gpr_strdup(args->uri->path); r->addresses = addresses; + r->channel_args = grpc_channel_args_copy(args->args); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &sockaddr_resolver_vtable); return &r->base; diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c index c2b59569fd..df1bb16166 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -52,6 +52,10 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/channel.h" +// +// connector +// + typedef struct { grpc_connector base; gpr_refcount refs; @@ -157,35 +161,20 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con, static const grpc_connector_vtable connector_vtable = { connector_ref, connector_unref, connector_shutdown, connector_connect}; -typedef struct { - grpc_client_channel_factory base; - gpr_refcount refs; - grpc_channel_args *merge_args; -} client_channel_factory; +// +// client_channel_factory +// static void client_channel_factory_ref( - grpc_client_channel_factory *cc_factory) { - client_channel_factory *f = (client_channel_factory *)cc_factory; - gpr_ref(&f->refs); -} + grpc_client_channel_factory *cc_factory) {} static void client_channel_factory_unref( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) { - client_channel_factory *f = (client_channel_factory *)cc_factory; - if (gpr_unref(&f->refs)) { - grpc_channel_args_destroy(f->merge_args); - gpr_free(f); - } -} + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {} static grpc_subchannel *client_channel_factory_create_subchannel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, grpc_subchannel_args *args) { - client_channel_factory *f = (client_channel_factory *)cc_factory; connector *c = gpr_malloc(sizeof(*c)); - grpc_channel_args *final_args = - grpc_channel_args_merge(args->args, f->merge_args); - grpc_subchannel *s; memset(c, 0, sizeof(*c)); c->base.vtable = &connector_vtable; gpr_ref_init(&c->refs, 1); @@ -197,10 +186,8 @@ static grpc_subchannel *client_channel_factory_create_subchannel( grpc_http_connect_handshaker_create(proxy_name, args->server_name)); gpr_free(proxy_name); } - args->args = final_args; - s = grpc_subchannel_create(exec_ctx, &c->base, args); + grpc_subchannel *s = grpc_subchannel_create(exec_ctx, &c->base, args); grpc_connector_unref(exec_ctx, &c->base); - grpc_channel_args_destroy(final_args); return s; } @@ -208,12 +195,9 @@ static grpc_channel *client_channel_factory_create_channel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, const char *target, grpc_client_channel_type type, grpc_channel_args *args) { - client_channel_factory *f = (client_channel_factory *)cc_factory; - grpc_channel_args *final_args = grpc_channel_args_merge(args, f->merge_args); - grpc_channel *channel = grpc_channel_create(exec_ctx, target, final_args, + grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); - grpc_channel_args_destroy(final_args); - grpc_resolver *resolver = grpc_resolver_create(target); + grpc_resolver *resolver = grpc_resolver_create(target, args); if (!resolver) { GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "client_channel_factory_create_channel"); @@ -221,7 +205,7 @@ static grpc_channel *client_channel_factory_create_channel( } grpc_client_channel_finish_initialization( - exec_ctx, grpc_channel_get_channel_stack(channel), resolver, &f->base); + exec_ctx, grpc_channel_get_channel_stack(channel), resolver, cc_factory); GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create_channel"); return channel; @@ -232,6 +216,9 @@ static const grpc_client_channel_factory_vtable client_channel_factory_vtable = client_channel_factory_create_subchannel, client_channel_factory_create_channel}; +static grpc_client_channel_factory client_channel_factory = { + &client_channel_factory_vtable}; + /* Create a client channel: Asynchronously: - resolve target - connect to it (trying alternatives as presented) @@ -245,16 +232,12 @@ grpc_channel *grpc_insecure_channel_create(const char *target, (target, args, reserved)); GPR_ASSERT(!reserved); - client_channel_factory *f = gpr_malloc(sizeof(*f)); - memset(f, 0, sizeof(*f)); - f->base.vtable = &client_channel_factory_vtable; - gpr_ref_init(&f->refs, 1); - f->merge_args = grpc_channel_args_copy(args); - + grpc_client_channel_factory *factory = + (grpc_client_channel_factory*)&client_channel_factory; grpc_channel *channel = client_channel_factory_create_channel( - &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL); + &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL); - grpc_client_channel_factory_unref(&exec_ctx, &f->base); + grpc_client_channel_factory_unref(&exec_ctx, factory); grpc_exec_ctx_finish(&exec_ctx); return channel != NULL ? channel : grpc_lame_client_channel_create( diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index 31c54ff74c..ac0a929de6 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -54,6 +54,10 @@ #include "src/core/lib/surface/channel.h" #include "src/core/lib/tsi/transport_security_interface.h" +// +// connector +// + typedef struct { grpc_connector base; gpr_refcount refs; @@ -216,10 +220,13 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con, static const grpc_connector_vtable connector_vtable = { connector_ref, connector_unref, connector_shutdown, connector_connect}; +// +// client_channel_factory +// + typedef struct { grpc_client_channel_factory base; gpr_refcount refs; - grpc_channel_args *merge_args; grpc_channel_security_connector *security_connector; } client_channel_factory; @@ -235,7 +242,6 @@ static void client_channel_factory_unref( if (gpr_unref(&f->refs)) { GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, "client_channel_factory"); - grpc_channel_args_destroy(f->merge_args); gpr_free(f); } } @@ -245,9 +251,6 @@ static grpc_subchannel *client_channel_factory_create_subchannel( grpc_subchannel_args *args) { client_channel_factory *f = (client_channel_factory *)cc_factory; connector *c = gpr_malloc(sizeof(*c)); - grpc_channel_args *final_args = - grpc_channel_args_merge(args->args, f->merge_args); - grpc_subchannel *s; memset(c, 0, sizeof(*c)); c->base.vtable = &connector_vtable; c->security_connector = f->security_connector; @@ -261,10 +264,8 @@ static grpc_subchannel *client_channel_factory_create_subchannel( } gpr_mu_init(&c->mu); gpr_ref_init(&c->refs, 1); - args->args = final_args; - s = grpc_subchannel_create(exec_ctx, &c->base, args); + grpc_subchannel *s = grpc_subchannel_create(exec_ctx, &c->base, args); grpc_connector_unref(exec_ctx, &c->base); - grpc_channel_args_destroy(final_args); return s; } @@ -273,13 +274,9 @@ static grpc_channel *client_channel_factory_create_channel( const char *target, grpc_client_channel_type type, grpc_channel_args *args) { client_channel_factory *f = (client_channel_factory *)cc_factory; - - grpc_channel_args *final_args = grpc_channel_args_merge(args, f->merge_args); - grpc_channel *channel = grpc_channel_create(exec_ctx, target, final_args, + grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); - grpc_channel_args_destroy(final_args); - - grpc_resolver *resolver = grpc_resolver_create(target); + grpc_resolver *resolver = grpc_resolver_create(target, args); if (resolver != NULL) { grpc_client_channel_finish_initialization( exec_ctx, grpc_channel_get_channel_stack(channel), resolver, &f->base); @@ -289,7 +286,6 @@ static grpc_channel *client_channel_factory_create_channel( "client_channel_factory_create_channel"); channel = NULL; } - GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, "client_channel_factory_create_channel"); return channel; @@ -308,19 +304,13 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, const char *target, const grpc_channel_args *args, void *reserved) { - grpc_arg connector_arg; - grpc_channel_args *args_copy; - grpc_channel_args *new_args_from_connector; - grpc_channel_security_connector *security_connector; - client_channel_factory *f; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_API_TRACE( "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", 4, (creds, target, args, reserved)); GPR_ASSERT(reserved == NULL); - + // Make sure security connector does not already exist in args. if (grpc_find_security_connector_in_args(args) != NULL) { gpr_log(GPR_ERROR, "Cannot set security context in channel args."); grpc_exec_ctx_finish(&exec_ctx); @@ -328,7 +318,9 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, target, GRPC_STATUS_INTERNAL, "Security connector exists in channel args."); } - + // Create security connector and construct new channel args. + grpc_channel_security_connector *security_connector; + grpc_channel_args *new_args_from_connector; if (grpc_channel_credentials_create_security_connector( creds, target, args, &security_connector, &new_args_from_connector) != GRPC_SECURITY_OK) { @@ -336,32 +328,28 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, return grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, "Failed to create security connector."); } - - connector_arg = grpc_security_connector_to_arg(&security_connector->base); - args_copy = grpc_channel_args_copy_and_add( + grpc_arg connector_arg = + grpc_security_connector_to_arg(&security_connector->base); + grpc_channel_args *new_args = grpc_channel_args_copy_and_add( new_args_from_connector != NULL ? new_args_from_connector : args, &connector_arg, 1); - - f = gpr_malloc(sizeof(*f)); - memset(f, 0, sizeof(*f)); - f->base.vtable = &client_channel_factory_vtable; - gpr_ref_init(&f->refs, 1); - - f->merge_args = grpc_channel_args_copy(args_copy); - grpc_channel_args_destroy(args_copy); if (new_args_from_connector != NULL) { grpc_channel_args_destroy(new_args_from_connector); } - + // Create client channel factory. + client_channel_factory *f = gpr_malloc(sizeof(*f)); + memset(f, 0, sizeof(*f)); + f->base.vtable = &client_channel_factory_vtable; + gpr_ref_init(&f->refs, 1); GRPC_SECURITY_CONNECTOR_REF(&security_connector->base, "grpc_secure_channel_create"); f->security_connector = security_connector; - + // Create channel. grpc_channel *channel = client_channel_factory_create_channel( - &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL); - + &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); + // Clean up. + grpc_channel_args_destroy(new_args); grpc_client_channel_factory_unref(&exec_ctx, &f->base); grpc_exec_ctx_finish(&exec_ctx); - return channel; /* may be NULL */ } -- cgit v1.2.3 From 16883a37efa49ef2d58ea57c6dbbba66497f2232 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 21 Oct 2016 10:30:58 -0700 Subject: Set user data vtable when creating grpc_lb_addresses. --- src/core/ext/client_config/lb_policy_factory.c | 55 +++++++++++++++++----- src/core/ext/client_config/lb_policy_factory.h | 23 ++++++--- src/core/ext/client_config/resolver_result.c | 2 +- src/core/ext/lb_policy/grpclb/grpclb.c | 27 +++++++---- src/core/ext/resolver/dns/native/dns_resolver.c | 4 +- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 10 ++-- test/core/end2end/fake_resolver.c | 10 ++-- 7 files changed, 93 insertions(+), 38 deletions(-) diff --git a/src/core/ext/client_config/lb_policy_factory.c b/src/core/ext/client_config/lb_policy_factory.c index c17af91a09..55e346180d 100644 --- a/src/core/ext/client_config/lb_policy_factory.c +++ b/src/core/ext/client_config/lb_policy_factory.c @@ -38,19 +38,20 @@ #include "src/core/ext/client_config/lb_policy_factory.h" -grpc_lb_addresses* grpc_lb_addresses_create(size_t num_addresses) { +grpc_lb_addresses* grpc_lb_addresses_create( + size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable) { grpc_lb_addresses* addresses = gpr_malloc(sizeof(grpc_lb_addresses)); addresses->num_addresses = num_addresses; + addresses->user_data_vtable = user_data_vtable; const size_t addresses_size = sizeof(grpc_lb_address) * num_addresses; addresses->addresses = gpr_malloc(addresses_size); memset(addresses->addresses, 0, addresses_size); return addresses; } -grpc_lb_addresses* grpc_lb_addresses_copy(grpc_lb_addresses* addresses, - void* (*user_data_copy)(void*)) { - grpc_lb_addresses* new_addresses = - grpc_lb_addresses_create(addresses->num_addresses); +grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses) { + grpc_lb_addresses* new_addresses = grpc_lb_addresses_create( + addresses->num_addresses, addresses->user_data_vtable); memcpy(new_addresses->addresses, addresses->addresses, sizeof(grpc_lb_address) * addresses->num_addresses); for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -58,9 +59,10 @@ grpc_lb_addresses* grpc_lb_addresses_copy(grpc_lb_addresses* addresses, new_addresses->addresses[i].balancer_name = gpr_strdup(new_addresses->addresses[i].balancer_name); } - if (user_data_copy != NULL) { + if (new_addresses->addresses[i].user_data != NULL) { new_addresses->addresses[i].user_data = - user_data_copy(new_addresses->addresses[i].user_data); + addresses->user_data_vtable->copy( + new_addresses->addresses[i].user_data); } } return new_addresses; @@ -71,6 +73,7 @@ void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index, bool is_balancer, char* balancer_name, void* user_data) { GPR_ASSERT(index < addresses->num_addresses); + if (user_data != NULL) GPR_ASSERT(addresses->user_data_vtable != NULL); grpc_lb_address* target = &addresses->addresses[index]; memcpy(target->address.addr, address, address_len); target->address.len = address_len; @@ -79,12 +82,42 @@ void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index, target->user_data = user_data; } -void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses, - void (*user_data_destroy)(void*)) { +int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, + const grpc_lb_addresses* addresses2) { + if (addresses1->num_addresses > addresses2->num_addresses) return 1; + if (addresses1->num_addresses < addresses2->num_addresses) return -1; + if (addresses1->user_data_vtable > addresses2->user_data_vtable) return 1; + if (addresses1->user_data_vtable < addresses2->user_data_vtable) return -1; + for (size_t i = 0; i < addresses1->num_addresses; ++i) { + const grpc_lb_address* target1 = &addresses1->addresses[i]; + const grpc_lb_address* target2 = &addresses2->addresses[i]; + if (target1->address.len > target2->address.len) return 1; + if (target1->address.len < target2->address.len) return -1; + int retval = memcmp( + target1->address.addr, target2->address.addr, target1->address.len); + if (retval != 0) return retval; + if (target1->is_balancer > target2->is_balancer) return 1; + if (target1->is_balancer < target2->is_balancer) return -1; + const char* balancer_name1 = target1->balancer_name != NULL + ? target1->balancer_name : ""; + const char* balancer_name2 = target2->balancer_name != NULL + ? target2->balancer_name : ""; + retval = strcmp(balancer_name1, balancer_name2); + if (retval != 0) return retval; + if (addresses1->user_data_vtable != NULL) { + retval = addresses1->user_data_vtable->cmp(target1->user_data, + target2->user_data); + if (retval != 0) return retval; + } + } + return 0; +} + +void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { for (size_t i = 0; i < addresses->num_addresses; ++i) { gpr_free(addresses->addresses[i].balancer_name); - if (user_data_destroy != NULL) { - user_data_destroy(addresses->addresses[i].user_data); + if (addresses->addresses[i].user_data != NULL) { + addresses->user_data_vtable->destroy(addresses->addresses[i].user_data); } } gpr_free(addresses->addresses); diff --git a/src/core/ext/client_config/lb_policy_factory.h b/src/core/ext/client_config/lb_policy_factory.h index 4e11501e01..61c3f419d1 100644 --- a/src/core/ext/client_config/lb_policy_factory.h +++ b/src/core/ext/client_config/lb_policy_factory.h @@ -59,19 +59,27 @@ typedef struct grpc_lb_address { void *user_data; } grpc_lb_address; +typedef struct grpc_lb_user_data_vtable { + void* (*copy)(void*); + void (*destroy)(void*); + int (*cmp)(void*, void*); +} grpc_lb_user_data_vtable; + typedef struct grpc_lb_addresses { size_t num_addresses; grpc_lb_address *addresses; + const grpc_lb_user_data_vtable *user_data_vtable; } grpc_lb_addresses; /** Returns a grpc_addresses struct with enough space for - * \a num_addresses addresses. */ -grpc_lb_addresses *grpc_lb_addresses_create(size_t num_addresses); + \a num_addresses addresses. The \a user_data_vtable argument may be + NULL if no user data will be added. */ +grpc_lb_addresses *grpc_lb_addresses_create( + size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable); /** Creates a copy of \a addresses. If \a user_data_copy is not NULL, * it will be invoked to copy the \a user_data field of each address. */ -grpc_lb_addresses *grpc_lb_addresses_copy(grpc_lb_addresses *addresses, - void *(*user_data_copy)(void *)); +grpc_lb_addresses *grpc_lb_addresses_copy(const grpc_lb_addresses *addresses); /** Sets the value of the address at index \a index of \a addresses. * \a address is a socket address of length \a address_len. @@ -81,10 +89,13 @@ void grpc_lb_addresses_set_address(grpc_lb_addresses *addresses, size_t index, bool is_balancer, char *balancer_name, void *user_data); +/** Compares \a addresses1 and \a addresses2. */ +int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1, + const grpc_lb_addresses *addresses2); + /** Destroys \a addresses. If \a user_data_destroy is not NULL, it will * be invoked to destroy the \a user_data field of each address. */ -void grpc_lb_addresses_destroy(grpc_lb_addresses *addresses, - void (*user_data_destroy)(void *)); +void grpc_lb_addresses_destroy(grpc_lb_addresses *addresses); /** Arguments passed to LB policies. */ /* TODO(roth, ctiller): Consider replacing this struct with diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c index 5f3600e7d9..e6a6f2da62 100644 --- a/src/core/ext/client_config/resolver_result.c +++ b/src/core/ext/client_config/resolver_result.c @@ -67,7 +67,7 @@ void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, grpc_resolver_result* result) { if (gpr_unref(&result->refs)) { gpr_free(result->server_name); - grpc_lb_addresses_destroy(result->addresses, NULL /* user_data_destroy */); + grpc_lb_addresses_destroy(result->addresses); gpr_free(result->lb_policy_name); grpc_channel_args_destroy(result->channel_args); gpr_free(result); diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 663f1d3300..1467508d6d 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -338,6 +338,21 @@ static bool is_server_valid(const grpc_grpclb_server *server, size_t idx, return true; } +/* vtable for LB tokens in grpc_lb_addresses. */ +static void* lb_token_copy(void *token) { + return token == NULL ? NULL : GRPC_MDELEM_REF(token); +} +static void lb_token_destroy(void *token) { + if (token != NULL) GRPC_MDELEM_UNREF(token); +} +static int lb_token_cmp(void* token1, void* token2) { + if (token1 > token2) return 1; + if (token1 < token2) return -1; + return 0; +} +static const grpc_lb_user_data_vtable lb_token_vtable = { + lb_token_copy, lb_token_destroy, lb_token_cmp}; + /* Returns addresses extracted from \a serverlist. */ static grpc_lb_addresses *process_serverlist( const grpc_grpclb_serverlist *serverlist) { @@ -349,7 +364,8 @@ static grpc_lb_addresses *process_serverlist( } if (num_valid == 0) return NULL; - grpc_lb_addresses *lb_addresses = grpc_lb_addresses_create(num_valid); + grpc_lb_addresses *lb_addresses = + grpc_lb_addresses_create(num_valid, &lb_token_vtable); /* second pass: actually populate the addresses and LB tokens (aka user data * to the outside world) to be read by the RR policy during its creation. @@ -410,11 +426,6 @@ static grpc_lb_addresses *process_serverlist( return lb_addresses; } -/* A plugin for grpc_lb_addresses_destroy that unrefs the LB token metadata. */ -static void lb_token_destroy(void *token) { - if (token != NULL) GRPC_MDELEM_UNREF(token); -} - /* perform a pick over \a rr_policy. Given that a pick can return immediately * (ignoring its completion callback) we need to perform the cleanups this * callback would be otherwise resposible for */ @@ -465,7 +476,7 @@ static grpc_lb_policy *create_rr_locked( if (glb_policy->addresses != NULL) { /* dispose of the previous version */ - grpc_lb_addresses_destroy(glb_policy->addresses, lb_token_destroy); + grpc_lb_addresses_destroy(glb_policy->addresses); } glb_policy->addresses = args.addresses; @@ -662,7 +673,7 @@ static void glb_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } gpr_mu_destroy(&glb_policy->mu); - grpc_lb_addresses_destroy(glb_policy->addresses, lb_token_destroy); + grpc_lb_addresses_destroy(glb_policy->addresses); gpr_free(glb_policy); } diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index a4f6ed8c4e..0694d8b6b7 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -170,8 +170,8 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, GPR_ASSERT(r->resolving); r->resolving = false; if (r->addresses != NULL) { - grpc_lb_addresses *addresses = - grpc_lb_addresses_create(r->addresses->naddrs); + grpc_lb_addresses *addresses = grpc_lb_addresses_create( + r->addresses->naddrs, NULL /* user_data_vtable */); for (size_t i = 0; i < r->addresses->naddrs; ++i) { grpc_lb_addresses_set_address( addresses, i, &r->addresses->addrs[i].addr, diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index eaaa2e47c2..d34094f8e8 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -121,8 +121,7 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, if (r->next_completion != NULL && !r->published) { r->published = true; *r->target_result = grpc_resolver_result_create( - r->target_name, - grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */), + r->target_name, grpc_lb_addresses_copy(r->addresses), NULL /* lb_policy_name */, grpc_channel_args_copy(r->channel_args)); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; @@ -133,7 +132,7 @@ static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { sockaddr_resolver *r = (sockaddr_resolver *)gr; gpr_mu_destroy(&r->mu); gpr_free(r->target_name); - grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); + grpc_lb_addresses_destroy(r->addresses); grpc_channel_args_destroy(r->channel_args); gpr_free(r); } @@ -178,7 +177,8 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, gpr_slice_buffer path_parts; gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - grpc_lb_addresses *addresses = grpc_lb_addresses_create(path_parts.count); + grpc_lb_addresses *addresses = grpc_lb_addresses_create( + path_parts.count, NULL /* user_data_vtable */); bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; @@ -196,7 +196,7 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, gpr_slice_buffer_destroy(&path_parts); gpr_slice_unref(path_slice); if (errors_found) { - grpc_lb_addresses_destroy(addresses, NULL /* user_data_destroy */); + grpc_lb_addresses_destroy(addresses); return NULL; } /* Instantiate resolver. */ diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index 32dc9e2711..67337f4f84 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -78,7 +78,7 @@ static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { fake_resolver* r = (fake_resolver*)gr; gpr_mu_destroy(&r->mu); gpr_free(r->target_name); - grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); + grpc_lb_addresses_destroy(r->addresses); gpr_free(r->lb_policy_name); grpc_method_config_table_unref(r->method_config_table); gpr_free(r); @@ -107,8 +107,7 @@ static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, lb_policy_args = grpc_channel_args_copy_and_add(NULL /* src */, &arg, 1); } *r->target_result = grpc_resolver_result_create( - r->target_name, - grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */), + r->target_name, grpc_lb_addresses_copy(r->addresses), r->lb_policy_name, lb_policy_args); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; @@ -168,7 +167,8 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, gpr_slice_buffer path_parts; gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - grpc_lb_addresses* addresses = grpc_lb_addresses_create(path_parts.count); + grpc_lb_addresses* addresses = grpc_lb_addresses_create( + path_parts.count, NULL /* user_data_vtable */); bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; @@ -187,7 +187,7 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, gpr_slice_buffer_destroy(&path_parts); gpr_slice_unref(path_slice); if (errors_found) { - grpc_lb_addresses_destroy(addresses, NULL /* user_data_destroy */); + grpc_lb_addresses_destroy(addresses); return NULL; } // Construct method config table. -- cgit v1.2.3 From 3686996786faa2671e487707c78b32c0e4a63d80 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 21 Oct 2016 10:43:45 -0700 Subject: Encode server name, LB policy name, and addresses in channel args. --- include/grpc/impl/codegen/grpc_types.h | 7 ++++++ src/core/ext/client_config/lb_policy_factory.c | 22 ++++++++++++++++++ src/core/ext/client_config/lb_policy_factory.h | 4 ++++ src/core/ext/resolver/dns/native/dns_resolver.c | 14 +++++++++--- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 13 +++++++++-- test/core/end2end/fake_resolver.c | 26 ++++++++++++++++++---- 6 files changed, 77 insertions(+), 9 deletions(-) diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index a3fc683e57..0be7ab2ad2 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -204,6 +204,13 @@ typedef struct { /** Service config data, to be passed to subchannels. Not intended for external use. */ #define GRPC_ARG_SERVICE_CONFIG "grpc.service_config" +/** LB policy name. */ +#define GRPC_ARG_LB_POLICY_NAME "grpc.lb_policy_name" +/** Server name. Not intended for external use. */ +#define GRPC_ARG_SERVER_NAME "grpc.server_name" +/** Resolved addresses in a form used by the LB policy. + Not intended for external use. */ +#define GRPC_ARG_LB_ADDRESSES "grpc.lb_addresses" /** \} */ /** Result of a grpc call. If the caller satisfies the prerequisites of a diff --git a/src/core/ext/client_config/lb_policy_factory.c b/src/core/ext/client_config/lb_policy_factory.c index 55e346180d..676fdaf555 100644 --- a/src/core/ext/client_config/lb_policy_factory.c +++ b/src/core/ext/client_config/lb_policy_factory.c @@ -124,6 +124,28 @@ void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { gpr_free(addresses); } +static void* lb_addresses_copy(void* addresses) { + return grpc_lb_addresses_copy(addresses); +} +static void lb_addresses_destroy(void* addresses) { + grpc_lb_addresses_destroy(addresses); +} +static int lb_addresses_cmp(void* addresses1, void* addresses2) { + return grpc_lb_addresses_cmp(addresses1, addresses2); +} +static const grpc_arg_pointer_vtable lb_addresses_arg_vtable = { + lb_addresses_copy, lb_addresses_destroy, lb_addresses_cmp}; + +grpc_arg grpc_lb_addresses_create_channel_arg( + const grpc_lb_addresses *addresses) { + grpc_arg arg; + arg.type = GRPC_ARG_POINTER; + arg.key = GRPC_ARG_LB_ADDRESSES; + arg.value.pointer.p = (void*)addresses; + arg.value.pointer.vtable = &lb_addresses_arg_vtable; + return arg; +} + void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory) { factory->vtable->ref(factory); } diff --git a/src/core/ext/client_config/lb_policy_factory.h b/src/core/ext/client_config/lb_policy_factory.h index 61c3f419d1..f0798a3167 100644 --- a/src/core/ext/client_config/lb_policy_factory.h +++ b/src/core/ext/client_config/lb_policy_factory.h @@ -97,6 +97,10 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1, * be invoked to destroy the \a user_data field of each address. */ void grpc_lb_addresses_destroy(grpc_lb_addresses *addresses); +/** Returns a channel arg containing \a addresses. */ +grpc_arg grpc_lb_addresses_create_channel_arg( + const grpc_lb_addresses *addresses); + /** Arguments passed to LB policies. */ /* TODO(roth, ctiller): Consider replacing this struct with grpc_channel_args. See comment in resolver_result.h for details. */ diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 0694d8b6b7..039fb2225d 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -55,6 +55,7 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** target name */ +// FIXME: remove target_name when resolver_result goes away char *target_name; /** name to resolve (usually the same as target_name) */ char *name_to_resolve; @@ -178,10 +179,12 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, r->addresses->addrs[i].len, false /* is_balancer */, NULL /* balancer_name */, NULL /* user_data */); } + grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); + grpc_channel_args* args = + grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); grpc_resolved_addresses_destroy(r->addresses); result = grpc_resolver_result_create( - r->target_name, addresses, NULL /* lb_policy_name */, - grpc_channel_args_copy(r->channel_args)); + r->target_name, addresses, NULL /* lb_policy_name */, args); } else { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); @@ -268,7 +271,12 @@ static grpc_resolver *dns_create(grpc_resolver_args *args, r->target_name = gpr_strdup(path); r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name; r->default_port = gpr_strdup(default_port); - r->channel_args = grpc_channel_args_copy(args->args); + grpc_arg server_name_arg; + server_name_arg.type = GRPC_ARG_STRING; + server_name_arg.key = GRPC_ARG_SERVER_NAME; + server_name_arg.value.string = (char*)path; + r->channel_args = + grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); gpr_backoff_init(&r->backoff_state, BACKOFF_MULTIPLIER, BACKOFF_JITTER, BACKOFF_MIN_SECONDS * 1000, BACKOFF_MAX_SECONDS * 1000); return &r->base; diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index d34094f8e8..93a34bf305 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -52,6 +52,7 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** the path component of the uri passed in */ +// FIXME: remove target_name when resolver_result goes away char *target_name; /** the addresses that we've 'resolved' */ grpc_lb_addresses *addresses; @@ -120,9 +121,12 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, sockaddr_resolver *r) { if (r->next_completion != NULL && !r->published) { r->published = true; + grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); + grpc_channel_args* args = + grpc_channel_args_copy_and_add(r->channel_args, &arg, 1); *r->target_result = grpc_resolver_result_create( r->target_name, grpc_lb_addresses_copy(r->addresses), - NULL /* lb_policy_name */, grpc_channel_args_copy(r->channel_args)); + NULL /* lb_policy_name */, args); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } @@ -204,7 +208,12 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, memset(r, 0, sizeof(*r)); r->target_name = gpr_strdup(args->uri->path); r->addresses = addresses; - r->channel_args = grpc_channel_args_copy(args->args); + grpc_arg server_name_arg; + server_name_arg.type = GRPC_ARG_STRING; + server_name_arg.key = GRPC_ARG_SERVER_NAME; + server_name_arg.value.string = args->uri->path; + r->channel_args = + grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &sockaddr_resolver_vtable); return &r->base; diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index 67337f4f84..f77f3eb27d 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -59,7 +59,9 @@ typedef struct { grpc_resolver base; // passed-in parameters +// FIXME: remove target_name once resolver_result is removed char* target_name; // the path component of the uri passed in + grpc_channel_args* channel_args; grpc_lb_addresses* addresses; char* lb_policy_name; grpc_method_config_table* method_config_table; @@ -78,6 +80,7 @@ static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { fake_resolver* r = (fake_resolver*)gr; gpr_mu_destroy(&r->mu); gpr_free(r->target_name); + grpc_channel_args_destroy(r->channel_args); grpc_lb_addresses_destroy(r->addresses); gpr_free(r->lb_policy_name); grpc_method_config_table_unref(r->method_config_table); @@ -100,15 +103,24 @@ static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, fake_resolver* r) { if (r->next_completion != NULL && !r->published) { r->published = true; - grpc_channel_args* lb_policy_args = NULL; + grpc_arg new_args[3]; + size_t num_args = 0; + new_args[num_args++] = grpc_lb_addresses_create_channel_arg(r->addresses); if (r->method_config_table != NULL) { - const grpc_arg arg = + new_args[num_args++] = grpc_method_config_table_create_channel_arg(r->method_config_table); - lb_policy_args = grpc_channel_args_copy_and_add(NULL /* src */, &arg, 1); } + if (r->lb_policy_name != NULL) { + new_args[num_args].type = GRPC_ARG_STRING; + new_args[num_args].key = GRPC_ARG_LB_POLICY_NAME; + new_args[num_args].value.string = r->lb_policy_name; + ++num_args; + } + grpc_channel_args* args = + grpc_channel_args_copy_and_add(r->channel_args, new_args, num_args); *r->target_result = grpc_resolver_result_create( r->target_name, grpc_lb_addresses_copy(r->addresses), - r->lb_policy_name, lb_policy_args); + r->lb_policy_name, args); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } @@ -233,6 +245,12 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, fake_resolver* r = gpr_malloc(sizeof(fake_resolver)); memset(r, 0, sizeof(*r)); r->target_name = gpr_strdup(args->uri->path); + grpc_arg server_name_arg; + server_name_arg.type = GRPC_ARG_STRING; + server_name_arg.key = GRPC_ARG_SERVER_NAME; + server_name_arg.value.string = r->target_name; + r->channel_args = + grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); r->addresses = addresses; r->lb_policy_name = gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy")); -- cgit v1.2.3 From 5bd7be0c55d4149cc6e2d5ee90f33fe5f7f6a7de Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 21 Oct 2016 14:19:50 -0700 Subject: Change LB policies to get their input from channel args. --- src/core/ext/client_config/client_channel.c | 10 +++- src/core/ext/lb_policy/grpclb/grpclb.c | 61 +++++++++++++++++++----- src/core/ext/lb_policy/pick_first/pick_first.c | 31 ++++++++---- src/core/ext/lb_policy/round_robin/round_robin.c | 30 ++++++++---- src/core/lib/channel/channel_args.c | 55 +++++++++++++++++---- src/core/lib/channel/channel_args.h | 11 +++++ 6 files changed, 155 insertions(+), 43 deletions(-) diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index d02dd5aacf..f23da5f35d 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -192,11 +192,17 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_resolver_result_get_channel_args(chand->resolver_result); lb_policy_args.client_channel_factory = chand->client_channel_factory; + // Find LB policy name. + const char *lb_policy_name = NULL; + const grpc_arg *lb_policy_name_arg = + grpc_channel_args_find(lb_policy_args.args, GRPC_ARG_LB_POLICY_NAME); + if (lb_policy_name_arg != NULL) { + GPR_ASSERT(lb_policy_name_arg->type == GRPC_ARG_STRING); + lb_policy_name = lb_policy_name_arg->value.string; + } // Special case: If all of the addresses are balancer addresses, // assume that we should use the grpclb policy, regardless of what the // resolver actually specified. - const char *lb_policy_name = - grpc_resolver_result_get_lb_policy_name(chand->resolver_result); bool found_backend_address = false; for (size_t i = 0; i < lb_policy_args.addresses->num_addresses; ++i) { if (!lb_policy_args.addresses->addresses[i].is_balancer) { diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 1467508d6d..fdc0bec996 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -470,9 +470,17 @@ static grpc_lb_policy *create_rr_locked( args.server_name = glb_policy->server_name; args.client_channel_factory = glb_policy->cc_factory; args.addresses = process_serverlist(serverlist); - args.args = glb_policy->args; + + // Replace the LB addresses in the channel args that we pass down to + // the subchannel. + static const char* keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; + const grpc_arg arg = grpc_lb_addresses_create_channel_arg(args.addresses); + args.args = grpc_channel_args_copy_and_add_and_remove( + glb_policy->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &arg, + 1); grpc_lb_policy *rr = grpc_lb_policy_create(exec_ctx, "round_robin", &args); + grpc_channel_args_destroy(args.args); if (glb_policy->addresses != NULL) { /* dispose of the previous version */ @@ -574,6 +582,13 @@ static void glb_rr_connectivity_changed(grpc_exec_ctx *exec_ctx, void *arg, static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, grpc_lb_policy_args *args) { + /* Get server name. */ + const grpc_arg* arg = + grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); + const char* server_name = + arg != NULL && arg->type == GRPC_ARG_STRING + ? arg->value.string : NULL; + /* Count the number of gRPC-LB addresses. There must be at least one. * TODO(roth): For now, we ignore non-balancer addresses, but in the * future, we may change the behavior such that we fall back to using @@ -581,22 +596,25 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, * time, this should be changed to allow a list with no balancer addresses, * since the resolver might fail to return a balancer address even when * this is the right LB policy to use. */ + arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); + GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); + grpc_lb_addresses* addresses = arg->value.pointer.p; size_t num_grpclb_addrs = 0; - for (size_t i = 0; i < args->addresses->num_addresses; ++i) { - if (args->addresses->addresses[i].is_balancer) ++num_grpclb_addrs; + for (size_t i = 0; i < addresses->num_addresses; ++i) { + if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; } if (num_grpclb_addrs == 0) return NULL; glb_lb_policy *glb_policy = gpr_malloc(sizeof(*glb_policy)); memset(glb_policy, 0, sizeof(*glb_policy)); - /* All input addresses in args->addresses come from a resolver that claims + /* All input addresses in addresses come from a resolver that claims * they are LB services. It's the resolver's responsibility to make sure * this * policy is only instantiated and used in that case. * * Create a client channel over them to communicate with a LB service */ - glb_policy->server_name = gpr_strdup(args->server_name); + glb_policy->server_name = gpr_strdup(server_name); glb_policy->cc_factory = args->client_channel_factory; glb_policy->args = grpc_channel_args_copy(args->args); GPR_ASSERT(glb_policy->cc_factory != NULL); @@ -606,20 +624,20 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, * TODO(dgq): support mixed ip version */ char **addr_strs = gpr_malloc(sizeof(char *) * num_grpclb_addrs); size_t addr_index = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { - if (args->addresses->addresses[i].user_data != NULL) { + for (size_t i = 0; i < addresses->num_addresses; i++) { + if (addresses->addresses[i].user_data != NULL) { gpr_log(GPR_ERROR, "This LB policy doesn't support user data. It will be ignored"); } - if (args->addresses->addresses[i].is_balancer) { + if (addresses->addresses[i].is_balancer) { if (addr_index == 0) { addr_strs[addr_index++] = grpc_sockaddr_to_uri( - (const struct sockaddr *)&args->addresses->addresses[i] + (const struct sockaddr *)&addresses->addresses[i] .address.addr); } else { GPR_ASSERT(grpc_sockaddr_to_string( &addr_strs[addr_index++], - (const struct sockaddr *)&args->addresses->addresses[i] + (const struct sockaddr *)&addresses->addresses[i] .address.addr, true) > 0); } @@ -629,10 +647,29 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, char *target_uri_str = gpr_strjoin_sep((const char **)addr_strs, num_grpclb_addrs, ",", &uri_path_len); - /* will pick using pick_first */ + /* Create a channel to talk to the LBs. + * + * We strip out the channel arg for the LB policy name, since we want + * to use the default (pick_first) in this case. + * + * We also strip out the channel arg for the resolved addresses, since + * that will be generated by the name resolver used in the LB channel. + * Note that the LB channel will use the sockaddr resolver, so this + * won't actually generate a query to DNS (or some other name service). + * However, the addresses returned by the sockaddr resolver will have + * is_balancer=false, whereas our own addresses have is_balancer=true. + * 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, + * as per the special case logic in client_channel.c. + */ + static const char* keys_to_remove[] = { + GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES}; + grpc_channel_args *new_args = grpc_channel_args_copy_and_remove( + args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove)); glb_policy->lb_channel = grpc_client_channel_factory_create_channel( exec_ctx, glb_policy->cc_factory, target_uri_str, - GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, args->args); + GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); + grpc_channel_args_destroy(new_args); gpr_free(target_uri_str); for (size_t i = 0; i < num_grpclb_addrs; i++) { diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index 3683079cf4..d95f0310b6 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -34,7 +34,9 @@ #include #include + #include "src/core/ext/client_config/lb_policy_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/connectivity_state.h" typedef struct pending_pick { @@ -432,14 +434,23 @@ static void pick_first_factory_unref(grpc_lb_policy_factory *factory) {} static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, grpc_lb_policy_args *args) { - GPR_ASSERT(args->addresses != NULL); GPR_ASSERT(args->client_channel_factory != NULL); + /* Get server name. */ + const grpc_arg* arg = + grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); + const char* server_name = + arg != NULL && arg->type == GRPC_ARG_STRING + ? arg->value.string : NULL; + /* Find the number of backend addresses. We ignore balancer * addresses, since we don't know how to handle them. */ + arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); + GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); + grpc_lb_addresses* addresses = arg->value.pointer.p; size_t num_addrs = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { - if (!args->addresses->addresses[i].is_balancer) ++num_addrs; + for (size_t i = 0; i < addresses->num_addresses; i++) { + if (!addresses->addresses[i].is_balancer) ++num_addrs; } if (num_addrs == 0) return NULL; @@ -450,22 +461,22 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, memset(p->subchannels, 0, sizeof(*p->subchannels) * num_addrs); grpc_subchannel_args sc_args; size_t subchannel_idx = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { + for (size_t i = 0; i < addresses->num_addresses; i++) { /* Skip balancer addresses, since we only know how to handle backends. */ - if (args->addresses->addresses[i].is_balancer) continue; + if (addresses->addresses[i].is_balancer) continue; - if (args->addresses->addresses[i].user_data != NULL) { + if (addresses->addresses[i].user_data != NULL) { gpr_log(GPR_ERROR, "This LB policy doesn't support user data. It will be ignored"); } memset(&sc_args, 0, sizeof(grpc_subchannel_args)); /* server_name will be copied as part of the subchannel creation. This makes - * the copying of args->server_name (a borrowed pointer) OK. */ - sc_args.server_name = args->server_name; + * the copying of server_name (a borrowed pointer) OK. */ + sc_args.server_name = server_name; sc_args.addr = - (struct sockaddr *)(&args->addresses->addresses[i].address.addr); - sc_args.addr_len = args->addresses->addresses[i].address.len; + (struct sockaddr *)(&addresses->addresses[i].address.addr); + sc_args.addr_len = addresses->addresses[i].address.len; sc_args.args = args->args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index 00a18974df..2deb0af99c 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -64,6 +64,7 @@ #include #include "src/core/ext/client_config/lb_policy_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" @@ -598,14 +599,23 @@ static void round_robin_factory_unref(grpc_lb_policy_factory *factory) {} static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, grpc_lb_policy_args *args) { - GPR_ASSERT(args->addresses != NULL); GPR_ASSERT(args->client_channel_factory != NULL); + /* Get server name. */ + const grpc_arg* arg = + grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); + const char* server_name = + arg != NULL && arg->type == GRPC_ARG_STRING + ? arg->value.string : NULL; + /* Find the number of backend addresses. We ignore balancer * addresses, since we don't know how to handle them. */ + arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); + GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); + grpc_lb_addresses* addresses = arg->value.pointer.p; size_t num_addrs = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { - if (!args->addresses->addresses[i].is_balancer) ++num_addrs; + for (size_t i = 0; i < addresses->num_addresses; i++) { + if (!addresses->addresses[i].is_balancer) ++num_addrs; } if (num_addrs == 0) return NULL; @@ -618,17 +628,17 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, grpc_subchannel_args sc_args; size_t subchannel_idx = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { + for (size_t i = 0; i < addresses->num_addresses; i++) { /* Skip balancer addresses, since we only know how to handle backends. */ - if (args->addresses->addresses[i].is_balancer) continue; + if (addresses->addresses[i].is_balancer) continue; memset(&sc_args, 0, sizeof(grpc_subchannel_args)); /* server_name will be copied as part of the subchannel creation. This makes - * the copying of args->server_name (a borrowed pointer) OK. */ - sc_args.server_name = args->server_name; + * the copying of server_name (a borrowed pointer) OK. */ + sc_args.server_name = server_name; sc_args.addr = - (struct sockaddr *)(&args->addresses->addresses[i].address.addr); - sc_args.addr_len = args->addresses->addresses[i].address.len; + (struct sockaddr *)(&addresses->addresses[i].address.addr); + sc_args.addr_len = addresses->addresses[i].address.len; sc_args.args = args->args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( @@ -641,7 +651,7 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, sd->policy = p; sd->index = subchannel_idx; sd->subchannel = subchannel; - sd->user_data = args->addresses->addresses[i].user_data; + sd->user_data = addresses->addresses[i].user_data; ++subchannel_idx; grpc_closure_init(&sd->connectivity_changed_closure, rr_connectivity_changed, sd); diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index 2957d2c818..0270d6f224 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -66,22 +66,59 @@ static grpc_arg copy_arg(const grpc_arg *src) { grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src, const grpc_arg *to_add, size_t num_to_add) { + return grpc_channel_args_copy_and_add_and_remove(src, NULL, 0, to_add, + num_to_add); +} + +grpc_channel_args *grpc_channel_args_copy_and_remove( + const grpc_channel_args *src, const char** to_remove, + size_t num_to_remove) { + return grpc_channel_args_copy_and_add_and_remove(src, to_remove, + num_to_remove, NULL, 0); +} + +static bool should_remove_arg(const grpc_arg* arg, const char** to_remove, + size_t num_to_remove) { + for (size_t i = 0; i < num_to_remove; ++i) { + if (strcmp(arg->key, to_remove[i]) == 0) return true; + } + return false; +} + +grpc_channel_args *grpc_channel_args_copy_and_add_and_remove( + const grpc_channel_args *src, const char** to_remove, size_t num_to_remove, + const grpc_arg *to_add, size_t num_to_add) { + // Figure out how many args we'll be copying. + size_t num_args_to_copy = 0; + if (src != NULL) { + for (size_t i = 0; i < src->num_args; ++i) { + if (!should_remove_arg(&src->args[i], to_remove, num_to_remove)) { + ++num_args_to_copy; + } + } + } + // Create result. grpc_channel_args *dst = gpr_malloc(sizeof(grpc_channel_args)); - size_t i; - size_t src_num_args = (src == NULL) ? 0 : src->num_args; - if (!src && !to_add) { - dst->num_args = 0; + dst->num_args = num_args_to_copy + num_to_add; + if (dst->num_args == 0) { dst->args = NULL; return dst; } - dst->num_args = src_num_args + num_to_add; dst->args = gpr_malloc(sizeof(grpc_arg) * dst->num_args); - for (i = 0; i < src_num_args; i++) { - dst->args[i] = copy_arg(&src->args[i]); + // Copy args from src that are not being removed. + size_t dst_idx = 0; + if (src != NULL) { + for (size_t i = 0; i < src->num_args; ++i) { + if (!should_remove_arg(&src->args[i], to_remove, num_to_remove)) { + dst->args[dst_idx++] = copy_arg(&src->args[i]); + } + } } - for (i = 0; i < num_to_add; i++) { - dst->args[i + src_num_args] = copy_arg(&to_add[i]); + // Add args from to_add. + for (size_t i = 0; i < num_to_add; ++i) { + dst->args[dst_idx++] = copy_arg(&to_add[i]); } + GPR_ASSERT(dst_idx == dst->num_args); return dst; } diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index a80340c0fa..1508d23748 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -51,6 +51,17 @@ grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src, const grpc_arg *to_add, size_t num_to_add); +/** Copies the arguments in \a src except for those whose keys are in + \a to_remove. */ +grpc_channel_args *grpc_channel_args_copy_and_remove( + const grpc_channel_args *src, const char** to_remove, size_t num_to_remove); + +/** Copies the arguments from \a src except for those whose keys are in + \a to_remove and appends the arguments in \a to_add. */ +grpc_channel_args *grpc_channel_args_copy_and_add_and_remove( + const grpc_channel_args *src, const char** to_remove, size_t num_to_remove, + const grpc_arg *to_add, size_t num_to_add); + /** Concatenate args from \a a and \a b into a new instance */ grpc_channel_args *grpc_channel_args_merge(const grpc_channel_args *a, const grpc_channel_args *b); -- cgit v1.2.3 From af842451318f73d0fd2dcb55f02baaa70c82f3f9 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 21 Oct 2016 15:05:15 -0700 Subject: Remove resolver_result. --- BUILD | 8 - CMakeLists.txt | 3 - Makefile | 3 - binding.gyp | 1 - build.yaml | 2 - config.m4 | 1 - gRPC-Core.podspec | 3 - grpc.gemspec | 2 - package.xml | 2 - src/core/ext/client_config/README.md | 21 +- src/core/ext/client_config/client_channel.c | 57 ++-- src/core/ext/client_config/lb_policy_factory.h | 4 - src/core/ext/client_config/resolver.c | 2 +- src/core/ext/client_config/resolver.h | 13 +- src/core/ext/client_config/resolver_factory.h | 2 - src/core/ext/client_config/resolver_result.c | 94 ------- src/core/ext/client_config/resolver_result.h | 69 ----- src/core/ext/lb_policy/grpclb/grpclb.c | 17 +- src/core/ext/resolver/dns/native/dns_resolver.c | 36 +-- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 17 +- src/python/grpcio/grpc_core_dependencies.py | 1 - test/core/end2end/fake_resolver.c | 16 +- tools/doxygen/Doxyfile.core.internal | 2 - tools/run_tests/sources_and_headers.json | 3 - tools/run_tests/tests.json | 312 ++++++++++----------- vsprojects/vcxproj/grpc/grpc.vcxproj | 3 - vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 6 - .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 3 - .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 6 - 29 files changed, 232 insertions(+), 477 deletions(-) delete mode 100644 src/core/ext/client_config/resolver_result.c delete mode 100644 src/core/ext/client_config/resolver_result.h diff --git a/BUILD b/BUILD index 5c4333463c..801310422e 100644 --- a/BUILD +++ b/BUILD @@ -304,7 +304,6 @@ cc_library( "src/core/ext/client_config/resolver.h", "src/core/ext/client_config/resolver_factory.h", "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", "src/core/ext/client_config/subchannel.h", "src/core/ext/client_config/subchannel_index.h", "src/core/ext/client_config/uri_parser.h", @@ -486,7 +485,6 @@ cc_library( "src/core/ext/client_config/resolver.c", "src/core/ext/client_config/resolver_factory.c", "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", "src/core/ext/client_config/subchannel.c", "src/core/ext/client_config/subchannel_index.c", "src/core/ext/client_config/uri_parser.c", @@ -686,7 +684,6 @@ cc_library( "src/core/ext/client_config/resolver.h", "src/core/ext/client_config/resolver_factory.h", "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", "src/core/ext/client_config/subchannel.h", "src/core/ext/client_config/subchannel_index.h", "src/core/ext/client_config/uri_parser.h", @@ -850,7 +847,6 @@ cc_library( "src/core/ext/client_config/resolver.c", "src/core/ext/client_config/resolver_factory.c", "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", "src/core/ext/client_config/subchannel.c", "src/core/ext/client_config/subchannel_index.c", "src/core/ext/client_config/uri_parser.c", @@ -1045,7 +1041,6 @@ cc_library( "src/core/ext/client_config/resolver.h", "src/core/ext/client_config/resolver_factory.h", "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", "src/core/ext/client_config/subchannel.h", "src/core/ext/client_config/subchannel_index.h", "src/core/ext/client_config/uri_parser.h", @@ -1202,7 +1197,6 @@ cc_library( "src/core/ext/client_config/resolver.c", "src/core/ext/client_config/resolver_factory.c", "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", "src/core/ext/client_config/subchannel.c", "src/core/ext/client_config/subchannel_index.c", "src/core/ext/client_config/uri_parser.c", @@ -1993,7 +1987,6 @@ objc_library( "src/core/ext/client_config/resolver.c", "src/core/ext/client_config/resolver_factory.c", "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", "src/core/ext/client_config/subchannel.c", "src/core/ext/client_config/subchannel_index.c", "src/core/ext/client_config/uri_parser.c", @@ -2195,7 +2188,6 @@ objc_library( "src/core/ext/client_config/resolver.h", "src/core/ext/client_config/resolver_factory.h", "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", "src/core/ext/client_config/subchannel.h", "src/core/ext/client_config/subchannel_index.h", "src/core/ext/client_config/uri_parser.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 893aac36fb..09febb191e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -451,7 +451,6 @@ add_library(grpc src/core/ext/client_config/resolver.c src/core/ext/client_config/resolver_factory.c src/core/ext/client_config/resolver_registry.c - src/core/ext/client_config/resolver_result.c src/core/ext/client_config/subchannel.c src/core/ext/client_config/subchannel_index.c src/core/ext/client_config/uri_parser.c @@ -686,7 +685,6 @@ add_library(grpc_cronet src/core/ext/client_config/resolver.c src/core/ext/client_config/resolver_factory.c src/core/ext/client_config/resolver_registry.c - src/core/ext/client_config/resolver_result.c src/core/ext/client_config/subchannel.c src/core/ext/client_config/subchannel_index.c src/core/ext/client_config/uri_parser.c @@ -919,7 +917,6 @@ add_library(grpc_unsecure src/core/ext/client_config/resolver.c src/core/ext/client_config/resolver_factory.c src/core/ext/client_config/resolver_registry.c - src/core/ext/client_config/resolver_result.c src/core/ext/client_config/subchannel.c src/core/ext/client_config/subchannel_index.c src/core/ext/client_config/uri_parser.c diff --git a/Makefile b/Makefile index 38be9e658c..7c3feedd4e 100644 --- a/Makefile +++ b/Makefile @@ -2708,7 +2708,6 @@ LIBGRPC_SRC = \ src/core/ext/client_config/resolver.c \ src/core/ext/client_config/resolver_factory.c \ src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ src/core/ext/client_config/subchannel.c \ src/core/ext/client_config/subchannel_index.c \ src/core/ext/client_config/uri_parser.c \ @@ -2961,7 +2960,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/client_config/resolver.c \ src/core/ext/client_config/resolver_factory.c \ src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ src/core/ext/client_config/subchannel.c \ src/core/ext/client_config/subchannel_index.c \ src/core/ext/client_config/uri_parser.c \ @@ -3425,7 +3423,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/client_config/resolver.c \ src/core/ext/client_config/resolver_factory.c \ src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ src/core/ext/client_config/subchannel.c \ src/core/ext/client_config/subchannel_index.c \ src/core/ext/client_config/uri_parser.c \ diff --git a/binding.gyp b/binding.gyp index 397bb1b639..0323906016 100644 --- a/binding.gyp +++ b/binding.gyp @@ -726,7 +726,6 @@ 'src/core/ext/client_config/resolver.c', 'src/core/ext/client_config/resolver_factory.c', 'src/core/ext/client_config/resolver_registry.c', - 'src/core/ext/client_config/resolver_result.c', 'src/core/ext/client_config/subchannel.c', 'src/core/ext/client_config/subchannel_index.c', 'src/core/ext/client_config/uri_parser.c', diff --git a/build.yaml b/build.yaml index 2a06653103..ee3d272743 100644 --- a/build.yaml +++ b/build.yaml @@ -363,7 +363,6 @@ filegroups: - src/core/ext/client_config/resolver.h - src/core/ext/client_config/resolver_factory.h - src/core/ext/client_config/resolver_registry.h - - src/core/ext/client_config/resolver_result.h - src/core/ext/client_config/subchannel.h - src/core/ext/client_config/subchannel_index.h - src/core/ext/client_config/uri_parser.h @@ -384,7 +383,6 @@ filegroups: - src/core/ext/client_config/resolver.c - src/core/ext/client_config/resolver_factory.c - src/core/ext/client_config/resolver_registry.c - - src/core/ext/client_config/resolver_result.c - src/core/ext/client_config/subchannel.c - src/core/ext/client_config/subchannel_index.c - src/core/ext/client_config/uri_parser.c diff --git a/config.m4 b/config.m4 index d8716753b6..49dc222fac 100644 --- a/config.m4 +++ b/config.m4 @@ -245,7 +245,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/client_config/resolver.c \ src/core/ext/client_config/resolver_factory.c \ src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ src/core/ext/client_config/subchannel.c \ src/core/ext/client_config/subchannel_index.c \ src/core/ext/client_config/uri_parser.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index bb1bbc5f0e..91358feab6 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -391,7 +391,6 @@ Pod::Spec.new do |s| 'src/core/ext/client_config/resolver.h', 'src/core/ext/client_config/resolver_factory.h', 'src/core/ext/client_config/resolver_registry.h', - 'src/core/ext/client_config/resolver_result.h', 'src/core/ext/client_config/subchannel.h', 'src/core/ext/client_config/subchannel_index.h', 'src/core/ext/client_config/uri_parser.h', @@ -577,7 +576,6 @@ Pod::Spec.new do |s| 'src/core/ext/client_config/resolver.c', 'src/core/ext/client_config/resolver_factory.c', 'src/core/ext/client_config/resolver_registry.c', - 'src/core/ext/client_config/resolver_result.c', 'src/core/ext/client_config/subchannel.c', 'src/core/ext/client_config/subchannel_index.c', 'src/core/ext/client_config/uri_parser.c', @@ -768,7 +766,6 @@ Pod::Spec.new do |s| 'src/core/ext/client_config/resolver.h', 'src/core/ext/client_config/resolver_factory.h', 'src/core/ext/client_config/resolver_registry.h', - 'src/core/ext/client_config/resolver_result.h', 'src/core/ext/client_config/subchannel.h', 'src/core/ext/client_config/subchannel_index.h', 'src/core/ext/client_config/uri_parser.h', diff --git a/grpc.gemspec b/grpc.gemspec index 85172922cc..dbf8502b7d 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -311,7 +311,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/client_config/resolver.h ) s.files += %w( src/core/ext/client_config/resolver_factory.h ) s.files += %w( src/core/ext/client_config/resolver_registry.h ) - s.files += %w( src/core/ext/client_config/resolver_result.h ) s.files += %w( src/core/ext/client_config/subchannel.h ) s.files += %w( src/core/ext/client_config/subchannel_index.h ) s.files += %w( src/core/ext/client_config/uri_parser.h ) @@ -497,7 +496,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/client_config/resolver.c ) s.files += %w( src/core/ext/client_config/resolver_factory.c ) s.files += %w( src/core/ext/client_config/resolver_registry.c ) - s.files += %w( src/core/ext/client_config/resolver_result.c ) s.files += %w( src/core/ext/client_config/subchannel.c ) s.files += %w( src/core/ext/client_config/subchannel_index.c ) s.files += %w( src/core/ext/client_config/uri_parser.c ) diff --git a/package.xml b/package.xml index 31a2822a75..d7517c01ad 100644 --- a/package.xml +++ b/package.xml @@ -318,7 +318,6 @@ - @@ -504,7 +503,6 @@ - diff --git a/src/core/ext/client_config/README.md b/src/core/ext/client_config/README.md index eda01e3e71..7c209db12e 100644 --- a/src/core/ext/client_config/README.md +++ b/src/core/ext/client_config/README.md @@ -5,28 +5,27 @@ This library provides high level configuration machinery to construct client channels and load balance between them. Each grpc_channel is created with a grpc_resolver. It is the resolver's duty -to resolve a name into configuration data for the channel. Such configuration -data might include: +to resolve a name into a set of arguments for the channel. Such arguments +might include: - a list of (ip, port) addresses to connect to - a load balancing policy to decide which server to send a request to - a set of filters to mutate outgoing requests (say, by adding metadata) -The resolver provides this data as a stream of grpc_resolver_result objects to -the channel. We represent configuration as a stream so that it can be changed -by the resolver during execution, by reacting to external events (such as a -new configuration file being pushed to some store). +The resolver provides this data as a stream of grpc_channel_args objects to +the channel. We represent arguments as a stream so that they can be changed +by the resolver during execution, by reacting to external events (such as +new service configuration data being pushed to some store). Load Balancing -------------- -Load balancing configuration is provided by a grpc_lb_policy object, stored as -part of grpc_resolver_result. +Load balancing configuration is provided by a grpc_lb_policy object. -The primary job of the load balancing policies is to pick a target server given only the -initial metadata for a request. It does this by providing a grpc_subchannel -object to the owning channel. +The primary job of the load balancing policies is to pick a target server +given only the initial metadata for a request. It does this by providing +a grpc_subchannel object to the owning channel. Sub-Channels diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index f23da5f35d..f1fca822e8 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -79,7 +79,7 @@ typedef struct client_channel_channel_data { /** method config table */ grpc_method_config_table *method_config_table; /** incoming resolver result - set by resolver.next() */ - grpc_resolver_result *resolver_result; + grpc_channel_args *resolver_result; /** a list of closures that are all waiting for config to come in */ grpc_closure_list waiting_for_config_closures; /** resolver callback */ @@ -184,41 +184,42 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, if (chand->resolver_result != NULL) { grpc_lb_policy_args lb_policy_args; - lb_policy_args.server_name = - grpc_resolver_result_get_server_name(chand->resolver_result); - lb_policy_args.addresses = - grpc_resolver_result_get_addresses(chand->resolver_result); - lb_policy_args.args = - grpc_resolver_result_get_channel_args(chand->resolver_result); + lb_policy_args.args = chand->resolver_result; lb_policy_args.client_channel_factory = chand->client_channel_factory; // Find LB policy name. const char *lb_policy_name = NULL; - const grpc_arg *lb_policy_name_arg = + const grpc_arg *channel_arg = grpc_channel_args_find(lb_policy_args.args, GRPC_ARG_LB_POLICY_NAME); - if (lb_policy_name_arg != NULL) { - GPR_ASSERT(lb_policy_name_arg->type == GRPC_ARG_STRING); - lb_policy_name = lb_policy_name_arg->value.string; + if (channel_arg != NULL) { + GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); + lb_policy_name = channel_arg->value.string; } // Special case: If all of the addresses are balancer addresses, // assume that we should use the grpclb policy, regardless of what the // resolver actually specified. - bool found_backend_address = false; - for (size_t i = 0; i < lb_policy_args.addresses->num_addresses; ++i) { - if (!lb_policy_args.addresses->addresses[i].is_balancer) { - found_backend_address = true; - break; + channel_arg = + grpc_channel_args_find(lb_policy_args.args, GRPC_ARG_LB_ADDRESSES); + if (channel_arg != NULL) { + GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); + grpc_lb_addresses* addresses = channel_arg->value.pointer.p; + bool found_backend_address = false; + for (size_t i = 0; i < addresses->num_addresses; ++i) { + if (!addresses->addresses[i].is_balancer) { + found_backend_address = true; + break; + } } - } - if (!found_backend_address) { - if (lb_policy_name != NULL && strcmp(lb_policy_name, "grpclb") != 0) { - gpr_log(GPR_INFO, - "resolver requested LB policy %s but provided only balancer " - "addresses, no backend addresses -- forcing use of grpclb LB " - "policy", - (lb_policy_name == NULL ? "(none)" : lb_policy_name)); + if (!found_backend_address) { + if (lb_policy_name != NULL && strcmp(lb_policy_name, "grpclb") != 0) { + gpr_log(GPR_INFO, + "resolver requested LB policy %s but provided only balancer " + "addresses, no backend addresses -- forcing use of grpclb LB " + "policy", + (lb_policy_name == NULL ? "(none)" : lb_policy_name)); + } + lb_policy_name = "grpclb"; } - lb_policy_name = "grpclb"; } // Use pick_first if nothing was specified and we didn't select grpclb // above. @@ -232,14 +233,14 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, state = grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); } - const grpc_arg *channel_arg = grpc_channel_args_find( - lb_policy_args.args, GRPC_ARG_SERVICE_CONFIG); + channel_arg = + grpc_channel_args_find(lb_policy_args.args, GRPC_ARG_SERVICE_CONFIG); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); method_config_table = grpc_method_config_table_ref( (grpc_method_config_table *)channel_arg->value.pointer.p); } - grpc_resolver_result_unref(exec_ctx, chand->resolver_result); + grpc_channel_args_destroy(chand->resolver_result); chand->resolver_result = NULL; } diff --git a/src/core/ext/client_config/lb_policy_factory.h b/src/core/ext/client_config/lb_policy_factory.h index f0798a3167..26fe8f17ae 100644 --- a/src/core/ext/client_config/lb_policy_factory.h +++ b/src/core/ext/client_config/lb_policy_factory.h @@ -102,11 +102,7 @@ grpc_arg grpc_lb_addresses_create_channel_arg( const grpc_lb_addresses *addresses); /** Arguments passed to LB policies. */ -/* TODO(roth, ctiller): Consider replacing this struct with - grpc_channel_args. See comment in resolver_result.h for details. */ typedef struct grpc_lb_policy_args { - const char *server_name; - grpc_lb_addresses *addresses; grpc_client_channel_factory *client_channel_factory; grpc_channel_args *args; } grpc_lb_policy_args; diff --git a/src/core/ext/client_config/resolver.c b/src/core/ext/client_config/resolver.c index 7534ea62af..d3ca12484f 100644 --- a/src/core/ext/client_config/resolver.c +++ b/src/core/ext/client_config/resolver.c @@ -76,7 +76,7 @@ void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, } void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **result, + grpc_channel_args **result, grpc_closure *on_complete) { resolver->vtable->next(exec_ctx, resolver, result, on_complete); } diff --git a/src/core/ext/client_config/resolver.h b/src/core/ext/client_config/resolver.h index 88ac262d51..b5979a5bfd 100644 --- a/src/core/ext/client_config/resolver.h +++ b/src/core/ext/client_config/resolver.h @@ -34,15 +34,13 @@ #ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H #define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H -#include "src/core/ext/client_config/resolver_result.h" #include "src/core/ext/client_config/subchannel.h" #include "src/core/lib/iomgr/iomgr.h" typedef struct grpc_resolver grpc_resolver; typedef struct grpc_resolver_vtable grpc_resolver_vtable; -/** grpc_resolver provides grpc_resolver_result objects to grpc_channel - objects */ +/** grpc_resolver provides grpc_channel_args objects to grpc_channel objects */ struct grpc_resolver { const grpc_resolver_vtable *vtable; gpr_refcount refs; @@ -53,7 +51,7 @@ struct grpc_resolver_vtable { void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); void (*channel_saw_error)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); void (*next)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **result, grpc_closure *on_complete); + grpc_channel_args **result, grpc_closure *on_complete); }; #ifdef GRPC_RESOLVER_REFCOUNT_DEBUG @@ -81,14 +79,13 @@ void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); -/** Get the next client config. Called by the channel to fetch a new - configuration. Expected to set *result with a new configuration, - and then schedule on_complete for execution. +/** Get the next result from the resolver. Expected to set *result with + new channel args and then schedule on_complete for execution. If resolution is fatally broken, set *result to NULL and schedule on_complete. */ void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **result, + grpc_channel_args **result, grpc_closure *on_complete); #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H */ diff --git a/src/core/ext/client_config/resolver_factory.h b/src/core/ext/client_config/resolver_factory.h index e70e056577..e97281c922 100644 --- a/src/core/ext/client_config/resolver_factory.h +++ b/src/core/ext/client_config/resolver_factory.h @@ -41,8 +41,6 @@ typedef struct grpc_resolver_factory grpc_resolver_factory; typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable; -/** grpc_resolver provides grpc_resolver_result objects to grpc_channel - objects */ struct grpc_resolver_factory { const grpc_resolver_factory_vtable *vtable; }; diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c deleted file mode 100644 index e6a6f2da62..0000000000 --- a/src/core/ext/client_config/resolver_result.c +++ /dev/null @@ -1,94 +0,0 @@ -// -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#include "src/core/ext/client_config/resolver_result.h" - -#include - -#include -#include - -#include "src/core/lib/channel/channel_args.h" - -struct grpc_resolver_result { - gpr_refcount refs; - char* server_name; - grpc_lb_addresses* addresses; - char* lb_policy_name; - grpc_channel_args* channel_args; -}; - -grpc_resolver_result* grpc_resolver_result_create( - const char* server_name, grpc_lb_addresses* addresses, - const char* lb_policy_name, grpc_channel_args* args) { - grpc_resolver_result* result = gpr_malloc(sizeof(*result)); - memset(result, 0, sizeof(*result)); - gpr_ref_init(&result->refs, 1); - result->server_name = gpr_strdup(server_name); - result->addresses = addresses; - result->lb_policy_name = gpr_strdup(lb_policy_name); - result->channel_args = args; - return result; -} - -void grpc_resolver_result_ref(grpc_resolver_result* result) { - gpr_ref(&result->refs); -} - -void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, - grpc_resolver_result* result) { - if (gpr_unref(&result->refs)) { - gpr_free(result->server_name); - grpc_lb_addresses_destroy(result->addresses); - gpr_free(result->lb_policy_name); - grpc_channel_args_destroy(result->channel_args); - gpr_free(result); - } -} - -const char* grpc_resolver_result_get_server_name(grpc_resolver_result* result) { - return result->server_name; -} - -grpc_lb_addresses* grpc_resolver_result_get_addresses( - grpc_resolver_result* result) { - return result->addresses; -} - -const char* grpc_resolver_result_get_lb_policy_name( - grpc_resolver_result* result) { - return result->lb_policy_name; -} - -grpc_channel_args* grpc_resolver_result_get_channel_args( - grpc_resolver_result* result) { - return result->channel_args; -} diff --git a/src/core/ext/client_config/resolver_result.h b/src/core/ext/client_config/resolver_result.h deleted file mode 100644 index f081c0448a..0000000000 --- a/src/core/ext/client_config/resolver_result.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H - -#include "src/core/ext/client_config/lb_policy_factory.h" -#include "src/core/lib/iomgr/resolve_address.h" - -// TODO(roth, ctiller): In the long term, we are considering replacing -// the resolver_result data structure with grpc_channel_args. The idea is -// that the resolver will return a set of channel args that contains the -// information that is currently in the resolver_result struct. For -// example, there will be specific args indicating the set of addresses -// and the name of the LB policy to instantiate. Note that if we did -// this, we would probably want to change the data structure of -// grpc_channel_args such to a hash table or AVL or some other data -// structure that does not require linear search to find keys. - -/// Results reported from a grpc_resolver. -typedef struct grpc_resolver_result grpc_resolver_result; - -/// Takes ownership of \a addresses and \a args. -grpc_resolver_result* grpc_resolver_result_create( - const char* server_name, grpc_lb_addresses* addresses, - const char* lb_policy_name, grpc_channel_args* args); - -void grpc_resolver_result_ref(grpc_resolver_result* result); -void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, - grpc_resolver_result* result); - -/// Accessors. Caller does NOT take ownership of results. -const char* grpc_resolver_result_get_server_name(grpc_resolver_result* result); -grpc_lb_addresses* grpc_resolver_result_get_addresses( - grpc_resolver_result* result); -const char* grpc_resolver_result_get_lb_policy_name( - grpc_resolver_result* result); -grpc_channel_args* grpc_resolver_result_get_channel_args( - grpc_resolver_result* result); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index fdc0bec996..9784150eef 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -465,16 +465,21 @@ static grpc_lb_policy *create_rr_locked( glb_lb_policy *glb_policy) { GPR_ASSERT(serverlist != NULL && serverlist->num_servers > 0); + if (glb_policy->addresses != NULL) { + /* dispose of the previous version */ + grpc_lb_addresses_destroy(glb_policy->addresses); + } + glb_policy->addresses = process_serverlist(serverlist); + grpc_lb_policy_args args; memset(&args, 0, sizeof(args)); - args.server_name = glb_policy->server_name; args.client_channel_factory = glb_policy->cc_factory; - args.addresses = process_serverlist(serverlist); // Replace the LB addresses in the channel args that we pass down to // the subchannel. static const char* keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; - const grpc_arg arg = grpc_lb_addresses_create_channel_arg(args.addresses); + const grpc_arg arg = + grpc_lb_addresses_create_channel_arg(glb_policy->addresses); args.args = grpc_channel_args_copy_and_add_and_remove( glb_policy->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &arg, 1); @@ -482,12 +487,6 @@ static grpc_lb_policy *create_rr_locked( grpc_lb_policy *rr = grpc_lb_policy_create(exec_ctx, "round_robin", &args); grpc_channel_args_destroy(args.args); - if (glb_policy->addresses != NULL) { - /* dispose of the previous version */ - grpc_lb_addresses_destroy(glb_policy->addresses); - } - glb_policy->addresses = args.addresses; - return rr; } diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 039fb2225d..cb3d8cea27 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -54,10 +54,7 @@ typedef struct { /** base class: must be first */ grpc_resolver base; - /** target name */ -// FIXME: remove target_name when resolver_result goes away - char *target_name; - /** name to resolve (usually the same as target_name) */ + /** name to resolve */ char *name_to_resolve; /** default port to use */ char *default_port; @@ -75,9 +72,9 @@ typedef struct { /** pending next completion, or NULL */ grpc_closure *next_completion; /** target result address for next completion */ - grpc_resolver_result **target_result; + grpc_channel_args **target_result; /** current (fully resolved) result */ - grpc_resolver_result *resolved_result; + grpc_channel_args *resolved_result; /** retry timer */ bool have_retry_timer; grpc_timer retry_timer; @@ -98,7 +95,7 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, static void dns_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *r); static void dns_channel_saw_error(grpc_exec_ctx *exec_ctx, grpc_resolver *r); static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *r, - grpc_resolver_result **target_result, + grpc_channel_args **target_result, grpc_closure *on_complete); static const grpc_resolver_vtable dns_resolver_vtable = { @@ -131,7 +128,7 @@ static void dns_channel_saw_error(grpc_exec_ctx *exec_ctx, } static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **target_result, + grpc_channel_args **target_result, grpc_closure *on_complete) { dns_resolver *r = (dns_resolver *)resolver; gpr_mu_lock(&r->mu); @@ -166,7 +163,7 @@ static void dns_on_retry_timer(grpc_exec_ctx *exec_ctx, void *arg, static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { dns_resolver *r = arg; - grpc_resolver_result *result = NULL; + grpc_channel_args *result = NULL; gpr_mu_lock(&r->mu); GPR_ASSERT(r->resolving); r->resolving = false; @@ -180,11 +177,9 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, NULL /* balancer_name */, NULL /* user_data */); } grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); - grpc_channel_args* args = - grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); + result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); grpc_resolved_addresses_destroy(r->addresses); - result = grpc_resolver_result_create( - r->target_name, addresses, NULL /* lb_policy_name */, args); + grpc_lb_addresses_destroy(addresses); } else { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); @@ -204,8 +199,8 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, grpc_timer_init(exec_ctx, &r->retry_timer, next_try, dns_on_retry_timer, r, now); } - if (r->resolved_result) { - grpc_resolver_result_unref(exec_ctx, r->resolved_result); + if (r->resolved_result != NULL) { + grpc_channel_args_destroy(r->resolved_result); } r->resolved_result = result; r->resolved_version++; @@ -229,10 +224,7 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, dns_resolver *r) { if (r->next_completion != NULL && r->resolved_version != r->published_version) { - *r->target_result = r->resolved_result; - if (r->resolved_result) { - grpc_resolver_result_ref(r->resolved_result); - } + *r->target_result = grpc_channel_args_copy(r->resolved_result); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; r->published_version = r->resolved_version; @@ -242,10 +234,9 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { dns_resolver *r = (dns_resolver *)gr; gpr_mu_destroy(&r->mu); - if (r->resolved_result) { - grpc_resolver_result_unref(exec_ctx, r->resolved_result); + if (r->resolved_result != NULL) { + grpc_channel_args_destroy(r->resolved_result); } - gpr_free(r->target_name); gpr_free(r->name_to_resolve); gpr_free(r->default_port); grpc_channel_args_destroy(r->channel_args); @@ -268,7 +259,6 @@ static grpc_resolver *dns_create(grpc_resolver_args *args, memset(r, 0, sizeof(*r)); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &dns_resolver_vtable); - r->target_name = gpr_strdup(path); r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name; r->default_port = gpr_strdup(default_port); grpc_arg server_name_arg; diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index 93a34bf305..3f161f2ebd 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -41,6 +41,7 @@ #include #include +#include "src/core/ext/client_config/lb_policy_factory.h" #include "src/core/ext/client_config/parse_address.h" #include "src/core/ext/client_config/resolver_registry.h" #include "src/core/lib/channel/channel_args.h" @@ -51,9 +52,6 @@ typedef struct { /** base class: must be first */ grpc_resolver base; - /** the path component of the uri passed in */ -// FIXME: remove target_name when resolver_result goes away - char *target_name; /** the addresses that we've 'resolved' */ grpc_lb_addresses *addresses; /** channel args */ @@ -65,7 +63,7 @@ typedef struct { /** pending next completion, or NULL */ grpc_closure *next_completion; /** target result address for next completion */ - grpc_resolver_result **target_result; + grpc_channel_args **target_result; } sockaddr_resolver; static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r); @@ -77,7 +75,7 @@ static void sockaddr_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *r); static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx, grpc_resolver *r); static void sockaddr_next(grpc_exec_ctx *exec_ctx, grpc_resolver *r, - grpc_resolver_result **target_result, + grpc_channel_args **target_result, grpc_closure *on_complete); static const grpc_resolver_vtable sockaddr_resolver_vtable = { @@ -106,7 +104,7 @@ static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx, } static void sockaddr_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **target_result, + grpc_channel_args **target_result, grpc_closure *on_complete) { sockaddr_resolver *r = (sockaddr_resolver *)resolver; gpr_mu_lock(&r->mu); @@ -122,11 +120,8 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, if (r->next_completion != NULL && !r->published) { r->published = true; grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); - grpc_channel_args* args = + *r->target_result = grpc_channel_args_copy_and_add(r->channel_args, &arg, 1); - *r->target_result = grpc_resolver_result_create( - r->target_name, grpc_lb_addresses_copy(r->addresses), - NULL /* lb_policy_name */, args); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } @@ -135,7 +130,6 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { sockaddr_resolver *r = (sockaddr_resolver *)gr; gpr_mu_destroy(&r->mu); - gpr_free(r->target_name); grpc_lb_addresses_destroy(r->addresses); grpc_channel_args_destroy(r->channel_args); gpr_free(r); @@ -206,7 +200,6 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, /* Instantiate resolver. */ sockaddr_resolver *r = gpr_malloc(sizeof(sockaddr_resolver)); memset(r, 0, sizeof(*r)); - r->target_name = gpr_strdup(args->uri->path); r->addresses = addresses; grpc_arg server_name_arg; server_name_arg.type = GRPC_ARG_STRING; diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index a40edfb090..d44b826fb8 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -239,7 +239,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/client_config/resolver.c', 'src/core/ext/client_config/resolver_factory.c', 'src/core/ext/client_config/resolver_registry.c', - 'src/core/ext/client_config/resolver_result.c', 'src/core/ext/client_config/subchannel.c', 'src/core/ext/client_config/subchannel_index.c', 'src/core/ext/client_config/uri_parser.c', diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index f77f3eb27d..8e0d8a45b3 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -42,6 +42,7 @@ #include #include +#include "src/core/ext/client_config/lb_policy_factory.h" #include "src/core/ext/client_config/method_config.h" #include "src/core/ext/client_config/parse_address.h" #include "src/core/ext/client_config/resolver_registry.h" @@ -59,8 +60,6 @@ typedef struct { grpc_resolver base; // passed-in parameters -// FIXME: remove target_name once resolver_result is removed - char* target_name; // the path component of the uri passed in grpc_channel_args* channel_args; grpc_lb_addresses* addresses; char* lb_policy_name; @@ -73,13 +72,12 @@ typedef struct { // pending next completion, or NULL grpc_closure* next_completion; // target result address for next completion - grpc_resolver_result** target_result; + grpc_channel_args** target_result; } fake_resolver; static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { fake_resolver* r = (fake_resolver*)gr; gpr_mu_destroy(&r->mu); - gpr_free(r->target_name); grpc_channel_args_destroy(r->channel_args); grpc_lb_addresses_destroy(r->addresses); gpr_free(r->lb_policy_name); @@ -116,11 +114,8 @@ static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, new_args[num_args].value.string = r->lb_policy_name; ++num_args; } - grpc_channel_args* args = + *r->target_result = grpc_channel_args_copy_and_add(r->channel_args, new_args, num_args); - *r->target_result = grpc_resolver_result_create( - r->target_name, grpc_lb_addresses_copy(r->addresses), - r->lb_policy_name, args); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; } @@ -136,7 +131,7 @@ static void fake_resolver_channel_saw_error(grpc_exec_ctx* exec_ctx, } static void fake_resolver_next(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, - grpc_resolver_result** target_result, + grpc_channel_args** target_result, grpc_closure* on_complete) { fake_resolver* r = (fake_resolver*)resolver; gpr_mu_lock(&r->mu); @@ -244,11 +239,10 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, // Instantiate resolver. fake_resolver* r = gpr_malloc(sizeof(fake_resolver)); memset(r, 0, sizeof(*r)); - r->target_name = gpr_strdup(args->uri->path); grpc_arg server_name_arg; server_name_arg.type = GRPC_ARG_STRING; server_name_arg.key = GRPC_ARG_SERVER_NAME; - server_name_arg.value.string = r->target_name; + server_name_arg.value.string = args->uri->path; r->channel_args = grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); r->addresses = addresses; diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e5c91cbb13..63d5b04ecc 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -928,7 +928,6 @@ src/core/ext/client_config/parse_address.h \ src/core/ext/client_config/resolver.h \ src/core/ext/client_config/resolver_factory.h \ src/core/ext/client_config/resolver_registry.h \ -src/core/ext/client_config/resolver_result.h \ src/core/ext/client_config/subchannel.h \ src/core/ext/client_config/subchannel_index.h \ src/core/ext/client_config/uri_parser.h \ @@ -1114,7 +1113,6 @@ src/core/ext/client_config/parse_address.c \ src/core/ext/client_config/resolver.c \ src/core/ext/client_config/resolver_factory.c \ src/core/ext/client_config/resolver_registry.c \ -src/core/ext/client_config/resolver_result.c \ src/core/ext/client_config/subchannel.c \ src/core/ext/client_config/subchannel_index.c \ src/core/ext/client_config/uri_parser.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 7cfb1d4c17..e8ceb294ef 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6735,7 +6735,6 @@ "src/core/ext/client_config/resolver.h", "src/core/ext/client_config/resolver_factory.h", "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", "src/core/ext/client_config/subchannel.h", "src/core/ext/client_config/subchannel_index.h", "src/core/ext/client_config/uri_parser.h" @@ -6773,8 +6772,6 @@ "src/core/ext/client_config/resolver_factory.h", "src/core/ext/client_config/resolver_registry.c", "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.c", - "src/core/ext/client_config/resolver_result.h", "src/core/ext/client_config/subchannel.c", "src/core/ext/client_config/subchannel.h", "src/core/ext/client_config/subchannel_index.c", diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 9ca4908eca..d831d6df0c 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -17002,7 +17002,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17023,7 +17025,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17044,7 +17048,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17065,7 +17071,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17086,7 +17094,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17107,7 +17117,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17128,7 +17140,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17149,7 +17163,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17170,7 +17186,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17191,7 +17209,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17212,7 +17232,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17233,7 +17255,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17254,7 +17278,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17275,7 +17301,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17296,7 +17324,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17317,7 +17347,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17338,7 +17370,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17359,7 +17393,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17380,7 +17416,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17401,7 +17439,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17422,7 +17462,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17443,7 +17485,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17464,7 +17508,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17485,7 +17531,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17506,7 +17554,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17527,7 +17577,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17548,7 +17600,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17569,7 +17623,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17590,7 +17646,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17611,7 +17669,9 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17632,7 +17692,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17653,7 +17715,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17674,7 +17738,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17695,7 +17761,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17716,7 +17784,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17737,7 +17807,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17758,7 +17830,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17779,7 +17853,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17800,7 +17876,9 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [], + "exclude_configs": [ + "msan" + ], "flaky": false, "language": "c", "name": "h2_sockpair_1byte_test", @@ -17822,9 +17900,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17846,9 +17922,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17870,9 +17944,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17894,9 +17966,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17918,9 +17988,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17942,9 +18010,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17966,9 +18032,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -17990,9 +18054,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18014,9 +18076,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18038,9 +18098,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18128,9 +18186,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18152,9 +18208,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18176,9 +18230,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18200,9 +18252,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18224,9 +18274,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18248,9 +18296,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18272,9 +18318,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18318,9 +18362,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18342,9 +18384,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18366,9 +18406,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18390,9 +18428,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18414,9 +18450,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18438,9 +18472,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18462,9 +18494,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18486,9 +18516,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18510,9 +18538,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18534,9 +18560,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18558,9 +18582,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18582,9 +18604,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18606,9 +18626,7 @@ "posix" ], "cpu_cost": 0.1, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18630,9 +18648,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18654,9 +18670,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18678,9 +18692,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18702,9 +18714,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18726,9 +18736,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18772,9 +18780,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18796,9 +18802,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18820,9 +18824,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", @@ -18844,9 +18846,7 @@ "posix" ], "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], + "exclude_configs": [], "flaky": false, "language": "c", "name": "h2_ssl_test", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index b8c0049db5..d7bbc43828 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -437,7 +437,6 @@ - @@ -787,8 +786,6 @@ - - diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index fb1f904811..2c19b37099 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -487,9 +487,6 @@ src\core\ext\client_config - - src\core\ext\client_config - src\core\ext\client_config @@ -1100,9 +1097,6 @@ src\core\ext\client_config - - src\core\ext\client_config - src\core\ext\client_config diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 519d7317ba..8ee7471e2c 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -403,7 +403,6 @@ - @@ -703,8 +702,6 @@ - - diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index d30df5c03d..c0582e8a4f 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -412,9 +412,6 @@ src\core\ext\client_config - - src\core\ext\client_config - src\core\ext\client_config @@ -938,9 +935,6 @@ src\core\ext\client_config - - src\core\ext\client_config - src\core\ext\client_config -- cgit v1.2.3 From 557c990c36dd281812016ad81fa79309078e807d Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 24 Oct 2016 11:12:05 -0700 Subject: clang-format --- src/core/ext/client_channel/client_channel.c | 2 +- src/core/ext/client_channel/lb_policy_factory.c | 19 ++++++------- src/core/ext/client_channel/lb_policy_factory.h | 8 +++--- src/core/ext/client_channel/resolver.c | 3 +- src/core/ext/client_channel/resolver.h | 3 +- src/core/ext/client_channel/resolver_registry.h | 2 +- src/core/ext/lb_policy/grpclb/grpclb.c | 32 ++++++++++------------ src/core/ext/lb_policy/pick_first/pick_first.c | 14 ++++------ src/core/ext/lb_policy/round_robin/round_robin.c | 12 ++++---- src/core/ext/resolver/dns/native/dns_resolver.c | 2 +- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 4 +-- .../chttp2/client/insecure/channel_create.c | 6 ++-- .../chttp2/client/secure/secure_channel_create.c | 4 +-- src/core/lib/channel/channel_args.c | 6 ++-- src/core/lib/channel/channel_args.h | 4 +-- test/core/end2end/fake_resolver.c | 4 +-- 16 files changed, 58 insertions(+), 67 deletions(-) diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 48459de44d..acebabe8b0 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -202,7 +202,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, grpc_channel_args_find(lb_policy_args.args, GRPC_ARG_LB_ADDRESSES); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); - grpc_lb_addresses* addresses = channel_arg->value.pointer.p; + grpc_lb_addresses *addresses = channel_arg->value.pointer.p; bool found_backend_address = false; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (!addresses->addresses[i].is_balancer) { diff --git a/src/core/ext/client_channel/lb_policy_factory.c b/src/core/ext/client_channel/lb_policy_factory.c index 67ff71fdae..8a474c8818 100644 --- a/src/core/ext/client_channel/lb_policy_factory.c +++ b/src/core/ext/client_channel/lb_policy_factory.c @@ -60,9 +60,8 @@ grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses) { gpr_strdup(new_addresses->addresses[i].balancer_name); } if (new_addresses->addresses[i].user_data != NULL) { - new_addresses->addresses[i].user_data = - addresses->user_data_vtable->copy( - new_addresses->addresses[i].user_data); + new_addresses->addresses[i].user_data = addresses->user_data_vtable->copy( + new_addresses->addresses[i].user_data); } } return new_addresses; @@ -93,15 +92,15 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, const grpc_lb_address* target2 = &addresses2->addresses[i]; if (target1->address.len > target2->address.len) return 1; if (target1->address.len < target2->address.len) return -1; - int retval = memcmp( - target1->address.addr, target2->address.addr, target1->address.len); + int retval = memcmp(target1->address.addr, target2->address.addr, + target1->address.len); if (retval != 0) return retval; if (target1->is_balancer > target2->is_balancer) return 1; if (target1->is_balancer < target2->is_balancer) return -1; - const char* balancer_name1 = target1->balancer_name != NULL - ? target1->balancer_name : ""; - const char* balancer_name2 = target2->balancer_name != NULL - ? target2->balancer_name : ""; + const char* balancer_name1 = + target1->balancer_name != NULL ? target1->balancer_name : ""; + const char* balancer_name2 = + target2->balancer_name != NULL ? target2->balancer_name : ""; retval = strcmp(balancer_name1, balancer_name2); if (retval != 0) return retval; if (addresses1->user_data_vtable != NULL) { @@ -137,7 +136,7 @@ static const grpc_arg_pointer_vtable lb_addresses_arg_vtable = { lb_addresses_copy, lb_addresses_destroy, lb_addresses_cmp}; grpc_arg grpc_lb_addresses_create_channel_arg( - const grpc_lb_addresses *addresses) { + const grpc_lb_addresses* addresses) { grpc_arg arg; arg.type = GRPC_ARG_POINTER; arg.key = GRPC_ARG_LB_ADDRESSES; diff --git a/src/core/ext/client_channel/lb_policy_factory.h b/src/core/ext/client_channel/lb_policy_factory.h index 27b0a4de01..c19126d04f 100644 --- a/src/core/ext/client_channel/lb_policy_factory.h +++ b/src/core/ext/client_channel/lb_policy_factory.h @@ -60,9 +60,9 @@ typedef struct grpc_lb_address { } grpc_lb_address; typedef struct grpc_lb_user_data_vtable { - void* (*copy)(void*); - void (*destroy)(void*); - int (*cmp)(void*, void*); + void *(*copy)(void *); + void (*destroy)(void *); + int (*cmp)(void *, void *); } grpc_lb_user_data_vtable; typedef struct grpc_lb_addresses { @@ -75,7 +75,7 @@ typedef struct grpc_lb_addresses { \a num_addresses addresses. The \a user_data_vtable argument may be NULL if no user data will be added. */ grpc_lb_addresses *grpc_lb_addresses_create( - size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable); + size_t num_addresses, const grpc_lb_user_data_vtable *user_data_vtable); /** Creates a copy of \a addresses. If \a user_data_copy is not NULL, * it will be invoked to copy the \a user_data field of each address. */ diff --git a/src/core/ext/client_channel/resolver.c b/src/core/ext/client_channel/resolver.c index 3b9b6d5641..2ae4fe862e 100644 --- a/src/core/ext/client_channel/resolver.c +++ b/src/core/ext/client_channel/resolver.c @@ -76,7 +76,6 @@ void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, } void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_channel_args **result, - grpc_closure *on_complete) { + grpc_channel_args **result, grpc_closure *on_complete) { resolver->vtable->next(exec_ctx, resolver, result, on_complete); } diff --git a/src/core/ext/client_channel/resolver.h b/src/core/ext/client_channel/resolver.h index a7097935d2..0bebcf00b3 100644 --- a/src/core/ext/client_channel/resolver.h +++ b/src/core/ext/client_channel/resolver.h @@ -85,7 +85,6 @@ void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, If resolution is fatally broken, set *result to NULL and schedule on_complete. */ void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_channel_args **result, - grpc_closure *on_complete); + grpc_channel_args **result, grpc_closure *on_complete); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H */ diff --git a/src/core/ext/client_channel/resolver_registry.h b/src/core/ext/client_channel/resolver_registry.h index 60e6d003fb..ca57bef6fb 100644 --- a/src/core/ext/client_channel/resolver_registry.h +++ b/src/core/ext/client_channel/resolver_registry.h @@ -59,7 +59,7 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory); return it. If a resolver factory was not found, return NULL. */ grpc_resolver *grpc_resolver_create(const char *target, - const grpc_channel_args* args); + const grpc_channel_args *args); /** Find a resolver factory given a name and return an (owned-by-the-caller) * reference to it */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 4594793518..b0ec5633a7 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -339,13 +339,13 @@ static bool is_server_valid(const grpc_grpclb_server *server, size_t idx, } /* vtable for LB tokens in grpc_lb_addresses. */ -static void* lb_token_copy(void *token) { +static void *lb_token_copy(void *token) { return token == NULL ? NULL : GRPC_MDELEM_REF(token); } static void lb_token_destroy(void *token) { if (token != NULL) GRPC_MDELEM_UNREF(token); } -static int lb_token_cmp(void* token1, void* token2) { +static int lb_token_cmp(void *token1, void *token2) { if (token1 > token2) return 1; if (token1 < token2) return -1; return 0; @@ -477,7 +477,7 @@ static grpc_lb_policy *create_rr_locked( // Replace the LB addresses in the channel args that we pass down to // the subchannel. - static const char* keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; + static const char *keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; const grpc_arg arg = grpc_lb_addresses_create_channel_arg(glb_policy->addresses); args.args = grpc_channel_args_copy_and_add_and_remove( @@ -582,11 +582,10 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, grpc_lb_policy_args *args) { /* Get server name. */ - const grpc_arg* arg = + const grpc_arg *arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); - const char* server_name = - arg != NULL && arg->type == GRPC_ARG_STRING - ? arg->value.string : NULL; + const char *server_name = + arg != NULL && arg->type == GRPC_ARG_STRING ? arg->value.string : NULL; /* Count the number of gRPC-LB addresses. There must be at least one. * TODO(roth): For now, we ignore non-balancer addresses, but in the @@ -597,7 +596,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, * this is the right LB policy to use. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); - grpc_lb_addresses* addresses = arg->value.pointer.p; + grpc_lb_addresses *addresses = arg->value.pointer.p; size_t num_grpclb_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; @@ -631,14 +630,13 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, if (addresses->addresses[i].is_balancer) { if (addr_index == 0) { addr_strs[addr_index++] = grpc_sockaddr_to_uri( - (const struct sockaddr *)&addresses->addresses[i] - .address.addr); + (const struct sockaddr *)&addresses->addresses[i].address.addr); } else { - GPR_ASSERT(grpc_sockaddr_to_string( - &addr_strs[addr_index++], - (const struct sockaddr *)&addresses->addresses[i] - .address.addr, - true) > 0); + GPR_ASSERT( + grpc_sockaddr_to_string( + &addr_strs[addr_index++], + (const struct sockaddr *)&addresses->addresses[i].address.addr, + true) > 0); } } } @@ -661,8 +659,8 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, * so that it does not wind up recursively using the grpclb LB policy, * as per the special case logic in client_channel.c. */ - static const char* keys_to_remove[] = { - GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES}; + static const char *keys_to_remove[] = {GRPC_ARG_LB_POLICY_NAME, + GRPC_ARG_LB_ADDRESSES}; grpc_channel_args *new_args = grpc_channel_args_copy_and_remove( args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove)); glb_policy->lb_channel = grpc_client_channel_factory_create_channel( diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index d3166f3416..da4341d30d 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -35,8 +35,8 @@ #include -#include "src/core/lib/channel/channel_args.h" #include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/connectivity_state.h" typedef struct pending_pick { @@ -437,17 +437,16 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, GPR_ASSERT(args->client_channel_factory != NULL); /* Get server name. */ - const grpc_arg* arg = + const grpc_arg *arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); - const char* server_name = - arg != NULL && arg->type == GRPC_ARG_STRING - ? arg->value.string : NULL; + const char *server_name = + arg != NULL && arg->type == GRPC_ARG_STRING ? arg->value.string : NULL; /* Find the number of backend addresses. We ignore balancer * addresses, since we don't know how to handle them. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); - grpc_lb_addresses* addresses = arg->value.pointer.p; + grpc_lb_addresses *addresses = arg->value.pointer.p; size_t num_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; i++) { if (!addresses->addresses[i].is_balancer) ++num_addrs; @@ -474,8 +473,7 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, /* server_name will be copied as part of the subchannel creation. This makes * the copying of server_name (a borrowed pointer) OK. */ sc_args.server_name = server_name; - sc_args.addr = - (struct sockaddr *)(&addresses->addresses[i].address.addr); + sc_args.addr = (struct sockaddr *)(&addresses->addresses[i].address.addr); sc_args.addr_len = addresses->addresses[i].address.len; sc_args.args = args->args; diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index 9f35ebf8be..b2676a7c86 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -602,17 +602,16 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, GPR_ASSERT(args->client_channel_factory != NULL); /* Get server name. */ - const grpc_arg* arg = + const grpc_arg *arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); - const char* server_name = - arg != NULL && arg->type == GRPC_ARG_STRING - ? arg->value.string : NULL; + const char *server_name = + arg != NULL && arg->type == GRPC_ARG_STRING ? arg->value.string : NULL; /* Find the number of backend addresses. We ignore balancer * addresses, since we don't know how to handle them. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); - grpc_lb_addresses* addresses = arg->value.pointer.p; + grpc_lb_addresses *addresses = arg->value.pointer.p; size_t num_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; i++) { if (!addresses->addresses[i].is_balancer) ++num_addrs; @@ -636,8 +635,7 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, /* server_name will be copied as part of the subchannel creation. This makes * the copying of server_name (a borrowed pointer) OK. */ sc_args.server_name = server_name; - sc_args.addr = - (struct sockaddr *)(&addresses->addresses[i].address.addr); + sc_args.addr = (struct sockaddr *)(&addresses->addresses[i].address.addr); sc_args.addr_len = addresses->addresses[i].address.len; sc_args.args = args->args; diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index fa6a254c59..4ca8a29b3a 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -264,7 +264,7 @@ static grpc_resolver *dns_create(grpc_resolver_args *args, grpc_arg server_name_arg; server_name_arg.type = GRPC_ARG_STRING; server_name_arg.key = GRPC_ARG_SERVER_NAME; - server_name_arg.value.string = (char*)path; + server_name_arg.value.string = (char *)path; r->channel_args = grpc_channel_args_copy_and_add(args->args, &server_name_arg, 1); gpr_backoff_init(&r->backoff_state, BACKOFF_MULTIPLIER, BACKOFF_JITTER, diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index b81b44099e..921e8f8f15 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -175,8 +175,8 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args, gpr_slice_buffer path_parts; gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - grpc_lb_addresses *addresses = grpc_lb_addresses_create( - path_parts.count, NULL /* user_data_vtable */); + grpc_lb_addresses *addresses = + grpc_lb_addresses_create(path_parts.count, NULL /* user_data_vtable */); bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c index cf017d0ea5..b3e1a71987 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -195,8 +195,8 @@ static grpc_channel *client_channel_factory_create_channel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, const char *target, grpc_client_channel_type type, grpc_channel_args *args) { - grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, - GRPC_CLIENT_CHANNEL, NULL); + grpc_channel *channel = + grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_resolver *resolver = grpc_resolver_create(target, args); if (!resolver) { GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, @@ -233,7 +233,7 @@ grpc_channel *grpc_insecure_channel_create(const char *target, GPR_ASSERT(!reserved); grpc_client_channel_factory *factory = - (grpc_client_channel_factory*)&client_channel_factory; + (grpc_client_channel_factory *)&client_channel_factory; grpc_channel *channel = client_channel_factory_create_channel( &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index 99929eb123..37e7b0bcf9 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -274,8 +274,8 @@ static grpc_channel *client_channel_factory_create_channel( const char *target, grpc_client_channel_type type, grpc_channel_args *args) { client_channel_factory *f = (client_channel_factory *)cc_factory; - grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, - GRPC_CLIENT_CHANNEL, NULL); + grpc_channel *channel = + grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_resolver *resolver = grpc_resolver_create(target, args); if (resolver != NULL) { grpc_client_channel_finish_initialization( diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index 0270d6f224..cfc072c0b5 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -71,13 +71,13 @@ grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src, } grpc_channel_args *grpc_channel_args_copy_and_remove( - const grpc_channel_args *src, const char** to_remove, + const grpc_channel_args *src, const char **to_remove, size_t num_to_remove) { return grpc_channel_args_copy_and_add_and_remove(src, to_remove, num_to_remove, NULL, 0); } -static bool should_remove_arg(const grpc_arg* arg, const char** to_remove, +static bool should_remove_arg(const grpc_arg *arg, const char **to_remove, size_t num_to_remove) { for (size_t i = 0; i < num_to_remove; ++i) { if (strcmp(arg->key, to_remove[i]) == 0) return true; @@ -86,7 +86,7 @@ static bool should_remove_arg(const grpc_arg* arg, const char** to_remove, } grpc_channel_args *grpc_channel_args_copy_and_add_and_remove( - const grpc_channel_args *src, const char** to_remove, size_t num_to_remove, + const grpc_channel_args *src, const char **to_remove, size_t num_to_remove, const grpc_arg *to_add, size_t num_to_add) { // Figure out how many args we'll be copying. size_t num_args_to_copy = 0; diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 1508d23748..1e05303471 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -54,12 +54,12 @@ grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src, /** Copies the arguments in \a src except for those whose keys are in \a to_remove. */ grpc_channel_args *grpc_channel_args_copy_and_remove( - const grpc_channel_args *src, const char** to_remove, size_t num_to_remove); + const grpc_channel_args *src, const char **to_remove, size_t num_to_remove); /** Copies the arguments from \a src except for those whose keys are in \a to_remove and appends the arguments in \a to_add. */ grpc_channel_args *grpc_channel_args_copy_and_add_and_remove( - const grpc_channel_args *src, const char** to_remove, size_t num_to_remove, + const grpc_channel_args *src, const char **to_remove, size_t num_to_remove, const grpc_arg *to_add, size_t num_to_add); /** Concatenate args from \a a and \a b into a new instance */ diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index 0dcfdcf43b..c5a916ef8b 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -174,8 +174,8 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, gpr_slice_buffer path_parts; gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - grpc_lb_addresses* addresses = grpc_lb_addresses_create( - path_parts.count, NULL /* user_data_vtable */); + grpc_lb_addresses* addresses = + grpc_lb_addresses_create(path_parts.count, NULL /* user_data_vtable */); bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; -- cgit v1.2.3 From 25db523baa162b6b5d0fa2a652aca2d37dfa6dba Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 24 Oct 2016 12:53:01 -0700 Subject: Fix sockaddr_resolver_test. --- .../core/client_channel/resolvers/sockaddr_resolver_test.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.c b/test/core/client_channel/resolvers/sockaddr_resolver_test.c index c39052cd9d..20c42b7387 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.c +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.c @@ -38,21 +38,23 @@ #include #include "src/core/ext/client_channel/resolver_registry.h" -#include "src/core/ext/client_channel/resolver_result.h" +#include "src/core/lib/channel/channel_args.h" #include "test/core/util/test_config.h" typedef struct on_resolution_arg { char *expected_server_name; - grpc_resolver_result *resolver_result; + grpc_channel_args *resolver_result; } on_resolution_arg; void on_resolution_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { on_resolution_arg *res = arg; - const char *server_name = - grpc_resolver_result_get_server_name(res->resolver_result); - GPR_ASSERT(strcmp(res->expected_server_name, server_name) == 0); - grpc_resolver_result_unref(exec_ctx, res->resolver_result); + const grpc_arg* channel_arg = + grpc_channel_args_find(res->resolver_result, GRPC_ARG_SERVER_NAME); + GPR_ASSERT(channel_arg != NULL); + GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); + GPR_ASSERT(strcmp(res->expected_server_name, channel_arg->value.string) == 0); + grpc_channel_args_destroy(res->resolver_result); } static void test_succeeds(grpc_resolver_factory *factory, const char *string) { -- cgit v1.2.3 From b367c1bed706bf408ac4c8f3664e1213505ddc3c Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 24 Oct 2016 12:59:07 -0700 Subject: Fix dns_resolver_connectivity_test. --- src/core/ext/resolver/dns/native/dns_resolver.c | 4 +++- test/core/client_channel/resolvers/dns_resolver_connectivity_test.c | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 4ca8a29b3a..958b8af8b2 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -224,7 +224,9 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, dns_resolver *r) { if (r->next_completion != NULL && r->resolved_version != r->published_version) { - *r->target_result = grpc_channel_args_copy(r->resolved_result); + *r->target_result = r->resolved_result == NULL + ? NULL + : grpc_channel_args_copy(r->resolved_result); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; r->published_version = r->resolved_version; diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c index 07723c229d..ffa167a0e7 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c @@ -37,6 +37,7 @@ #include #include "src/core/ext/client_channel/resolver_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/timer.h" #include "test/core/util/test_config.h" @@ -103,7 +104,7 @@ int main(int argc, char **argv) { grpc_resolver *resolver = create_resolver("dns:test"); - grpc_resolver_result *result = (grpc_resolver_result *)1; + grpc_channel_args *result = (grpc_channel_args *)1; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_event ev1; @@ -122,7 +123,7 @@ int main(int argc, char **argv) { GPR_ASSERT(wait_loop(30, &ev2)); GPR_ASSERT(result != NULL); - grpc_resolver_result_unref(&exec_ctx, result); + grpc_channel_args_destroy(result); GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); grpc_exec_ctx_finish(&exec_ctx); -- cgit v1.2.3 From 5f40e5ddf597169a5cf88d1b0471831f1db1edc0 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 24 Oct 2016 13:09:05 -0700 Subject: Minor clean-up. --- src/core/ext/client_channel/client_channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index acebabe8b0..dfa84b0d77 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -216,7 +216,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, "resolver requested LB policy %s but provided only balancer " "addresses, no backend addresses -- forcing use of grpclb LB " "policy", - (lb_policy_name == NULL ? "(none)" : lb_policy_name)); + lb_policy_name); } lb_policy_name = "grpclb"; } -- cgit v1.2.3 From e3a21005bfa42d974ee2b8a0776797ae2b7eea23 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 24 Oct 2016 13:29:05 -0700 Subject: Fix propagation of channel args for insecure channels. --- src/core/ext/client_channel/client_channel_factory.c | 4 ++-- src/core/ext/client_channel/client_channel_factory.h | 9 +++++---- src/core/ext/client_channel/subchannel.c | 2 +- src/core/ext/client_channel/subchannel.h | 2 +- src/core/ext/client_channel/subchannel_index.c | 6 +++--- src/core/ext/client_channel/subchannel_index.h | 4 ++-- src/core/ext/transport/chttp2/client/insecure/channel_create.c | 6 +++--- .../ext/transport/chttp2/client/secure/secure_channel_create.c | 4 ++-- test/cpp/end2end/end2end_test.cc | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/core/ext/client_channel/client_channel_factory.c b/src/core/ext/client_channel/client_channel_factory.c index db1cc9093c..4900832d57 100644 --- a/src/core/ext/client_channel/client_channel_factory.c +++ b/src/core/ext/client_channel/client_channel_factory.c @@ -44,14 +44,14 @@ void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, grpc_subchannel* grpc_client_channel_factory_create_subchannel( grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - grpc_subchannel_args* args) { + const grpc_subchannel_args* args) { return factory->vtable->create_subchannel(exec_ctx, factory, args); } grpc_channel* grpc_client_channel_factory_create_channel( grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, const char* target, grpc_client_channel_type type, - grpc_channel_args* args) { + const grpc_channel_args* args) { return factory->vtable->create_client_channel(exec_ctx, factory, target, type, args); } diff --git a/src/core/ext/client_channel/client_channel_factory.h b/src/core/ext/client_channel/client_channel_factory.h index 28828c2eb6..2b8fc577b3 100644 --- a/src/core/ext/client_channel/client_channel_factory.h +++ b/src/core/ext/client_channel/client_channel_factory.h @@ -60,12 +60,12 @@ struct grpc_client_channel_factory_vtable { void (*unref)(grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory); grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - grpc_subchannel_args *args); + const grpc_subchannel_args *args); grpc_channel *(*create_client_channel)(grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, const char *target, grpc_client_channel_type type, - grpc_channel_args *args); + const grpc_channel_args *args); }; void grpc_client_channel_factory_ref(grpc_client_channel_factory *factory); @@ -75,11 +75,12 @@ void grpc_client_channel_factory_unref(grpc_exec_ctx *exec_ctx, /** Create a new grpc_subchannel */ grpc_subchannel *grpc_client_channel_factory_create_subchannel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - grpc_subchannel_args *args); + const grpc_subchannel_args *args); /** Create a new grpc_channel */ grpc_channel *grpc_client_channel_factory_create_channel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - const char *target, grpc_client_channel_type type, grpc_channel_args *args); + const char *target, grpc_client_channel_type type, + const grpc_channel_args *args); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_CLIENT_CHANNEL_FACTORY_H */ diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 672e5c3a91..b35bb79bc7 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -298,7 +298,7 @@ void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - grpc_subchannel_args *args) { + const grpc_subchannel_args *args) { grpc_subchannel_key *key = grpc_subchannel_key_create(connector, args); grpc_subchannel *c = grpc_subchannel_index_find(exec_ctx, key); if (c) { diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index c4a7da0c24..0f34cff14b 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -174,6 +174,6 @@ struct grpc_subchannel_args { /** create a subchannel given a connector */ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - grpc_subchannel_args *args); + const grpc_subchannel_args *args); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_SUBCHANNEL_H */ diff --git a/src/core/ext/client_channel/subchannel_index.c b/src/core/ext/client_channel/subchannel_index.c index bf22975fba..7c547f8edb 100644 --- a/src/core/ext/client_channel/subchannel_index.c +++ b/src/core/ext/client_channel/subchannel_index.c @@ -73,7 +73,7 @@ static grpc_exec_ctx *current_ctx() { } static grpc_subchannel_key *create_key( - grpc_connector *connector, grpc_subchannel_args *args, + grpc_connector *connector, const grpc_subchannel_args *args, grpc_channel_args *(*copy_channel_args)(const grpc_channel_args *args)) { grpc_subchannel_key *k = gpr_malloc(sizeof(*k)); k->connector = grpc_connector_ref(connector); @@ -96,8 +96,8 @@ static grpc_subchannel_key *create_key( return k; } -grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *connector, - grpc_subchannel_args *args) { +grpc_subchannel_key *grpc_subchannel_key_create( + grpc_connector *connector, const grpc_subchannel_args *args) { return create_key(connector, args, grpc_channel_args_normalize); } diff --git a/src/core/ext/client_channel/subchannel_index.h b/src/core/ext/client_channel/subchannel_index.h index 5b3af6b054..a67bd5e219 100644 --- a/src/core/ext/client_channel/subchannel_index.h +++ b/src/core/ext/client_channel/subchannel_index.h @@ -43,8 +43,8 @@ typedef struct grpc_subchannel_key grpc_subchannel_key; /** Create a key that can be used to uniquely identify a subchannel */ -grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *con, - grpc_subchannel_args *args); +grpc_subchannel_key *grpc_subchannel_key_create( + grpc_connector *con, const grpc_subchannel_args *args); /** Destroy a subchannel key */ void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx, diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c index b3e1a71987..6dc7316991 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -173,7 +173,7 @@ static void client_channel_factory_unref( static grpc_subchannel *client_channel_factory_create_subchannel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - grpc_subchannel_args *args) { + const grpc_subchannel_args *args) { connector *c = gpr_malloc(sizeof(*c)); memset(c, 0, sizeof(*c)); c->base.vtable = &connector_vtable; @@ -194,7 +194,7 @@ static grpc_subchannel *client_channel_factory_create_subchannel( static grpc_channel *client_channel_factory_create_channel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, const char *target, grpc_client_channel_type type, - grpc_channel_args *args) { + const grpc_channel_args *args) { grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_resolver *resolver = grpc_resolver_create(target, args); @@ -235,7 +235,7 @@ grpc_channel *grpc_insecure_channel_create(const char *target, grpc_client_channel_factory *factory = (grpc_client_channel_factory *)&client_channel_factory; grpc_channel *channel = client_channel_factory_create_channel( - &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL); + &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args); grpc_client_channel_factory_unref(&exec_ctx, factory); grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index 37e7b0bcf9..a4f1858aa2 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -248,7 +248,7 @@ static void client_channel_factory_unref( static grpc_subchannel *client_channel_factory_create_subchannel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - grpc_subchannel_args *args) { + const grpc_subchannel_args *args) { client_channel_factory *f = (client_channel_factory *)cc_factory; connector *c = gpr_malloc(sizeof(*c)); memset(c, 0, sizeof(*c)); @@ -272,7 +272,7 @@ static grpc_subchannel *client_channel_factory_create_subchannel( static grpc_channel *client_channel_factory_create_channel( grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, const char *target, grpc_client_channel_type type, - grpc_channel_args *args) { + const grpc_channel_args *args) { client_channel_factory *f = (client_channel_factory *)cc_factory; grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index b1d3ce92f6..7af0fb997e 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -636,7 +636,7 @@ TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) { auto iter = trailing_metadata.find("user-agent"); EXPECT_TRUE(iter != trailing_metadata.end()); grpc::string expected_prefix = user_agent_prefix_ + " grpc-c++/"; - EXPECT_TRUE(iter->second.starts_with(expected_prefix)); + EXPECT_TRUE(iter->second.starts_with(expected_prefix)) << iter->second; } TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { -- cgit v1.2.3 From e917f5d96a58cdfc0aceaa1337d505eef1cef885 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 25 Oct 2016 07:48:28 -0700 Subject: Update comments. --- src/core/ext/client_channel/lb_policy_factory.h | 6 ++---- src/core/ext/client_channel/resolver.h | 10 +++++----- src/core/ext/client_channel/resolver_registry.h | 4 +++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/ext/client_channel/lb_policy_factory.h b/src/core/ext/client_channel/lb_policy_factory.h index c19126d04f..e2b8080a32 100644 --- a/src/core/ext/client_channel/lb_policy_factory.h +++ b/src/core/ext/client_channel/lb_policy_factory.h @@ -77,8 +77,7 @@ typedef struct grpc_lb_addresses { grpc_lb_addresses *grpc_lb_addresses_create( size_t num_addresses, const grpc_lb_user_data_vtable *user_data_vtable); -/** Creates a copy of \a addresses. If \a user_data_copy is not NULL, - * it will be invoked to copy the \a user_data field of each address. */ +/** Creates a copy of \a addresses. */ grpc_lb_addresses *grpc_lb_addresses_copy(const grpc_lb_addresses *addresses); /** Sets the value of the address at index \a index of \a addresses. @@ -93,8 +92,7 @@ void grpc_lb_addresses_set_address(grpc_lb_addresses *addresses, size_t index, int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1, const grpc_lb_addresses *addresses2); -/** Destroys \a addresses. If \a user_data_destroy is not NULL, it will - * be invoked to destroy the \a user_data field of each address. */ +/** Destroys \a addresses. */ void grpc_lb_addresses_destroy(grpc_lb_addresses *addresses); /** Returns a channel arg containing \a addresses. */ diff --git a/src/core/ext/client_channel/resolver.h b/src/core/ext/client_channel/resolver.h index 0bebcf00b3..96ece92b9d 100644 --- a/src/core/ext/client_channel/resolver.h +++ b/src/core/ext/client_channel/resolver.h @@ -40,7 +40,7 @@ typedef struct grpc_resolver grpc_resolver; typedef struct grpc_resolver_vtable grpc_resolver_vtable; -/** grpc_resolver provides grpc_channel_args objects to grpc_channel objects */ +/** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ struct grpc_resolver { const grpc_resolver_vtable *vtable; gpr_refcount refs; @@ -79,11 +79,11 @@ void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); -/** Get the next result from the resolver. Expected to set *result with - new channel args and then schedule on_complete for execution. +/** Get the next result from the resolver. Expected to set \a *result with + new channel args and then schedule \a on_complete for execution. - If resolution is fatally broken, set *result to NULL and - schedule on_complete. */ + If resolution is fatally broken, set \a *result to NULL and + schedule \a on_complete. */ void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, grpc_channel_args **result, grpc_closure *on_complete); diff --git a/src/core/ext/client_channel/resolver_registry.h b/src/core/ext/client_channel/resolver_registry.h index ca57bef6fb..2a95a669f0 100644 --- a/src/core/ext/client_channel/resolver_registry.h +++ b/src/core/ext/client_channel/resolver_registry.h @@ -57,7 +57,9 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory); was not NULL). If a resolver factory was found, use it to instantiate a resolver and return it. - If a resolver factory was not found, return NULL. */ + If a resolver factory was not found, return NULL. + \a args is a set of channel arguments to be included in the result + (typically the set of arguments passed in from the client API). */ grpc_resolver *grpc_resolver_create(const char *target, const grpc_channel_args *args); -- cgit v1.2.3 From f0b2ec0435aebf64c6c4f8c2fe39917acfb23ef1 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 25 Oct 2016 07:49:36 -0700 Subject: clang-format --- test/core/client_channel/resolvers/sockaddr_resolver_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.c b/test/core/client_channel/resolvers/sockaddr_resolver_test.c index 20c42b7387..ebf311ab83 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.c +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.c @@ -49,7 +49,7 @@ typedef struct on_resolution_arg { void on_resolution_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { on_resolution_arg *res = arg; - const grpc_arg* channel_arg = + const grpc_arg *channel_arg = grpc_channel_args_find(res->resolver_result, GRPC_ARG_SERVER_NAME); GPR_ASSERT(channel_arg != NULL); GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); -- cgit v1.2.3 From b477cebbe77fca069fb2a4bb1e9806e0891ead83 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 25 Oct 2016 08:04:54 -0700 Subject: Fix asan bug. --- src/core/ext/transport/chttp2/client/secure/secure_channel_create.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index a4f1858aa2..00eb82e12a 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -346,6 +346,8 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, grpc_channel *channel = client_channel_factory_create_channel( &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); // Clean up. + GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, + "client_channel_factory_create_channel"); grpc_channel_args_destroy(new_args); grpc_client_channel_factory_unref(&exec_ctx, &f->base); grpc_exec_ctx_finish(&exec_ctx); -- cgit v1.2.3 From 0d34499bed969d80251f6db60997f7089efec9c2 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Tue, 25 Oct 2016 12:01:58 -0700 Subject: Remove status message check from node interop client The node interop client was checking that the status message for the test unimplemented_method was an empty string. This behavior is not guaranteed, and thus the check should be removed. --- src/node/interop/interop_client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index a59a66b2aa..46ddecfb1f 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -380,7 +380,6 @@ function unimplementedService(client, done) { client.unimplementedCall({}, function(err, resp) { assert(err); assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED); - assert(!err.message); done(); }); } -- cgit v1.2.3 From 9785c8f9c43bddebb4e01162f2f0e702521b861c Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Tue, 25 Oct 2016 12:04:24 -0700 Subject: Implement the advanced interop tests for Python Add the code for three new interop tests: unimplemented_method, unimplemented_service, and custom_metadata. Fix and refactor the code for status_code_and_message. --- src/python/grpcio_tests/tests/interop/client.py | 5 +- src/python/grpcio_tests/tests/interop/methods.py | 188 +++++++++++++++++------ tools/run_tests/run_interop_tests.py | 4 +- 3 files changed, 145 insertions(+), 52 deletions(-) diff --git a/src/python/grpcio_tests/tests/interop/client.py b/src/python/grpcio_tests/tests/interop/client.py index 9d61d18975..4fbf58f7d9 100644 --- a/src/python/grpcio_tests/tests/interop/client.py +++ b/src/python/grpcio_tests/tests/interop/client.py @@ -106,7 +106,10 @@ def _stub(args): (('grpc.ssl_target_name_override', args.server_host_override,),)) else: channel = grpc.insecure_channel(target) - return test_pb2.TestServiceStub(channel) + if args.test_case == "unimplemented_service": + return test_pb2.UnimplementedServiceStub(channel) + else: + return test_pb2.TestServiceStub(channel) def _test_case_from_arg(test_case_arg): diff --git a/src/python/grpcio_tests/tests/interop/methods.py b/src/python/grpcio_tests/tests/interop/methods.py index 7edd75c56c..52e56f3502 100644 --- a/src/python/grpcio_tests/tests/interop/methods.py +++ b/src/python/grpcio_tests/tests/interop/methods.py @@ -44,25 +44,43 @@ from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing import messages_pb2 from src.proto.grpc.testing import test_pb2 +_INITIAL_METADATA_KEY = "x-grpc-test-echo-initial" +_TRAILING_METADATA_KEY = "x-grpc-test-echo-trailing-bin" + +def _maybe_echo_metadata(servicer_context): + """Copies metadata from request to response if it is present.""" + invocation_metadata = dict(servicer_context.invocation_metadata()) + if _INITIAL_METADATA_KEY in invocation_metadata: + initial_metadatum = ( + _INITIAL_METADATA_KEY, invocation_metadata[_INITIAL_METADATA_KEY]) + servicer_context.send_initial_metadata((initial_metadatum,)) + if _TRAILING_METADATA_KEY in invocation_metadata: + trailing_metadatum = ( + _TRAILING_METADATA_KEY, invocation_metadata[_TRAILING_METADATA_KEY]) + servicer_context.set_trailing_metadata((trailing_metadatum,)) + +def _maybe_echo_status_and_message(request, servicer_context): + """Sets the response context code and details if the request asks for them""" + if request.HasField('response_status'): + servicer_context.set_code(request.response_status.code) + servicer_context.set_details(request.response_status.message) class TestService(test_pb2.TestServiceServicer): def EmptyCall(self, request, context): + _maybe_echo_metadata(context) return empty_pb2.Empty() def UnaryCall(self, request, context): - if request.HasField('response_status'): - context.set_code(request.response_status.code) - context.set_details(request.response_status.message) + _maybe_echo_metadata(context) + _maybe_echo_status_and_message(request, context) return messages_pb2.SimpleResponse( payload=messages_pb2.Payload( type=messages_pb2.COMPRESSABLE, body=b'\x00' * request.response_size)) def StreamingOutputCall(self, request, context): - if request.HasField('response_status'): - context.set_code(request.response_status.code) - context.set_details(request.response_status.message) + _maybe_echo_status_and_message(request, context) for response_parameters in request.response_parameters: yield messages_pb2.StreamingOutputCallResponse( payload=messages_pb2.Payload( @@ -78,10 +96,9 @@ class TestService(test_pb2.TestServiceServicer): aggregated_payload_size=aggregate_size) def FullDuplexCall(self, request_iterator, context): + _maybe_echo_metadata(context) for request in request_iterator: - if request.HasField('response_status'): - context.set_code(request.response_status.code) - context.set_details(request.response_status.message) + _maybe_echo_status_and_message(request, context) for response_parameters in request.response_parameters: yield messages_pb2.StreamingOutputCallResponse( payload=messages_pb2.Payload( @@ -94,23 +111,46 @@ class TestService(test_pb2.TestServiceServicer): return self.FullDuplexCall(request_iterator, context) +def _expect_status_code(call, expected_code): + if call.code() != expected_code: + raise ValueError( + 'expected code %s, got %s' % (expected_code, call.code())) + + +def _expect_status_details(call, expected_details): + if call.details() != expected_details: + raise ValueError( + 'expected message %s, got %s' % (expected_details, call.details())) + + +def _validate_status_code_and_details(call, expected_code, expected_details): + _expect_status_code(call, expected_code) + _expect_status_details(call, expected_details) + + +def _validate_payload_type_and_length(response, expected_type, expected_length): + if response.payload.type is not expected_type: + raise ValueError( + 'expected payload type %s, got %s' % + (expected_type, type(response.payload.type))) + elif len(response.payload.body) != expected_length: + raise ValueError( + 'expected payload body size %d, got %d' % + (expected_length, len(response.payload.body))) + + def _large_unary_common_behavior( stub, fill_username, fill_oauth_scope, call_credentials): + size = 314159 request = messages_pb2.SimpleRequest( - response_type=messages_pb2.COMPRESSABLE, response_size=314159, + response_type=messages_pb2.COMPRESSABLE, response_size=size, payload=messages_pb2.Payload(body=b'\x00' * 271828), fill_username=fill_username, fill_oauth_scope=fill_oauth_scope) response_future = stub.UnaryCall.future( request, credentials=call_credentials) response = response_future.result() - if response.payload.type is not messages_pb2.COMPRESSABLE: - raise ValueError( - 'response payload type is "%s"!' % type(response.payload.type)) - elif len(response.payload.body) != 314159: - raise ValueError( - 'response body of incorrect size %d!' % len(response.payload.body)) - else: - return response + _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, size) + return response def _empty_unary(stub): @@ -152,12 +192,9 @@ def _server_streaming(stub): ) response_iterator = stub.StreamingOutputCall(request) for index, response in enumerate(response_iterator): - if response.payload.type != messages_pb2.COMPRESSABLE: - raise ValueError( - 'response body of invalid type %s!' % response.payload.type) - elif len(response.payload.body) != sizes[index]: - raise ValueError( - 'response body of invalid size %d!' % len(response.payload.body)) + _validate_payload_type_and_length( + response, messages_pb2.COMPRESSABLE, sizes[index]) + def _cancel_after_begin(stub): sizes = (27182, 8, 1828, 45904,) @@ -224,12 +261,8 @@ def _ping_pong(stub): payload=messages_pb2.Payload(body=b'\x00' * payload_size)) pipe.add(request) response = next(response_iterator) - if response.payload.type != messages_pb2.COMPRESSABLE: - raise ValueError( - 'response body of invalid type %s!' % response.payload.type) - if len(response.payload.body) != response_size: - raise ValueError( - 'response body of invalid size %d!' % len(response.payload.body)) + _validate_payload_type_and_length( + response, messages_pb2.COMPRESSABLE, response_size) def _cancel_after_first_response(stub): @@ -291,36 +324,84 @@ def _empty_stream(stub): def _status_code_and_message(stub): - message = 'test status message' + details = 'test status message' code = 2 status = grpc.StatusCode.UNKNOWN # code = 2 + + # Test with a UnaryCall request = messages_pb2.SimpleRequest( response_type=messages_pb2.COMPRESSABLE, response_size=1, payload=messages_pb2.Payload(body=b'\x00'), - response_status=messages_pb2.EchoStatus(code=code, message=message) + response_status=messages_pb2.EchoStatus(code=code, message=details) ) response_future = stub.UnaryCall.future(request) - if response_future.code() != status: - raise ValueError( - 'expected code %s, got %s' % (status, response_future.code())) - elif response_future.details() != message: - raise ValueError( - 'expected message %s, got %s' % (message, response_future.details())) + _validate_status_code_and_details(response_future, status, details) - request = messages_pb2.StreamingOutputCallRequest( + # Test with a FullDuplexCall + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe) + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=( + messages_pb2.ResponseParameters(size=1),), + payload=messages_pb2.Payload(body=b'\x00'), + response_status=messages_pb2.EchoStatus(code=code, message=details)) + pipe.add(request) # sends the initial request. + # Dropping out of with block closes the pipe + _validate_status_code_and_details(response_iterator, status, details) + + +def _unimplemented_method(test_service_stub): + response_future = ( + test_service_stub.UnimplementedCall.future(empty_pb2.Empty())) + _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) + + +def _unimplemented_service(unimplemented_service_stub): + response_future = ( + unimplemented_service_stub.UnimplementedCall.future(empty_pb2.Empty())) + _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) + + +def _custom_metadata(stub): + initial_metadata_value = "test_initial_metadata_value" + trailing_metadata_value = "\x0a\x0b\x0a\x0b\x0a\x0b" + metadata = ( + (_INITIAL_METADATA_KEY, initial_metadata_value), + (_TRAILING_METADATA_KEY, trailing_metadata_value)) + + def _validate_metadata(response): + initial_metadata = dict(response.initial_metadata()) + if initial_metadata[_INITIAL_METADATA_KEY] != initial_metadata_value: + raise ValueError( + 'expected initial metadata %s, got %s' % ( + initial_metadata_value, initial_metadata[_INITIAL_METADATA_KEY])) + trailing_metadata = dict(response.trailing_metadata()) + if trailing_metadata[_TRAILING_METADATA_KEY] != trailing_metadata_value: + raise ValueError( + 'expected trailing metadata %s, got %s' % ( + trailing_metadata_value, initial_metadata[_TRAILING_METADATA_KEY])) + + # Testing with UnaryCall + request = messages_pb2.SimpleRequest( response_type=messages_pb2.COMPRESSABLE, - response_parameters=( - messages_pb2.ResponseParameters(size=1),), - response_status=messages_pb2.EchoStatus(code=code, message=message)) - response_iterator = stub.StreamingOutputCall(request) - if response_future.code() != status: - raise ValueError( - 'expected code %s, got %s' % (status, response_iterator.code())) - elif response_future.details() != message: - raise ValueError( - 'expected message %s, got %s' % (message, response_iterator.details())) + response_size=1, + payload=messages_pb2.Payload(body=b'\x00')) + response_future = stub.UnaryCall.future(request, metadata=metadata) + _validate_metadata(response_future) + # Testing with FullDuplexCall + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe, metadata=metadata) + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=( + messages_pb2.ResponseParameters(size=1),)) + pipe.add(request) # Sends the request + next(response_iterator) # Causes server to send trailing metadata + # Dropping out of the with block closes the pipe + _validate_metadata(response_iterator) def _compute_engine_creds(stub, args): response = _large_unary_common_behavior(stub, True, True, None) @@ -381,6 +462,9 @@ class TestCase(enum.Enum): CANCEL_AFTER_FIRST_RESPONSE = 'cancel_after_first_response' EMPTY_STREAM = 'empty_stream' STATUS_CODE_AND_MESSAGE = 'status_code_and_message' + UNIMPLEMENTED_METHOD = 'unimplemented_method' + UNIMPLEMENTED_SERVICE = 'unimplemented_service' + CUSTOM_METADATA = "custom_metadata" COMPUTE_ENGINE_CREDS = 'compute_engine_creds' OAUTH2_AUTH_TOKEN = 'oauth2_auth_token' JWT_TOKEN_CREDS = 'jwt_token_creds' @@ -408,6 +492,12 @@ class TestCase(enum.Enum): _empty_stream(stub) elif self is TestCase.STATUS_CODE_AND_MESSAGE: _status_code_and_message(stub) + elif self is TestCase.UNIMPLEMENTED_METHOD: + _unimplemented_method(stub) + elif self is TestCase.UNIMPLEMENTED_SERVICE: + _unimplemented_service(stub) + elif self is TestCase.CUSTOM_METADATA: + _custom_metadata(stub) elif self is TestCase.COMPUTE_ENGINE_CREDS: _compute_engine_creds(stub, args) elif self is TestCase.OAUTH2_AUTH_TOKEN: diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index 29f6533398..0c6efda1f4 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -385,10 +385,10 @@ class PythonLanguage: 'PYTHONPATH': '{}/src/python/gens'.format(DOCKER_WORKDIR_ROOT)} def unimplemented_test_cases(self): - return _SKIP_ADVANCED + _SKIP_COMPRESSION + return _SKIP_COMPRESSION def unimplemented_test_cases_server(self): - return _SKIP_ADVANCED + _SKIP_COMPRESSION + return _SKIP_COMPRESSION def __str__(self): return 'python' -- cgit v1.2.3 From d148e8e6741f167aeff3294128e2476031363f8b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 26 Oct 2016 15:28:35 +0200 Subject: Make ServerCallContext.Peer lazy --- src/csharp/Grpc.Core/Internal/ServerCallHandler.cs | 12 ++++++------ src/csharp/Grpc.Core/ServerCallContext.cs | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs index 1dbd4bbdc1..600811ddd6 100644 --- a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs +++ b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs @@ -76,7 +76,7 @@ namespace Grpc.Core.Internal Status status; Tuple responseTuple = null; - var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken); + var context = HandlerUtils.NewContext(newRpc, responseStream, asyncCall.CancellationToken); try { GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false)); @@ -134,7 +134,7 @@ namespace Grpc.Core.Internal var responseStream = new ServerResponseStream(asyncCall); Status status; - var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken); + var context = HandlerUtils.NewContext(newRpc, responseStream, asyncCall.CancellationToken); try { GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false)); @@ -193,7 +193,7 @@ namespace Grpc.Core.Internal Status status; Tuple responseTuple = null; - var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken); + var context = HandlerUtils.NewContext(newRpc, responseStream, asyncCall.CancellationToken); try { var response = await handler(requestStream, context).ConfigureAwait(false); @@ -250,7 +250,7 @@ namespace Grpc.Core.Internal var responseStream = new ServerResponseStream(asyncCall); Status status; - var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken); + var context = HandlerUtils.NewContext(newRpc, responseStream, asyncCall.CancellationToken); try { await handler(requestStream, responseStream, context).ConfigureAwait(false); @@ -324,13 +324,13 @@ namespace Grpc.Core.Internal return writeOptions != null ? writeOptions.Flags : default(WriteFlags); } - public static ServerCallContext NewContext(ServerRpcNew newRpc, string peer, ServerResponseStream serverResponseStream, CancellationToken cancellationToken) + public static ServerCallContext NewContext(ServerRpcNew newRpc, ServerResponseStream serverResponseStream, CancellationToken cancellationToken) where TRequest : class where TResponse : class { DateTime realtimeDeadline = newRpc.Deadline.ToClockType(ClockType.Realtime).ToDateTime(); - return new ServerCallContext(newRpc.Call, newRpc.Method, newRpc.Host, peer, realtimeDeadline, + return new ServerCallContext(newRpc.Call, newRpc.Method, newRpc.Host, realtimeDeadline, newRpc.RequestMetadata, cancellationToken, serverResponseStream.WriteResponseHeadersAsync, serverResponseStream); } } diff --git a/src/csharp/Grpc.Core/ServerCallContext.cs b/src/csharp/Grpc.Core/ServerCallContext.cs index 09a6b882a6..8f28fbc045 100644 --- a/src/csharp/Grpc.Core/ServerCallContext.cs +++ b/src/csharp/Grpc.Core/ServerCallContext.cs @@ -48,7 +48,6 @@ namespace Grpc.Core private readonly CallSafeHandle callHandle; private readonly string method; private readonly string host; - private readonly string peer; private readonly DateTime deadline; private readonly Metadata requestHeaders; private readonly CancellationToken cancellationToken; @@ -58,13 +57,12 @@ namespace Grpc.Core private Func writeHeadersFunc; private IHasWriteOptions writeOptionsHolder; - internal ServerCallContext(CallSafeHandle callHandle, string method, string host, string peer, DateTime deadline, Metadata requestHeaders, CancellationToken cancellationToken, + internal ServerCallContext(CallSafeHandle callHandle, string method, string host, DateTime deadline, Metadata requestHeaders, CancellationToken cancellationToken, Func writeHeadersFunc, IHasWriteOptions writeOptionsHolder) { this.callHandle = callHandle; this.method = method; this.host = host; - this.peer = peer; this.deadline = deadline; this.requestHeaders = requestHeaders; this.cancellationToken = cancellationToken; @@ -115,7 +113,10 @@ namespace Grpc.Core { get { - return this.peer; + // Getting the peer lazily is fine as the native call is guaranteed + // not to be disposed before user-supplied server side handler returns. + // Most users won't need to read this field anyway. + return this.callHandle.GetPeer(); } } -- cgit v1.2.3 From 13339bf7ea5e0ac687dc290b3225effc9f99bfd5 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 26 Oct 2016 16:38:00 +0200 Subject: SafeHandleZeroIsInvalid cleanup --- src/csharp/Grpc.Core/Internal/SafeHandleZeroIsInvalid.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/csharp/Grpc.Core/Internal/SafeHandleZeroIsInvalid.cs b/src/csharp/Grpc.Core/Internal/SafeHandleZeroIsInvalid.cs index 230faacff6..a637a54f58 100644 --- a/src/csharp/Grpc.Core/Internal/SafeHandleZeroIsInvalid.cs +++ b/src/csharp/Grpc.Core/Internal/SafeHandleZeroIsInvalid.cs @@ -45,10 +45,6 @@ namespace Grpc.Core.Internal { } - public SafeHandleZeroIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) - { - } - public override bool IsInvalid { get @@ -56,11 +52,5 @@ namespace Grpc.Core.Internal return handle == IntPtr.Zero; } } - - protected override bool ReleaseHandle() - { - // handle is not owned. - return true; - } } } -- cgit v1.2.3 From 49f89f0c05e25e0b01fc12844ff88b62579a5501 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 26 Oct 2016 11:16:59 -0700 Subject: clang-format --- src/core/ext/lb_policy/grpclb/grpclb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 6d73c48cc3..6da4febf26 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -637,9 +637,9 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, addr_strs[addr_index++] = grpc_sockaddr_to_uri(&addresses->addresses[i].address); } else { - GPR_ASSERT(grpc_sockaddr_to_string( - &addr_strs[addr_index++], - &addresses->addresses[i].address, true) > 0); + GPR_ASSERT(grpc_sockaddr_to_string(&addr_strs[addr_index++], + &addresses->addresses[i].address, + true) > 0); } } } -- cgit v1.2.3 From 49607a8afa2fa58e3546c6e3b7b3cf90bb74414b Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 26 Oct 2016 11:17:37 -0700 Subject: Ran generate_projects.sh --- tools/run_tests/tests.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index c86b14f63e..5cb50cc999 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -1306,6 +1306,7 @@ ], "cpu_cost": 1.0, "exclude_configs": [], + "exclude_iomgrs": [], "flaky": false, "gtest": false, "language": "c", @@ -1321,6 +1322,7 @@ ], "cpu_cost": 1.0, "exclude_configs": [], + "exclude_iomgrs": [], "flaky": false, "gtest": false, "language": "c", -- cgit v1.2.3