|
|
|
@ -138,6 +138,8 @@ struct round_robin_lb_policy { |
|
|
|
|
size_t num_ready; |
|
|
|
|
/** how many subchannels are in state TRANSIENT_FAILURE */ |
|
|
|
|
size_t num_transient_failures; |
|
|
|
|
/** how many subchannels are in state SHUTDOWN */ |
|
|
|
|
size_t num_shutdown; |
|
|
|
|
/** how many subchannels are in state IDLE */ |
|
|
|
|
size_t num_idle; |
|
|
|
|
|
|
|
|
@ -381,6 +383,8 @@ static void update_state_counters_locked(subchannel_data *sd) { |
|
|
|
|
++p->num_ready; |
|
|
|
|
} else if (sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { |
|
|
|
|
++p->num_transient_failures; |
|
|
|
|
} else if (sd->curr_connectivity_state == GRPC_CHANNEL_SHUTDOWN) { |
|
|
|
|
++p->num_shutdown; |
|
|
|
|
} else if (sd->curr_connectivity_state == GRPC_CHANNEL_IDLE) { |
|
|
|
|
++p->num_idle; |
|
|
|
|
} |
|
|
|
@ -401,7 +405,7 @@ static grpc_connectivity_state update_lb_connectivity_status_locked( |
|
|
|
|
* CHECK: sd->curr_connectivity_state == CONNECTING. |
|
|
|
|
* |
|
|
|
|
* 3) RULE: ALL subchannels are SHUTDOWN => policy is SHUTDOWN. |
|
|
|
|
* CHECK: p->num_subchannels = 0. |
|
|
|
|
* CHECK: p->num_shutdown == p->num_subchannels. |
|
|
|
|
* |
|
|
|
|
* 4) RULE: ALL subchannels are TRANSIENT_FAILURE => policy is |
|
|
|
|
* TRANSIENT_FAILURE. |
|
|
|
@ -411,34 +415,35 @@ static grpc_connectivity_state update_lb_connectivity_status_locked( |
|
|
|
|
* CHECK: p->num_idle == p->num_subchannels. |
|
|
|
|
*/ |
|
|
|
|
round_robin_lb_policy *p = sd->policy; |
|
|
|
|
grpc_connectivity_state new_state = sd->curr_connectivity_state; |
|
|
|
|
if (p->num_ready > 0) { /* 1) READY */ |
|
|
|
|
grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_READY, |
|
|
|
|
GRPC_ERROR_NONE, "rr_ready"); |
|
|
|
|
return GRPC_CHANNEL_READY; |
|
|
|
|
new_state = GRPC_CHANNEL_READY; |
|
|
|
|
} else if (sd->curr_connectivity_state == |
|
|
|
|
GRPC_CHANNEL_CONNECTING) { /* 2) CONNECTING */ |
|
|
|
|
grpc_connectivity_state_set(exec_ctx, &p->state_tracker, |
|
|
|
|
GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, |
|
|
|
|
"rr_connecting"); |
|
|
|
|
return GRPC_CHANNEL_CONNECTING; |
|
|
|
|
} else if (p->num_subchannels == 0) { /* 3) SHUTDOWN */ |
|
|
|
|
new_state = GRPC_CHANNEL_CONNECTING; |
|
|
|
|
} else if (p->num_shutdown == p->num_subchannels) { /* 3) SHUTDOWN */ |
|
|
|
|
grpc_connectivity_state_set(exec_ctx, &p->state_tracker, |
|
|
|
|
GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), |
|
|
|
|
"rr_shutdown"); |
|
|
|
|
return GRPC_CHANNEL_SHUTDOWN; |
|
|
|
|
new_state = GRPC_CHANNEL_SHUTDOWN; |
|
|
|
|
} else if (p->num_transient_failures == |
|
|
|
|
p->num_subchannels) { /* 4) TRANSIENT_FAILURE */ |
|
|
|
|
grpc_connectivity_state_set(exec_ctx, &p->state_tracker, |
|
|
|
|
GRPC_CHANNEL_TRANSIENT_FAILURE, |
|
|
|
|
GRPC_ERROR_REF(error), "rr_transient_failure"); |
|
|
|
|
return GRPC_CHANNEL_TRANSIENT_FAILURE; |
|
|
|
|
new_state = GRPC_CHANNEL_TRANSIENT_FAILURE; |
|
|
|
|
} else if (p->num_idle == p->num_subchannels) { /* 5) IDLE */ |
|
|
|
|
grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_IDLE, |
|
|
|
|
GRPC_ERROR_NONE, "rr_idle"); |
|
|
|
|
return GRPC_CHANNEL_IDLE; |
|
|
|
|
new_state = GRPC_CHANNEL_IDLE; |
|
|
|
|
} |
|
|
|
|
/* no change */ |
|
|
|
|
return sd->curr_connectivity_state; |
|
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
|
return new_state; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
|