|
|
|
@ -73,9 +73,9 @@ typedef struct { |
|
|
|
|
guarded by mu_config */ |
|
|
|
|
grpc_client_config *incoming_configuration; |
|
|
|
|
/** a list of closures that are all waiting for config to come in */ |
|
|
|
|
grpc_iomgr_call_list waiting_for_config_closures; |
|
|
|
|
grpc_call_list waiting_for_config_closures; |
|
|
|
|
/** resolver callback */ |
|
|
|
|
grpc_iomgr_closure on_config_changed; |
|
|
|
|
grpc_closure on_config_changed; |
|
|
|
|
/** connectivity state being tracked */ |
|
|
|
|
grpc_connectivity_state_tracker state_tracker; |
|
|
|
|
/** when an lb_policy arrives, should we try to exit idle */ |
|
|
|
@ -91,7 +91,7 @@ typedef struct { |
|
|
|
|
update the channel, and create a new watcher */ |
|
|
|
|
typedef struct { |
|
|
|
|
channel_data *chand; |
|
|
|
|
grpc_iomgr_closure on_changed; |
|
|
|
|
grpc_closure on_changed; |
|
|
|
|
grpc_connectivity_state state; |
|
|
|
|
grpc_lb_policy *lb_policy; |
|
|
|
|
} lb_policy_connectivity_watcher; |
|
|
|
@ -115,7 +115,7 @@ struct call_data { |
|
|
|
|
call_state state; |
|
|
|
|
gpr_timespec deadline; |
|
|
|
|
grpc_subchannel *picked_channel; |
|
|
|
|
grpc_iomgr_closure async_setup_task; |
|
|
|
|
grpc_closure async_setup_task; |
|
|
|
|
grpc_transport_stream_op waiting_op; |
|
|
|
|
/* our child call stack */ |
|
|
|
|
grpc_subchannel_call *subchannel_call; |
|
|
|
@ -123,9 +123,9 @@ struct call_data { |
|
|
|
|
grpc_linked_mdelem details; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static grpc_iomgr_closure *merge_into_waiting_op( |
|
|
|
|
grpc_call_element *elem, |
|
|
|
|
grpc_transport_stream_op *new_op) GRPC_MUST_USE_RESULT; |
|
|
|
|
static grpc_closure *merge_into_waiting_op(grpc_call_element *elem, |
|
|
|
|
grpc_transport_stream_op *new_op) |
|
|
|
|
GRPC_MUST_USE_RESULT; |
|
|
|
|
|
|
|
|
|
static void handle_op_after_cancellation(grpc_call_element *elem, |
|
|
|
|
grpc_transport_stream_op *op) { |
|
|
|
@ -160,7 +160,7 @@ static void handle_op_after_cancellation(grpc_call_element *elem, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
grpc_iomgr_closure closure; |
|
|
|
|
grpc_closure closure; |
|
|
|
|
grpc_call_element *elem; |
|
|
|
|
} waiting_call; |
|
|
|
|
|
|
|
|
@ -179,10 +179,9 @@ static void add_to_lb_policy_wait_queue_locked_state_config( |
|
|
|
|
grpc_call_element *elem) { |
|
|
|
|
channel_data *chand = elem->channel_data; |
|
|
|
|
waiting_call *wc = gpr_malloc(sizeof(*wc)); |
|
|
|
|
grpc_iomgr_closure_init(&wc->closure, continue_with_pick, wc); |
|
|
|
|
grpc_closure_init(&wc->closure, continue_with_pick, wc); |
|
|
|
|
wc->elem = elem; |
|
|
|
|
grpc_iomgr_call_list_add(&chand->waiting_for_config_closures, &wc->closure, |
|
|
|
|
1); |
|
|
|
|
grpc_call_list_add(&chand->waiting_for_config_closures, &wc->closure, 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int is_empty(void *p, int len) { |
|
|
|
@ -230,7 +229,7 @@ static void started_call(void *arg, int iomgr_success) { |
|
|
|
|
static void picked_target(void *arg, int iomgr_success) { |
|
|
|
|
call_data *calld = arg; |
|
|
|
|
grpc_pollset *pollset; |
|
|
|
|
grpc_iomgr_call_list call_list = GRPC_IOMGR_CALL_LIST_INIT; |
|
|
|
|
grpc_call_list call_list = GRPC_CALL_LIST_INIT; |
|
|
|
|
|
|
|
|
|
if (calld->picked_channel == NULL) { |
|
|
|
|
/* treat this like a cancellation */ |
|
|
|
@ -246,19 +245,19 @@ static void picked_target(void *arg, int iomgr_success) { |
|
|
|
|
calld->state = CALL_WAITING_FOR_CALL; |
|
|
|
|
pollset = calld->waiting_op.bind_pollset; |
|
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
|
grpc_iomgr_closure_init(&calld->async_setup_task, started_call, calld); |
|
|
|
|
grpc_closure_init(&calld->async_setup_task, started_call, calld); |
|
|
|
|
grpc_subchannel_create_call(calld->picked_channel, pollset, |
|
|
|
|
&calld->subchannel_call, |
|
|
|
|
&calld->async_setup_task, &call_list); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
grpc_iomgr_call_list_run(call_list); |
|
|
|
|
grpc_call_list_run(call_list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_iomgr_closure *merge_into_waiting_op( |
|
|
|
|
grpc_call_element *elem, grpc_transport_stream_op *new_op) { |
|
|
|
|
static grpc_closure *merge_into_waiting_op(grpc_call_element *elem, |
|
|
|
|
grpc_transport_stream_op *new_op) { |
|
|
|
|
call_data *calld = elem->call_data; |
|
|
|
|
grpc_iomgr_closure *consumed_op = NULL; |
|
|
|
|
grpc_closure *consumed_op = NULL; |
|
|
|
|
grpc_transport_stream_op *waiting_op = &calld->waiting_op; |
|
|
|
|
GPR_ASSERT((waiting_op->send_ops != NULL) + (new_op->send_ops != NULL) <= 1); |
|
|
|
|
GPR_ASSERT((waiting_op->recv_ops != NULL) + (new_op->recv_ops != NULL) <= 1); |
|
|
|
@ -312,7 +311,7 @@ static void perform_transport_stream_op(grpc_call_element *elem, |
|
|
|
|
grpc_subchannel_call *subchannel_call; |
|
|
|
|
grpc_lb_policy *lb_policy; |
|
|
|
|
grpc_transport_stream_op op2; |
|
|
|
|
grpc_iomgr_call_list call_list = GRPC_IOMGR_CALL_LIST_INIT; |
|
|
|
|
grpc_call_list call_list = GRPC_CALL_LIST_INIT; |
|
|
|
|
GPR_ASSERT(elem->filter == &grpc_client_channel_filter); |
|
|
|
|
GRPC_CALL_LOG_OP(GPR_INFO, elem, op); |
|
|
|
|
|
|
|
|
@ -330,7 +329,7 @@ static void perform_transport_stream_op(grpc_call_element *elem, |
|
|
|
|
break; |
|
|
|
|
case CALL_WAITING_FOR_SEND: |
|
|
|
|
GPR_ASSERT(!continuation); |
|
|
|
|
grpc_iomgr_call_list_add(&call_list, merge_into_waiting_op(elem, op), 1); |
|
|
|
|
grpc_call_list_add(&call_list, merge_into_waiting_op(elem, op), 1); |
|
|
|
|
if (!calld->waiting_op.send_ops && |
|
|
|
|
calld->waiting_op.cancel_with_status == GRPC_STATUS_OK) { |
|
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
@ -359,8 +358,7 @@ static void perform_transport_stream_op(grpc_call_element *elem, |
|
|
|
|
handle_op_after_cancellation(elem, op); |
|
|
|
|
handle_op_after_cancellation(elem, &op2); |
|
|
|
|
} else { |
|
|
|
|
grpc_iomgr_call_list_add(&call_list, merge_into_waiting_op(elem, op), |
|
|
|
|
1); |
|
|
|
|
grpc_call_list_add(&call_list, merge_into_waiting_op(elem, op), 1); |
|
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -397,8 +395,7 @@ static void perform_transport_stream_op(grpc_call_element *elem, |
|
|
|
|
GPR_ASSERT(op->send_ops->ops[0].type == GRPC_OP_METADATA); |
|
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
|
|
|
|
|
|
grpc_iomgr_closure_init(&calld->async_setup_task, picked_target, |
|
|
|
|
calld); |
|
|
|
|
grpc_closure_init(&calld->async_setup_task, picked_target, calld); |
|
|
|
|
grpc_lb_policy_pick(lb_policy, bind_pollset, initial_metadata, |
|
|
|
|
&calld->picked_channel, |
|
|
|
|
&calld->async_setup_task, &call_list); |
|
|
|
@ -427,7 +424,7 @@ static void perform_transport_stream_op(grpc_call_element *elem, |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_iomgr_call_list_run(call_list); |
|
|
|
|
grpc_call_list_run(call_list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void cc_start_transport_stream_op(grpc_call_element *elem, |
|
|
|
@ -437,10 +434,10 @@ static void cc_start_transport_stream_op(grpc_call_element *elem, |
|
|
|
|
|
|
|
|
|
static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy, |
|
|
|
|
grpc_connectivity_state current_state, |
|
|
|
|
grpc_iomgr_call_list *cl); |
|
|
|
|
grpc_call_list *cl); |
|
|
|
|
|
|
|
|
|
static void on_lb_policy_state_changed_locked(lb_policy_connectivity_watcher *w, |
|
|
|
|
grpc_iomgr_call_list *cl) { |
|
|
|
|
grpc_call_list *cl) { |
|
|
|
|
/* check if the notification is for a stale policy */ |
|
|
|
|
if (w->lb_policy != w->chand->lb_policy) return; |
|
|
|
|
|
|
|
|
@ -453,13 +450,13 @@ static void on_lb_policy_state_changed_locked(lb_policy_connectivity_watcher *w, |
|
|
|
|
|
|
|
|
|
static void on_lb_policy_state_changed(void *arg, int iomgr_success) { |
|
|
|
|
lb_policy_connectivity_watcher *w = arg; |
|
|
|
|
grpc_iomgr_call_list cl = GRPC_IOMGR_CALL_LIST_INIT; |
|
|
|
|
grpc_call_list cl = GRPC_CALL_LIST_INIT; |
|
|
|
|
|
|
|
|
|
gpr_mu_lock(&w->chand->mu_config); |
|
|
|
|
on_lb_policy_state_changed_locked(w, &cl); |
|
|
|
|
gpr_mu_unlock(&w->chand->mu_config); |
|
|
|
|
|
|
|
|
|
grpc_iomgr_call_list_run(cl); |
|
|
|
|
grpc_call_list_run(cl); |
|
|
|
|
|
|
|
|
|
GRPC_CHANNEL_INTERNAL_UNREF(w->chand->master, "watch_lb_policy"); |
|
|
|
|
gpr_free(w); |
|
|
|
@ -467,12 +464,12 @@ static void on_lb_policy_state_changed(void *arg, int iomgr_success) { |
|
|
|
|
|
|
|
|
|
static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy, |
|
|
|
|
grpc_connectivity_state current_state, |
|
|
|
|
grpc_iomgr_call_list *call_list) { |
|
|
|
|
grpc_call_list *call_list) { |
|
|
|
|
lb_policy_connectivity_watcher *w = gpr_malloc(sizeof(*w)); |
|
|
|
|
GRPC_CHANNEL_INTERNAL_REF(chand->master, "watch_lb_policy"); |
|
|
|
|
|
|
|
|
|
w->chand = chand; |
|
|
|
|
grpc_iomgr_closure_init(&w->on_changed, on_lb_policy_state_changed, w); |
|
|
|
|
grpc_closure_init(&w->on_changed, on_lb_policy_state_changed, w); |
|
|
|
|
w->state = current_state; |
|
|
|
|
w->lb_policy = lb_policy; |
|
|
|
|
grpc_lb_policy_notify_on_state_change(lb_policy, &w->state, &w->on_changed, |
|
|
|
@ -485,7 +482,7 @@ static void cc_on_config_changed(void *arg, int iomgr_success) { |
|
|
|
|
grpc_lb_policy *old_lb_policy; |
|
|
|
|
grpc_resolver *old_resolver; |
|
|
|
|
grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; |
|
|
|
|
grpc_iomgr_call_list cl = GRPC_IOMGR_CALL_LIST_INIT; |
|
|
|
|
grpc_call_list cl = GRPC_CALL_LIST_INIT; |
|
|
|
|
int exit_idle = 0; |
|
|
|
|
|
|
|
|
|
if (chand->incoming_configuration != NULL) { |
|
|
|
@ -505,7 +502,7 @@ static void cc_on_config_changed(void *arg, int iomgr_success) { |
|
|
|
|
old_lb_policy = chand->lb_policy; |
|
|
|
|
chand->lb_policy = lb_policy; |
|
|
|
|
if (lb_policy != NULL || chand->resolver == NULL /* disconnected */) { |
|
|
|
|
grpc_iomgr_call_list_move(&chand->waiting_for_config_closures, &cl); |
|
|
|
|
grpc_call_list_move(&chand->waiting_for_config_closures, &cl); |
|
|
|
|
} |
|
|
|
|
if (lb_policy != NULL && chand->exit_idle_when_lb_policy_arrives) { |
|
|
|
|
GRPC_LB_POLICY_REF(lb_policy, "exit_idle"); |
|
|
|
@ -553,7 +550,7 @@ static void cc_on_config_changed(void *arg, int iomgr_success) { |
|
|
|
|
GRPC_LB_POLICY_UNREF(lb_policy, "config_change"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_iomgr_call_list_run(cl); |
|
|
|
|
grpc_call_list_run(cl); |
|
|
|
|
GRPC_CHANNEL_INTERNAL_UNREF(chand->master, "resolver"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -562,10 +559,10 @@ static void cc_start_transport_op(grpc_channel_element *elem, |
|
|
|
|
grpc_lb_policy *lb_policy = NULL; |
|
|
|
|
channel_data *chand = elem->channel_data; |
|
|
|
|
grpc_resolver *destroy_resolver = NULL; |
|
|
|
|
grpc_iomgr_call_list call_list = GRPC_IOMGR_CALL_LIST_INIT; |
|
|
|
|
grpc_call_list call_list = GRPC_CALL_LIST_INIT; |
|
|
|
|
|
|
|
|
|
if (op->on_consumed) { |
|
|
|
|
grpc_iomgr_call_list_add(&call_list, op->on_consumed, 1); |
|
|
|
|
grpc_call_list_add(&call_list, op->on_consumed, 1); |
|
|
|
|
op->on_consumed = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -612,7 +609,7 @@ static void cc_start_transport_op(grpc_channel_element *elem, |
|
|
|
|
GRPC_LB_POLICY_UNREF(lb_policy, "broadcast"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_iomgr_call_list_run(call_list); |
|
|
|
|
grpc_call_list_run(call_list); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Constructor for call_data */ |
|
|
|
@ -677,8 +674,7 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, |
|
|
|
|
chand->mdctx = metadata_context; |
|
|
|
|
chand->master = master; |
|
|
|
|
grpc_pollset_set_init(&chand->pollset_set); |
|
|
|
|
grpc_iomgr_closure_init(&chand->on_config_changed, cc_on_config_changed, |
|
|
|
|
chand); |
|
|
|
|
grpc_closure_init(&chand->on_config_changed, cc_on_config_changed, chand); |
|
|
|
|
|
|
|
|
|
grpc_connectivity_state_init(&chand->state_tracker, |
|
|
|
|
GRPC_CHANNEL_IDLE, "client_channel"); |
|
|
|
@ -722,7 +718,7 @@ void grpc_client_channel_set_resolver(grpc_channel_stack *channel_stack, |
|
|
|
|
GPR_ASSERT(!chand->resolver); |
|
|
|
|
chand->resolver = resolver; |
|
|
|
|
GRPC_RESOLVER_REF(resolver, "channel"); |
|
|
|
|
if (!grpc_iomgr_call_list_empty(chand->waiting_for_config_closures) || |
|
|
|
|
if (!grpc_call_list_empty(chand->waiting_for_config_closures) || |
|
|
|
|
chand->exit_idle_when_lb_policy_arrives) { |
|
|
|
|
chand->started_resolving = 1; |
|
|
|
|
GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver"); |
|
|
|
@ -733,8 +729,7 @@ void grpc_client_channel_set_resolver(grpc_channel_stack *channel_stack, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_connectivity_state grpc_client_channel_check_connectivity_state( |
|
|
|
|
grpc_channel_element *elem, int try_to_connect, |
|
|
|
|
grpc_iomgr_call_list *call_list) { |
|
|
|
|
grpc_channel_element *elem, int try_to_connect, grpc_call_list *call_list) { |
|
|
|
|
channel_data *chand = elem->channel_data; |
|
|
|
|
grpc_connectivity_state out; |
|
|
|
|
gpr_mu_lock(&chand->mu_config); |
|
|
|
@ -758,7 +753,7 @@ grpc_connectivity_state grpc_client_channel_check_connectivity_state( |
|
|
|
|
|
|
|
|
|
void grpc_client_channel_watch_connectivity_state( |
|
|
|
|
grpc_channel_element *elem, grpc_connectivity_state *state, |
|
|
|
|
grpc_iomgr_closure *on_complete, grpc_iomgr_call_list *call_list) { |
|
|
|
|
grpc_closure *on_complete, grpc_call_list *call_list) { |
|
|
|
|
channel_data *chand = elem->channel_data; |
|
|
|
|
gpr_mu_lock(&chand->mu_config); |
|
|
|
|
grpc_connectivity_state_notify_on_state_change(&chand->state_tracker, state, |
|
|
|
|