Update with changes in client_config and resolver_result

reviewable/pr7771/r1
Yuchen Zeng 8 years ago
parent 6988838a67
commit aa8c66c9d5
  1. 4
      CMakeLists.txt
  2. 82
      src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c
  3. 2
      test/core/client_config/resolvers/sockaddr_resolver_test.c
  4. 3
      tools/run_tests/sources_and_headers.json

@ -1616,6 +1616,8 @@ target_include_directories(gen_percent_encoding_tables
PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${PROTOBUF_ROOT_DIR}/src
PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${ZLIB_ROOT_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib
PRIVATE ${CARES_ROOT_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/c-ares
) )
@ -1851,6 +1853,8 @@ target_include_directories(grpc_php_plugin
PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${PROTOBUF_ROOT_DIR}/src
PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${ZLIB_ROOT_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib
PRIVATE ${CARES_ROOT_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/c-ares
) )
target_link_libraries(grpc_php_plugin target_link_libraries(grpc_php_plugin

@ -38,6 +38,7 @@
#include <grpc/support/host_port.h> #include <grpc/support/host_port.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#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/lb_policy_registry.h"
#include "src/core/ext/client_config/resolver_registry.h" #include "src/core/ext/client_config/resolver_registry.h"
#include "src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h"
@ -56,24 +57,22 @@ typedef struct {
grpc_resolver base; grpc_resolver base;
/** refcount */ /** refcount */
gpr_refcount refs; gpr_refcount refs;
/** name to resolve */ /** target name */
char *name; char *target_name;
/** name to resolve (usually the same as target_name) */
char *name_to_resolve;
/** default port to use */ /** default port to use */
char *default_port; char *default_port;
/** subchannel factory */
grpc_client_channel_factory *client_channel_factory;
/** load balancing policy name */ /** load balancing policy name */
char *lb_policy_name; char *lb_policy_name;
/** polling entity for driving the async IO events */
grpc_polling_entity *pollent;
/** mutex guarding the rest of the state */ /** mutex guarding the rest of the state */
gpr_mu mu; gpr_mu mu;
/** are we currently resolving? */ /** are we currently resolving? */
int resolving; bool resolving;
/** which version of resolved_result have we published? */ /** which version of the result have we published? */
int published_version; int published_version;
/** which version of resolved_result is current? */ /** which version of the result is current? */
int resolved_version; int resolved_version;
/** pending next completion, or NULL */ /** pending next completion, or NULL */
grpc_closure *next_completion; grpc_closure *next_completion;
@ -90,6 +89,7 @@ typedef struct {
/** currently resolving addresses */ /** currently resolving addresses */
grpc_resolved_addresses *addresses; grpc_resolved_addresses *addresses;
grpc_polling_entity *pollent;
} dns_resolver; } dns_resolver;
static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r); static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
@ -155,29 +155,27 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) { grpc_error *error) {
dns_resolver *r = arg; dns_resolver *r = arg;
grpc_resolver_result *result = NULL; grpc_resolver_result *result = NULL;
grpc_lb_policy *lb_policy;
gpr_mu_lock(&r->mu); gpr_mu_lock(&r->mu);
GPR_ASSERT(r->resolving); GPR_ASSERT(r->resolving);
r->resolving = 0; r->resolving = false;
grpc_resolved_addresses *addresses = r->addresses; if (r->addresses != NULL) {
if (addresses != NULL) { grpc_lb_addresses *addresses =
grpc_lb_policy_args lb_policy_args; grpc_lb_addresses_create(r->addresses->naddrs);
result = grpc_resolver_result_create(); for (size_t i = 0; i < r->addresses->naddrs; ++i) {
memset(&lb_policy_args, 0, sizeof(lb_policy_args)); grpc_lb_addresses_set_address(
lb_policy_args.addresses = addresses; addresses, i, &r->addresses->addrs[i].addr,
lb_policy_args.client_channel_factory = r->client_channel_factory; r->addresses->addrs[i].len, false /* is_balancer */,
lb_policy = NULL /* balancer_name */, NULL /* user_data */);
grpc_lb_policy_create(exec_ctx, r->lb_policy_name, &lb_policy_args);
if (lb_policy != NULL) {
grpc_resolver_result_set_lb_policy(result, lb_policy);
GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "construction");
} }
grpc_resolved_addresses_destroy(r->addresses);
result = grpc_resolver_result_create(r->target_name, addresses,
r->lb_policy_name, NULL);
;
if (r->pollent) { if (r->pollent) {
grpc_polling_entity_del_from_pollset_set(exec_ctx, r->pollent, grpc_polling_entity_del_from_pollset_set(exec_ctx, r->pollent,
r->base.pollset_set); r->base.pollset_set);
r->pollent = NULL; r->pollent = NULL;
} }
grpc_resolved_addresses_destroy(addresses);
} else { } else {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now);
@ -220,7 +218,7 @@ static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
gpr_backoff_reset(&r->backoff_state); gpr_backoff_reset(&r->backoff_state);
GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GRPC_RESOLVER_REF(&r->base, "dns-resolving");
GPR_ASSERT(!r->resolving); GPR_ASSERT(!r->resolving);
r->resolving = 1; r->resolving = true;
r->addresses = NULL; r->addresses = NULL;
r->pollent = NULL; r->pollent = NULL;
if (grpc_ares_need_poll_entity() && pollent) { if (grpc_ares_need_poll_entity() && pollent) {
@ -231,7 +229,7 @@ static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
gpr_log(GPR_DEBUG, "dns_next is called without giving a pollent"); gpr_log(GPR_DEBUG, "dns_next is called without giving a pollent");
} }
grpc_resolve_address_ares( grpc_resolve_address_ares(
exec_ctx, r->name, r->default_port, r->base.pollset_set, exec_ctx, r->name_to_resolve, r->default_port, r->base.pollset_set,
grpc_closure_create(dns_on_resolved, r), &r->addresses); grpc_closure_create(dns_on_resolved, r), &r->addresses);
} else { } else {
dns_maybe_finish_next_locked(exec_ctx, r); dns_maybe_finish_next_locked(exec_ctx, r);
@ -243,10 +241,10 @@ static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx,
dns_resolver *r) { dns_resolver *r) {
GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GRPC_RESOLVER_REF(&r->base, "dns-resolving");
GPR_ASSERT(!r->resolving); GPR_ASSERT(!r->resolving);
r->resolving = 1; r->resolving = true;
r->addresses = NULL; r->addresses = NULL;
grpc_resolve_address_ares( grpc_resolve_address_ares(
exec_ctx, r->name, r->default_port, r->base.pollset_set, exec_ctx, r->name_to_resolve, r->default_port, r->base.pollset_set,
grpc_closure_create(dns_on_resolved, r), &r->addresses); grpc_closure_create(dns_on_resolved, r), &r->addresses);
} }
@ -271,8 +269,8 @@ static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
if (r->resolved_result) { if (r->resolved_result) {
grpc_resolver_result_unref(exec_ctx, r->resolved_result); grpc_resolver_result_unref(exec_ctx, r->resolved_result);
} }
grpc_client_channel_factory_unref(exec_ctx, r->client_channel_factory); gpr_free(r->target_name);
gpr_free(r->name); gpr_free(r->name_to_resolve);
gpr_free(r->default_port); gpr_free(r->default_port);
gpr_free(r->lb_policy_name); gpr_free(r->lb_policy_name);
gpr_free(r); gpr_free(r);
@ -281,34 +279,26 @@ static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
static grpc_resolver *dns_create(grpc_resolver_args *args, static grpc_resolver *dns_create(grpc_resolver_args *args,
const char *default_port, const char *default_port,
const char *lb_policy_name) { const char *lb_policy_name) {
dns_resolver *r;
grpc_error *error = GRPC_ERROR_NONE;
const char *path = args->uri->path;
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");
return NULL; return NULL;
} }
// Get name from args.
error = grpc_ares_init(); const char *path = args->uri->path;
if (error != GRPC_ERROR_NONE) {
GRPC_LOG_IF_ERROR("ares_library_init() failed", error);
return NULL;
}
if (path[0] == '/') ++path; if (path[0] == '/') ++path;
// Get proxy name, if any.
r = gpr_malloc(sizeof(dns_resolver)); char *proxy_name = grpc_get_http_proxy_server();
// Create resolver.
dns_resolver *r = gpr_malloc(sizeof(dns_resolver));
memset(r, 0, sizeof(*r)); memset(r, 0, sizeof(*r));
gpr_ref_init(&r->refs, 1); gpr_ref_init(&r->refs, 1);
gpr_mu_init(&r->mu); gpr_mu_init(&r->mu);
grpc_resolver_init(&r->base, &dns_resolver_vtable); grpc_resolver_init(&r->base, &dns_resolver_vtable);
r->name = gpr_strdup(path); 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->default_port = gpr_strdup(default_port);
r->client_channel_factory = args->client_channel_factory;
gpr_backoff_init(&r->backoff_state, BACKOFF_MULTIPLIER, BACKOFF_JITTER, gpr_backoff_init(&r->backoff_state, BACKOFF_MULTIPLIER, BACKOFF_JITTER,
BACKOFF_MIN_SECONDS * 1000, BACKOFF_MAX_SECONDS * 1000); BACKOFF_MIN_SECONDS * 1000, BACKOFF_MAX_SECONDS * 1000);
grpc_client_channel_factory_ref(r->client_channel_factory);
r->lb_policy_name = gpr_strdup(lb_policy_name); r->lb_policy_name = gpr_strdup(lb_policy_name);
return &r->base; return &r->base;
} }

@ -74,7 +74,7 @@ static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
grpc_closure *on_resolution = grpc_closure *on_resolution =
grpc_closure_create(on_resolution_cb, &on_res_arg); grpc_closure_create(on_resolution_cb, &on_res_arg);
grpc_resolver_next(&exec_ctx, resolver, &on_res_arg.resolver_result, grpc_resolver_next(&exec_ctx, resolver, NULL, &on_res_arg.resolver_result,
on_resolution); on_resolution);
GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds");
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);

@ -361,6 +361,7 @@
"grpc_test_util" "grpc_test_util"
], ],
"headers": [], "headers": [],
"is_filegroup": false,
"language": "c", "language": "c",
"name": "dns_resolver_connectivity_test", "name": "dns_resolver_connectivity_test",
"src": [ "src": [
@ -5965,6 +5966,7 @@
"third_party/c-ares/config-win32.h", "third_party/c-ares/config-win32.h",
"third_party/c-ares/setup_once.h" "third_party/c-ares/setup_once.h"
], ],
"is_filegroup": false,
"language": "c", "language": "c",
"name": "ares", "name": "ares",
"src": [ "src": [
@ -6845,6 +6847,7 @@
"src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver.h", "src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver.h",
"src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h" "src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h"
], ],
"is_filegroup": true,
"language": "c", "language": "c",
"name": "grpc_resolver_dns_ares", "name": "grpc_resolver_dns_ares",
"src": [ "src": [

Loading…
Cancel
Save