Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * 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 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * 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. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Yash Tibrewal | 37fdb73 | 2017-09-25 16:45:02 -0700 | [diff] [blame] | 19 | #include <grpc/support/port_platform.h> |
| 20 | |
Craig Tiller | 9eb0fde | 2017-03-31 16:59:30 -0700 | [diff] [blame] | 21 | #include "src/core/ext/filters/client_channel/client_channel.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 22 | |
Yash Tibrewal | fcd26bc | 2017-09-25 15:08:28 -0700 | [diff] [blame] | 23 | #include <inttypes.h> |
Mark D. Roth | 4c0fe49 | 2016-08-31 13:51:55 -0700 | [diff] [blame] | 24 | #include <stdbool.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 25 | #include <stdio.h> |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 26 | #include <string.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 27 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 28 | #include <grpc/support/alloc.h> |
| 29 | #include <grpc/support/log.h> |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 30 | #include <grpc/support/string_util.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 31 | #include <grpc/support/sync.h> |
| 32 | #include <grpc/support/useful.h> |
| 33 | |
Craig Tiller | 9eb0fde | 2017-03-31 16:59:30 -0700 | [diff] [blame] | 34 | #include "src/core/ext/filters/client_channel/http_connect_handshaker.h" |
| 35 | #include "src/core/ext/filters/client_channel/lb_policy_registry.h" |
| 36 | #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h" |
| 37 | #include "src/core/ext/filters/client_channel/resolver_registry.h" |
| 38 | #include "src/core/ext/filters/client_channel/retry_throttle.h" |
| 39 | #include "src/core/ext/filters/client_channel/subchannel.h" |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 40 | #include "src/core/ext/filters/deadline/deadline_filter.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 41 | #include "src/core/lib/channel/channel_args.h" |
| 42 | #include "src/core/lib/channel/connected_channel.h" |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 43 | #include "src/core/lib/iomgr/combiner.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 44 | #include "src/core/lib/iomgr/iomgr.h" |
Mark D. Roth | 4c0fe49 | 2016-08-31 13:51:55 -0700 | [diff] [blame] | 45 | #include "src/core/lib/iomgr/polling_entity.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 46 | #include "src/core/lib/profiling/timers.h" |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 47 | #include "src/core/lib/slice/slice_internal.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 48 | #include "src/core/lib/support/string.h" |
| 49 | #include "src/core/lib/surface/channel.h" |
| 50 | #include "src/core/lib/transport/connectivity_state.h" |
Mark D. Roth | 9fe284e | 2016-09-12 11:22:27 -0700 | [diff] [blame] | 51 | #include "src/core/lib/transport/metadata.h" |
| 52 | #include "src/core/lib/transport/metadata_batch.h" |
Mark D. Roth | ea846a0 | 2016-11-03 11:32:54 -0700 | [diff] [blame] | 53 | #include "src/core/lib/transport/service_config.h" |
Mark D. Roth | 9fe284e | 2016-09-12 11:22:27 -0700 | [diff] [blame] | 54 | #include "src/core/lib/transport/static_metadata.h" |
Craig Tiller | 8910ac6 | 2015-10-08 16:49:15 -0700 | [diff] [blame] | 55 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 56 | /* Client channel implementation */ |
| 57 | |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 58 | grpc_core::Tracer grpc_client_channel_trace |
| 59 | (false, "client_channel"); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 60 | |
Mark D. Roth | 26b7be4 | 2016-10-24 10:08:07 -0700 | [diff] [blame] | 61 | /************************************************************************* |
| 62 | * METHOD-CONFIG TABLE |
| 63 | */ |
| 64 | |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 65 | typedef enum { |
Craig Tiller | 7acc37e | 2017-02-28 10:01:37 -0800 | [diff] [blame] | 66 | /* zero so it can be default initialized */ |
| 67 | WAIT_FOR_READY_UNSET = 0, |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 68 | WAIT_FOR_READY_FALSE, |
| 69 | WAIT_FOR_READY_TRUE |
| 70 | } wait_for_ready_value; |
| 71 | |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 72 | typedef struct { |
| 73 | gpr_refcount refs; |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 74 | grpc_millis timeout; |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 75 | wait_for_ready_value wait_for_ready; |
| 76 | } method_parameters; |
| 77 | |
Mark D. Roth | 722de8d | 2017-02-27 10:50:44 -0800 | [diff] [blame] | 78 | static method_parameters *method_parameters_ref( |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 79 | method_parameters *method_params) { |
| 80 | gpr_ref(&method_params->refs); |
| 81 | return method_params; |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 84 | static void method_parameters_unref(method_parameters *method_params) { |
| 85 | if (gpr_unref(&method_params->refs)) { |
| 86 | gpr_free(method_params); |
| 87 | } |
| 88 | } |
| 89 | |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 90 | static void method_parameters_free(grpc_exec_ctx *exec_ctx, void *value) { |
Yash Tibrewal | bc130da | 2017-09-12 22:44:08 -0700 | [diff] [blame] | 91 | method_parameters_unref((method_parameters *)value); |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 94 | static bool parse_wait_for_ready(grpc_json *field, |
| 95 | wait_for_ready_value *wait_for_ready) { |
| 96 | if (field->type != GRPC_JSON_TRUE && field->type != GRPC_JSON_FALSE) { |
| 97 | return false; |
| 98 | } |
| 99 | *wait_for_ready = field->type == GRPC_JSON_TRUE ? WAIT_FOR_READY_TRUE |
| 100 | : WAIT_FOR_READY_FALSE; |
| 101 | return true; |
| 102 | } |
| 103 | |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 104 | static bool parse_timeout(grpc_json *field, grpc_millis *timeout) { |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 105 | if (field->type != GRPC_JSON_STRING) return false; |
| 106 | size_t len = strlen(field->value); |
| 107 | if (field->value[len - 1] != 's') return false; |
| 108 | char *buf = gpr_strdup(field->value); |
| 109 | buf[len - 1] = '\0'; // Remove trailing 's'. |
| 110 | char *decimal_point = strchr(buf, '.'); |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 111 | int nanos = 0; |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 112 | if (decimal_point != NULL) { |
| 113 | *decimal_point = '\0'; |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 114 | nanos = gpr_parse_nonnegative_int(decimal_point + 1); |
| 115 | if (nanos == -1) { |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 116 | gpr_free(buf); |
| 117 | return false; |
| 118 | } |
| 119 | // There should always be exactly 3, 6, or 9 fractional digits. |
| 120 | int multiplier = 1; |
| 121 | switch (strlen(decimal_point + 1)) { |
| 122 | case 9: |
| 123 | break; |
| 124 | case 6: |
| 125 | multiplier *= 1000; |
| 126 | break; |
| 127 | case 3: |
| 128 | multiplier *= 1000000; |
| 129 | break; |
| 130 | default: // Unsupported number of digits. |
| 131 | gpr_free(buf); |
| 132 | return false; |
| 133 | } |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 134 | nanos *= multiplier; |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 135 | } |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 136 | int seconds = gpr_parse_nonnegative_int(buf); |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 137 | gpr_free(buf); |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 138 | if (seconds == -1) return false; |
| 139 | *timeout = seconds * GPR_MS_PER_SEC + nanos / GPR_NS_PER_MS; |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 140 | return true; |
| 141 | } |
| 142 | |
Mark D. Roth | e30baeb | 2016-11-03 08:16:19 -0700 | [diff] [blame] | 143 | static void *method_parameters_create_from_json(const grpc_json *json) { |
Mark D. Roth | c968e60 | 2016-11-02 14:07:36 -0700 | [diff] [blame] | 144 | wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET; |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 145 | grpc_millis timeout = 0; |
Mark D. Roth | 47f1084 | 2016-11-03 08:45:27 -0700 | [diff] [blame] | 146 | for (grpc_json *field = json->child; field != NULL; field = field->next) { |
Mark D. Roth | c968e60 | 2016-11-02 14:07:36 -0700 | [diff] [blame] | 147 | if (field->key == NULL) continue; |
Mark D. Roth | 84c8a02 | 2016-11-10 09:39:34 -0800 | [diff] [blame] | 148 | if (strcmp(field->key, "waitForReady") == 0) { |
Mark D. Roth | c968e60 | 2016-11-02 14:07:36 -0700 | [diff] [blame] | 149 | if (wait_for_ready != WAIT_FOR_READY_UNSET) return NULL; // Duplicate. |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 150 | if (!parse_wait_for_ready(field, &wait_for_ready)) return NULL; |
Mark D. Roth | c968e60 | 2016-11-02 14:07:36 -0700 | [diff] [blame] | 151 | } else if (strcmp(field->key, "timeout") == 0) { |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 152 | if (timeout > 0) return NULL; // Duplicate. |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 153 | if (!parse_timeout(field, &timeout)) return NULL; |
Mark D. Roth | c968e60 | 2016-11-02 14:07:36 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 156 | method_parameters *value = |
| 157 | (method_parameters *)gpr_malloc(sizeof(method_parameters)); |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 158 | gpr_ref_init(&value->refs, 1); |
Mark D. Roth | c968e60 | 2016-11-02 14:07:36 -0700 | [diff] [blame] | 159 | value->timeout = timeout; |
| 160 | value->wait_for_ready = wait_for_ready; |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 161 | return value; |
| 162 | } |
| 163 | |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 164 | struct external_connectivity_watcher; |
| 165 | |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 166 | /************************************************************************* |
| 167 | * CHANNEL-WIDE FUNCTIONS |
| 168 | */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 169 | |
Craig Tiller | 800dacb | 2015-10-06 09:10:26 -0700 | [diff] [blame] | 170 | typedef struct client_channel_channel_data { |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 171 | /** resolver for this channel */ |
| 172 | grpc_resolver *resolver; |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 173 | /** have we started resolving this channel */ |
Mark D. Roth | 4c0fe49 | 2016-08-31 13:51:55 -0700 | [diff] [blame] | 174 | bool started_resolving; |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 175 | /** is deadline checking enabled? */ |
| 176 | bool deadline_checking_enabled; |
Mark D. Roth | 0e48a9a | 2016-09-08 14:14:39 -0700 | [diff] [blame] | 177 | /** client channel factory */ |
| 178 | grpc_client_channel_factory *client_channel_factory; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 179 | |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 180 | /** combiner protecting all variables below in this data structure */ |
| 181 | grpc_combiner *combiner; |
Mark D. Roth | 046cf76 | 2016-09-26 11:13:51 -0700 | [diff] [blame] | 182 | /** currently active load balancer */ |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 183 | grpc_lb_policy *lb_policy; |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 184 | /** retry throttle data */ |
| 185 | grpc_server_retry_throttle_data *retry_throttle_data; |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 186 | /** maps method names to method_parameters structs */ |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 187 | grpc_slice_hash_table *method_params_table; |
Mark D. Roth | 046cf76 | 2016-09-26 11:13:51 -0700 | [diff] [blame] | 188 | /** incoming resolver result - set by resolver.next() */ |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 189 | grpc_channel_args *resolver_result; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 190 | /** a list of closures that are all waiting for resolver result to come in */ |
| 191 | grpc_closure_list waiting_for_resolver_result_closures; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 192 | /** resolver callback */ |
Mark D. Roth | ff4df06 | 2016-08-22 15:02:49 -0700 | [diff] [blame] | 193 | grpc_closure on_resolver_result_changed; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 194 | /** connectivity state being tracked */ |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 195 | grpc_connectivity_state_tracker state_tracker; |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 196 | /** when an lb_policy arrives, should we try to exit idle */ |
Mark D. Roth | 4c0fe49 | 2016-08-31 13:51:55 -0700 | [diff] [blame] | 197 | bool exit_idle_when_lb_policy_arrives; |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 198 | /** owning stack */ |
| 199 | grpc_channel_stack *owning_stack; |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 200 | /** interested parties (owned) */ |
| 201 | grpc_pollset_set *interested_parties; |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 202 | |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 203 | /* external_connectivity_watcher_list head is guarded by its own mutex, since |
| 204 | * counts need to be grabbed immediately without polling on a cq */ |
| 205 | gpr_mu external_connectivity_watcher_list_mu; |
| 206 | struct external_connectivity_watcher *external_connectivity_watcher_list_head; |
| 207 | |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 208 | /* the following properties are guarded by a mutex since API's require them |
Craig Tiller | 46dd790 | 2017-02-23 09:42:16 -0800 | [diff] [blame] | 209 | to be instantaneously available */ |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 210 | gpr_mu info_mu; |
| 211 | char *info_lb_policy_name; |
| 212 | /** service config in JSON form */ |
| 213 | char *info_service_config_json; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 214 | } channel_data; |
| 215 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 216 | /** We create one watcher for each new lb_policy that is returned from a |
Mark D. Roth | 4c0fe49 | 2016-08-31 13:51:55 -0700 | [diff] [blame] | 217 | resolver, to watch for state changes from the lb_policy. When a state |
| 218 | change is seen, we update the channel, and create a new watcher. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 219 | typedef struct { |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 220 | channel_data *chand; |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 221 | grpc_closure on_changed; |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 222 | grpc_connectivity_state state; |
| 223 | grpc_lb_policy *lb_policy; |
| 224 | } lb_policy_connectivity_watcher; |
| 225 | |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 226 | static void watch_lb_policy_locked(grpc_exec_ctx *exec_ctx, channel_data *chand, |
| 227 | grpc_lb_policy *lb_policy, |
| 228 | grpc_connectivity_state current_state); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 229 | |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 230 | static void set_channel_connectivity_state_locked(grpc_exec_ctx *exec_ctx, |
| 231 | channel_data *chand, |
| 232 | grpc_connectivity_state state, |
Craig Tiller | 804ff71 | 2016-05-05 16:25:40 -0700 | [diff] [blame] | 233 | grpc_error *error, |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 234 | const char *reason) { |
David Garcia Quintas | 3725128 | 2017-04-14 13:46:03 -0700 | [diff] [blame] | 235 | /* TODO: Improve failure handling: |
| 236 | * - Make it possible for policies to return GRPC_CHANNEL_TRANSIENT_FAILURE. |
| 237 | * - Hand over pending picks from old policies during the switch that happens |
| 238 | * when resolver provides an update. */ |
David Garcia Quintas | 956f700 | 2017-04-13 15:40:06 -0700 | [diff] [blame] | 239 | if (chand->lb_policy != NULL) { |
| 240 | if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { |
| 241 | /* cancel picks with wait_for_ready=false */ |
| 242 | grpc_lb_policy_cancel_picks_locked( |
| 243 | exec_ctx, chand->lb_policy, |
| 244 | /* mask= */ GRPC_INITIAL_METADATA_WAIT_FOR_READY, |
| 245 | /* check= */ 0, GRPC_ERROR_REF(error)); |
| 246 | } else if (state == GRPC_CHANNEL_SHUTDOWN) { |
| 247 | /* cancel all picks */ |
| 248 | grpc_lb_policy_cancel_picks_locked(exec_ctx, chand->lb_policy, |
| 249 | /* mask= */ 0, /* check= */ 0, |
| 250 | GRPC_ERROR_REF(error)); |
| 251 | } |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 252 | } |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 253 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 254 | gpr_log(GPR_DEBUG, "chand=%p: setting connectivity state to %s", chand, |
| 255 | grpc_connectivity_state_name(state)); |
| 256 | } |
Craig Tiller | 9ccf5f1 | 2016-05-07 21:41:01 -0700 | [diff] [blame] | 257 | grpc_connectivity_state_set(exec_ctx, &chand->state_tracker, state, error, |
| 258 | reason); |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Craig Tiller | 804ff71 | 2016-05-05 16:25:40 -0700 | [diff] [blame] | 261 | static void on_lb_policy_state_changed_locked(grpc_exec_ctx *exec_ctx, |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 262 | void *arg, grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 263 | lb_policy_connectivity_watcher *w = (lb_policy_connectivity_watcher *)arg; |
Craig Tiller | cb2609f | 2015-11-24 17:19:19 -0800 | [diff] [blame] | 264 | grpc_connectivity_state publish_state = w->state; |
Craig Tiller | c5de835 | 2017-02-09 14:08:05 -0800 | [diff] [blame] | 265 | /* check if the notification is for the latest policy */ |
| 266 | if (w->lb_policy == w->chand->lb_policy) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 267 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 268 | gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, |
| 269 | w->lb_policy, grpc_connectivity_state_name(w->state)); |
| 270 | } |
Craig Tiller | c5de835 | 2017-02-09 14:08:05 -0800 | [diff] [blame] | 271 | if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != NULL) { |
| 272 | publish_state = GRPC_CHANNEL_TRANSIENT_FAILURE; |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 273 | grpc_resolver_channel_saw_error_locked(exec_ctx, w->chand->resolver); |
Craig Tiller | c5de835 | 2017-02-09 14:08:05 -0800 | [diff] [blame] | 274 | GRPC_LB_POLICY_UNREF(exec_ctx, w->chand->lb_policy, "channel"); |
| 275 | w->chand->lb_policy = NULL; |
| 276 | } |
| 277 | set_channel_connectivity_state_locked(exec_ctx, w->chand, publish_state, |
| 278 | GRPC_ERROR_REF(error), "lb_changed"); |
| 279 | if (w->state != GRPC_CHANNEL_SHUTDOWN) { |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 280 | watch_lb_policy_locked(exec_ctx, w->chand, w->lb_policy, w->state); |
Craig Tiller | c5de835 | 2017-02-09 14:08:05 -0800 | [diff] [blame] | 281 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 282 | } |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 283 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "watch_lb_policy"); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 284 | gpr_free(w); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 287 | static void watch_lb_policy_locked(grpc_exec_ctx *exec_ctx, channel_data *chand, |
| 288 | grpc_lb_policy *lb_policy, |
| 289 | grpc_connectivity_state current_state) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 290 | lb_policy_connectivity_watcher *w = |
| 291 | (lb_policy_connectivity_watcher *)gpr_malloc(sizeof(*w)); |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 292 | GRPC_CHANNEL_STACK_REF(chand->owning_stack, "watch_lb_policy"); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 293 | w->chand = chand; |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 294 | GRPC_CLOSURE_INIT(&w->on_changed, on_lb_policy_state_changed_locked, w, |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 295 | grpc_combiner_scheduler(chand->combiner)); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 296 | w->state = current_state; |
| 297 | w->lb_policy = lb_policy; |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 298 | grpc_lb_policy_notify_on_state_change_locked(exec_ctx, lb_policy, &w->state, |
| 299 | &w->on_changed); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 302 | static void start_resolving_locked(grpc_exec_ctx *exec_ctx, |
| 303 | channel_data *chand) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 304 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 305 | gpr_log(GPR_DEBUG, "chand=%p: starting name resolution", chand); |
| 306 | } |
| 307 | GPR_ASSERT(!chand->started_resolving); |
| 308 | chand->started_resolving = true; |
| 309 | GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); |
| 310 | grpc_resolver_next_locked(exec_ctx, chand->resolver, &chand->resolver_result, |
| 311 | &chand->on_resolver_result_changed); |
| 312 | } |
| 313 | |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 314 | typedef struct { |
| 315 | char *server_name; |
| 316 | grpc_server_retry_throttle_data *retry_throttle_data; |
| 317 | } service_config_parsing_state; |
| 318 | |
| 319 | static void parse_retry_throttle_params(const grpc_json *field, void *arg) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 320 | service_config_parsing_state *parsing_state = |
| 321 | (service_config_parsing_state *)arg; |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 322 | if (strcmp(field->key, "retryThrottling") == 0) { |
| 323 | if (parsing_state->retry_throttle_data != NULL) return; // Duplicate. |
| 324 | if (field->type != GRPC_JSON_OBJECT) return; |
| 325 | int max_milli_tokens = 0; |
| 326 | int milli_token_ratio = 0; |
| 327 | for (grpc_json *sub_field = field->child; sub_field != NULL; |
| 328 | sub_field = sub_field->next) { |
Mark D. Roth | b332256 | 2017-02-23 14:38:02 -0800 | [diff] [blame] | 329 | if (sub_field->key == NULL) return; |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 330 | if (strcmp(sub_field->key, "maxTokens") == 0) { |
| 331 | if (max_milli_tokens != 0) return; // Duplicate. |
| 332 | if (sub_field->type != GRPC_JSON_NUMBER) return; |
| 333 | max_milli_tokens = gpr_parse_nonnegative_int(sub_field->value); |
| 334 | if (max_milli_tokens == -1) return; |
| 335 | max_milli_tokens *= 1000; |
| 336 | } else if (strcmp(sub_field->key, "tokenRatio") == 0) { |
| 337 | if (milli_token_ratio != 0) return; // Duplicate. |
| 338 | if (sub_field->type != GRPC_JSON_NUMBER) return; |
| 339 | // We support up to 3 decimal digits. |
| 340 | size_t whole_len = strlen(sub_field->value); |
| 341 | uint32_t multiplier = 1; |
| 342 | uint32_t decimal_value = 0; |
| 343 | const char *decimal_point = strchr(sub_field->value, '.'); |
| 344 | if (decimal_point != NULL) { |
| 345 | whole_len = (size_t)(decimal_point - sub_field->value); |
| 346 | multiplier = 1000; |
| 347 | size_t decimal_len = strlen(decimal_point + 1); |
| 348 | if (decimal_len > 3) decimal_len = 3; |
| 349 | if (!gpr_parse_bytes_to_uint32(decimal_point + 1, decimal_len, |
| 350 | &decimal_value)) { |
| 351 | return; |
| 352 | } |
| 353 | uint32_t decimal_multiplier = 1; |
| 354 | for (size_t i = 0; i < (3 - decimal_len); ++i) { |
| 355 | decimal_multiplier *= 10; |
| 356 | } |
| 357 | decimal_value *= decimal_multiplier; |
| 358 | } |
| 359 | uint32_t whole_value; |
| 360 | if (!gpr_parse_bytes_to_uint32(sub_field->value, whole_len, |
| 361 | &whole_value)) { |
| 362 | return; |
| 363 | } |
| 364 | milli_token_ratio = (int)((whole_value * multiplier) + decimal_value); |
Mark D. Roth | b332256 | 2017-02-23 14:38:02 -0800 | [diff] [blame] | 365 | if (milli_token_ratio <= 0) return; |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | parsing_state->retry_throttle_data = |
| 369 | grpc_retry_throttle_map_get_data_for_server( |
| 370 | parsing_state->server_name, max_milli_tokens, milli_token_ratio); |
| 371 | } |
| 372 | } |
| 373 | |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 374 | static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, |
| 375 | void *arg, grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 376 | channel_data *chand = (channel_data *)arg; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 377 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 378 | gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand, |
| 379 | grpc_error_string(error)); |
| 380 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 381 | // Extract the following fields from the resolver result, if non-NULL. |
Mark D. Roth | 15494b5 | 2017-07-12 15:26:55 -0700 | [diff] [blame] | 382 | bool lb_policy_updated = false; |
Yash Tibrewal | 9eb8672 | 2017-09-17 23:43:30 -0700 | [diff] [blame] | 383 | char *lb_policy_name_dup = NULL; |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 384 | bool lb_policy_name_changed = false; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 385 | grpc_lb_policy *new_lb_policy = NULL; |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 386 | char *service_config_json = NULL; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 387 | grpc_server_retry_throttle_data *retry_throttle_data = NULL; |
| 388 | grpc_slice_hash_table *method_params_table = NULL; |
Mark D. Roth | 046cf76 | 2016-09-26 11:13:51 -0700 | [diff] [blame] | 389 | if (chand->resolver_result != NULL) { |
Mark D. Roth | 5bd7be0 | 2016-10-21 14:19:50 -0700 | [diff] [blame] | 390 | // Find LB policy name. |
Yash Tibrewal | 9eb8672 | 2017-09-17 23:43:30 -0700 | [diff] [blame] | 391 | const char *lb_policy_name = NULL; |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 392 | const grpc_arg *channel_arg = |
Mark D. Roth | 4112499 | 2016-11-03 11:22:20 -0700 | [diff] [blame] | 393 | grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_POLICY_NAME); |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 394 | if (channel_arg != NULL) { |
| 395 | GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); |
| 396 | lb_policy_name = channel_arg->value.string; |
Mark D. Roth | 5bd7be0 | 2016-10-21 14:19:50 -0700 | [diff] [blame] | 397 | } |
Mark D. Roth | 1eb96dc | 2017-03-22 12:19:03 -0700 | [diff] [blame] | 398 | // Special case: If at least one balancer address is present, we use |
| 399 | // the grpclb policy, regardless of what the resolver actually specified. |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 400 | channel_arg = |
Mark D. Roth | 4112499 | 2016-11-03 11:22:20 -0700 | [diff] [blame] | 401 | grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); |
David Garcia Quintas | 143cb77 | 2017-03-31 13:39:27 -0700 | [diff] [blame] | 402 | if (channel_arg != NULL && channel_arg->type == GRPC_ARG_POINTER) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 403 | grpc_lb_addresses *addresses = |
| 404 | (grpc_lb_addresses *)channel_arg->value.pointer.p; |
Mark D. Roth | 1eb96dc | 2017-03-22 12:19:03 -0700 | [diff] [blame] | 405 | bool found_balancer_address = false; |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 406 | for (size_t i = 0; i < addresses->num_addresses; ++i) { |
Mark D. Roth | 1eb96dc | 2017-03-22 12:19:03 -0700 | [diff] [blame] | 407 | if (addresses->addresses[i].is_balancer) { |
| 408 | found_balancer_address = true; |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 409 | break; |
| 410 | } |
Mark D. Roth | 88405f7 | 2016-10-03 08:24:52 -0700 | [diff] [blame] | 411 | } |
Mark D. Roth | 1eb96dc | 2017-03-22 12:19:03 -0700 | [diff] [blame] | 412 | if (found_balancer_address) { |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 413 | if (lb_policy_name != NULL && strcmp(lb_policy_name, "grpclb") != 0) { |
| 414 | gpr_log(GPR_INFO, |
Mark D. Roth | 1eb96dc | 2017-03-22 12:19:03 -0700 | [diff] [blame] | 415 | "resolver requested LB policy %s but provided at least one " |
| 416 | "balancer address -- forcing use of grpclb LB policy", |
Mark D. Roth | 5f40e5d | 2016-10-24 13:09:05 -0700 | [diff] [blame] | 417 | lb_policy_name); |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 418 | } |
| 419 | lb_policy_name = "grpclb"; |
Mark D. Roth | 88405f7 | 2016-10-03 08:24:52 -0700 | [diff] [blame] | 420 | } |
Mark D. Roth | 88405f7 | 2016-10-03 08:24:52 -0700 | [diff] [blame] | 421 | } |
| 422 | // Use pick_first if nothing was specified and we didn't select grpclb |
| 423 | // above. |
| 424 | if (lb_policy_name == NULL) lb_policy_name = "pick_first"; |
Mark D. Roth | 4112499 | 2016-11-03 11:22:20 -0700 | [diff] [blame] | 425 | grpc_lb_policy_args lb_policy_args; |
| 426 | lb_policy_args.args = chand->resolver_result; |
| 427 | lb_policy_args.client_channel_factory = chand->client_channel_factory; |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 428 | lb_policy_args.combiner = chand->combiner; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 429 | // Check to see if we're already using the right LB policy. |
| 430 | // Note: It's safe to use chand->info_lb_policy_name here without |
| 431 | // taking a lock on chand->info_mu, because this function is the |
| 432 | // only thing that modifies its value, and it can only be invoked |
| 433 | // once at any given time. |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 434 | lb_policy_name_changed = |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 435 | chand->info_lb_policy_name == NULL || |
| 436 | strcmp(chand->info_lb_policy_name, lb_policy_name) != 0; |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 437 | if (chand->lb_policy != NULL && !lb_policy_name_changed) { |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 438 | // Continue using the same LB policy. Update with new addresses. |
Mark D. Roth | 15494b5 | 2017-07-12 15:26:55 -0700 | [diff] [blame] | 439 | lb_policy_updated = true; |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 440 | grpc_lb_policy_update_locked(exec_ctx, chand->lb_policy, &lb_policy_args); |
| 441 | } else { |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 442 | // Instantiate new LB policy. |
| 443 | new_lb_policy = |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 444 | grpc_lb_policy_create(exec_ctx, lb_policy_name, &lb_policy_args); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 445 | if (new_lb_policy == NULL) { |
| 446 | gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", lb_policy_name); |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 447 | } |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 448 | } |
Mark D. Roth | 4112499 | 2016-11-03 11:22:20 -0700 | [diff] [blame] | 449 | // Find service config. |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 450 | channel_arg = |
Mark D. Roth | 4112499 | 2016-11-03 11:22:20 -0700 | [diff] [blame] | 451 | grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVICE_CONFIG); |
Mark D. Roth | 046cf76 | 2016-09-26 11:13:51 -0700 | [diff] [blame] | 452 | if (channel_arg != NULL) { |
Mark D. Roth | 9ec28af | 2016-11-03 12:32:39 -0700 | [diff] [blame] | 453 | GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 454 | service_config_json = gpr_strdup(channel_arg->value.string); |
Mark D. Roth | 70a1abd | 2016-11-04 09:26:37 -0700 | [diff] [blame] | 455 | grpc_service_config *service_config = |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 456 | grpc_service_config_create(service_config_json); |
Mark D. Roth | bdc58b2 | 2016-11-04 09:25:57 -0700 | [diff] [blame] | 457 | if (service_config != NULL) { |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 458 | channel_arg = |
| 459 | grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVER_URI); |
| 460 | GPR_ASSERT(channel_arg != NULL); |
| 461 | GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); |
Mark D. Roth | 9ccbc4d | 2017-03-15 08:30:04 -0700 | [diff] [blame] | 462 | grpc_uri *uri = |
| 463 | grpc_uri_parse(exec_ctx, channel_arg->value.string, true); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 464 | GPR_ASSERT(uri->path[0] != '\0'); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 465 | service_config_parsing_state parsing_state; |
| 466 | memset(&parsing_state, 0, sizeof(parsing_state)); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 467 | parsing_state.server_name = |
| 468 | uri->path[0] == '/' ? uri->path + 1 : uri->path; |
| 469 | grpc_service_config_parse_global_params( |
| 470 | service_config, parse_retry_throttle_params, &parsing_state); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 471 | grpc_uri_destroy(uri); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 472 | retry_throttle_data = parsing_state.retry_throttle_data; |
Mark D. Roth | bdc58b2 | 2016-11-04 09:25:57 -0700 | [diff] [blame] | 473 | method_params_table = grpc_service_config_create_method_config_table( |
Craig Tiller | b28c7e8 | 2016-11-18 10:29:04 -0800 | [diff] [blame] | 474 | exec_ctx, service_config, method_parameters_create_from_json, |
Mark D. Roth | e300670 | 2017-04-19 07:43:56 -0700 | [diff] [blame] | 475 | method_parameters_free); |
Mark D. Roth | bdc58b2 | 2016-11-04 09:25:57 -0700 | [diff] [blame] | 476 | grpc_service_config_destroy(service_config); |
| 477 | } |
Mark D. Roth | 9fe284e | 2016-09-12 11:22:27 -0700 | [diff] [blame] | 478 | } |
Mark D. Roth | f79ce7d | 2016-11-04 08:43:36 -0700 | [diff] [blame] | 479 | // Before we clean up, save a copy of lb_policy_name, since it might |
| 480 | // be pointing to data inside chand->resolver_result. |
| 481 | // The copy will be saved in chand->lb_policy_name below. |
Yash Tibrewal | 9eb8672 | 2017-09-17 23:43:30 -0700 | [diff] [blame] | 482 | lb_policy_name_dup = gpr_strdup(lb_policy_name); |
Craig Tiller | 87a7e1f | 2016-11-09 09:42:19 -0800 | [diff] [blame] | 483 | grpc_channel_args_destroy(exec_ctx, chand->resolver_result); |
Mark D. Roth | 046cf76 | 2016-09-26 11:13:51 -0700 | [diff] [blame] | 484 | chand->resolver_result = NULL; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 485 | } |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 486 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 487 | gpr_log(GPR_DEBUG, |
| 488 | "chand=%p: resolver result: lb_policy_name=\"%s\"%s, " |
| 489 | "service_config=\"%s\"", |
Yash Tibrewal | 9eb8672 | 2017-09-17 23:43:30 -0700 | [diff] [blame] | 490 | chand, lb_policy_name_dup, |
| 491 | lb_policy_name_changed ? " (changed)" : "", service_config_json); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 492 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 493 | // Now swap out fields in chand. Note that the new values may still |
| 494 | // be NULL if (e.g.) the resolver failed to return results or the |
| 495 | // results did not contain the necessary data. |
| 496 | // |
| 497 | // First, swap out the data used by cc_get_channel_info(). |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 498 | gpr_mu_lock(&chand->info_mu); |
Yash Tibrewal | 9eb8672 | 2017-09-17 23:43:30 -0700 | [diff] [blame] | 499 | if (lb_policy_name_dup != NULL) { |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 500 | gpr_free(chand->info_lb_policy_name); |
Yash Tibrewal | 9eb8672 | 2017-09-17 23:43:30 -0700 | [diff] [blame] | 501 | chand->info_lb_policy_name = lb_policy_name_dup; |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 502 | } |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 503 | if (service_config_json != NULL) { |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 504 | gpr_free(chand->info_service_config_json); |
| 505 | chand->info_service_config_json = service_config_json; |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 506 | } |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 507 | gpr_mu_unlock(&chand->info_mu); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 508 | // Swap out the retry throttle data. |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 509 | if (chand->retry_throttle_data != NULL) { |
| 510 | grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); |
| 511 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 512 | chand->retry_throttle_data = retry_throttle_data; |
| 513 | // Swap out the method params table. |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 514 | if (chand->method_params_table != NULL) { |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 515 | grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); |
Mark D. Roth | 046cf76 | 2016-09-26 11:13:51 -0700 | [diff] [blame] | 516 | } |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 517 | chand->method_params_table = method_params_table; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 518 | // If we have a new LB policy or are shutting down (in which case |
| 519 | // new_lb_policy will be NULL), swap out the LB policy, unreffing the |
| 520 | // old one and removing its fds from chand->interested_parties. |
| 521 | // Note that we do NOT do this if either (a) we updated the existing |
| 522 | // LB policy above or (b) we failed to create the new LB policy (in |
| 523 | // which case we want to continue using the most recent one we had). |
| 524 | if (new_lb_policy != NULL || error != GRPC_ERROR_NONE || |
| 525 | chand->resolver == NULL) { |
| 526 | if (chand->lb_policy != NULL) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 527 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 528 | gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand, |
| 529 | chand->lb_policy); |
| 530 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 531 | grpc_pollset_set_del_pollset_set(exec_ctx, |
| 532 | chand->lb_policy->interested_parties, |
| 533 | chand->interested_parties); |
| 534 | GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 535 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 536 | chand->lb_policy = new_lb_policy; |
| 537 | } |
| 538 | // Now that we've swapped out the relevant fields of chand, check for |
| 539 | // error or shutdown. |
| 540 | if (error != GRPC_ERROR_NONE || chand->resolver == NULL) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 541 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 542 | gpr_log(GPR_DEBUG, "chand=%p: shutting down", chand); |
| 543 | } |
Craig Tiller | 76a5c0e | 2016-03-09 09:05:30 -0800 | [diff] [blame] | 544 | if (chand->resolver != NULL) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 545 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 546 | gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); |
| 547 | } |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 548 | grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); |
Craig Tiller | 76a5c0e | 2016-03-09 09:05:30 -0800 | [diff] [blame] | 549 | GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); |
| 550 | chand->resolver = NULL; |
| 551 | } |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 552 | set_channel_connectivity_state_locked( |
Craig Tiller | d925c93 | 2016-06-06 08:38:50 -0700 | [diff] [blame] | 553 | exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, |
ncteisen | 4b36a3d | 2017-03-13 19:08:06 -0700 | [diff] [blame] | 554 | GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 555 | "Got resolver result after disconnection", &error, 1), |
Craig Tiller | 804ff71 | 2016-05-05 16:25:40 -0700 | [diff] [blame] | 556 | "resolver_gone"); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 557 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "resolver"); |
| 558 | grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, |
| 559 | GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( |
| 560 | "Channel disconnected", &error, 1)); |
| 561 | GRPC_CLOSURE_LIST_SCHED(exec_ctx, |
| 562 | &chand->waiting_for_resolver_result_closures); |
| 563 | } else { // Not shutting down. |
| 564 | grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; |
| 565 | grpc_error *state_error = |
| 566 | GRPC_ERROR_CREATE_FROM_STATIC_STRING("No load balancing policy"); |
| 567 | if (new_lb_policy != NULL) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 568 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 569 | gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand); |
| 570 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 571 | GRPC_ERROR_UNREF(state_error); |
| 572 | state = grpc_lb_policy_check_connectivity_locked(exec_ctx, new_lb_policy, |
| 573 | &state_error); |
| 574 | grpc_pollset_set_add_pollset_set(exec_ctx, |
| 575 | new_lb_policy->interested_parties, |
| 576 | chand->interested_parties); |
| 577 | GRPC_CLOSURE_LIST_SCHED(exec_ctx, |
| 578 | &chand->waiting_for_resolver_result_closures); |
| 579 | if (chand->exit_idle_when_lb_policy_arrives) { |
| 580 | grpc_lb_policy_exit_idle_locked(exec_ctx, new_lb_policy); |
| 581 | chand->exit_idle_when_lb_policy_arrives = false; |
| 582 | } |
| 583 | watch_lb_policy_locked(exec_ctx, chand, new_lb_policy, state); |
| 584 | } |
Mark D. Roth | 15494b5 | 2017-07-12 15:26:55 -0700 | [diff] [blame] | 585 | if (!lb_policy_updated) { |
| 586 | set_channel_connectivity_state_locked(exec_ctx, chand, state, |
| 587 | GRPC_ERROR_REF(state_error), |
| 588 | "new_lb+resolver"); |
| 589 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 590 | grpc_resolver_next_locked(exec_ctx, chand->resolver, |
| 591 | &chand->resolver_result, |
| 592 | &chand->on_resolver_result_changed); |
| 593 | GRPC_ERROR_UNREF(state_error); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 594 | } |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Craig Tiller | a8610c0 | 2017-02-14 10:05:11 -0800 | [diff] [blame] | 597 | static void start_transport_op_locked(grpc_exec_ctx *exec_ctx, void *arg, |
| 598 | grpc_error *error_ignored) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 599 | grpc_transport_op *op = (grpc_transport_op *)arg; |
| 600 | grpc_channel_element *elem = |
| 601 | (grpc_channel_element *)op->handler_private.extra_arg; |
| 602 | channel_data *chand = (channel_data *)elem->channel_data; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame] | 603 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 604 | if (op->on_connectivity_state_change != NULL) { |
| 605 | grpc_connectivity_state_notify_on_state_change( |
| 606 | exec_ctx, &chand->state_tracker, op->connectivity_state, |
| 607 | op->on_connectivity_state_change); |
| 608 | op->on_connectivity_state_change = NULL; |
| 609 | op->connectivity_state = NULL; |
| 610 | } |
| 611 | |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 612 | if (op->send_ping != NULL) { |
Craig Tiller | 87b71e2 | 2015-12-07 15:14:14 -0800 | [diff] [blame] | 613 | if (chand->lb_policy == NULL) { |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 614 | GRPC_CLOSURE_SCHED( |
ncteisen | 4b36a3d | 2017-03-13 19:08:06 -0700 | [diff] [blame] | 615 | exec_ctx, op->send_ping, |
| 616 | GRPC_ERROR_CREATE_FROM_STATIC_STRING("Ping with no load balancing")); |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 617 | } else { |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 618 | grpc_lb_policy_ping_one_locked(exec_ctx, chand->lb_policy, op->send_ping); |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 619 | op->bind_pollset = NULL; |
| 620 | } |
| 621 | op->send_ping = NULL; |
| 622 | } |
| 623 | |
Craig Tiller | 1c51edc | 2016-05-07 16:18:43 -0700 | [diff] [blame] | 624 | if (op->disconnect_with_error != GRPC_ERROR_NONE) { |
| 625 | if (chand->resolver != NULL) { |
| 626 | set_channel_connectivity_state_locked( |
Craig Tiller | d925c93 | 2016-06-06 08:38:50 -0700 | [diff] [blame] | 627 | exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, |
Craig Tiller | 1c51edc | 2016-05-07 16:18:43 -0700 | [diff] [blame] | 628 | GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 629 | grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); |
Craig Tiller | 1c51edc | 2016-05-07 16:18:43 -0700 | [diff] [blame] | 630 | GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); |
| 631 | chand->resolver = NULL; |
| 632 | if (!chand->started_resolving) { |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 633 | grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, |
Craig Tiller | 1c51edc | 2016-05-07 16:18:43 -0700 | [diff] [blame] | 634 | GRPC_ERROR_REF(op->disconnect_with_error)); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 635 | GRPC_CLOSURE_LIST_SCHED(exec_ctx, |
| 636 | &chand->waiting_for_resolver_result_closures); |
Craig Tiller | 1c51edc | 2016-05-07 16:18:43 -0700 | [diff] [blame] | 637 | } |
| 638 | if (chand->lb_policy != NULL) { |
| 639 | grpc_pollset_set_del_pollset_set(exec_ctx, |
| 640 | chand->lb_policy->interested_parties, |
| 641 | chand->interested_parties); |
| 642 | GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); |
| 643 | chand->lb_policy = NULL; |
| 644 | } |
Craig Tiller | b12d22a | 2016-04-23 12:50:21 -0700 | [diff] [blame] | 645 | } |
Craig Tiller | 1c51edc | 2016-05-07 16:18:43 -0700 | [diff] [blame] | 646 | GRPC_ERROR_UNREF(op->disconnect_with_error); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 647 | } |
Craig Tiller | d2e5cfc | 2017-02-09 13:02:20 -0800 | [diff] [blame] | 648 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "start_transport_op"); |
| 649 | |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 650 | GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void cc_start_transport_op(grpc_exec_ctx *exec_ctx, |
| 654 | grpc_channel_element *elem, |
| 655 | grpc_transport_op *op) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 656 | channel_data *chand = (channel_data *)elem->channel_data; |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 657 | |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 658 | GPR_ASSERT(op->set_accept_stream == false); |
| 659 | if (op->bind_pollset != NULL) { |
| 660 | grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, |
| 661 | op->bind_pollset); |
| 662 | } |
| 663 | |
Craig Tiller | c55c102 | 2017-03-10 10:26:42 -0800 | [diff] [blame] | 664 | op->handler_private.extra_arg = elem; |
Craig Tiller | d2e5cfc | 2017-02-09 13:02:20 -0800 | [diff] [blame] | 665 | GRPC_CHANNEL_STACK_REF(chand->owning_stack, "start_transport_op"); |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 666 | GRPC_CLOSURE_SCHED( |
Craig Tiller | c55c102 | 2017-03-10 10:26:42 -0800 | [diff] [blame] | 667 | exec_ctx, |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 668 | GRPC_CLOSURE_INIT(&op->handler_private.closure, start_transport_op_locked, |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 669 | op, grpc_combiner_scheduler(chand->combiner)), |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 670 | GRPC_ERROR_NONE); |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 671 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 672 | |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 673 | static void cc_get_channel_info(grpc_exec_ctx *exec_ctx, |
| 674 | grpc_channel_element *elem, |
Mark D. Roth | f79ce7d | 2016-11-04 08:43:36 -0700 | [diff] [blame] | 675 | const grpc_channel_info *info) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 676 | channel_data *chand = (channel_data *)elem->channel_data; |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 677 | gpr_mu_lock(&chand->info_mu); |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 678 | if (info->lb_policy_name != NULL) { |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 679 | *info->lb_policy_name = chand->info_lb_policy_name == NULL |
Mark D. Roth | 78afd77 | 2016-11-04 12:49:49 -0700 | [diff] [blame] | 680 | ? NULL |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 681 | : gpr_strdup(chand->info_lb_policy_name); |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 682 | } |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 683 | if (info->service_config_json != NULL) { |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 684 | *info->service_config_json = |
| 685 | chand->info_service_config_json == NULL |
| 686 | ? NULL |
| 687 | : gpr_strdup(chand->info_service_config_json); |
Mark D. Roth | c625c7a | 2016-11-09 14:12:37 -0800 | [diff] [blame] | 688 | } |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 689 | gpr_mu_unlock(&chand->info_mu); |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 692 | /* Constructor for channel_data */ |
Mark D. Roth | c108788 | 2016-11-18 10:54:45 -0800 | [diff] [blame] | 693 | static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, |
Mark D. Roth | 5e2566e | 2016-11-18 10:53:13 -0800 | [diff] [blame] | 694 | grpc_channel_element *elem, |
| 695 | grpc_channel_element_args *args) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 696 | channel_data *chand = (channel_data *)elem->channel_data; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 697 | GPR_ASSERT(args->is_last); |
| 698 | GPR_ASSERT(elem->filter == &grpc_client_channel_filter); |
Mark D. Roth | 21d4b2d | 2016-11-18 09:53:41 -0800 | [diff] [blame] | 699 | // Initialize data members. |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 700 | chand->combiner = grpc_combiner_create(); |
Craig Tiller | d8547751 | 2017-02-09 12:02:39 -0800 | [diff] [blame] | 701 | gpr_mu_init(&chand->info_mu); |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 702 | gpr_mu_init(&chand->external_connectivity_watcher_list_mu); |
| 703 | |
| 704 | gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); |
| 705 | chand->external_connectivity_watcher_list_head = NULL; |
| 706 | gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); |
| 707 | |
Mark D. Roth | 21d4b2d | 2016-11-18 09:53:41 -0800 | [diff] [blame] | 708 | chand->owning_stack = args->channel_stack; |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 709 | GRPC_CLOSURE_INIT(&chand->on_resolver_result_changed, |
Craig Tiller | befafe6 | 2017-02-09 11:30:54 -0800 | [diff] [blame] | 710 | on_resolver_result_changed_locked, chand, |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 711 | grpc_combiner_scheduler(chand->combiner)); |
Mark D. Roth | 21d4b2d | 2016-11-18 09:53:41 -0800 | [diff] [blame] | 712 | chand->interested_parties = grpc_pollset_set_create(); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 713 | grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE, |
| 714 | "client_channel"); |
Mark D. Roth | 21d4b2d | 2016-11-18 09:53:41 -0800 | [diff] [blame] | 715 | // Record client channel factory. |
| 716 | const grpc_arg *arg = grpc_channel_args_find(args->channel_args, |
| 717 | GRPC_ARG_CLIENT_CHANNEL_FACTORY); |
David Garcia Quintas | 228a514 | 2017-03-30 19:43:00 -0700 | [diff] [blame] | 718 | if (arg == NULL) { |
| 719 | return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
| 720 | "Missing client channel factory in args for client channel filter"); |
| 721 | } |
| 722 | if (arg->type != GRPC_ARG_POINTER) { |
| 723 | return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
| 724 | "client channel factory arg must be a pointer"); |
| 725 | } |
Yash Tibrewal | bc130da | 2017-09-12 22:44:08 -0700 | [diff] [blame] | 726 | grpc_client_channel_factory_ref( |
| 727 | (grpc_client_channel_factory *)arg->value.pointer.p); |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 728 | chand->client_channel_factory = |
| 729 | (grpc_client_channel_factory *)arg->value.pointer.p; |
Mark D. Roth | dc9bee7 | 2017-02-07 12:29:14 -0800 | [diff] [blame] | 730 | // Get server name to resolve, using proxy mapper if needed. |
Mark D. Roth | 86e9059 | 2016-11-18 09:56:40 -0800 | [diff] [blame] | 731 | arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); |
David Garcia Quintas | 228a514 | 2017-03-30 19:43:00 -0700 | [diff] [blame] | 732 | if (arg == NULL) { |
| 733 | return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
| 734 | "Missing server uri in args for client channel filter"); |
| 735 | } |
| 736 | if (arg->type != GRPC_ARG_STRING) { |
| 737 | return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
| 738 | "server uri arg must be a string"); |
| 739 | } |
Mark D. Roth | dc9bee7 | 2017-02-07 12:29:14 -0800 | [diff] [blame] | 740 | char *proxy_name = NULL; |
| 741 | grpc_channel_args *new_args = NULL; |
| 742 | grpc_proxy_mappers_map_name(exec_ctx, arg->value.string, args->channel_args, |
| 743 | &proxy_name, &new_args); |
| 744 | // Instantiate resolver. |
Mark D. Roth | 45ccec5 | 2017-01-18 14:04:01 -0800 | [diff] [blame] | 745 | chand->resolver = grpc_resolver_create( |
Mark D. Roth | dc9bee7 | 2017-02-07 12:29:14 -0800 | [diff] [blame] | 746 | exec_ctx, proxy_name != NULL ? proxy_name : arg->value.string, |
| 747 | new_args != NULL ? new_args : args->channel_args, |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 748 | chand->interested_parties, chand->combiner); |
Mark D. Roth | dc9bee7 | 2017-02-07 12:29:14 -0800 | [diff] [blame] | 749 | if (proxy_name != NULL) gpr_free(proxy_name); |
| 750 | if (new_args != NULL) grpc_channel_args_destroy(exec_ctx, new_args); |
Mark D. Roth | 5e2566e | 2016-11-18 10:53:13 -0800 | [diff] [blame] | 751 | if (chand->resolver == NULL) { |
ncteisen | 4b36a3d | 2017-03-13 19:08:06 -0700 | [diff] [blame] | 752 | return GRPC_ERROR_CREATE_FROM_STATIC_STRING("resolver creation failed"); |
Mark D. Roth | 5e2566e | 2016-11-18 10:53:13 -0800 | [diff] [blame] | 753 | } |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 754 | chand->deadline_checking_enabled = |
| 755 | grpc_deadline_checking_enabled(args->channel_args); |
Mark D. Roth | 5e2566e | 2016-11-18 10:53:13 -0800 | [diff] [blame] | 756 | return GRPC_ERROR_NONE; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 759 | static void shutdown_resolver_locked(grpc_exec_ctx *exec_ctx, void *arg, |
| 760 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 761 | grpc_resolver *resolver = (grpc_resolver *)arg; |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 762 | grpc_resolver_shutdown_locked(exec_ctx, resolver); |
| 763 | GRPC_RESOLVER_UNREF(exec_ctx, resolver, "channel"); |
| 764 | } |
| 765 | |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 766 | /* Destructor for channel_data */ |
| 767 | static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, |
| 768 | grpc_channel_element *elem) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 769 | channel_data *chand = (channel_data *)elem->channel_data; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 770 | if (chand->resolver != NULL) { |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 771 | GRPC_CLOSURE_SCHED( |
| 772 | exec_ctx, GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 773 | grpc_combiner_scheduler(chand->combiner)), |
Craig Tiller | 972470b | 2017-02-09 15:05:36 -0800 | [diff] [blame] | 774 | GRPC_ERROR_NONE); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 775 | } |
Mark D. Roth | 0e48a9a | 2016-09-08 14:14:39 -0700 | [diff] [blame] | 776 | if (chand->client_channel_factory != NULL) { |
| 777 | grpc_client_channel_factory_unref(exec_ctx, chand->client_channel_factory); |
| 778 | } |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 779 | if (chand->lb_policy != NULL) { |
| 780 | grpc_pollset_set_del_pollset_set(exec_ctx, |
| 781 | chand->lb_policy->interested_parties, |
| 782 | chand->interested_parties); |
| 783 | GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); |
| 784 | } |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 785 | gpr_free(chand->info_lb_policy_name); |
| 786 | gpr_free(chand->info_service_config_json); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 787 | if (chand->retry_throttle_data != NULL) { |
| 788 | grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); |
| 789 | } |
Mark D. Roth | 9d48094 | 2016-10-19 14:18:05 -0700 | [diff] [blame] | 790 | if (chand->method_params_table != NULL) { |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 791 | grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); |
Mark D. Roth | 9fe284e | 2016-09-12 11:22:27 -0700 | [diff] [blame] | 792 | } |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 793 | grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); |
Craig Tiller | 9e5ac1b | 2017-02-14 22:25:50 -0800 | [diff] [blame] | 794 | grpc_pollset_set_destroy(exec_ctx, chand->interested_parties); |
Craig Tiller | f102167 | 2017-02-09 21:29:50 -0800 | [diff] [blame] | 795 | GRPC_COMBINER_UNREF(exec_ctx, chand->combiner, "client_channel"); |
Craig Tiller | d8547751 | 2017-02-09 12:02:39 -0800 | [diff] [blame] | 796 | gpr_mu_destroy(&chand->info_mu); |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 797 | gpr_mu_destroy(&chand->external_connectivity_watcher_list_mu); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /************************************************************************* |
| 801 | * PER-CALL FUNCTIONS |
| 802 | */ |
| 803 | |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 804 | // Max number of batches that can be pending on a call at any given |
| 805 | // time. This includes: |
| 806 | // recv_initial_metadata |
| 807 | // send_initial_metadata |
| 808 | // recv_message |
| 809 | // send_message |
| 810 | // recv_trailing_metadata |
| 811 | // send_trailing_metadata |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 812 | // We also add room for a single cancel_stream batch. |
| 813 | #define MAX_WAITING_BATCHES 7 |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 814 | |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 815 | /** Call data. Holds a pointer to grpc_subchannel_call and the |
| 816 | associated machinery to create such a pointer. |
| 817 | Handles queueing of stream ops until a call object is ready, waiting |
| 818 | for initial metadata before trying to create a call object, |
| 819 | and handling cancellation gracefully. */ |
| 820 | typedef struct client_channel_call_data { |
Mark D. Roth | 72f6da8 | 2016-09-02 13:42:38 -0700 | [diff] [blame] | 821 | // State for handling deadlines. |
| 822 | // The code in deadline_filter.c requires this to be the first field. |
Mark D. Roth | 72f6da8 | 2016-09-02 13:42:38 -0700 | [diff] [blame] | 823 | // TODO(roth): This is slightly sub-optimal in that grpc_deadline_state |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 824 | // and this struct both independently store pointers to the call stack |
| 825 | // and call combiner. If/when we have time, find a way to avoid this |
| 826 | // without breaking the grpc_deadline_state abstraction. |
Mark D. Roth | 72f6da8 | 2016-09-02 13:42:38 -0700 | [diff] [blame] | 827 | grpc_deadline_state deadline_state; |
Mark D. Roth | f28763c | 2016-09-14 15:18:40 -0700 | [diff] [blame] | 828 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 829 | grpc_slice path; // Request path. |
Mark D. Roth | e40dd29 | 2016-10-05 14:58:37 -0700 | [diff] [blame] | 830 | gpr_timespec call_start_time; |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 831 | grpc_millis deadline; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 832 | gpr_arena *arena; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 833 | grpc_call_stack *owning_call; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 834 | grpc_call_combiner *call_combiner; |
| 835 | |
Mark D. Roth | 9ccbc4d | 2017-03-15 08:30:04 -0700 | [diff] [blame] | 836 | grpc_server_retry_throttle_data *retry_throttle_data; |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 837 | method_parameters *method_params; |
Mark D. Roth | aa850a7 | 2016-09-26 13:38:02 -0700 | [diff] [blame] | 838 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 839 | grpc_subchannel_call *subchannel_call; |
| 840 | grpc_error *error; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 841 | |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 842 | grpc_lb_policy *lb_policy; // Holds ref while LB pick is pending. |
| 843 | grpc_closure lb_pick_closure; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 844 | grpc_closure lb_pick_cancel_closure; |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 845 | |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 846 | grpc_connected_subchannel *connected_subchannel; |
Mark D. Roth | 09e458c | 2017-05-02 08:13:26 -0700 | [diff] [blame] | 847 | grpc_call_context_element subchannel_call_context[GRPC_CONTEXT_COUNT]; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 848 | grpc_polling_entity *pollent; |
| 849 | |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 850 | grpc_transport_stream_op_batch *waiting_for_pick_batches[MAX_WAITING_BATCHES]; |
| 851 | size_t waiting_for_pick_batches_count; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 852 | grpc_closure handle_pending_batch_in_call_combiner[MAX_WAITING_BATCHES]; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 853 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 854 | grpc_transport_stream_op_batch *initial_metadata_batch; |
David Garcia Quintas | d1a47f1 | 2016-09-02 12:46:44 +0200 | [diff] [blame] | 855 | |
| 856 | grpc_linked_mdelem lb_token_mdelem; |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 857 | |
| 858 | grpc_closure on_complete; |
| 859 | grpc_closure *original_on_complete; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 860 | } call_data; |
| 861 | |
Craig Tiller | 8b1d59c | 2016-12-27 15:15:30 -0800 | [diff] [blame] | 862 | grpc_subchannel_call *grpc_client_channel_get_subchannel_call( |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 863 | grpc_call_element *elem) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 864 | call_data *calld = (call_data *)elem->call_data; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 865 | return calld->subchannel_call; |
Craig Tiller | 8b1d59c | 2016-12-27 15:15:30 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 868 | // This is called via the call combiner, so access to calld is synchronized. |
| 869 | static void waiting_for_pick_batches_add( |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 870 | call_data *calld, grpc_transport_stream_op_batch *batch) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 871 | if (batch->send_initial_metadata) { |
| 872 | GPR_ASSERT(calld->initial_metadata_batch == NULL); |
| 873 | calld->initial_metadata_batch = batch; |
| 874 | } else { |
| 875 | GPR_ASSERT(calld->waiting_for_pick_batches_count < MAX_WAITING_BATCHES); |
| 876 | calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count++] = |
| 877 | batch; |
| 878 | } |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 881 | // This is called via the call combiner, so access to calld is synchronized. |
| 882 | static void fail_pending_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, |
| 883 | void *arg, grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 884 | call_data *calld = (call_data *)arg; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 885 | if (calld->waiting_for_pick_batches_count > 0) { |
| 886 | --calld->waiting_for_pick_batches_count; |
| 887 | grpc_transport_stream_op_batch_finish_with_failure( |
| 888 | exec_ctx, |
| 889 | calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count], |
| 890 | GRPC_ERROR_REF(error), calld->call_combiner); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | // This is called via the call combiner, so access to calld is synchronized. |
| 895 | static void waiting_for_pick_batches_fail(grpc_exec_ctx *exec_ctx, |
| 896 | grpc_call_element *elem, |
| 897 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 898 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 899 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 900 | gpr_log(GPR_DEBUG, |
| 901 | "chand=%p calld=%p: failing %" PRIdPTR " pending batches: %s", |
| 902 | elem->channel_data, calld, calld->waiting_for_pick_batches_count, |
| 903 | grpc_error_string(error)); |
| 904 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 905 | for (size_t i = 0; i < calld->waiting_for_pick_batches_count; ++i) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 906 | GRPC_CLOSURE_INIT(&calld->handle_pending_batch_in_call_combiner[i], |
| 907 | fail_pending_batch_in_call_combiner, calld, |
| 908 | grpc_schedule_on_exec_ctx); |
| 909 | GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, |
| 910 | &calld->handle_pending_batch_in_call_combiner[i], |
| 911 | GRPC_ERROR_REF(error), |
| 912 | "waiting_for_pick_batches_fail"); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 913 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 914 | if (calld->initial_metadata_batch != NULL) { |
| 915 | grpc_transport_stream_op_batch_finish_with_failure( |
| 916 | exec_ctx, calld->initial_metadata_batch, GRPC_ERROR_REF(error), |
| 917 | calld->call_combiner); |
| 918 | } else { |
| 919 | GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, |
| 920 | "waiting_for_pick_batches_fail"); |
| 921 | } |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 922 | GRPC_ERROR_UNREF(error); |
| 923 | } |
| 924 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 925 | // This is called via the call combiner, so access to calld is synchronized. |
| 926 | static void run_pending_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, |
| 927 | void *arg, grpc_error *ignored) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 928 | call_data *calld = (call_data *)arg; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 929 | if (calld->waiting_for_pick_batches_count > 0) { |
| 930 | --calld->waiting_for_pick_batches_count; |
| 931 | grpc_subchannel_call_process_op( |
| 932 | exec_ctx, calld->subchannel_call, |
| 933 | calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count]); |
Craig Tiller | 57726ca | 2016-09-12 11:59:45 -0700 | [diff] [blame] | 934 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // This is called via the call combiner, so access to calld is synchronized. |
| 938 | static void waiting_for_pick_batches_resume(grpc_exec_ctx *exec_ctx, |
| 939 | grpc_call_element *elem) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 940 | channel_data *chand = (channel_data *)elem->channel_data; |
| 941 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 942 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 943 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending %" PRIdPTR |
| 944 | " pending batches to subchannel_call=%p", |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 945 | chand, calld, calld->waiting_for_pick_batches_count, |
| 946 | calld->subchannel_call); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 947 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 948 | for (size_t i = 0; i < calld->waiting_for_pick_batches_count; ++i) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 949 | GRPC_CLOSURE_INIT(&calld->handle_pending_batch_in_call_combiner[i], |
| 950 | run_pending_batch_in_call_combiner, calld, |
| 951 | grpc_schedule_on_exec_ctx); |
| 952 | GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, |
| 953 | &calld->handle_pending_batch_in_call_combiner[i], |
| 954 | GRPC_ERROR_NONE, |
| 955 | "waiting_for_pick_batches_resume"); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 956 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 957 | GPR_ASSERT(calld->initial_metadata_batch != NULL); |
| 958 | grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, |
| 959 | calld->initial_metadata_batch); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 962 | // Applies service config to the call. Must be invoked once we know |
| 963 | // that the resolver has returned results to the channel. |
| 964 | static void apply_service_config_to_call_locked(grpc_exec_ctx *exec_ctx, |
| 965 | grpc_call_element *elem) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 966 | channel_data *chand = (channel_data *)elem->channel_data; |
| 967 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 968 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 969 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call", |
| 970 | chand, calld); |
| 971 | } |
Mark D. Roth | 9ccbc4d | 2017-03-15 08:30:04 -0700 | [diff] [blame] | 972 | if (chand->retry_throttle_data != NULL) { |
| 973 | calld->retry_throttle_data = |
| 974 | grpc_server_retry_throttle_data_ref(chand->retry_throttle_data); |
| 975 | } |
Craig Tiller | 11c17d4 | 2017-03-13 13:36:34 -0700 | [diff] [blame] | 976 | if (chand->method_params_table != NULL) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 977 | calld->method_params = (method_parameters *)grpc_method_config_table_get( |
Craig Tiller | 11c17d4 | 2017-03-13 13:36:34 -0700 | [diff] [blame] | 978 | exec_ctx, chand->method_params_table, calld->path); |
| 979 | if (calld->method_params != NULL) { |
| 980 | method_parameters_ref(calld->method_params); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 981 | // If the deadline from the service config is shorter than the one |
| 982 | // from the client API, reset the deadline timer. |
| 983 | if (chand->deadline_checking_enabled && |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 984 | calld->method_params->timeout != 0) { |
| 985 | const grpc_millis per_method_deadline = |
Craig Tiller | 9a8c3f3 | 2017-07-21 13:14:14 -0700 | [diff] [blame] | 986 | grpc_timespec_to_millis_round_up(calld->call_start_time) + |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 987 | calld->method_params->timeout; |
| 988 | if (per_method_deadline < calld->deadline) { |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 989 | calld->deadline = per_method_deadline; |
| 990 | grpc_deadline_state_reset(exec_ctx, elem, calld->deadline); |
| 991 | } |
Craig Tiller | 11c17d4 | 2017-03-13 13:36:34 -0700 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | } |
Craig Tiller | 11c17d4 | 2017-03-13 13:36:34 -0700 | [diff] [blame] | 995 | } |
Craig Tiller | ea4a4f1 | 2017-03-13 13:36:52 -0700 | [diff] [blame] | 996 | |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 997 | static void create_subchannel_call_locked(grpc_exec_ctx *exec_ctx, |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 998 | grpc_call_element *elem, |
| 999 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1000 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1001 | call_data *calld = (call_data *)elem->call_data; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1002 | const grpc_connected_subchannel_call_args call_args = { |
Yash Tibrewal | d8b84a2 | 2017-09-25 13:38:03 -0700 | [diff] [blame] | 1003 | calld->pollent, // pollent |
| 1004 | calld->path, // path |
| 1005 | calld->call_start_time, // start_time |
| 1006 | calld->deadline, // deadline |
| 1007 | calld->arena, // arena |
| 1008 | calld->subchannel_call_context, // context |
| 1009 | calld->call_combiner // call_combiner |
| 1010 | }; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1011 | grpc_error *new_error = grpc_connected_subchannel_create_call( |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1012 | exec_ctx, calld->connected_subchannel, &call_args, |
| 1013 | &calld->subchannel_call); |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1014 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1015 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: create subchannel_call=%p: error=%s", |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1016 | chand, calld, calld->subchannel_call, grpc_error_string(new_error)); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1017 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1018 | if (new_error != GRPC_ERROR_NONE) { |
| 1019 | new_error = grpc_error_add_child(new_error, error); |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1020 | waiting_for_pick_batches_fail(exec_ctx, elem, new_error); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1021 | } else { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1022 | waiting_for_pick_batches_resume(exec_ctx, elem); |
Craig Tiller | 11c17d4 | 2017-03-13 13:36:34 -0700 | [diff] [blame] | 1023 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1024 | GRPC_ERROR_UNREF(error); |
Craig Tiller | 11c17d4 | 2017-03-13 13:36:34 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1027 | // Invoked when a pick is completed, on both success or failure. |
| 1028 | static void pick_done_locked(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
| 1029 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1030 | call_data *calld = (call_data *)elem->call_data; |
| 1031 | channel_data *chand = (channel_data *)elem->channel_data; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1032 | if (calld->connected_subchannel == NULL) { |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1033 | // Failed to create subchannel. |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1034 | GRPC_ERROR_UNREF(calld->error); |
| 1035 | calld->error = error == GRPC_ERROR_NONE |
| 1036 | ? GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
| 1037 | "Call dropped by load balancing policy") |
| 1038 | : GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( |
| 1039 | "Failed to create subchannel", &error, 1); |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1040 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1041 | gpr_log(GPR_DEBUG, |
| 1042 | "chand=%p calld=%p: failed to create subchannel: error=%s", chand, |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1043 | calld, grpc_error_string(calld->error)); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1044 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1045 | waiting_for_pick_batches_fail(exec_ctx, elem, GRPC_ERROR_REF(calld->error)); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1046 | } else { |
Mark D. Roth | 9fe284e | 2016-09-12 11:22:27 -0700 | [diff] [blame] | 1047 | /* Create call on subchannel. */ |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1048 | create_subchannel_call_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1049 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1050 | GRPC_ERROR_UNREF(error); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1053 | // A wrapper around pick_done_locked() that is used in cases where |
| 1054 | // either (a) the pick was deferred pending a resolver result or (b) the |
| 1055 | // pick was done asynchronously. Removes the call's polling entity from |
| 1056 | // chand->interested_parties before invoking pick_done_locked(). |
| 1057 | static void async_pick_done_locked(grpc_exec_ctx *exec_ctx, |
| 1058 | grpc_call_element *elem, grpc_error *error) { |
| 1059 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1060 | call_data *calld = (call_data *)elem->call_data; |
| 1061 | grpc_polling_entity_del_from_pollset_set(exec_ctx, calld->pollent, |
| 1062 | chand->interested_parties); |
| 1063 | pick_done_locked(exec_ctx, elem, error); |
| 1064 | } |
| 1065 | |
| 1066 | // Note: This runs under the client_channel combiner, but will NOT be |
| 1067 | // holding the call combiner. |
| 1068 | static void pick_callback_cancel_locked(grpc_exec_ctx *exec_ctx, void *arg, |
| 1069 | grpc_error *error) { |
| 1070 | grpc_call_element *elem = (grpc_call_element *)arg; |
| 1071 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1072 | call_data *calld = (call_data *)elem->call_data; |
| 1073 | if (calld->lb_policy != NULL) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1074 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1075 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p", |
| 1076 | chand, calld, calld->lb_policy); |
| 1077 | } |
| 1078 | grpc_lb_policy_cancel_pick_locked(exec_ctx, calld->lb_policy, |
| 1079 | &calld->connected_subchannel, |
| 1080 | GRPC_ERROR_REF(error)); |
| 1081 | } |
| 1082 | GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_callback_cancel"); |
| 1083 | } |
| 1084 | |
| 1085 | // Callback invoked by grpc_lb_policy_pick_locked() for async picks. |
| 1086 | // Unrefs the LB policy and invokes async_pick_done_locked(). |
| 1087 | static void pick_callback_done_locked(grpc_exec_ctx *exec_ctx, void *arg, |
| 1088 | grpc_error *error) { |
| 1089 | grpc_call_element *elem = (grpc_call_element *)arg; |
| 1090 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1091 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1092 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1093 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously", |
| 1094 | chand, calld); |
| 1095 | } |
| 1096 | GPR_ASSERT(calld->lb_policy != NULL); |
| 1097 | GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); |
| 1098 | calld->lb_policy = NULL; |
| 1099 | async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); |
| 1100 | } |
| 1101 | |
| 1102 | // Takes a ref to chand->lb_policy and calls grpc_lb_policy_pick_locked(). |
| 1103 | // If the pick was completed synchronously, unrefs the LB policy and |
| 1104 | // returns true. |
| 1105 | static bool pick_callback_start_locked(grpc_exec_ctx *exec_ctx, |
| 1106 | grpc_call_element *elem) { |
| 1107 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1108 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1109 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1110 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p", |
| 1111 | chand, calld, chand->lb_policy); |
| 1112 | } |
| 1113 | apply_service_config_to_call_locked(exec_ctx, elem); |
| 1114 | // If the application explicitly set wait_for_ready, use that. |
| 1115 | // Otherwise, if the service config specified a value for this |
| 1116 | // method, use that. |
| 1117 | uint32_t initial_metadata_flags = |
| 1118 | calld->initial_metadata_batch->payload->send_initial_metadata |
| 1119 | .send_initial_metadata_flags; |
| 1120 | const bool wait_for_ready_set_from_api = |
| 1121 | initial_metadata_flags & |
| 1122 | GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET; |
| 1123 | const bool wait_for_ready_set_from_service_config = |
| 1124 | calld->method_params != NULL && |
| 1125 | calld->method_params->wait_for_ready != WAIT_FOR_READY_UNSET; |
| 1126 | if (!wait_for_ready_set_from_api && wait_for_ready_set_from_service_config) { |
| 1127 | if (calld->method_params->wait_for_ready == WAIT_FOR_READY_TRUE) { |
| 1128 | initial_metadata_flags |= GRPC_INITIAL_METADATA_WAIT_FOR_READY; |
| 1129 | } else { |
| 1130 | initial_metadata_flags &= ~GRPC_INITIAL_METADATA_WAIT_FOR_READY; |
| 1131 | } |
| 1132 | } |
| 1133 | const grpc_lb_policy_pick_args inputs = { |
| 1134 | calld->initial_metadata_batch->payload->send_initial_metadata |
| 1135 | .send_initial_metadata, |
| 1136 | initial_metadata_flags, &calld->lb_token_mdelem}; |
| 1137 | // Keep a ref to the LB policy in calld while the pick is pending. |
| 1138 | GRPC_LB_POLICY_REF(chand->lb_policy, "pick_subchannel"); |
| 1139 | calld->lb_policy = chand->lb_policy; |
| 1140 | GRPC_CLOSURE_INIT(&calld->lb_pick_closure, pick_callback_done_locked, elem, |
| 1141 | grpc_combiner_scheduler(chand->combiner)); |
| 1142 | const bool pick_done = grpc_lb_policy_pick_locked( |
| 1143 | exec_ctx, chand->lb_policy, &inputs, &calld->connected_subchannel, |
| 1144 | calld->subchannel_call_context, NULL, &calld->lb_pick_closure); |
| 1145 | if (pick_done) { |
| 1146 | /* synchronous grpc_lb_policy_pick call. Unref the LB policy. */ |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1147 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1148 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed synchronously", |
| 1149 | chand, calld); |
| 1150 | } |
| 1151 | GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); |
| 1152 | calld->lb_policy = NULL; |
| 1153 | } else { |
| 1154 | GRPC_CALL_STACK_REF(calld->owning_call, "pick_callback_cancel"); |
| 1155 | grpc_call_combiner_set_notify_on_cancel( |
| 1156 | exec_ctx, calld->call_combiner, |
| 1157 | GRPC_CLOSURE_INIT(&calld->lb_pick_cancel_closure, |
| 1158 | pick_callback_cancel_locked, elem, |
| 1159 | grpc_combiner_scheduler(chand->combiner))); |
| 1160 | } |
| 1161 | return pick_done; |
| 1162 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1163 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1164 | typedef struct { |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1165 | grpc_call_element *elem; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1166 | bool finished; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1167 | grpc_closure closure; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1168 | grpc_closure cancel_closure; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1169 | } pick_after_resolver_result_args; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1170 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1171 | // Note: This runs under the client_channel combiner, but will NOT be |
| 1172 | // holding the call combiner. |
| 1173 | static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx *exec_ctx, |
| 1174 | void *arg, |
| 1175 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1176 | pick_after_resolver_result_args *args = |
| 1177 | (pick_after_resolver_result_args *)arg; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1178 | if (args->finished) { |
| 1179 | gpr_free(args); |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1180 | return; |
Mark D. Roth | 764cf04 | 2017-09-01 09:00:06 -0700 | [diff] [blame] | 1181 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1182 | // If we don't yet have a resolver result, then a closure for |
| 1183 | // pick_after_resolver_result_done_locked() will have been added to |
| 1184 | // chand->waiting_for_resolver_result_closures, and it may not be invoked |
| 1185 | // until after this call has been destroyed. We mark the operation as |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1186 | // finished, so that when pick_after_resolver_result_done_locked() |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1187 | // is called, it will be a no-op. We also immediately invoke |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1188 | // async_pick_done_locked() to propagate the error back to the caller. |
| 1189 | args->finished = true; |
| 1190 | grpc_call_element *elem = args->elem; |
| 1191 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1192 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1193 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1194 | gpr_log(GPR_DEBUG, |
| 1195 | "chand=%p calld=%p: cancelling pick waiting for resolver result", |
| 1196 | chand, calld); |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1197 | } |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1198 | // Note: Although we are not in the call combiner here, we are |
| 1199 | // basically stealing the call combiner from the pending pick, so |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1200 | // it's safe to call async_pick_done_locked() here -- we are |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1201 | // essentially calling it here instead of calling it in |
| 1202 | // pick_after_resolver_result_done_locked(). |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1203 | async_pick_done_locked(exec_ctx, elem, |
| 1204 | GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( |
| 1205 | "Pick cancelled", &error, 1)); |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1208 | static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx, |
| 1209 | void *arg, |
| 1210 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1211 | pick_after_resolver_result_args *args = |
| 1212 | (pick_after_resolver_result_args *)arg; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1213 | if (args->finished) { |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1214 | /* cancelled, do nothing */ |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1215 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1216 | gpr_log(GPR_DEBUG, "call cancelled before resolver result"); |
| 1217 | } |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1218 | gpr_free(args); |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1219 | return; |
| 1220 | } |
| 1221 | args->finished = true; |
| 1222 | grpc_call_element *elem = args->elem; |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1223 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1224 | call_data *calld = (call_data *)elem->call_data; |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1225 | if (error != GRPC_ERROR_NONE) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1226 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1227 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data", |
| 1228 | chand, calld); |
| 1229 | } |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1230 | async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); |
Mark D. Roth | 9dab7d5 | 2016-10-07 07:48:03 -0700 | [diff] [blame] | 1231 | } else { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1232 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b2b9a0f | 2017-09-01 09:06:47 -0700 | [diff] [blame] | 1233 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick", |
| 1234 | chand, calld); |
| 1235 | } |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1236 | if (pick_callback_start_locked(exec_ctx, elem)) { |
| 1237 | // Even if the LB policy returns a result synchronously, we have |
| 1238 | // already added our polling entity to chand->interested_parties |
| 1239 | // in order to wait for the resolver result, so we need to |
| 1240 | // remove it here. Therefore, we call async_pick_done_locked() |
| 1241 | // instead of pick_done_locked(). |
| 1242 | async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_NONE); |
Mark D. Roth | 9dab7d5 | 2016-10-07 07:48:03 -0700 | [diff] [blame] | 1243 | } |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1244 | } |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1247 | static void pick_after_resolver_result_start_locked(grpc_exec_ctx *exec_ctx, |
| 1248 | grpc_call_element *elem) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1249 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1250 | call_data *calld = (call_data *)elem->call_data; |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1251 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1252 | gpr_log(GPR_DEBUG, |
| 1253 | "chand=%p calld=%p: deferring pick pending resolver result", chand, |
| 1254 | calld); |
Mark D. Roth | 64a317c | 2017-05-02 08:27:08 -0700 | [diff] [blame] | 1255 | } |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1256 | pick_after_resolver_result_args *args = |
| 1257 | (pick_after_resolver_result_args *)gpr_zalloc(sizeof(*args)); |
| 1258 | args->elem = elem; |
| 1259 | GRPC_CLOSURE_INIT(&args->closure, pick_after_resolver_result_done_locked, |
| 1260 | args, grpc_combiner_scheduler(chand->combiner)); |
| 1261 | grpc_closure_list_append(&chand->waiting_for_resolver_result_closures, |
| 1262 | &args->closure, GRPC_ERROR_NONE); |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1263 | grpc_call_combiner_set_notify_on_cancel( |
| 1264 | exec_ctx, calld->call_combiner, |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1265 | GRPC_CLOSURE_INIT(&args->cancel_closure, |
| 1266 | pick_after_resolver_result_cancel_locked, args, |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1267 | grpc_combiner_scheduler(chand->combiner))); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1270 | static void start_pick_locked(grpc_exec_ctx *exec_ctx, void *arg, |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1271 | grpc_error *ignored) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1272 | grpc_call_element *elem = (grpc_call_element *)arg; |
| 1273 | call_data *calld = (call_data *)elem->call_data; |
| 1274 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1275 | GPR_ASSERT(calld->connected_subchannel == NULL); |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1276 | if (chand->lb_policy != NULL) { |
| 1277 | // We already have an LB policy, so ask it for a pick. |
| 1278 | if (pick_callback_start_locked(exec_ctx, elem)) { |
| 1279 | // Pick completed synchronously. |
| 1280 | pick_done_locked(exec_ctx, elem, GRPC_ERROR_NONE); |
| 1281 | return; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1282 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1283 | } else { |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1284 | // We do not yet have an LB policy, so wait for a resolver result. |
| 1285 | if (chand->resolver == NULL) { |
| 1286 | pick_done_locked(exec_ctx, elem, |
| 1287 | GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); |
| 1288 | return; |
| 1289 | } |
| 1290 | if (!chand->started_resolving) { |
| 1291 | start_resolving_locked(exec_ctx, chand); |
| 1292 | } |
| 1293 | pick_after_resolver_result_start_locked(exec_ctx, elem); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1294 | } |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1295 | // We need to wait for either a resolver result or for an async result |
| 1296 | // from the LB policy. Add the polling entity from call_data to the |
| 1297 | // channel_data's interested_parties, so that the I/O of the LB policy |
| 1298 | // and resolver can be done under it. The polling entity will be |
| 1299 | // removed in async_pick_done_locked(). |
| 1300 | grpc_polling_entity_add_to_pollset_set(exec_ctx, calld->pollent, |
| 1301 | chand->interested_parties); |
Craig Tiller | a11bfc8 | 2017-02-14 09:56:33 -0800 | [diff] [blame] | 1302 | } |
| 1303 | |
Mark D. Roth | de14410 | 2017-03-15 10:11:03 -0700 | [diff] [blame] | 1304 | static void on_complete(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1305 | grpc_call_element *elem = (grpc_call_element *)arg; |
| 1306 | call_data *calld = (call_data *)elem->call_data; |
Mark D. Roth | 9ccbc4d | 2017-03-15 08:30:04 -0700 | [diff] [blame] | 1307 | if (calld->retry_throttle_data != NULL) { |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 1308 | if (error == GRPC_ERROR_NONE) { |
| 1309 | grpc_server_retry_throttle_data_record_success( |
Mark D. Roth | 9ccbc4d | 2017-03-15 08:30:04 -0700 | [diff] [blame] | 1310 | calld->retry_throttle_data); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 1311 | } else { |
| 1312 | // TODO(roth): In a subsequent PR, check the return value here and |
Mark D. Roth | b332256 | 2017-02-23 14:38:02 -0800 | [diff] [blame] | 1313 | // decide whether or not to retry. Note that we should only |
| 1314 | // record failures whose statuses match the configured retryable |
| 1315 | // or non-fatal status codes. |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 1316 | grpc_server_retry_throttle_data_record_failure( |
Mark D. Roth | 9ccbc4d | 2017-03-15 08:30:04 -0700 | [diff] [blame] | 1317 | calld->retry_throttle_data); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 1318 | } |
| 1319 | } |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1320 | GRPC_CLOSURE_RUN(exec_ctx, calld->original_on_complete, |
Mark D. Roth | 95039b5 | 2017-02-24 07:59:45 -0800 | [diff] [blame] | 1321 | GRPC_ERROR_REF(error)); |
Mark D. Roth | d6d192d | 2017-02-23 08:58:42 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Craig Tiller | e1b51da | 2017-03-31 15:44:33 -0700 | [diff] [blame] | 1324 | static void cc_start_transport_stream_op_batch( |
| 1325 | grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1326 | grpc_transport_stream_op_batch *batch) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1327 | call_data *calld = (call_data *)elem->call_data; |
| 1328 | channel_data *chand = (channel_data *)elem->channel_data; |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 1329 | if (chand->deadline_checking_enabled) { |
Craig Tiller | 29ebc57 | 2017-04-04 08:00:55 -0700 | [diff] [blame] | 1330 | grpc_deadline_state_client_start_transport_stream_op_batch(exec_ctx, elem, |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1331 | batch); |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 1332 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1333 | GPR_TIMER_BEGIN("cc_start_transport_stream_op_batch", 0); |
| 1334 | // If we've previously been cancelled, immediately fail any new batches. |
| 1335 | if (calld->error != GRPC_ERROR_NONE) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1336 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1337 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: failing batch with error: %s", |
| 1338 | chand, calld, grpc_error_string(calld->error)); |
| 1339 | } |
| 1340 | grpc_transport_stream_op_batch_finish_with_failure( |
| 1341 | exec_ctx, batch, GRPC_ERROR_REF(calld->error), calld->call_combiner); |
| 1342 | goto done; |
| 1343 | } |
| 1344 | if (batch->cancel_stream) { |
| 1345 | // Stash a copy of cancel_error in our call data, so that we can use |
| 1346 | // it for subsequent operations. This ensures that if the call is |
| 1347 | // cancelled before any batches are passed down (e.g., if the deadline |
| 1348 | // is in the past when the call starts), we can return the right |
| 1349 | // error to the caller when the first batch does get passed down. |
| 1350 | GRPC_ERROR_UNREF(calld->error); |
| 1351 | calld->error = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error); |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1352 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1353 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: recording cancel_error=%s", chand, |
| 1354 | calld, grpc_error_string(calld->error)); |
| 1355 | } |
| 1356 | // If we have a subchannel call, send the cancellation batch down. |
| 1357 | // Otherwise, fail all pending batches. |
| 1358 | if (calld->subchannel_call != NULL) { |
| 1359 | grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); |
| 1360 | } else { |
| 1361 | waiting_for_pick_batches_add(calld, batch); |
| 1362 | waiting_for_pick_batches_fail(exec_ctx, elem, |
| 1363 | GRPC_ERROR_REF(calld->error)); |
| 1364 | } |
| 1365 | goto done; |
| 1366 | } |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1367 | // Intercept on_complete for recv_trailing_metadata so that we can |
| 1368 | // check retry throttle status. |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1369 | if (batch->recv_trailing_metadata) { |
| 1370 | GPR_ASSERT(batch->on_complete != NULL); |
| 1371 | calld->original_on_complete = batch->on_complete; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1372 | GRPC_CLOSURE_INIT(&calld->on_complete, on_complete, elem, |
| 1373 | grpc_schedule_on_exec_ctx); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1374 | batch->on_complete = &calld->on_complete; |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1375 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1376 | // Check if we've already gotten a subchannel call. |
| 1377 | // Note that once we have completed the pick, we do not need to enter |
| 1378 | // the channel combiner, which is more efficient (especially for |
| 1379 | // streaming calls). |
| 1380 | if (calld->subchannel_call != NULL) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1381 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1382 | gpr_log(GPR_DEBUG, |
| 1383 | "chand=%p calld=%p: sending batch to subchannel_call=%p", chand, |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1384 | calld, calld->subchannel_call); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1385 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1386 | grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1387 | goto done; |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1388 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1389 | // We do not yet have a subchannel call. |
| 1390 | // Add the batch to the waiting-for-pick list. |
| 1391 | waiting_for_pick_batches_add(calld, batch); |
| 1392 | // For batches containing a send_initial_metadata op, enter the channel |
| 1393 | // combiner to start a pick. |
| 1394 | if (batch->send_initial_metadata) { |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1395 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | b292960 | 2017-09-11 09:31:11 -0700 | [diff] [blame] | 1396 | gpr_log(GPR_DEBUG, "chand=%p calld=%p: entering client_channel combiner", |
| 1397 | chand, calld); |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1398 | } |
| 1399 | GRPC_CLOSURE_SCHED( |
| 1400 | exec_ctx, |
| 1401 | GRPC_CLOSURE_INIT(&batch->handler_private.closure, start_pick_locked, |
| 1402 | elem, grpc_combiner_scheduler(chand->combiner)), |
| 1403 | GRPC_ERROR_NONE); |
| 1404 | } else { |
| 1405 | // For all other batches, release the call combiner. |
Craig Tiller | 6014e8a | 2017-10-16 13:50:29 -0700 | [diff] [blame^] | 1406 | if (grpc_client_channel_trace.enabled()) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1407 | gpr_log(GPR_DEBUG, |
| 1408 | "chand=%p calld=%p: saved batch, yeilding call combiner", chand, |
| 1409 | calld); |
| 1410 | } |
| 1411 | GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, |
| 1412 | "batch does not include send_initial_metadata"); |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1413 | } |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1414 | done: |
Craig Tiller | a0f3abd | 2017-03-31 15:42:16 -0700 | [diff] [blame] | 1415 | GPR_TIMER_END("cc_start_transport_stream_op_batch", 0); |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1418 | /* Constructor for call_data */ |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1419 | static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, |
| 1420 | grpc_call_element *elem, |
Craig Tiller | c52ba3a | 2017-02-15 22:57:43 -0800 | [diff] [blame] | 1421 | const grpc_call_element_args *args) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1422 | call_data *calld = (call_data *)elem->call_data; |
| 1423 | channel_data *chand = (channel_data *)elem->channel_data; |
Mark D. Roth | e40dd29 | 2016-10-05 14:58:37 -0700 | [diff] [blame] | 1424 | // Initialize data members. |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 1425 | calld->path = grpc_slice_ref_internal(args->path); |
Mark D. Roth | ff08f33 | 2016-10-14 13:01:01 -0700 | [diff] [blame] | 1426 | calld->call_start_time = args->start_time; |
Craig Tiller | 89c1428 | 2017-07-19 15:32:27 -0700 | [diff] [blame] | 1427 | calld->deadline = args->deadline; |
Craig Tiller | d426cac | 2017-03-13 12:30:45 -0700 | [diff] [blame] | 1428 | calld->arena = args->arena; |
Mark D. Roth | 66f3d2b | 2017-09-01 09:02:17 -0700 | [diff] [blame] | 1429 | calld->owning_call = args->call_stack; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1430 | calld->call_combiner = args->call_combiner; |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 1431 | if (chand->deadline_checking_enabled) { |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1432 | grpc_deadline_state_init(exec_ctx, elem, args->call_stack, |
| 1433 | args->call_combiner, calld->deadline); |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 1434 | } |
Mark D. Roth | 0badbe8 | 2016-06-23 10:15:12 -0700 | [diff] [blame] | 1435 | return GRPC_ERROR_NONE; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /* Destructor for call_data */ |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1439 | static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, |
| 1440 | grpc_call_element *elem, |
| 1441 | const grpc_call_final_info *final_info, |
Craig Tiller | d426cac | 2017-03-13 12:30:45 -0700 | [diff] [blame] | 1442 | grpc_closure *then_schedule_closure) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1443 | call_data *calld = (call_data *)elem->call_data; |
| 1444 | channel_data *chand = (channel_data *)elem->channel_data; |
Craig Tiller | 3be7dd0 | 2017-04-03 14:30:03 -0700 | [diff] [blame] | 1445 | if (chand->deadline_checking_enabled) { |
| 1446 | grpc_deadline_state_destroy(exec_ctx, elem); |
| 1447 | } |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 1448 | grpc_slice_unref_internal(exec_ctx, calld->path); |
Mark D. Roth | 95b627b | 2017-02-24 11:02:58 -0800 | [diff] [blame] | 1449 | if (calld->method_params != NULL) { |
| 1450 | method_parameters_unref(calld->method_params); |
| 1451 | } |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1452 | GRPC_ERROR_UNREF(calld->error); |
| 1453 | if (calld->subchannel_call != NULL) { |
| 1454 | grpc_subchannel_call_set_cleanup_closure(calld->subchannel_call, |
Craig Tiller | f7c8c9f | 2017-05-17 15:22:05 -0700 | [diff] [blame] | 1455 | then_schedule_closure); |
Craig Tiller | d426cac | 2017-03-13 12:30:45 -0700 | [diff] [blame] | 1456 | then_schedule_closure = NULL; |
Mark D. Roth | 76e264b | 2017-08-25 09:03:33 -0700 | [diff] [blame] | 1457 | GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, calld->subchannel_call, |
Craig Tiller | f7c8c9f | 2017-05-17 15:22:05 -0700 | [diff] [blame] | 1458 | "client_channel_destroy_call"); |
Mark D. Roth | 4c0fe49 | 2016-08-31 13:51:55 -0700 | [diff] [blame] | 1459 | } |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1460 | GPR_ASSERT(calld->lb_policy == NULL); |
Mark D. Roth | 0ca0be8 | 2017-06-20 07:49:33 -0700 | [diff] [blame] | 1461 | GPR_ASSERT(calld->waiting_for_pick_batches_count == 0); |
Craig Tiller | 693d394 | 2016-10-27 16:51:25 -0700 | [diff] [blame] | 1462 | if (calld->connected_subchannel != NULL) { |
| 1463 | GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, calld->connected_subchannel, |
| 1464 | "picked"); |
| 1465 | } |
Mark D. Roth | 09e458c | 2017-05-02 08:13:26 -0700 | [diff] [blame] | 1466 | for (size_t i = 0; i < GRPC_CONTEXT_COUNT; ++i) { |
| 1467 | if (calld->subchannel_call_context[i].value != NULL) { |
| 1468 | calld->subchannel_call_context[i].destroy( |
| 1469 | calld->subchannel_call_context[i].value); |
| 1470 | } |
| 1471 | } |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1472 | GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1473 | } |
| 1474 | |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 1475 | static void cc_set_pollset_or_pollset_set(grpc_exec_ctx *exec_ctx, |
| 1476 | grpc_call_element *elem, |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 1477 | grpc_polling_entity *pollent) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1478 | call_data *calld = (call_data *)elem->call_data; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 1479 | calld->pollent = pollent; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1480 | } |
| 1481 | |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1482 | /************************************************************************* |
| 1483 | * EXPORTED SYMBOLS |
| 1484 | */ |
| 1485 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1486 | const grpc_channel_filter grpc_client_channel_filter = { |
Craig Tiller | a0f3abd | 2017-03-31 15:42:16 -0700 | [diff] [blame] | 1487 | cc_start_transport_stream_op_batch, |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 1488 | cc_start_transport_op, |
| 1489 | sizeof(call_data), |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1490 | cc_init_call_elem, |
David Garcia Quintas | 4afce7e | 2016-04-18 16:25:17 -0700 | [diff] [blame] | 1491 | cc_set_pollset_or_pollset_set, |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1492 | cc_destroy_call_elem, |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 1493 | sizeof(channel_data), |
Mark D. Roth | 2a5959f | 2016-09-01 08:20:27 -0700 | [diff] [blame] | 1494 | cc_init_channel_elem, |
| 1495 | cc_destroy_channel_elem, |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 1496 | cc_get_channel_info, |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 1497 | "client-channel", |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 1498 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1499 | |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1500 | static void try_to_connect_locked(grpc_exec_ctx *exec_ctx, void *arg, |
| 1501 | grpc_error *error_ignored) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1502 | channel_data *chand = (channel_data *)arg; |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1503 | if (chand->lb_policy != NULL) { |
Craig Tiller | 2400bf5 | 2017-02-09 16:25:19 -0800 | [diff] [blame] | 1504 | grpc_lb_policy_exit_idle_locked(exec_ctx, chand->lb_policy); |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1505 | } else { |
| 1506 | chand->exit_idle_when_lb_policy_arrives = true; |
| 1507 | if (!chand->started_resolving && chand->resolver != NULL) { |
Mark D. Roth | 60751fe | 2017-07-07 12:50:33 -0700 | [diff] [blame] | 1508 | start_resolving_locked(exec_ctx, chand); |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1509 | } |
| 1510 | } |
Craig Tiller | d2e5cfc | 2017-02-09 13:02:20 -0800 | [diff] [blame] | 1511 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "try_to_connect"); |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 1514 | grpc_connectivity_state grpc_client_channel_check_connectivity_state( |
| 1515 | grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1516 | channel_data *chand = (channel_data *)elem->channel_data; |
Craig Tiller | a8610c0 | 2017-02-14 10:05:11 -0800 | [diff] [blame] | 1517 | grpc_connectivity_state out = |
| 1518 | grpc_connectivity_state_check(&chand->state_tracker); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 1519 | if (out == GRPC_CHANNEL_IDLE && try_to_connect) { |
Craig Tiller | d2e5cfc | 2017-02-09 13:02:20 -0800 | [diff] [blame] | 1520 | GRPC_CHANNEL_STACK_REF(chand->owning_stack, "try_to_connect"); |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1521 | GRPC_CLOSURE_SCHED( |
| 1522 | exec_ctx, GRPC_CLOSURE_CREATE(try_to_connect_locked, chand, |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 1523 | grpc_combiner_scheduler(chand->combiner)), |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1524 | GRPC_ERROR_NONE); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 1525 | } |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 1526 | return out; |
| 1527 | } |
| 1528 | |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1529 | typedef struct external_connectivity_watcher { |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1530 | channel_data *chand; |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 1531 | grpc_polling_entity pollent; |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1532 | grpc_closure *on_complete; |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1533 | grpc_closure *watcher_timer_init; |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1534 | grpc_connectivity_state *state; |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1535 | grpc_closure my_closure; |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1536 | struct external_connectivity_watcher *next; |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1537 | } external_connectivity_watcher; |
| 1538 | |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1539 | static external_connectivity_watcher *lookup_external_connectivity_watcher( |
| 1540 | channel_data *chand, grpc_closure *on_complete) { |
| 1541 | gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); |
| 1542 | external_connectivity_watcher *w = |
| 1543 | chand->external_connectivity_watcher_list_head; |
| 1544 | while (w != NULL && w->on_complete != on_complete) { |
| 1545 | w = w->next; |
| 1546 | } |
| 1547 | gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); |
| 1548 | return w; |
| 1549 | } |
| 1550 | |
| 1551 | static void external_connectivity_watcher_list_append( |
| 1552 | channel_data *chand, external_connectivity_watcher *w) { |
| 1553 | GPR_ASSERT(!lookup_external_connectivity_watcher(chand, w->on_complete)); |
| 1554 | |
| 1555 | gpr_mu_lock(&w->chand->external_connectivity_watcher_list_mu); |
| 1556 | GPR_ASSERT(!w->next); |
| 1557 | w->next = chand->external_connectivity_watcher_list_head; |
| 1558 | chand->external_connectivity_watcher_list_head = w; |
| 1559 | gpr_mu_unlock(&w->chand->external_connectivity_watcher_list_mu); |
| 1560 | } |
| 1561 | |
| 1562 | static void external_connectivity_watcher_list_remove( |
| 1563 | channel_data *chand, external_connectivity_watcher *too_remove) { |
| 1564 | GPR_ASSERT( |
| 1565 | lookup_external_connectivity_watcher(chand, too_remove->on_complete)); |
| 1566 | gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); |
| 1567 | if (too_remove == chand->external_connectivity_watcher_list_head) { |
| 1568 | chand->external_connectivity_watcher_list_head = too_remove->next; |
| 1569 | gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); |
| 1570 | return; |
| 1571 | } |
| 1572 | external_connectivity_watcher *w = |
| 1573 | chand->external_connectivity_watcher_list_head; |
| 1574 | while (w != NULL) { |
| 1575 | if (w->next == too_remove) { |
| 1576 | w->next = w->next->next; |
| 1577 | gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); |
| 1578 | return; |
| 1579 | } |
| 1580 | w = w->next; |
| 1581 | } |
| 1582 | GPR_UNREACHABLE_CODE(return ); |
| 1583 | } |
| 1584 | |
| 1585 | int grpc_client_channel_num_external_connectivity_watchers( |
| 1586 | grpc_channel_element *elem) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1587 | channel_data *chand = (channel_data *)elem->channel_data; |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1588 | int count = 0; |
| 1589 | |
| 1590 | gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); |
| 1591 | external_connectivity_watcher *w = |
| 1592 | chand->external_connectivity_watcher_list_head; |
| 1593 | while (w != NULL) { |
| 1594 | count++; |
| 1595 | w = w->next; |
| 1596 | } |
| 1597 | gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); |
| 1598 | |
| 1599 | return count; |
| 1600 | } |
| 1601 | |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 1602 | static void on_external_watch_complete(grpc_exec_ctx *exec_ctx, void *arg, |
Craig Tiller | 804ff71 | 2016-05-05 16:25:40 -0700 | [diff] [blame] | 1603 | grpc_error *error) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1604 | external_connectivity_watcher *w = (external_connectivity_watcher *)arg; |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1605 | grpc_closure *follow_up = w->on_complete; |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 1606 | grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, |
| 1607 | w->chand->interested_parties); |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 1608 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, |
| 1609 | "external_connectivity_watcher"); |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1610 | external_connectivity_watcher_list_remove(w->chand, w); |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1611 | gpr_free(w); |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1612 | GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1613 | } |
| 1614 | |
Craig Tiller | a8610c0 | 2017-02-14 10:05:11 -0800 | [diff] [blame] | 1615 | static void watch_connectivity_state_locked(grpc_exec_ctx *exec_ctx, void *arg, |
| 1616 | grpc_error *error_ignored) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1617 | external_connectivity_watcher *w = (external_connectivity_watcher *)arg; |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1618 | external_connectivity_watcher *found = NULL; |
| 1619 | if (w->state != NULL) { |
| 1620 | external_connectivity_watcher_list_append(w->chand, w); |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1621 | GRPC_CLOSURE_RUN(exec_ctx, w->watcher_timer_init, GRPC_ERROR_NONE); |
| 1622 | GRPC_CLOSURE_INIT(&w->my_closure, on_external_watch_complete, w, |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1623 | grpc_schedule_on_exec_ctx); |
| 1624 | grpc_connectivity_state_notify_on_state_change( |
| 1625 | exec_ctx, &w->chand->state_tracker, w->state, &w->my_closure); |
| 1626 | } else { |
| 1627 | GPR_ASSERT(w->watcher_timer_init == NULL); |
| 1628 | found = lookup_external_connectivity_watcher(w->chand, w->on_complete); |
| 1629 | if (found) { |
| 1630 | GPR_ASSERT(found->on_complete == w->on_complete); |
| 1631 | grpc_connectivity_state_notify_on_state_change( |
| 1632 | exec_ctx, &found->chand->state_tracker, NULL, &found->my_closure); |
| 1633 | } |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 1634 | grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, |
| 1635 | w->chand->interested_parties); |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1636 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, |
| 1637 | "external_connectivity_watcher"); |
| 1638 | gpr_free(w); |
| 1639 | } |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1640 | } |
| 1641 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 1642 | void grpc_client_channel_watch_connectivity_state( |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 1643 | grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, |
| 1644 | grpc_polling_entity pollent, grpc_connectivity_state *state, |
| 1645 | grpc_closure *closure, grpc_closure *watcher_timer_init) { |
Yash Tibrewal | ca3c1c0 | 2017-09-07 22:47:16 -0700 | [diff] [blame] | 1646 | channel_data *chand = (channel_data *)elem->channel_data; |
| 1647 | external_connectivity_watcher *w = |
| 1648 | (external_connectivity_watcher *)gpr_zalloc(sizeof(*w)); |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 1649 | w->chand = chand; |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 1650 | w->pollent = pollent; |
Mark D. Roth | 9221083 | 2017-05-02 15:04:39 -0700 | [diff] [blame] | 1651 | w->on_complete = closure; |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1652 | w->state = state; |
Alexander Polcyn | c3b1f18 | 2017-04-18 13:51:36 -0700 | [diff] [blame] | 1653 | w->watcher_timer_init = watcher_timer_init; |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 1654 | grpc_polling_entity_add_to_pollset_set(exec_ctx, &w->pollent, |
| 1655 | chand->interested_parties); |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 1656 | GRPC_CHANNEL_STACK_REF(w->chand->owning_stack, |
| 1657 | "external_connectivity_watcher"); |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1658 | GRPC_CLOSURE_SCHED( |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1659 | exec_ctx, |
ncteisen | 274bbbe | 2017-06-08 14:57:11 -0700 | [diff] [blame] | 1660 | GRPC_CLOSURE_INIT(&w->my_closure, watch_connectivity_state_locked, w, |
Craig Tiller | ee4b145 | 2017-05-12 10:56:03 -0700 | [diff] [blame] | 1661 | grpc_combiner_scheduler(chand->combiner)), |
Craig Tiller | 613dafa | 2017-02-09 12:00:43 -0800 | [diff] [blame] | 1662 | GRPC_ERROR_NONE); |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 1663 | } |