grpc 1.17.1 → 1.18.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -0,0 +1,177 @@
1
+ /*
2
+ *
3
+ * Copyright 2018 gRPC authors.
4
+ *
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
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
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.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_REQUEST_ROUTING_H
20
+ #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_REQUEST_ROUTING_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
25
+ #include "src/core/ext/filters/client_channel/client_channel_factory.h"
26
+ #include "src/core/ext/filters/client_channel/lb_policy.h"
27
+ #include "src/core/ext/filters/client_channel/resolver.h"
28
+ #include "src/core/lib/channel/channel_args.h"
29
+ #include "src/core/lib/channel/channel_stack.h"
30
+ #include "src/core/lib/debug/trace.h"
31
+ #include "src/core/lib/gprpp/inlined_vector.h"
32
+ #include "src/core/lib/gprpp/orphanable.h"
33
+ #include "src/core/lib/iomgr/call_combiner.h"
34
+ #include "src/core/lib/iomgr/closure.h"
35
+ #include "src/core/lib/iomgr/polling_entity.h"
36
+ #include "src/core/lib/iomgr/pollset_set.h"
37
+ #include "src/core/lib/transport/connectivity_state.h"
38
+ #include "src/core/lib/transport/metadata_batch.h"
39
+
40
+ namespace grpc_core {
41
+
42
+ class RequestRouter {
43
+ public:
44
+ class Request {
45
+ public:
46
+ // Synchronous callback that applies the service config to a call.
47
+ // Returns false if the call should be failed.
48
+ typedef bool (*ApplyServiceConfigCallback)(void* user_data);
49
+
50
+ Request(grpc_call_stack* owning_call, grpc_call_combiner* call_combiner,
51
+ grpc_polling_entity* pollent,
52
+ grpc_metadata_batch* send_initial_metadata,
53
+ uint32_t* send_initial_metadata_flags,
54
+ ApplyServiceConfigCallback apply_service_config,
55
+ void* apply_service_config_user_data, grpc_closure* on_route_done);
56
+
57
+ ~Request();
58
+
59
+ // TODO(roth): It seems a bit ugly to expose this member in a
60
+ // non-const way. Find a better API to avoid this.
61
+ LoadBalancingPolicy::PickState* pick() { return &pick_; }
62
+
63
+ private:
64
+ friend class RequestRouter;
65
+
66
+ class ResolverResultWaiter;
67
+ class AsyncPickCanceller;
68
+
69
+ void ProcessServiceConfigAndStartLbPickLocked();
70
+ void StartLbPickLocked();
71
+ static void LbPickDoneLocked(void* arg, grpc_error* error);
72
+
73
+ void MaybeAddCallToInterestedPartiesLocked();
74
+ void MaybeRemoveCallFromInterestedPartiesLocked();
75
+
76
+ // Populated by caller.
77
+ grpc_call_stack* owning_call_;
78
+ grpc_call_combiner* call_combiner_;
79
+ grpc_polling_entity* pollent_;
80
+ ApplyServiceConfigCallback apply_service_config_;
81
+ void* apply_service_config_user_data_;
82
+ grpc_closure* on_route_done_;
83
+ LoadBalancingPolicy::PickState pick_;
84
+
85
+ // Internal state.
86
+ RequestRouter* request_router_ = nullptr;
87
+ bool pollent_added_to_interested_parties_ = false;
88
+ grpc_closure on_pick_done_;
89
+ AsyncPickCanceller* pick_canceller_ = nullptr;
90
+ };
91
+
92
+ // Synchronous callback that takes the service config JSON string and
93
+ // LB policy name.
94
+ // Returns true if the service config has changed since the last result.
95
+ typedef bool (*ProcessResolverResultCallback)(void* user_data,
96
+ const grpc_channel_args& args,
97
+ const char** lb_policy_name,
98
+ grpc_json** lb_policy_config);
99
+
100
+ RequestRouter(grpc_channel_stack* owning_stack, grpc_combiner* combiner,
101
+ grpc_client_channel_factory* client_channel_factory,
102
+ grpc_pollset_set* interested_parties, TraceFlag* tracer,
103
+ ProcessResolverResultCallback process_resolver_result,
104
+ void* process_resolver_result_user_data, const char* target_uri,
105
+ const grpc_channel_args* args, grpc_error** error);
106
+
107
+ ~RequestRouter();
108
+
109
+ void set_channelz_node(channelz::ClientChannelNode* channelz_node) {
110
+ channelz_node_ = channelz_node;
111
+ }
112
+
113
+ void RouteCallLocked(Request* request);
114
+
115
+ // TODO(roth): Add methods to cancel picks.
116
+
117
+ void ShutdownLocked(grpc_error* error);
118
+
119
+ void ExitIdleLocked();
120
+ void ResetConnectionBackoffLocked();
121
+
122
+ grpc_connectivity_state GetConnectivityState();
123
+ void NotifyOnConnectivityStateChange(grpc_connectivity_state* state,
124
+ grpc_closure* closure);
125
+
126
+ LoadBalancingPolicy* lb_policy() const { return lb_policy_.get(); }
127
+
128
+ private:
129
+ using TraceStringVector = grpc_core::InlinedVector<char*, 3>;
130
+
131
+ class ReresolutionRequestHandler;
132
+ class LbConnectivityWatcher;
133
+
134
+ void StartResolvingLocked();
135
+ void OnResolverShutdownLocked(grpc_error* error);
136
+ void CreateNewLbPolicyLocked(const char* lb_policy_name, grpc_json* lb_config,
137
+ grpc_connectivity_state* connectivity_state,
138
+ grpc_error** connectivity_error,
139
+ TraceStringVector* trace_strings);
140
+ void MaybeAddTraceMessagesForAddressChangesLocked(
141
+ TraceStringVector* trace_strings);
142
+ void ConcatenateAndAddChannelTraceLocked(
143
+ TraceStringVector* trace_strings) const;
144
+ static void OnResolverResultChangedLocked(void* arg, grpc_error* error);
145
+
146
+ void SetConnectivityStateLocked(grpc_connectivity_state state,
147
+ grpc_error* error, const char* reason);
148
+
149
+ // Passed in from caller at construction time.
150
+ grpc_channel_stack* owning_stack_;
151
+ grpc_combiner* combiner_;
152
+ grpc_client_channel_factory* client_channel_factory_;
153
+ grpc_pollset_set* interested_parties_;
154
+ TraceFlag* tracer_;
155
+
156
+ channelz::ClientChannelNode* channelz_node_ = nullptr;
157
+
158
+ // Resolver and associated state.
159
+ OrphanablePtr<Resolver> resolver_;
160
+ ProcessResolverResultCallback process_resolver_result_;
161
+ void* process_resolver_result_user_data_;
162
+ bool started_resolving_ = false;
163
+ grpc_channel_args* resolver_result_ = nullptr;
164
+ bool previous_resolution_contained_addresses_ = false;
165
+ grpc_closure_list waiting_for_resolver_result_closures_;
166
+ grpc_closure on_resolver_result_changed_;
167
+
168
+ // LB policy and associated state.
169
+ OrphanablePtr<LoadBalancingPolicy> lb_policy_;
170
+ bool exit_idle_when_lb_policy_arrives_ = false;
171
+
172
+ grpc_connectivity_state_tracker state_tracker_;
173
+ };
174
+
175
+ } // namespace grpc_core
176
+
177
+ #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_REQUEST_ROUTING_H */
@@ -27,7 +27,7 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount(false,
27
27
  namespace grpc_core {
28
28
 
29
29
  Resolver::Resolver(grpc_combiner* combiner)
30
- : InternallyRefCountedWithTracing(&grpc_trace_resolver_refcount),
30
+ : InternallyRefCounted(&grpc_trace_resolver_refcount),
31
31
  combiner_(GRPC_COMBINER_REF(combiner, "resolver")) {}
32
32
 
33
33
  Resolver::~Resolver() { GRPC_COMBINER_UNREF(combiner_, "resolver"); }
@@ -44,7 +44,7 @@ namespace grpc_core {
44
44
  ///
45
45
  /// Note: All methods with a "Locked" suffix must be called from the
46
46
  /// combiner passed to the constructor.
47
- class Resolver : public InternallyRefCountedWithTracing<Resolver> {
47
+ class Resolver : public InternallyRefCounted<Resolver> {
48
48
  public:
49
49
  // Not copyable nor movable.
50
50
  Resolver(const Resolver&) = delete;
@@ -33,6 +33,7 @@
33
33
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
34
34
  #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
35
35
  #include "src/core/ext/filters/client_channel/resolver_registry.h"
36
+ #include "src/core/ext/filters/client_channel/server_address.h"
36
37
  #include "src/core/lib/backoff/backoff.h"
37
38
  #include "src/core/lib/channel/channel_args.h"
38
39
  #include "src/core/lib/gpr/env.h"
@@ -117,7 +118,7 @@ class AresDnsResolver : public Resolver {
117
118
  /// retry backoff state
118
119
  BackOff backoff_;
119
120
  /// currently resolving addresses
120
- grpc_lb_addresses* lb_addresses_ = nullptr;
121
+ UniquePtr<ServerAddressList> addresses_;
121
122
  /// currently resolving service config
122
123
  char* service_config_json_ = nullptr;
123
124
  // has shutdown been initiated
@@ -169,7 +170,7 @@ AresDnsResolver::AresDnsResolver(const ResolverArgs& args)
169
170
  }
170
171
 
171
172
  AresDnsResolver::~AresDnsResolver() {
172
- gpr_log(GPR_DEBUG, "destroying AresDnsResolver");
173
+ GRPC_CARES_TRACE_LOG("resolver:%p destroying AresDnsResolver", this);
173
174
  if (resolved_result_ != nullptr) {
174
175
  grpc_channel_args_destroy(resolved_result_);
175
176
  }
@@ -181,7 +182,8 @@ AresDnsResolver::~AresDnsResolver() {
181
182
 
182
183
  void AresDnsResolver::NextLocked(grpc_channel_args** target_result,
183
184
  grpc_closure* on_complete) {
184
- gpr_log(GPR_DEBUG, "AresDnsResolver::NextLocked() is called.");
185
+ GRPC_CARES_TRACE_LOG("resolver:%p AresDnsResolver::NextLocked() is called.",
186
+ this);
185
187
  GPR_ASSERT(next_completion_ == nullptr);
186
188
  next_completion_ = on_complete;
187
189
  target_result_ = target_result;
@@ -224,12 +226,14 @@ void AresDnsResolver::ShutdownLocked() {
224
226
  void AresDnsResolver::OnNextResolutionLocked(void* arg, grpc_error* error) {
225
227
  AresDnsResolver* r = static_cast<AresDnsResolver*>(arg);
226
228
  GRPC_CARES_TRACE_LOG(
227
- "%p re-resolution timer fired. error: %s. shutdown_initiated_: %d", r,
228
- grpc_error_string(error), r->shutdown_initiated_);
229
+ "resolver:%p re-resolution timer fired. error: %s. shutdown_initiated_: "
230
+ "%d",
231
+ r, grpc_error_string(error), r->shutdown_initiated_);
229
232
  r->have_next_resolution_timer_ = false;
230
233
  if (error == GRPC_ERROR_NONE && !r->shutdown_initiated_) {
231
234
  if (!r->resolving_) {
232
- GRPC_CARES_TRACE_LOG("%p start resolving due to re-resolution timer", r);
235
+ GRPC_CARES_TRACE_LOG(
236
+ "resolver:%p start resolving due to re-resolution timer", r);
233
237
  r->StartResolvingLocked();
234
238
  }
235
239
  }
@@ -314,20 +318,20 @@ void AresDnsResolver::OnResolvedLocked(void* arg, grpc_error* error) {
314
318
  r->resolving_ = false;
315
319
  gpr_free(r->pending_request_);
316
320
  r->pending_request_ = nullptr;
317
- if (r->lb_addresses_ != nullptr) {
321
+ if (r->addresses_ != nullptr) {
318
322
  static const char* args_to_remove[1];
319
323
  size_t num_args_to_remove = 0;
320
324
  grpc_arg args_to_add[2];
321
325
  size_t num_args_to_add = 0;
322
326
  args_to_add[num_args_to_add++] =
323
- grpc_lb_addresses_create_channel_arg(r->lb_addresses_);
327
+ CreateServerAddressListChannelArg(r->addresses_.get());
324
328
  char* service_config_string = nullptr;
325
329
  if (r->service_config_json_ != nullptr) {
326
330
  service_config_string = ChooseServiceConfig(r->service_config_json_);
327
331
  gpr_free(r->service_config_json_);
328
332
  if (service_config_string != nullptr) {
329
- gpr_log(GPR_INFO, "selected service config choice: %s",
330
- service_config_string);
333
+ GRPC_CARES_TRACE_LOG("resolver:%p selected service config choice: %s",
334
+ r, service_config_string);
331
335
  args_to_remove[num_args_to_remove++] = GRPC_ARG_SERVICE_CONFIG;
332
336
  args_to_add[num_args_to_add++] = grpc_channel_arg_string_create(
333
337
  (char*)GRPC_ARG_SERVICE_CONFIG, service_config_string);
@@ -337,17 +341,17 @@ void AresDnsResolver::OnResolvedLocked(void* arg, grpc_error* error) {
337
341
  r->channel_args_, args_to_remove, num_args_to_remove, args_to_add,
338
342
  num_args_to_add);
339
343
  gpr_free(service_config_string);
340
- grpc_lb_addresses_destroy(r->lb_addresses_);
344
+ r->addresses_.reset();
341
345
  // Reset backoff state so that we start from the beginning when the
342
346
  // next request gets triggered.
343
347
  r->backoff_.Reset();
344
348
  } else if (!r->shutdown_initiated_) {
345
349
  const char* msg = grpc_error_string(error);
346
- gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg);
350
+ GRPC_CARES_TRACE_LOG("resolver:%p dns resolution failed: %s", r, msg);
347
351
  grpc_millis next_try = r->backoff_.NextAttemptTime();
348
352
  grpc_millis timeout = next_try - ExecCtx::Get()->Now();
349
- gpr_log(GPR_INFO, "dns resolution failed (will retry): %s",
350
- grpc_error_string(error));
353
+ GRPC_CARES_TRACE_LOG("resolver:%p dns resolution failed (will retry): %s",
354
+ r, grpc_error_string(error));
351
355
  GPR_ASSERT(!r->have_next_resolution_timer_);
352
356
  r->have_next_resolution_timer_ = true;
353
357
  // TODO(roth): We currently deal with this ref manually. Once the
@@ -356,9 +360,10 @@ void AresDnsResolver::OnResolvedLocked(void* arg, grpc_error* error) {
356
360
  RefCountedPtr<Resolver> self = r->Ref(DEBUG_LOCATION, "retry-timer");
357
361
  self.release();
358
362
  if (timeout > 0) {
359
- gpr_log(GPR_DEBUG, "retrying in %" PRId64 " milliseconds", timeout);
363
+ GRPC_CARES_TRACE_LOG("resolver:%p retrying in %" PRId64 " milliseconds",
364
+ r, timeout);
360
365
  } else {
361
- gpr_log(GPR_DEBUG, "retrying immediately");
366
+ GRPC_CARES_TRACE_LOG("resolver:%p retrying immediately", r);
362
367
  }
363
368
  grpc_timer_init(&r->next_resolution_timer_, next_try,
364
369
  &r->on_next_resolution_);
@@ -384,10 +389,10 @@ void AresDnsResolver::MaybeStartResolvingLocked() {
384
389
  if (ms_until_next_resolution > 0) {
385
390
  const grpc_millis last_resolution_ago =
386
391
  grpc_core::ExecCtx::Get()->Now() - last_resolution_timestamp_;
387
- gpr_log(GPR_DEBUG,
388
- "In cooldown from last resolution (from %" PRId64
389
- " ms ago). Will resolve again in %" PRId64 " ms",
390
- last_resolution_ago, ms_until_next_resolution);
392
+ GRPC_CARES_TRACE_LOG(
393
+ "resolver:%p In cooldown from last resolution (from %" PRId64
394
+ " ms ago). Will resolve again in %" PRId64 " ms",
395
+ this, last_resolution_ago, ms_until_next_resolution);
391
396
  have_next_resolution_timer_ = true;
392
397
  // TODO(roth): We currently deal with this ref manually. Once the
393
398
  // new closure API is done, find a way to track this ref with the timer
@@ -404,7 +409,6 @@ void AresDnsResolver::MaybeStartResolvingLocked() {
404
409
  }
405
410
 
406
411
  void AresDnsResolver::StartResolvingLocked() {
407
- gpr_log(GPR_DEBUG, "Start resolving.");
408
412
  // TODO(roth): We currently deal with this ref manually. Once the
409
413
  // new closure API is done, find a way to track this ref with the timer
410
414
  // callback as part of the type system.
@@ -412,14 +416,15 @@ void AresDnsResolver::StartResolvingLocked() {
412
416
  self.release();
413
417
  GPR_ASSERT(!resolving_);
414
418
  resolving_ = true;
415
- lb_addresses_ = nullptr;
416
419
  service_config_json_ = nullptr;
417
420
  pending_request_ = grpc_dns_lookup_ares_locked(
418
421
  dns_server_, name_to_resolve_, kDefaultPort, interested_parties_,
419
- &on_resolved_, &lb_addresses_, true /* check_grpclb */,
422
+ &on_resolved_, &addresses_, true /* check_grpclb */,
420
423
  request_service_config_ ? &service_config_json_ : nullptr,
421
424
  query_timeout_ms_, combiner());
422
425
  last_resolution_timestamp_ = grpc_core::ExecCtx::Get()->Now();
426
+ GRPC_CARES_TRACE_LOG("resolver:%p Started resolving. pending_request_:%p",
427
+ this, pending_request_);
423
428
  }
424
429
 
425
430
  void AresDnsResolver::MaybeFinishNextLocked() {
@@ -427,7 +432,8 @@ void AresDnsResolver::MaybeFinishNextLocked() {
427
432
  *target_result_ = resolved_result_ == nullptr
428
433
  ? nullptr
429
434
  : grpc_channel_args_copy(resolved_result_);
430
- gpr_log(GPR_DEBUG, "AresDnsResolver::MaybeFinishNextLocked()");
435
+ GRPC_CARES_TRACE_LOG("resolver:%p AresDnsResolver::MaybeFinishNextLocked()",
436
+ this);
431
437
  GRPC_CLOSURE_SCHED(next_completion_, GRPC_ERROR_NONE);
432
438
  next_completion_ = nullptr;
433
439
  published_version_ = resolved_version_;
@@ -465,11 +471,16 @@ static grpc_error* blocking_resolve_address_ares(
465
471
  static grpc_address_resolver_vtable ares_resolver = {
466
472
  grpc_resolve_address_ares, blocking_resolve_address_ares};
467
473
 
474
+ static bool should_use_ares(const char* resolver_env) {
475
+ return resolver_env != nullptr && gpr_stricmp(resolver_env, "ares") == 0;
476
+ }
477
+
468
478
  void grpc_resolver_dns_ares_init() {
469
479
  char* resolver_env = gpr_getenv("GRPC_DNS_RESOLVER");
470
480
  /* TODO(zyc): Turn on c-ares based resolver by default after the address
471
481
  sorter and the CNAME support are added. */
472
- if (resolver_env != nullptr && gpr_stricmp(resolver_env, "ares") == 0) {
482
+ if (should_use_ares(resolver_env)) {
483
+ gpr_log(GPR_DEBUG, "Using ares dns resolver");
473
484
  address_sorting_init();
474
485
  grpc_error* error = grpc_ares_init();
475
486
  if (error != GRPC_ERROR_NONE) {
@@ -489,7 +500,7 @@ void grpc_resolver_dns_ares_init() {
489
500
 
490
501
  void grpc_resolver_dns_ares_shutdown() {
491
502
  char* resolver_env = gpr_getenv("GRPC_DNS_RESOLVER");
492
- if (resolver_env != nullptr && gpr_stricmp(resolver_env, "ares") == 0) {
503
+ if (should_use_ares(resolver_env)) {
493
504
  address_sorting_shutdown();
494
505
  grpc_ares_cleanup();
495
506
  }
@@ -31,6 +31,7 @@
31
31
  #include <grpc/support/time.h>
32
32
  #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
33
33
  #include "src/core/lib/gpr/string.h"
34
+ #include "src/core/lib/iomgr/combiner.h"
34
35
  #include "src/core/lib/iomgr/iomgr_internal.h"
35
36
  #include "src/core/lib/iomgr/sockaddr_utils.h"
36
37
  #include "src/core/lib/iomgr/timer.h"
@@ -89,15 +90,18 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver);
89
90
 
90
91
  static grpc_ares_ev_driver* grpc_ares_ev_driver_ref(
91
92
  grpc_ares_ev_driver* ev_driver) {
92
- gpr_log(GPR_DEBUG, "Ref ev_driver %" PRIuPTR, (uintptr_t)ev_driver);
93
+ GRPC_CARES_TRACE_LOG("request:%p Ref ev_driver %p", ev_driver->request,
94
+ ev_driver);
93
95
  gpr_ref(&ev_driver->refs);
94
96
  return ev_driver;
95
97
  }
96
98
 
97
99
  static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) {
98
- gpr_log(GPR_DEBUG, "Unref ev_driver %" PRIuPTR, (uintptr_t)ev_driver);
100
+ GRPC_CARES_TRACE_LOG("request:%p Unref ev_driver %p", ev_driver->request,
101
+ ev_driver);
99
102
  if (gpr_unref(&ev_driver->refs)) {
100
- gpr_log(GPR_DEBUG, "destroy ev_driver %" PRIuPTR, (uintptr_t)ev_driver);
103
+ GRPC_CARES_TRACE_LOG("request:%p destroy ev_driver %p", ev_driver->request,
104
+ ev_driver);
101
105
  GPR_ASSERT(ev_driver->fds == nullptr);
102
106
  GRPC_COMBINER_UNREF(ev_driver->combiner, "free ares event driver");
103
107
  ares_destroy(ev_driver->channel);
@@ -107,7 +111,8 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) {
107
111
  }
108
112
 
109
113
  static void fd_node_destroy_locked(fd_node* fdn) {
110
- gpr_log(GPR_DEBUG, "delete fd: %s", fdn->grpc_polled_fd->GetName());
114
+ GRPC_CARES_TRACE_LOG("request:%p delete fd: %s", fdn->ev_driver->request,
115
+ fdn->grpc_polled_fd->GetName());
111
116
  GPR_ASSERT(!fdn->readable_registered);
112
117
  GPR_ASSERT(!fdn->writable_registered);
113
118
  GPR_ASSERT(fdn->already_shutdown);
@@ -135,7 +140,7 @@ grpc_error* grpc_ares_ev_driver_create_locked(grpc_ares_ev_driver** ev_driver,
135
140
  memset(&opts, 0, sizeof(opts));
136
141
  opts.flags |= ARES_FLAG_STAYOPEN;
137
142
  int status = ares_init_options(&(*ev_driver)->channel, &opts, ARES_OPT_FLAGS);
138
- gpr_log(GPR_DEBUG, "grpc_ares_ev_driver_create_locked");
143
+ GRPC_CARES_TRACE_LOG("request:%p grpc_ares_ev_driver_create_locked", request);
139
144
  if (status != ARES_SUCCESS) {
140
145
  char* err_msg;
141
146
  gpr_asprintf(&err_msg, "Failed to init ares channel. C-ares error: %s",
@@ -202,8 +207,9 @@ static fd_node* pop_fd_node_locked(fd_node** head, ares_socket_t as) {
202
207
  static void on_timeout_locked(void* arg, grpc_error* error) {
203
208
  grpc_ares_ev_driver* driver = static_cast<grpc_ares_ev_driver*>(arg);
204
209
  GRPC_CARES_TRACE_LOG(
205
- "ev_driver=%p on_timeout_locked. driver->shutting_down=%d. err=%s",
206
- driver, driver->shutting_down, grpc_error_string(error));
210
+ "request:%p ev_driver=%p on_timeout_locked. driver->shutting_down=%d. "
211
+ "err=%s",
212
+ driver->request, driver, driver->shutting_down, grpc_error_string(error));
207
213
  if (!driver->shutting_down && error == GRPC_ERROR_NONE) {
208
214
  grpc_ares_ev_driver_shutdown_locked(driver);
209
215
  }
@@ -215,7 +221,8 @@ static void on_readable_locked(void* arg, grpc_error* error) {
215
221
  grpc_ares_ev_driver* ev_driver = fdn->ev_driver;
216
222
  const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked();
217
223
  fdn->readable_registered = false;
218
- gpr_log(GPR_DEBUG, "readable on %s", fdn->grpc_polled_fd->GetName());
224
+ GRPC_CARES_TRACE_LOG("request:%p readable on %s", fdn->ev_driver->request,
225
+ fdn->grpc_polled_fd->GetName());
219
226
  if (error == GRPC_ERROR_NONE) {
220
227
  do {
221
228
  ares_process_fd(ev_driver->channel, as, ARES_SOCKET_BAD);
@@ -238,7 +245,8 @@ static void on_writable_locked(void* arg, grpc_error* error) {
238
245
  grpc_ares_ev_driver* ev_driver = fdn->ev_driver;
239
246
  const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked();
240
247
  fdn->writable_registered = false;
241
- gpr_log(GPR_DEBUG, "writable on %s", fdn->grpc_polled_fd->GetName());
248
+ GRPC_CARES_TRACE_LOG("request:%p writable on %s", ev_driver->request,
249
+ fdn->grpc_polled_fd->GetName());
242
250
  if (error == GRPC_ERROR_NONE) {
243
251
  ares_process_fd(ev_driver->channel, ARES_SOCKET_BAD, as);
244
252
  } else {
@@ -277,7 +285,8 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) {
277
285
  fdn->grpc_polled_fd =
278
286
  ev_driver->polled_fd_factory->NewGrpcPolledFdLocked(
279
287
  socks[i], ev_driver->pollset_set, ev_driver->combiner);
280
- gpr_log(GPR_DEBUG, "new fd: %s", fdn->grpc_polled_fd->GetName());
288
+ GRPC_CARES_TRACE_LOG("request:%p new fd: %s", ev_driver->request,
289
+ fdn->grpc_polled_fd->GetName());
281
290
  fdn->ev_driver = ev_driver;
282
291
  fdn->readable_registered = false;
283
292
  fdn->writable_registered = false;
@@ -294,8 +303,9 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) {
294
303
  if (ARES_GETSOCK_READABLE(socks_bitmask, i) &&
295
304
  !fdn->readable_registered) {
296
305
  grpc_ares_ev_driver_ref(ev_driver);
297
- gpr_log(GPR_DEBUG, "notify read on: %s",
298
- fdn->grpc_polled_fd->GetName());
306
+ GRPC_CARES_TRACE_LOG("request:%p notify read on: %s",
307
+ ev_driver->request,
308
+ fdn->grpc_polled_fd->GetName());
299
309
  fdn->grpc_polled_fd->RegisterForOnReadableLocked(&fdn->read_closure);
300
310
  fdn->readable_registered = true;
301
311
  }
@@ -303,8 +313,9 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) {
303
313
  // has not been registered with this socket.
304
314
  if (ARES_GETSOCK_WRITABLE(socks_bitmask, i) &&
305
315
  !fdn->writable_registered) {
306
- gpr_log(GPR_DEBUG, "notify write on: %s",
307
- fdn->grpc_polled_fd->GetName());
316
+ GRPC_CARES_TRACE_LOG("request:%p notify write on: %s",
317
+ ev_driver->request,
318
+ fdn->grpc_polled_fd->GetName());
308
319
  grpc_ares_ev_driver_ref(ev_driver);
309
320
  fdn->grpc_polled_fd->RegisterForOnWriteableLocked(
310
321
  &fdn->write_closure);
@@ -331,7 +342,8 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) {
331
342
  // If the ev driver has no working fd, all the tasks are done.
332
343
  if (new_list == nullptr) {
333
344
  ev_driver->working = false;
334
- gpr_log(GPR_DEBUG, "ev driver stop working");
345
+ GRPC_CARES_TRACE_LOG("request:%p ev driver stop working",
346
+ ev_driver->request);
335
347
  }
336
348
  }
337
349
 
@@ -344,9 +356,9 @@ void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver* ev_driver) {
344
356
  ? GRPC_MILLIS_INF_FUTURE
345
357
  : ev_driver->query_timeout_ms + grpc_core::ExecCtx::Get()->Now();
346
358
  GRPC_CARES_TRACE_LOG(
347
- "ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in %" PRId64
348
- " ms",
349
- ev_driver, timeout);
359
+ "request:%p ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in "
360
+ "%" PRId64 " ms",
361
+ ev_driver->request, ev_driver, timeout);
350
362
  grpc_ares_ev_driver_ref(ev_driver);
351
363
  grpc_timer_init(&ev_driver->query_timeout, timeout,
352
364
  &ev_driver->on_timeout_locked);