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