diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2016-04-05 16:04:30 -0700 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2016-04-05 16:04:30 -0700 |
commit | 2c7f8f1f1c5ecd12a0c8fe7a08e77f77599b6578 (patch) | |
tree | f9d6609b2f0ed9e150da97181f71e48282c2c4a4 /src/core/ext/resolver/sockaddr | |
parent | 39d1a66bb9c878181ddf101d88a61f7aff91e427 (diff) | |
parent | f47240e25316168b5291f1a7e299539a16b7ff8f (diff) |
Merge pull request #6037 from dgquintas/sockaddr_resolver_lb_2
added grpclb support to sockaddr resolver
Diffstat (limited to 'src/core/ext/resolver/sockaddr')
-rw-r--r-- | src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index b50b4ee480..76c03c08b5 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/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 <string.h> #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> +#include <grpc/support/port_platform.h> #include <grpc/support/string_util.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)); memset(r, 0, sizeof(*r)); - r->lb_policy_name = NULL; - if (0 != strcmp(args->uri->query, "")) { - gpr_slice query_slice; - gpr_slice_buffer query_parts; - - query_slice = - gpr_slice_new(args->uri->query, strlen(args->uri->query), do_nothing); - gpr_slice_buffer_init(&query_parts); - gpr_slice_split(query_slice, "=", &query_parts); - GPR_ASSERT(query_parts.count == 2); - if (0 == gpr_slice_str_cmp(query_parts.slices[0], "lb_policy")) { - r->lb_policy_name = gpr_dump_slice(query_parts.slices[1], GPR_DUMP_ASCII); - } - gpr_slice_buffer_destroy(&query_parts); - gpr_slice_unref(query_slice); + r->lb_policy_name = + gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy")); + const char *lb_enabled_qpart = + grpc_uri_get_query_arg(args->uri, "lb_enabled"); + /* anything other than "0" is interpreted as true */ + const bool lb_enabled = + (lb_enabled_qpart != NULL && (strcmp("0", lb_enabled_qpart) != 0)); + + if (r->lb_policy_name != NULL && strcmp("grpclb", r->lb_policy_name) == 0 && + !lb_enabled) { + /* we want grpclb but the "resolved" addresses aren't LB enabled. Bail + * out, as this is meant mostly for tests. */ + gpr_log(GPR_ERROR, + "Requested 'grpclb' LB policy but resolved addresses don't " + "support load balancing."); + abort(); } + if (r->lb_policy_name == NULL) { r->lb_policy_name = gpr_strdup(default_lb_policy_name); } |