blob: a6a9a2645f4d96ec21afc07c633a2999c5e61218 [file] [log] [blame]
Craig Tiller3bc8ebd2015-06-24 15:41:15 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Craig Tiller3bc8ebd2015-06-24 15:41:15 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Craig Tiller3bc8ebd2015-06-24 15:41:15 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller3bc8ebd2015-06-24 15:41:15 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Craig Tiller3bc8ebd2015-06-24 15:41:15 -070016 *
17 */
18
Craig Tillereb3b12e2015-06-26 14:42:49 -070019#include <string.h>
20
21#include <grpc/support/alloc.h>
Mark D. Roth5bd7be02016-10-21 14:19:50 -070022
Mark D. Roth5e9848e2017-10-06 13:59:32 -070023#include "src/core/ext/filters/client_channel/lb_policy/subchannel_list.h"
Craig Tiller9eb0fde2017-03-31 16:59:30 -070024#include "src/core/ext/filters/client_channel/lb_policy_registry.h"
25#include "src/core/ext/filters/client_channel/subchannel.h"
David Garcia Quintas87d5a312017-06-06 19:45:58 -070026#include "src/core/ext/filters/client_channel/subchannel_index.h"
Mark D. Roth557c9902016-10-24 11:12:05 -070027#include "src/core/lib/channel/channel_args.h"
Craig Tiller2400bf52017-02-09 16:25:19 -080028#include "src/core/lib/iomgr/combiner.h"
Mark D. Roth0748f392017-01-13 09:22:44 -080029#include "src/core/lib/iomgr/sockaddr_utils.h"
Craig Tiller9533d042016-03-25 17:11:06 -070030#include "src/core/lib/transport/connectivity_state.h"
Craig Tillereb3b12e2015-06-26 14:42:49 -070031
ncteisen7712c7c2017-07-12 23:11:27 -070032grpc_tracer_flag grpc_lb_pick_first_trace =
33 GRPC_TRACER_INITIALIZER(false, "pick_first");
David Garcia Quintas87d5a312017-06-06 19:45:58 -070034
Craig Tillera82950e2015-09-22 12:33:20 -070035typedef struct pending_pick {
Craig Tillerbaa14a92017-11-03 09:09:36 -070036 struct pending_pick* next;
Craig Tiller8c0d96f2016-03-11 14:27:52 -080037 uint32_t initial_metadata_flags;
Craig Tillerbaa14a92017-11-03 09:09:36 -070038 grpc_connected_subchannel** target;
39 grpc_closure* on_complete;
Craig Tillereb3b12e2015-06-26 14:42:49 -070040} pending_pick;
41
Craig Tillera82950e2015-09-22 12:33:20 -070042typedef struct {
Craig Tillereb3b12e2015-06-26 14:42:49 -070043 /** base policy: must be first */
44 grpc_lb_policy base;
Craig Tillereb3b12e2015-06-26 14:42:49 -070045 /** all our subchannels */
Craig Tillerbaa14a92017-11-03 09:09:36 -070046 grpc_lb_subchannel_list* subchannel_list;
Mark D. Roth5132d0e2017-10-13 13:20:52 -070047 /** latest pending subchannel list */
Craig Tillerbaa14a92017-11-03 09:09:36 -070048 grpc_lb_subchannel_list* latest_pending_subchannel_list;
Mark D. Roth5132d0e2017-10-13 13:20:52 -070049 /** selected subchannel in \a subchannel_list */
Craig Tillerbaa14a92017-11-03 09:09:36 -070050 grpc_lb_subchannel_data* selected;
Craig Tillereb3b12e2015-06-26 14:42:49 -070051 /** have we started picking? */
David Garcia Quintas87d5a312017-06-06 19:45:58 -070052 bool started_picking;
Craig Tillera14215a2015-07-17 17:21:08 -070053 /** are we shut down? */
David Garcia Quintas87d5a312017-06-06 19:45:58 -070054 bool shutdown;
Craig Tillereb3b12e2015-06-26 14:42:49 -070055 /** list of picks that are waiting on connectivity */
Craig Tillerbaa14a92017-11-03 09:09:36 -070056 pending_pick* pending_picks;
Craig Tillerc7b5f762015-06-27 11:48:42 -070057 /** our connectivity state tracker */
58 grpc_connectivity_state_tracker state_tracker;
Craig Tillereb3b12e2015-06-26 14:42:49 -070059} pick_first_lb_policy;
60
Craig Tillerbaa14a92017-11-03 09:09:36 -070061static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) {
62 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
Craig Tiller4782d922017-11-10 09:53:21 -080063 GPR_ASSERT(p->subchannel_list == nullptr);
64 GPR_ASSERT(p->latest_pending_subchannel_list == nullptr);
65 GPR_ASSERT(p->pending_picks == nullptr);
Craig Tillera82950e2015-09-22 12:33:20 -070066 grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker);
Craig Tillera82950e2015-09-22 12:33:20 -070067 gpr_free(p);
Mark D. Roth5e9848e2017-10-06 13:59:32 -070068 grpc_subchannel_index_unref();
David Garcia Quintasaf084dc2017-06-27 13:42:54 -070069 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
Craig Tillerbaa14a92017-11-03 09:09:36 -070070 gpr_log(GPR_DEBUG, "Pick First %p destroyed.", (void*)p);
David Garcia Quintasaf084dc2017-06-27 13:42:54 -070071 }
Craig Tillereb3b12e2015-06-26 14:42:49 -070072}
73
Craig Tillerbaa14a92017-11-03 09:09:36 -070074static void shutdown_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p,
75 grpc_error* error) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -070076 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
77 gpr_log(GPR_DEBUG, "Pick First %p Shutting down", p);
78 }
David Garcia Quintas87d5a312017-06-06 19:45:58 -070079 p->shutdown = true;
Craig Tillerbaa14a92017-11-03 09:09:36 -070080 pending_pick* pp;
Craig Tiller4782d922017-11-10 09:53:21 -080081 while ((pp = p->pending_picks) != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -070082 p->pending_picks = pp->next;
Craig Tiller4782d922017-11-10 09:53:21 -080083 *pp->target = nullptr;
Mark D. Roth5e9848e2017-10-06 13:59:32 -070084 GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error));
85 gpr_free(pp);
86 }
Mark D. Roth62ca6ce2017-10-10 10:01:51 -070087 grpc_connectivity_state_set(exec_ctx, &p->state_tracker,
88 GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error),
89 "shutdown");
Craig Tiller4782d922017-11-10 09:53:21 -080090 if (p->subchannel_list != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -070091 grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list,
92 "pf_shutdown");
Craig Tiller4782d922017-11-10 09:53:21 -080093 p->subchannel_list = nullptr;
Craig Tiller48613042015-11-29 14:45:11 -080094 }
Craig Tiller4782d922017-11-10 09:53:21 -080095 if (p->latest_pending_subchannel_list != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -070096 grpc_lb_subchannel_list_shutdown_and_unref(
97 exec_ctx, p->latest_pending_subchannel_list, "pf_shutdown");
Craig Tiller4782d922017-11-10 09:53:21 -080098 p->latest_pending_subchannel_list = nullptr;
Craig Tillera82950e2015-09-22 12:33:20 -070099 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700100 GRPC_ERROR_UNREF(error);
101}
102
Craig Tillerbaa14a92017-11-03 09:09:36 -0700103static void pf_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) {
104 shutdown_locked(exec_ctx, (pick_first_lb_policy*)pol,
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700105 GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"));
Craig Tillereb3b12e2015-06-26 14:42:49 -0700106}
107
Craig Tillerbaa14a92017-11-03 09:09:36 -0700108static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol,
109 grpc_connected_subchannel** target,
110 grpc_error* error) {
111 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
112 pending_pick* pp = p->pending_picks;
Craig Tiller4782d922017-11-10 09:53:21 -0800113 p->pending_picks = nullptr;
114 while (pp != nullptr) {
Craig Tillerbaa14a92017-11-03 09:09:36 -0700115 pending_pick* next = pp->next;
Craig Tiller577c9b22015-11-02 14:11:15 -0800116 if (pp->target == target) {
Craig Tiller4782d922017-11-10 09:53:21 -0800117 *target = nullptr;
ncteisen274bbbe2017-06-08 14:57:11 -0700118 GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete,
ncteisen4b36a3d2017-03-13 19:08:06 -0700119 GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
120 "Pick Cancelled", &error, 1));
Craig Tiller577c9b22015-11-02 14:11:15 -0800121 gpr_free(pp);
122 } else {
123 pp->next = p->pending_picks;
124 p->pending_picks = pp;
125 }
126 pp = next;
127 }
Mark D. Roth5f844002016-09-08 08:20:53 -0700128 GRPC_ERROR_UNREF(error);
Craig Tiller577c9b22015-11-02 14:11:15 -0800129}
130
Craig Tillerbaa14a92017-11-03 09:09:36 -0700131static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol,
Craig Tiller2400bf52017-02-09 16:25:19 -0800132 uint32_t initial_metadata_flags_mask,
133 uint32_t initial_metadata_flags_eq,
Craig Tillerbaa14a92017-11-03 09:09:36 -0700134 grpc_error* error) {
135 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
136 pending_pick* pp = p->pending_picks;
Craig Tiller4782d922017-11-10 09:53:21 -0800137 p->pending_picks = nullptr;
138 while (pp != nullptr) {
Craig Tillerbaa14a92017-11-03 09:09:36 -0700139 pending_pick* next = pp->next;
Craig Tiller8c0d96f2016-03-11 14:27:52 -0800140 if ((pp->initial_metadata_flags & initial_metadata_flags_mask) ==
141 initial_metadata_flags_eq) {
ncteisen274bbbe2017-06-08 14:57:11 -0700142 GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete,
ncteisen4b36a3d2017-03-13 19:08:06 -0700143 GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
144 "Pick Cancelled", &error, 1));
Craig Tiller8c0d96f2016-03-11 14:27:52 -0800145 gpr_free(pp);
146 } else {
147 pp->next = p->pending_picks;
148 p->pending_picks = pp;
149 }
150 pp = next;
151 }
Mark D. Rothe65ff112016-09-09 13:48:38 -0700152 GRPC_ERROR_UNREF(error);
Craig Tiller8c0d96f2016-03-11 14:27:52 -0800153}
154
Craig Tillerbaa14a92017-11-03 09:09:36 -0700155static void start_picking_locked(grpc_exec_ctx* exec_ctx,
156 pick_first_lb_policy* p) {
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700157 p->started_picking = true;
Craig Tiller4782d922017-11-10 09:53:21 -0800158 if (p->subchannel_list != nullptr && p->subchannel_list->num_subchannels > 0) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700159 p->subchannel_list->checking_subchannel = 0;
160 grpc_lb_subchannel_list_ref_for_connectivity_watch(
161 p->subchannel_list, "connectivity_watch+start_picking");
162 grpc_lb_subchannel_data_start_connectivity_watch(
163 exec_ctx, &p->subchannel_list->subchannels[0]);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700164 }
Craig Tiller48cb07c2015-07-15 16:16:15 -0700165}
166
Craig Tillerbaa14a92017-11-03 09:09:36 -0700167static void pf_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) {
168 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
Craig Tillera82950e2015-09-22 12:33:20 -0700169 if (!p->started_picking) {
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700170 start_picking_locked(exec_ctx, p);
Craig Tillera82950e2015-09-22 12:33:20 -0700171 }
Craig Tillereb3b12e2015-06-26 14:42:49 -0700172}
173
Craig Tillerbaa14a92017-11-03 09:09:36 -0700174static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol,
175 const grpc_lb_policy_pick_args* pick_args,
176 grpc_connected_subchannel** target,
177 grpc_call_context_element* context, void** user_data,
178 grpc_closure* on_complete) {
179 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700180 // If we have a selected subchannel already, return synchronously.
Craig Tiller4782d922017-11-10 09:53:21 -0800181 if (p->selected != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700182 *target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected->connected_subchannel,
183 "picked");
Craig Tiller86c0f8a2015-12-01 20:05:40 -0800184 return 1;
185 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700186 // No subchannel selected yet, so handle asynchronously.
Craig Tiller2400bf52017-02-09 16:25:19 -0800187 if (!p->started_picking) {
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700188 start_picking_locked(exec_ctx, p);
Craig Tillera82950e2015-09-22 12:33:20 -0700189 }
Craig Tillerbaa14a92017-11-03 09:09:36 -0700190 pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp));
Craig Tiller2400bf52017-02-09 16:25:19 -0800191 pp->next = p->pending_picks;
192 pp->target = target;
193 pp->initial_metadata_flags = pick_args->initial_metadata_flags;
194 pp->on_complete = on_complete;
195 p->pending_picks = pp;
196 return 0;
Craig Tiller45724b32015-09-22 10:42:19 -0700197}
198
Craig Tillerbaa14a92017-11-03 09:09:36 -0700199static void destroy_unselected_subchannels_locked(grpc_exec_ctx* exec_ctx,
200 pick_first_lb_policy* p) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700201 for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) {
Craig Tillerbaa14a92017-11-03 09:09:36 -0700202 grpc_lb_subchannel_data* sd = &p->subchannel_list->subchannels[i];
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700203 if (p->selected != sd) {
204 grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd,
205 "selected_different_subchannel");
206 }
Craig Tillerb09d84d2015-10-06 09:12:16 -0700207 }
Craig Tillerb09d84d2015-10-06 09:12:16 -0700208}
209
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700210static grpc_connectivity_state pf_check_connectivity_locked(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700211 grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) {
212 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700213 return grpc_connectivity_state_get(&p->state_tracker, error);
214}
215
Craig Tillerbaa14a92017-11-03 09:09:36 -0700216static void pf_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx,
217 grpc_lb_policy* pol,
218 grpc_connectivity_state* current,
219 grpc_closure* notify) {
220 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700221 grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker,
222 current, notify);
223}
224
Craig Tillerbaa14a92017-11-03 09:09:36 -0700225static void pf_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol,
226 grpc_closure* closure) {
227 pick_first_lb_policy* p = (pick_first_lb_policy*)pol;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700228 if (p->selected) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700229 grpc_connected_subchannel_ping(exec_ctx, p->selected->connected_subchannel,
230 closure);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700231 } else {
ncteisen274bbbe2017-06-08 14:57:11 -0700232 GRPC_CLOSURE_SCHED(exec_ctx, closure,
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700233 GRPC_ERROR_CREATE_FROM_STATIC_STRING("Not connected"));
234 }
235}
236
Craig Tillerbaa14a92017-11-03 09:09:36 -0700237static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg,
238 grpc_error* error);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700239
Craig Tillerbaa14a92017-11-03 09:09:36 -0700240static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy,
241 const grpc_lb_policy_args* args) {
242 pick_first_lb_policy* p = (pick_first_lb_policy*)policy;
243 const grpc_arg* arg =
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700244 grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES);
Craig Tiller4782d922017-11-10 09:53:21 -0800245 if (arg == nullptr || arg->type != GRPC_ARG_POINTER) {
246 if (p->subchannel_list == nullptr) {
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700247 // If we don't have a current subchannel list, go into TRANSIENT FAILURE.
248 grpc_connectivity_state_set(
249 exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
250 GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"),
251 "pf_update_missing");
252 } else {
253 // otherwise, keep using the current subchannel list (ignore this update).
254 gpr_log(GPR_ERROR,
255 "No valid LB addresses channel arg for Pick First %p update, "
256 "ignoring.",
Craig Tillerbaa14a92017-11-03 09:09:36 -0700257 (void*)p);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700258 }
259 return;
260 }
Craig Tillerbaa14a92017-11-03 09:09:36 -0700261 const grpc_lb_addresses* addresses =
262 (const grpc_lb_addresses*)arg->value.pointer.p;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700263 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
264 gpr_log(GPR_INFO, "Pick First %p received update with %lu addresses",
Craig Tillerbaa14a92017-11-03 09:09:36 -0700265 (void*)p, (unsigned long)addresses->num_addresses);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700266 }
Craig Tillerbaa14a92017-11-03 09:09:36 -0700267 grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create(
Mark D. Roth901bb4f2017-10-11 08:49:07 -0700268 exec_ctx, &p->base, &grpc_lb_pick_first_trace, addresses, args,
269 pf_connectivity_changed_locked);
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700270 if (subchannel_list->num_subchannels == 0) {
271 // Empty update or no valid subchannels. Unsubscribe from all current
272 // subchannels and put the channel in TRANSIENT_FAILURE.
273 grpc_connectivity_state_set(
274 exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
275 GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"),
276 "pf_update_empty");
Craig Tiller4782d922017-11-10 09:53:21 -0800277 if (p->subchannel_list != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700278 grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list,
279 "sl_shutdown_empty_update");
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700280 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700281 p->subchannel_list = subchannel_list; // Empty list.
Craig Tiller4782d922017-11-10 09:53:21 -0800282 p->selected = nullptr;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700283 return;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700284 }
Craig Tiller4782d922017-11-10 09:53:21 -0800285 if (p->selected == nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700286 // We don't yet have a selected subchannel, so replace the current
287 // subchannel list immediately.
Craig Tiller4782d922017-11-10 09:53:21 -0800288 if (p->subchannel_list != nullptr) {
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700289 grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list,
290 "pf_update_before_selected");
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700291 }
292 p->subchannel_list = subchannel_list;
293 } else {
294 // We do have a selected subchannel.
295 // Check if it's present in the new list. If so, we're done.
296 for (size_t i = 0; i < subchannel_list->num_subchannels; ++i) {
Craig Tillerbaa14a92017-11-03 09:09:36 -0700297 grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i];
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700298 if (sd->subchannel == p->selected->subchannel) {
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700299 // The currently selected subchannel is in the update: we are done.
300 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
301 gpr_log(GPR_INFO,
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700302 "Pick First %p found already selected subchannel %p "
Mark D. Rothe9b10832017-10-26 13:18:25 -0700303 "at update index %" PRIuPTR " of %" PRIuPTR "; update done",
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700304 p, p->selected->subchannel, i,
305 subchannel_list->num_subchannels);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700306 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700307 grpc_lb_subchannel_list_ref_for_connectivity_watch(
308 subchannel_list, "connectivity_watch+replace_selected");
309 grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd);
Craig Tiller4782d922017-11-10 09:53:21 -0800310 if (p->subchannel_list != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700311 grpc_lb_subchannel_list_shutdown_and_unref(
312 exec_ctx, p->subchannel_list, "pf_update_includes_selected");
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700313 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700314 p->subchannel_list = subchannel_list;
Craig Tiller4782d922017-11-10 09:53:21 -0800315 if (p->selected->connected_subchannel != nullptr) {
Mark D. Roth6e5ce722017-10-27 09:37:41 -0700316 sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF(
317 p->selected->connected_subchannel, "pf_update_includes_selected");
318 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700319 p->selected = sd;
320 destroy_unselected_subchannels_locked(exec_ctx, p);
321 // If there was a previously pending update (which may or may
322 // not have contained the currently selected subchannel), drop
323 // it, so that it doesn't override what we've done here.
Craig Tiller4782d922017-11-10 09:53:21 -0800324 if (p->latest_pending_subchannel_list != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700325 grpc_lb_subchannel_list_shutdown_and_unref(
326 exec_ctx, p->latest_pending_subchannel_list,
327 "pf_update_includes_selected+outdated");
Craig Tiller4782d922017-11-10 09:53:21 -0800328 p->latest_pending_subchannel_list = nullptr;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700329 }
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700330 return;
331 }
332 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700333 // Not keeping the previous selected subchannel, so set the latest
334 // pending subchannel list to the new subchannel list. We will wait
335 // for it to report READY before swapping it into the current
336 // subchannel list.
Craig Tiller4782d922017-11-10 09:53:21 -0800337 if (p->latest_pending_subchannel_list != nullptr) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700338 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
339 gpr_log(GPR_DEBUG,
340 "Pick First %p Shutting down latest pending subchannel list "
341 "%p, about to be replaced by newer latest %p",
Craig Tillerbaa14a92017-11-03 09:09:36 -0700342 (void*)p, (void*)p->latest_pending_subchannel_list,
343 (void*)subchannel_list);
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700344 }
345 grpc_lb_subchannel_list_shutdown_and_unref(
346 exec_ctx, p->latest_pending_subchannel_list,
347 "sl_outdated_dont_smash");
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700348 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700349 p->latest_pending_subchannel_list = subchannel_list;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700350 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700351 // If we've started picking, start trying to connect to the first
352 // subchannel in the new list.
Mark D. Roth5132d0e2017-10-13 13:20:52 -0700353 if (p->started_picking) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700354 grpc_lb_subchannel_list_ref_for_connectivity_watch(
355 subchannel_list, "connectivity_watch+update");
356 grpc_lb_subchannel_data_start_connectivity_watch(
357 exec_ctx, &subchannel_list->subchannels[0]);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700358 }
359}
360
Craig Tillerbaa14a92017-11-03 09:09:36 -0700361static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg,
362 grpc_error* error) {
363 grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg;
364 pick_first_lb_policy* p = (pick_first_lb_policy*)sd->subchannel_list->policy;
David Garcia Quintasaf084dc2017-06-27 13:42:54 -0700365 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700366 gpr_log(GPR_DEBUG,
Mark D. Rothe9b10832017-10-26 13:18:25 -0700367 "Pick First %p connectivity changed for subchannel %p (%" PRIuPTR
368 " of %" PRIuPTR
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700369 "), subchannel_list %p: state=%s p->shutdown=%d "
370 "sd->subchannel_list->shutting_down=%d error=%s",
Craig Tillerbaa14a92017-11-03 09:09:36 -0700371 (void*)p, (void*)sd->subchannel,
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700372 sd->subchannel_list->checking_subchannel,
Craig Tillerbaa14a92017-11-03 09:09:36 -0700373 sd->subchannel_list->num_subchannels, (void*)sd->subchannel_list,
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700374 grpc_connectivity_state_name(sd->pending_connectivity_state_unsafe),
375 p->shutdown, sd->subchannel_list->shutting_down,
376 grpc_error_string(error));
David Garcia Quintasaf084dc2017-06-27 13:42:54 -0700377 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700378 // If the policy is shutting down, unref and return.
379 if (p->shutdown) {
380 grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd);
381 grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_shutdown");
382 grpc_lb_subchannel_list_unref_for_connectivity_watch(
383 exec_ctx, sd->subchannel_list, "pf_shutdown");
384 return;
385 }
386 // If the subchannel list is shutting down, stop watching.
387 if (sd->subchannel_list->shutting_down || error == GRPC_ERROR_CANCELLED) {
388 grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd);
389 grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_sl_shutdown");
390 grpc_lb_subchannel_list_unref_for_connectivity_watch(
391 exec_ctx, sd->subchannel_list, "pf_sl_shutdown");
392 return;
393 }
394 // If we're still here, the notification must be for a subchannel in
395 // either the current or latest pending subchannel lists.
396 GPR_ASSERT(sd->subchannel_list == p->subchannel_list ||
397 sd->subchannel_list == p->latest_pending_subchannel_list);
Mark D. Roth5132d0e2017-10-13 13:20:52 -0700398 // Update state.
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700399 sd->curr_connectivity_state = sd->pending_connectivity_state_unsafe;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700400 // Handle updates for the currently selected subchannel.
401 if (p->selected == sd) {
402 // If the new state is anything other than READY and there is a
403 // pending update, switch to the pending update.
404 if (sd->curr_connectivity_state != GRPC_CHANNEL_READY &&
Craig Tiller4782d922017-11-10 09:53:21 -0800405 p->latest_pending_subchannel_list != nullptr) {
406 p->selected = nullptr;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700407 grpc_lb_subchannel_list_shutdown_and_unref(
408 exec_ctx, p->subchannel_list, "selected_not_ready+switch_to_update");
409 p->subchannel_list = p->latest_pending_subchannel_list;
Craig Tiller4782d922017-11-10 09:53:21 -0800410 p->latest_pending_subchannel_list = nullptr;
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700411 grpc_connectivity_state_set(
Mark D. Roth99f54e12017-10-16 09:55:53 -0700412 exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700413 GRPC_ERROR_REF(error), "selected_not_ready+switch_to_update");
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700414 } else {
Mark D. Roth62ca6ce2017-10-10 10:01:51 -0700415 if (sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700416 /* if the selected channel goes bad, we're done */
417 sd->curr_connectivity_state = GRPC_CHANNEL_SHUTDOWN;
418 }
419 grpc_connectivity_state_set(exec_ctx, &p->state_tracker,
420 sd->curr_connectivity_state,
421 GRPC_ERROR_REF(error), "selected_changed");
422 if (sd->curr_connectivity_state != GRPC_CHANNEL_SHUTDOWN) {
423 // Renew notification.
424 grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd);
425 } else {
426 grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd);
427 grpc_lb_subchannel_list_unref_for_connectivity_watch(
428 exec_ctx, sd->subchannel_list, "pf_selected_shutdown");
Mark D. Rothaadf9f42017-10-19 07:53:53 -0700429 shutdown_locked(exec_ctx, p, GRPC_ERROR_REF(error));
David Garcia Quintasaf084dc2017-06-27 13:42:54 -0700430 }
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700431 }
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700432 return;
433 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700434 // If we get here, there are two possible cases:
435 // 1. We do not currently have a selected subchannel, and the update is
436 // for a subchannel in p->subchannel_list that we're trying to
437 // connect to. The goal here is to find a subchannel that we can
438 // select.
439 // 2. We do currently have a selected subchannel, and the update is
440 // for a subchannel in p->latest_pending_subchannel_list. The
441 // goal here is to find a subchannel from the update that we can
442 // select in place of the current one.
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700443 if (sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE ||
444 sd->curr_connectivity_state == GRPC_CHANNEL_SHUTDOWN) {
445 grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd);
446 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700447 while (true) {
448 switch (sd->curr_connectivity_state) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700449 case GRPC_CHANNEL_READY: {
450 // Case 2. Promote p->latest_pending_subchannel_list to
451 // p->subchannel_list.
452 if (sd->subchannel_list == p->latest_pending_subchannel_list) {
Craig Tiller4782d922017-11-10 09:53:21 -0800453 GPR_ASSERT(p->subchannel_list != nullptr);
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700454 grpc_lb_subchannel_list_shutdown_and_unref(
455 exec_ctx, p->subchannel_list, "finish_update");
456 p->subchannel_list = p->latest_pending_subchannel_list;
Craig Tiller4782d922017-11-10 09:53:21 -0800457 p->latest_pending_subchannel_list = nullptr;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700458 }
459 // Cases 1 and 2.
Craig Tillera82950e2015-09-22 12:33:20 -0700460 grpc_connectivity_state_set(exec_ctx, &p->state_tracker,
Craig Tiller804ff712016-05-05 16:25:40 -0700461 GRPC_CHANNEL_READY, GRPC_ERROR_NONE,
462 "connecting_ready");
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700463 sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF(
464 grpc_subchannel_get_connected_subchannel(sd->subchannel),
465 "connected");
466 p->selected = sd;
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700467 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
Craig Tillerbaa14a92017-11-03 09:09:36 -0700468 gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", (void*)p,
469 (void*)sd->subchannel);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700470 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700471 // Drop all other subchannels, since we are now connected.
472 destroy_unselected_subchannels_locked(exec_ctx, p);
473 // Update any calls that were waiting for a pick.
Craig Tillerbaa14a92017-11-03 09:09:36 -0700474 pending_pick* pp;
Craig Tillera82950e2015-09-22 12:33:20 -0700475 while ((pp = p->pending_picks)) {
476 p->pending_picks = pp->next;
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700477 *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF(
478 p->selected->connected_subchannel, "picked");
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700479 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
480 gpr_log(GPR_INFO,
481 "Servicing pending pick with selected subchannel %p",
Craig Tillerbaa14a92017-11-03 09:09:36 -0700482 (void*)p->selected);
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700483 }
ncteisen274bbbe2017-06-08 14:57:11 -0700484 GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE);
Craig Tillera82950e2015-09-22 12:33:20 -0700485 gpr_free(pp);
486 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700487 // Renew notification.
488 grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd);
489 return;
490 }
491 case GRPC_CHANNEL_TRANSIENT_FAILURE: {
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700492 do {
493 sd->subchannel_list->checking_subchannel =
494 (sd->subchannel_list->checking_subchannel + 1) %
495 sd->subchannel_list->num_subchannels;
496 sd = &sd->subchannel_list
497 ->subchannels[sd->subchannel_list->checking_subchannel];
Craig Tiller4782d922017-11-10 09:53:21 -0800498 } while (sd->subchannel == nullptr);
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700499 // Case 1: Only set state to TRANSIENT_FAILURE if we've tried
500 // all subchannels.
501 if (sd->subchannel_list->checking_subchannel == 0 &&
502 sd->subchannel_list == p->subchannel_list) {
Craig Tiller804ff712016-05-05 16:25:40 -0700503 grpc_connectivity_state_set(
504 exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
Craig Tillerf707d622016-05-06 14:26:12 -0700505 GRPC_ERROR_REF(error), "connecting_transient_failure");
Craig Tiller131b6de2016-03-31 17:05:28 -0700506 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700507 sd->curr_connectivity_state =
508 grpc_subchannel_check_connectivity(sd->subchannel, &error);
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700509 GRPC_ERROR_UNREF(error);
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700510 if (sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
511 // Reuses the connectivity refs from the previous watch.
512 grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd);
513 return;
Craig Tillera82950e2015-09-22 12:33:20 -0700514 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700515 break; // Go back to top of loop.
516 }
Craig Tillera82950e2015-09-22 12:33:20 -0700517 case GRPC_CHANNEL_CONNECTING:
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700518 case GRPC_CHANNEL_IDLE: {
519 // Only update connectivity state in case 1.
520 if (sd->subchannel_list == p->subchannel_list) {
Craig Tiller804ff712016-05-05 16:25:40 -0700521 grpc_connectivity_state_set(
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700522 exec_ctx, &p->state_tracker, GRPC_CHANNEL_CONNECTING,
523 GRPC_ERROR_REF(error), "connecting_changed");
524 }
525 // Renew notification.
526 grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd);
527 return;
528 }
529 case GRPC_CHANNEL_SHUTDOWN: {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700530 grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd,
531 "pf_candidate_shutdown");
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700532 // Advance to next subchannel and check its state.
Craig Tillerbaa14a92017-11-03 09:09:36 -0700533 grpc_lb_subchannel_data* original_sd = sd;
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700534 do {
535 sd->subchannel_list->checking_subchannel =
536 (sd->subchannel_list->checking_subchannel + 1) %
537 sd->subchannel_list->num_subchannels;
538 sd = &sd->subchannel_list
539 ->subchannels[sd->subchannel_list->checking_subchannel];
Craig Tiller4782d922017-11-10 09:53:21 -0800540 } while (sd->subchannel == nullptr && sd != original_sd);
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700541 if (sd == original_sd) {
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700542 grpc_lb_subchannel_list_unref_for_connectivity_watch(
543 exec_ctx, sd->subchannel_list, "pf_candidate_shutdown");
544 shutdown_locked(exec_ctx, p,
545 GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
546 "Pick first exhausted channels", &error, 1));
547 return;
548 }
549 if (sd->subchannel_list == p->subchannel_list) {
Craig Tiller804ff712016-05-05 16:25:40 -0700550 grpc_connectivity_state_set(
551 exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
Craig Tillerf707d622016-05-06 14:26:12 -0700552 GRPC_ERROR_REF(error), "subchannel_failed");
Craig Tillera82950e2015-09-22 12:33:20 -0700553 }
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700554 sd->curr_connectivity_state =
555 grpc_subchannel_check_connectivity(sd->subchannel, &error);
Mark D. Roth7ba40ba2017-10-10 13:17:13 -0700556 GRPC_ERROR_UNREF(error);
Mark D. Roth5e9848e2017-10-06 13:59:32 -0700557 if (sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
558 // Reuses the connectivity refs from the previous watch.
559 grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd);
560 return;
561 }
562 // For any other state, go back to top of loop.
563 // We will reuse the connectivity refs from the previous watch.
564 }
Craig Tiller1ada6ad2015-07-16 16:19:14 -0700565 }
Craig Tillera82950e2015-09-22 12:33:20 -0700566 }
Craig Tillereb3b12e2015-06-26 14:42:49 -0700567}
568
569static const grpc_lb_policy_vtable pick_first_lb_policy_vtable = {
Craig Tiller2400bf52017-02-09 16:25:19 -0800570 pf_destroy,
571 pf_shutdown_locked,
572 pf_pick_locked,
573 pf_cancel_pick_locked,
574 pf_cancel_picks_locked,
575 pf_ping_one_locked,
576 pf_exit_idle_locked,
577 pf_check_connectivity_locked,
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700578 pf_notify_on_state_change_locked,
579 pf_update_locked};
Craig Tillereb3b12e2015-06-26 14:42:49 -0700580
Craig Tillerbaa14a92017-11-03 09:09:36 -0700581static void pick_first_factory_ref(grpc_lb_policy_factory* factory) {}
David Garcia Quintas5c4543d2015-09-03 15:49:56 -0700582
Craig Tillerbaa14a92017-11-03 09:09:36 -0700583static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {}
David Garcia Quintas5c4543d2015-09-03 15:49:56 -0700584
Craig Tillerbaa14a92017-11-03 09:09:36 -0700585static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx,
586 grpc_lb_policy_factory* factory,
587 grpc_lb_policy_args* args) {
Craig Tiller4782d922017-11-10 09:53:21 -0800588 GPR_ASSERT(args->client_channel_factory != nullptr);
Craig Tillerbaa14a92017-11-03 09:09:36 -0700589 pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p));
David Garcia Quintasaf084dc2017-06-27 13:42:54 -0700590 if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) {
Craig Tillerbaa14a92017-11-03 09:09:36 -0700591 gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p);
David Garcia Quintasaf084dc2017-06-27 13:42:54 -0700592 }
David Garcia Quintas87d5a312017-06-06 19:45:58 -0700593 pf_update_locked(exec_ctx, &p->base, args);
Craig Tiller2400bf52017-02-09 16:25:19 -0800594 grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable, args->combiner);
Juanli Shen6502ecc2017-09-13 13:10:54 -0700595 grpc_subchannel_index_ref();
Craig Tillereb3b12e2015-06-26 14:42:49 -0700596 return &p->base;
597}
David Garcia Quintas5c4543d2015-09-03 15:49:56 -0700598
599static const grpc_lb_policy_factory_vtable pick_first_factory_vtable = {
Craig Tillera82950e2015-09-22 12:33:20 -0700600 pick_first_factory_ref, pick_first_factory_unref, create_pick_first,
601 "pick_first"};
David Garcia Quintas5c4543d2015-09-03 15:49:56 -0700602
603static grpc_lb_policy_factory pick_first_lb_policy_factory = {
Craig Tillera82950e2015-09-22 12:33:20 -0700604 &pick_first_factory_vtable};
David Garcia Quintas5c4543d2015-09-03 15:49:56 -0700605
Craig Tillerbaa14a92017-11-03 09:09:36 -0700606static grpc_lb_policy_factory* pick_first_lb_factory_create() {
David Garcia Quintas5c4543d2015-09-03 15:49:56 -0700607 return &pick_first_lb_policy_factory;
608}
Craig Tillerfb433852016-03-29 08:51:07 -0700609
610/* Plugin registration */
611
Yash Tibrewal83062842017-09-21 18:56:08 -0700612extern "C" void grpc_lb_policy_pick_first_init() {
Craig Tiller3113ef42016-03-29 09:03:14 -0700613 grpc_register_lb_policy(pick_first_lb_factory_create());
ncteisen06bce6e2017-07-10 07:58:49 -0700614 grpc_register_tracer(&grpc_lb_pick_first_trace);
Craig Tillerfb433852016-03-29 08:51:07 -0700615}
616
Yash Tibrewal83062842017-09-21 18:56:08 -0700617extern "C" void grpc_lb_policy_pick_first_shutdown() {}