Merge pull request #6037 from dgquintas/sockaddr_resolver_lb_2

added grpclb support to sockaddr resolver
pull/6029/head^2
Jan Tattermusch 9 years ago
commit 2c7f8f1f1c
  1. 36
      src/core/ext/resolver/sockaddr/sockaddr_resolver.c

@ -31,13 +31,13 @@
* *
*/ */
#include <grpc/support/port_platform.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/host_port.h> #include <grpc/support/host_port.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/client_config/lb_policy_registry.h" #include "src/core/lib/client_config/lb_policy_registry.h"
@ -263,22 +263,24 @@ static grpc_resolver *sockaddr_create(
r = gpr_malloc(sizeof(sockaddr_resolver)); r = gpr_malloc(sizeof(sockaddr_resolver));
memset(r, 0, sizeof(*r)); memset(r, 0, sizeof(*r));
r->lb_policy_name = NULL; r->lb_policy_name =
if (0 != strcmp(args->uri->query, "")) { gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy"));
gpr_slice query_slice; const char *lb_enabled_qpart =
gpr_slice_buffer query_parts; grpc_uri_get_query_arg(args->uri, "lb_enabled");
/* anything other than "0" is interpreted as true */
query_slice = const bool lb_enabled =
gpr_slice_new(args->uri->query, strlen(args->uri->query), do_nothing); (lb_enabled_qpart != NULL && (strcmp("0", lb_enabled_qpart) != 0));
gpr_slice_buffer_init(&query_parts);
gpr_slice_split(query_slice, "=", &query_parts); if (r->lb_policy_name != NULL && strcmp("grpclb", r->lb_policy_name) == 0 &&
GPR_ASSERT(query_parts.count == 2); !lb_enabled) {
if (0 == gpr_slice_str_cmp(query_parts.slices[0], "lb_policy")) { /* we want grpclb but the "resolved" addresses aren't LB enabled. Bail
r->lb_policy_name = gpr_dump_slice(query_parts.slices[1], GPR_DUMP_ASCII); * out, as this is meant mostly for tests. */
} gpr_log(GPR_ERROR,
gpr_slice_buffer_destroy(&query_parts); "Requested 'grpclb' LB policy but resolved addresses don't "
gpr_slice_unref(query_slice); "support load balancing.");
abort();
} }
if (r->lb_policy_name == NULL) { if (r->lb_policy_name == NULL) {
r->lb_policy_name = gpr_strdup(default_lb_policy_name); r->lb_policy_name = gpr_strdup(default_lb_policy_name);
} }

Loading…
Cancel
Save