Add grpc_pollset_set as an arg in grpc_resolver_create

pull/8789/head
Yuchen Zeng 8 years ago
parent 8fe21f2b19
commit 63e3e3b1df
  1. 4
      src/core/ext/client_channel/client_channel.c
  2. 2
      src/core/ext/client_channel/resolver.c
  3. 2
      src/core/ext/client_channel/resolver.h
  4. 5
      src/core/ext/client_channel/resolver_factory.c
  5. 8
      src/core/ext/client_channel/resolver_factory.h
  6. 9
      src/core/ext/client_channel/resolver_registry.c
  7. 6
      src/core/ext/client_channel/resolver_registry.h
  8. 18
      src/core/ext/resolver/dns/native/dns_resolver.c
  9. 3
      src/core/ext/resolver/sockaddr/sockaddr_resolver.c
  10. 9
      test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
  11. 4
      test/core/client_channel/resolvers/dns_resolver_test.c
  12. 4
      test/core/client_channel/resolvers/sockaddr_resolver_test.c
  13. 3
      test/core/end2end/fake_resolver.c

@ -526,7 +526,9 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx,
arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(arg != NULL); GPR_ASSERT(arg != NULL);
GPR_ASSERT(arg->type == GRPC_ARG_STRING); GPR_ASSERT(arg->type == GRPC_ARG_STRING);
chand->resolver = grpc_resolver_create(arg->value.string, args->channel_args); chand->resolver =
grpc_resolver_create(exec_ctx, arg->value.string, args->channel_args,
chand->interested_parties);
if (chand->resolver == NULL) { if (chand->resolver == NULL) {
return GRPC_ERROR_CREATE("resolver creation failed"); return GRPC_ERROR_CREATE("resolver creation failed");
} }

@ -36,7 +36,6 @@
void grpc_resolver_init(grpc_resolver *resolver, void grpc_resolver_init(grpc_resolver *resolver,
const grpc_resolver_vtable *vtable) { const grpc_resolver_vtable *vtable) {
resolver->vtable = vtable; resolver->vtable = vtable;
resolver->pollset_set = grpc_pollset_set_create();
gpr_ref_init(&resolver->refs, 1); gpr_ref_init(&resolver->refs, 1);
} }
@ -63,7 +62,6 @@ void grpc_resolver_unref(grpc_resolver *resolver,
void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) {
#endif #endif
if (gpr_unref(&resolver->refs)) { if (gpr_unref(&resolver->refs)) {
grpc_pollset_set_destroy(resolver->pollset_set);
resolver->vtable->destroy(exec_ctx, resolver); resolver->vtable->destroy(exec_ctx, resolver);
} }
} }

@ -36,7 +36,6 @@
#include "src/core/ext/client_channel/subchannel.h" #include "src/core/ext/client_channel/subchannel.h"
#include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/pollset_set.h"
typedef struct grpc_resolver grpc_resolver; typedef struct grpc_resolver grpc_resolver;
typedef struct grpc_resolver_vtable grpc_resolver_vtable; typedef struct grpc_resolver_vtable grpc_resolver_vtable;
@ -44,7 +43,6 @@ typedef struct grpc_resolver_vtable grpc_resolver_vtable;
/** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */
struct grpc_resolver { struct grpc_resolver {
const grpc_resolver_vtable *vtable; const grpc_resolver_vtable *vtable;
grpc_pollset_set *pollset_set;
gpr_refcount refs; gpr_refcount refs;
}; };

@ -43,9 +43,10 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* factory) {
/** Create a resolver instance for a name */ /** Create a resolver instance for a name */
grpc_resolver* grpc_resolver_factory_create_resolver( grpc_resolver* grpc_resolver_factory_create_resolver(
grpc_resolver_factory* factory, grpc_resolver_args* args) { grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory,
grpc_resolver_args* args) {
if (factory == NULL) return NULL; if (factory == NULL) return NULL;
return factory->vtable->create_resolver(factory, args); return factory->vtable->create_resolver(exec_ctx, factory, args);
} }
char* grpc_resolver_factory_get_default_authority( char* grpc_resolver_factory_get_default_authority(

@ -37,6 +37,7 @@
#include "src/core/ext/client_channel/client_channel_factory.h" #include "src/core/ext/client_channel/client_channel_factory.h"
#include "src/core/ext/client_channel/resolver.h" #include "src/core/ext/client_channel/resolver.h"
#include "src/core/ext/client_channel/uri_parser.h" #include "src/core/ext/client_channel/uri_parser.h"
#include "src/core/lib/iomgr/pollset_set.h"
typedef struct grpc_resolver_factory grpc_resolver_factory; typedef struct grpc_resolver_factory grpc_resolver_factory;
typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable; typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable;
@ -48,6 +49,7 @@ struct grpc_resolver_factory {
typedef struct grpc_resolver_args { typedef struct grpc_resolver_args {
grpc_uri *uri; grpc_uri *uri;
const grpc_channel_args *args; const grpc_channel_args *args;
grpc_pollset_set *pollset_set;
} grpc_resolver_args; } grpc_resolver_args;
struct grpc_resolver_factory_vtable { struct grpc_resolver_factory_vtable {
@ -55,7 +57,8 @@ struct grpc_resolver_factory_vtable {
void (*unref)(grpc_resolver_factory *factory); void (*unref)(grpc_resolver_factory *factory);
/** Implementation of grpc_resolver_factory_create_resolver */ /** Implementation of grpc_resolver_factory_create_resolver */
grpc_resolver *(*create_resolver)(grpc_resolver_factory *factory, grpc_resolver *(*create_resolver)(grpc_exec_ctx *exec_ctx,
grpc_resolver_factory *factory,
grpc_resolver_args *args); grpc_resolver_args *args);
/** Implementation of grpc_resolver_factory_get_default_authority */ /** Implementation of grpc_resolver_factory_get_default_authority */
@ -70,7 +73,8 @@ void grpc_resolver_factory_unref(grpc_resolver_factory *resolver);
/** Create a resolver instance for a name */ /** Create a resolver instance for a name */
grpc_resolver *grpc_resolver_factory_create_resolver( grpc_resolver *grpc_resolver_factory_create_resolver(
grpc_resolver_factory *factory, grpc_resolver_args *args); grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory,
grpc_resolver_args *args);
/** Return a (freshly allocated with gpr_malloc) string representing /** Return a (freshly allocated with gpr_malloc) string representing
the default authority to use for this scheme. */ the default authority to use for this scheme. */

@ -131,8 +131,9 @@ static grpc_resolver_factory *resolve_factory(const char *target,
return factory; return factory;
} }
grpc_resolver *grpc_resolver_create(const char *target, grpc_resolver *grpc_resolver_create(grpc_exec_ctx *exec_ctx, const char *target,
const grpc_channel_args *args) { const grpc_channel_args *args,
grpc_pollset_set *pollset_set) {
grpc_uri *uri = NULL; grpc_uri *uri = NULL;
char *canonical_target = NULL; char *canonical_target = NULL;
grpc_resolver_factory *factory = grpc_resolver_factory *factory =
@ -142,7 +143,9 @@ grpc_resolver *grpc_resolver_create(const char *target,
memset(&resolver_args, 0, sizeof(resolver_args)); memset(&resolver_args, 0, sizeof(resolver_args));
resolver_args.uri = uri; resolver_args.uri = uri;
resolver_args.args = args; resolver_args.args = args;
resolver = grpc_resolver_factory_create_resolver(factory, &resolver_args); resolver_args.pollset_set = pollset_set;
resolver =
grpc_resolver_factory_create_resolver(exec_ctx, factory, &resolver_args);
grpc_uri_destroy(uri); grpc_uri_destroy(uri);
gpr_free(canonical_target); gpr_free(canonical_target);
return resolver; return resolver;

@ -35,6 +35,7 @@
#define GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_REGISTRY_H #define GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_REGISTRY_H
#include "src/core/ext/client_channel/resolver_factory.h" #include "src/core/ext/client_channel/resolver_factory.h"
#include "src/core/lib/iomgr/pollset_set.h"
void grpc_resolver_registry_init(); void grpc_resolver_registry_init();
void grpc_resolver_registry_shutdown(void); void grpc_resolver_registry_shutdown(void);
@ -60,8 +61,9 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory);
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 \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). */ (typically the set of arguments passed in from the client API). */
grpc_resolver *grpc_resolver_create(const char *target, grpc_resolver *grpc_resolver_create(grpc_exec_ctx *exec_ctx, const char *target,
const grpc_channel_args *args); const grpc_channel_args *args,
grpc_pollset_set *pollset_set);
/** Find a resolver factory given a name and return an (owned-by-the-caller) /** Find a resolver factory given a name and return an (owned-by-the-caller)
* reference to it */ * reference to it */

@ -61,6 +61,8 @@ typedef struct {
char *default_port; char *default_port;
/** channel args. */ /** channel args. */
grpc_channel_args *channel_args; grpc_channel_args *channel_args;
/** pollset_set to drive the name resolution process */
grpc_pollset_set *interested_parties;
/** mutex guarding the rest of the state */ /** mutex guarding the rest of the state */
gpr_mu mu; gpr_mu mu;
@ -218,7 +220,7 @@ static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx,
r->resolving = true; r->resolving = true;
r->addresses = NULL; r->addresses = NULL;
grpc_resolve_address(exec_ctx, r->name_to_resolve, r->default_port, grpc_resolve_address(exec_ctx, r->name_to_resolve, r->default_port,
r->base.pollset_set, r->interested_parties,
grpc_closure_create(dns_on_resolved, r), &r->addresses); grpc_closure_create(dns_on_resolved, r), &r->addresses);
} }
@ -241,13 +243,15 @@ static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
if (r->resolved_result != NULL) { if (r->resolved_result != NULL) {
grpc_channel_args_destroy(r->resolved_result); grpc_channel_args_destroy(r->resolved_result);
} }
grpc_pollset_set_destroy(r->interested_parties);
gpr_free(r->name_to_resolve); gpr_free(r->name_to_resolve);
gpr_free(r->default_port); gpr_free(r->default_port);
grpc_channel_args_destroy(r->channel_args); grpc_channel_args_destroy(r->channel_args);
gpr_free(r); gpr_free(r);
} }
static grpc_resolver *dns_create(grpc_resolver_args *args, static grpc_resolver *dns_create(grpc_exec_ctx *exec_ctx,
grpc_resolver_args *args,
const char *default_port) { const char *default_port) {
if (0 != strcmp(args->uri->authority, "")) { if (0 != strcmp(args->uri->authority, "")) {
gpr_log(GPR_ERROR, "authority based dns uri's not supported"); gpr_log(GPR_ERROR, "authority based dns uri's not supported");
@ -266,6 +270,11 @@ static grpc_resolver *dns_create(grpc_resolver_args *args,
r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name; r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name;
r->default_port = gpr_strdup(default_port); r->default_port = gpr_strdup(default_port);
r->channel_args = grpc_channel_args_copy(args->args); r->channel_args = grpc_channel_args_copy(args->args);
r->interested_parties = grpc_pollset_set_create();
if (args->pollset_set != NULL) {
grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties,
args->pollset_set);
}
gpr_backoff_init(&r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS, gpr_backoff_init(&r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS,
GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER, GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER,
GRPC_DNS_RECONNECT_JITTER, GRPC_DNS_RECONNECT_JITTER,
@ -283,8 +292,9 @@ static void dns_factory_ref(grpc_resolver_factory *factory) {}
static void dns_factory_unref(grpc_resolver_factory *factory) {} static void dns_factory_unref(grpc_resolver_factory *factory) {}
static grpc_resolver *dns_factory_create_resolver( static grpc_resolver *dns_factory_create_resolver(
grpc_resolver_factory *factory, grpc_resolver_args *args) { grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory,
return dns_create(args, "https"); grpc_resolver_args *args) {
return dns_create(exec_ctx, args, "https");
} }
static char *dns_factory_get_default_host_name(grpc_resolver_factory *factory, static char *dns_factory_get_default_host_name(grpc_resolver_factory *factory,

@ -214,7 +214,8 @@ static void sockaddr_factory_unref(grpc_resolver_factory *factory) {}
#define DECL_FACTORY(name) \ #define DECL_FACTORY(name) \
static grpc_resolver *name##_factory_create_resolver( \ static grpc_resolver *name##_factory_create_resolver( \
grpc_resolver_factory *factory, grpc_resolver_args *args) { \ grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, \
grpc_resolver_args *args) { \
return sockaddr_create(args, parse_##name); \ return sockaddr_create(args, parse_##name); \
} \ } \
static const grpc_resolver_factory_vtable name##_factory_vtable = { \ static const grpc_resolver_factory_vtable name##_factory_vtable = { \

@ -63,7 +63,8 @@ static grpc_error *my_resolve_address(const char *name, const char *addr,
} }
} }
static grpc_resolver *create_resolver(const char *name) { static grpc_resolver *create_resolver(grpc_exec_ctx *exec_ctx,
const char *name) {
grpc_resolver_factory *factory = grpc_resolver_factory_lookup("dns"); grpc_resolver_factory *factory = grpc_resolver_factory_lookup("dns");
grpc_uri *uri = grpc_uri_parse(name, 0); grpc_uri *uri = grpc_uri_parse(name, 0);
GPR_ASSERT(uri); GPR_ASSERT(uri);
@ -71,7 +72,7 @@ static grpc_resolver *create_resolver(const char *name) {
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.uri = uri; args.uri = uri;
grpc_resolver *resolver = grpc_resolver *resolver =
grpc_resolver_factory_create_resolver(factory, &args); grpc_resolver_factory_create_resolver(exec_ctx, factory, &args);
grpc_resolver_factory_unref(factory); grpc_resolver_factory_unref(factory);
grpc_uri_destroy(uri); grpc_uri_destroy(uri);
return resolver; return resolver;
@ -101,12 +102,10 @@ int main(int argc, char **argv) {
grpc_init(); grpc_init();
gpr_mu_init(&g_mu); gpr_mu_init(&g_mu);
grpc_blocking_resolve_address = my_resolve_address; grpc_blocking_resolve_address = my_resolve_address;
grpc_resolver *resolver = create_resolver("dns:test");
grpc_channel_args *result = (grpc_channel_args *)1; grpc_channel_args *result = (grpc_channel_args *)1;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resolver *resolver = create_resolver(&exec_ctx, "dns:test");
gpr_event ev1; gpr_event ev1;
gpr_event_init(&ev1); gpr_event_init(&ev1);
grpc_resolver_next(&exec_ctx, resolver, &result, grpc_resolver_next(&exec_ctx, resolver, &result,

@ -48,7 +48,7 @@ static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
GPR_ASSERT(uri); GPR_ASSERT(uri);
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.uri = uri; args.uri = uri;
resolver = grpc_resolver_factory_create_resolver(factory, &args); resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args);
GPR_ASSERT(resolver != NULL); GPR_ASSERT(resolver != NULL);
GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds");
grpc_uri_destroy(uri); grpc_uri_destroy(uri);
@ -65,7 +65,7 @@ static void test_fails(grpc_resolver_factory *factory, const char *string) {
GPR_ASSERT(uri); GPR_ASSERT(uri);
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.uri = uri; args.uri = uri;
resolver = grpc_resolver_factory_create_resolver(factory, &args); resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args);
GPR_ASSERT(resolver == NULL); GPR_ASSERT(resolver == NULL);
grpc_uri_destroy(uri); grpc_uri_destroy(uri);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);

@ -62,7 +62,7 @@ static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
GPR_ASSERT(uri); GPR_ASSERT(uri);
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.uri = uri; args.uri = uri;
resolver = grpc_resolver_factory_create_resolver(factory, &args); resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args);
GPR_ASSERT(resolver != NULL); GPR_ASSERT(resolver != NULL);
on_resolution_arg on_res_arg; on_resolution_arg on_res_arg;
@ -88,7 +88,7 @@ static void test_fails(grpc_resolver_factory *factory, const char *string) {
GPR_ASSERT(uri); GPR_ASSERT(uri);
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.uri = uri; args.uri = uri;
resolver = grpc_resolver_factory_create_resolver(factory, &args); resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args);
GPR_ASSERT(resolver == NULL); GPR_ASSERT(resolver == NULL);
grpc_uri_destroy(uri); grpc_uri_destroy(uri);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);

@ -140,7 +140,8 @@ static void fake_resolver_factory_unref(grpc_resolver_factory* factory) {}
static void do_nothing(void* ignored) {} static void do_nothing(void* ignored) {}
static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, static grpc_resolver* fake_resolver_create(grpc_exec_ctx* exec_ctx,
grpc_resolver_factory* factory,
grpc_resolver_args* args) { grpc_resolver_args* args) {
if (0 != strcmp(args->uri->authority, "")) { if (0 != strcmp(args->uri->authority, "")) {
gpr_log(GPR_ERROR, "authority based uri's not supported by the %s scheme", gpr_log(GPR_ERROR, "authority based uri's not supported by the %s scheme",

Loading…
Cancel
Save