diff options
author | Mark D. Roth <roth@google.com> | 2016-10-04 07:19:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-04 07:19:47 -0700 |
commit | 9ab8ba73d6887ea902528426480dafb14b1c8214 (patch) | |
tree | 3a3d772e137eb44da21c132b2ea10c9514cca931 /src/core/ext/client_config | |
parent | 08ce4b92c231496102d768c18f6ae94403fb6878 (diff) | |
parent | 88405f70c16ab7a7679bb189b321bb565764e829 (diff) |
Merge pull request #8263 from markdroth/grpclb_resolver_semantic_fix
Centralized logic for choosing the right LB policy.
Diffstat (limited to 'src/core/ext/client_config')
-rw-r--r-- | src/core/ext/client_config/client_channel.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c index 3b4747bebc..f3befe9b47 100644 --- a/src/core/ext/client_config/client_channel.c +++ b/src/core/ext/client_config/client_channel.c @@ -185,10 +185,34 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, lb_policy_args.additional_args = grpc_resolver_result_get_lb_policy_args(chand->resolver_result); lb_policy_args.client_channel_factory = chand->client_channel_factory; - lb_policy = grpc_lb_policy_create( - exec_ctx, - grpc_resolver_result_get_lb_policy_name(chand->resolver_result), - &lb_policy_args); + + // 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) { + 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)); + } + lb_policy_name = "grpclb"; + } + // Use pick_first if nothing was specified and we didn't select grpclb + // above. + if (lb_policy_name == NULL) lb_policy_name = "pick_first"; + + lb_policy = + grpc_lb_policy_create(exec_ctx, lb_policy_name, &lb_policy_args); if (lb_policy != NULL) { GRPC_LB_POLICY_REF(lb_policy, "config_change"); GRPC_ERROR_UNREF(state_error); |