grpc 1.18.0 → 1.19.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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +301 -33
  3. data/include/grpc/grpc_security.h +195 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +17 -1
  5. data/include/grpc/impl/codegen/port_platform.h +36 -0
  6. data/include/grpc/impl/codegen/slice.h +1 -1
  7. data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
  8. data/src/core/ext/filters/client_channel/client_channel.cc +74 -69
  9. data/src/core/ext/filters/client_channel/client_channel.h +2 -2
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +5 -6
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +5 -4
  12. data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -2
  13. data/src/core/ext/filters/client_channel/client_channel_factory.h +4 -4
  14. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
  15. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +176 -0
  16. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  17. data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -8
  18. data/src/core/ext/filters/client_channel/health/health_check_client.h +1 -1
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -156
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +30 -1
  21. data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +28 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -8
  25. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +23 -24
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +80 -15
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +6 -1
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  30. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  31. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  32. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  33. data/src/core/ext/filters/client_channel/request_routing.cc +13 -3
  34. data/src/core/ext/filters/client_channel/request_routing.h +5 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -6
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  37. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -35
  38. data/src/core/ext/filters/client_channel/subchannel.cc +698 -791
  39. data/src/core/ext/filters/client_channel/subchannel.h +213 -123
  40. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  41. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +5 -2
  43. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  44. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  45. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +5 -7
  46. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +19 -27
  47. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +18 -19
  48. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +27 -6
  49. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  50. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -2
  51. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +8 -5
  53. data/src/core/lib/channel/handshaker.cc +141 -214
  54. data/src/core/lib/channel/handshaker.h +110 -101
  55. data/src/core/lib/channel/handshaker_factory.h +11 -19
  56. data/src/core/lib/channel/handshaker_registry.cc +64 -52
  57. data/src/core/lib/channel/handshaker_registry.h +21 -16
  58. data/src/core/lib/gpr/log_posix.cc +2 -1
  59. data/src/core/lib/gpr/time.cc +8 -0
  60. data/src/core/lib/gpr/time_posix.cc +8 -2
  61. data/src/core/lib/gprpp/optional.h +47 -0
  62. data/src/core/lib/http/httpcli_security_connector.cc +13 -14
  63. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  64. data/src/core/lib/iomgr/buffer_list.h +70 -8
  65. data/src/core/lib/iomgr/combiner.cc +11 -3
  66. data/src/core/lib/iomgr/error.cc +9 -5
  67. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -0
  68. data/src/core/lib/iomgr/ev_epollex_linux.cc +136 -162
  69. data/src/core/lib/iomgr/ev_poll_posix.cc +3 -0
  70. data/src/core/lib/iomgr/ev_posix.cc +4 -0
  71. data/src/core/lib/iomgr/ev_posix.h +4 -0
  72. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  73. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  74. data/src/core/lib/iomgr/executor.cc +122 -87
  75. data/src/core/lib/iomgr/executor.h +53 -48
  76. data/src/core/lib/iomgr/fork_posix.cc +6 -4
  77. data/src/core/lib/iomgr/{network_status_tracker.cc → grpc_if_nametoindex.h} +8 -14
  78. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  79. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  80. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  81. data/src/core/lib/iomgr/iomgr.cc +6 -5
  82. data/src/core/lib/iomgr/iomgr.h +8 -0
  83. data/src/core/lib/iomgr/iomgr_custom.cc +6 -2
  84. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  85. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  86. data/src/core/lib/iomgr/iomgr_posix.cc +10 -1
  87. data/src/core/lib/iomgr/iomgr_windows.cc +8 -1
  88. data/src/core/lib/iomgr/port.h +1 -0
  89. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  90. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  91. data/src/core/lib/iomgr/tcp_custom.cc +0 -4
  92. data/src/core/lib/iomgr/tcp_posix.cc +58 -44
  93. data/src/core/lib/iomgr/tcp_uv.cc +0 -1
  94. data/src/core/lib/iomgr/tcp_windows.cc +0 -4
  95. data/src/core/lib/iomgr/timer_manager.cc +8 -0
  96. data/src/core/lib/iomgr/udp_server.cc +6 -4
  97. data/src/core/lib/json/json.cc +1 -4
  98. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  99. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  100. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  101. data/src/core/lib/security/credentials/credentials.h +9 -1
  102. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -2
  103. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  104. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  105. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -0
  106. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  107. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
  108. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -0
  109. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  110. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +213 -0
  111. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  112. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  113. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  114. data/src/core/lib/security/security_connector/security_connector.h +2 -2
  115. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -6
  116. data/src/core/lib/security/security_connector/ssl_utils.h +33 -0
  117. data/src/core/lib/security/transport/security_handshaker.cc +267 -300
  118. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  119. data/src/core/lib/security/transport/server_auth_filter.cc +1 -0
  120. data/src/core/lib/surface/call.cc +5 -1
  121. data/src/core/lib/surface/channel_init.h +5 -0
  122. data/src/core/lib/surface/completion_queue.cc +4 -7
  123. data/src/core/lib/surface/init.cc +5 -3
  124. data/src/core/lib/surface/init_secure.cc +1 -1
  125. data/src/core/lib/surface/server.cc +19 -17
  126. data/src/core/lib/surface/version.cc +1 -1
  127. data/src/core/lib/transport/service_config.h +1 -0
  128. data/src/core/lib/transport/static_metadata.cc +279 -279
  129. data/src/core/lib/transport/transport.cc +5 -3
  130. data/src/core/tsi/ssl_transport_security.cc +10 -4
  131. data/src/ruby/ext/grpc/extconf.rb +12 -4
  132. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  133. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  134. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  135. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  136. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  137. data/src/ruby/ext/grpc/rb_grpc.c +22 -23
  138. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -0
  140. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +27 -0
  141. data/src/ruby/ext/grpc/rb_server.c +8 -4
  142. data/src/ruby/lib/grpc/version.rb +1 -1
  143. metadata +46 -39
  144. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  145. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  146. data/src/core/lib/channel/handshaker_factory.cc +0 -42
@@ -23,55 +23,50 @@
23
23
 
24
24
  #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
25
25
  #include "src/core/ext/filters/client_channel/connector.h"
26
+ #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
27
+ #include "src/core/lib/backoff/backoff.h"
26
28
  #include "src/core/lib/channel/channel_stack.h"
27
29
  #include "src/core/lib/gpr/arena.h"
28
30
  #include "src/core/lib/gprpp/ref_counted.h"
29
31
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
30
32
  #include "src/core/lib/iomgr/polling_entity.h"
33
+ #include "src/core/lib/iomgr/timer.h"
31
34
  #include "src/core/lib/transport/connectivity_state.h"
32
35
  #include "src/core/lib/transport/metadata.h"
33
36
 
34
37
  // Channel arg containing a grpc_resolved_address to connect to.
35
38
  #define GRPC_ARG_SUBCHANNEL_ADDRESS "grpc.subchannel_address"
36
39
 
37
- /** A (sub-)channel that knows how to connect to exactly one target
38
- address. Provides a target for load balancing. */
39
- typedef struct grpc_subchannel grpc_subchannel;
40
- typedef struct grpc_subchannel_call grpc_subchannel_call;
41
- typedef struct grpc_subchannel_args grpc_subchannel_args;
42
- typedef struct grpc_subchannel_key grpc_subchannel_key;
43
-
40
+ // For debugging refcounting.
44
41
  #ifndef NDEBUG
45
- #define GRPC_SUBCHANNEL_REF(p, r) \
46
- grpc_subchannel_ref((p), __FILE__, __LINE__, (r))
42
+ #define GRPC_SUBCHANNEL_REF(p, r) (p)->Ref(__FILE__, __LINE__, (r))
47
43
  #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \
48
- grpc_subchannel_ref_from_weak_ref((p), __FILE__, __LINE__, (r))
49
- #define GRPC_SUBCHANNEL_UNREF(p, r) \
50
- grpc_subchannel_unref((p), __FILE__, __LINE__, (r))
51
- #define GRPC_SUBCHANNEL_WEAK_REF(p, r) \
52
- grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r))
53
- #define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) \
54
- grpc_subchannel_weak_unref((p), __FILE__, __LINE__, (r))
55
- #define GRPC_SUBCHANNEL_CALL_REF(p, r) \
56
- grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r))
57
- #define GRPC_SUBCHANNEL_CALL_UNREF(p, r) \
58
- grpc_subchannel_call_unref((p), __FILE__, __LINE__, (r))
44
+ (p)->RefFromWeakRef(__FILE__, __LINE__, (r))
45
+ #define GRPC_SUBCHANNEL_UNREF(p, r) (p)->Unref(__FILE__, __LINE__, (r))
46
+ #define GRPC_SUBCHANNEL_WEAK_REF(p, r) (p)->WeakRef(__FILE__, __LINE__, (r))
47
+ #define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) (p)->WeakUnref(__FILE__, __LINE__, (r))
59
48
  #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \
60
- , const char *file, int line, const char *reason
49
+ const char *file, int line, const char *reason
50
+ #define GRPC_SUBCHANNEL_REF_REASON reason
51
+ #define GRPC_SUBCHANNEL_REF_MUTATE_EXTRA_ARGS \
52
+ , GRPC_SUBCHANNEL_REF_EXTRA_ARGS, const char* purpose
53
+ #define GRPC_SUBCHANNEL_REF_MUTATE_PURPOSE(x) , file, line, reason, x
61
54
  #else
62
- #define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p))
63
- #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \
64
- grpc_subchannel_ref_from_weak_ref((p))
65
- #define GRPC_SUBCHANNEL_UNREF(p, r) grpc_subchannel_unref((p))
66
- #define GRPC_SUBCHANNEL_WEAK_REF(p, r) grpc_subchannel_weak_ref((p))
67
- #define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) grpc_subchannel_weak_unref((p))
68
- #define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p))
69
- #define GRPC_SUBCHANNEL_CALL_UNREF(p, r) grpc_subchannel_call_unref((p))
55
+ #define GRPC_SUBCHANNEL_REF(p, r) (p)->Ref()
56
+ #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) (p)->RefFromWeakRef()
57
+ #define GRPC_SUBCHANNEL_UNREF(p, r) (p)->Unref()
58
+ #define GRPC_SUBCHANNEL_WEAK_REF(p, r) (p)->WeakRef()
59
+ #define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) (p)->WeakUnref()
70
60
  #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS
61
+ #define GRPC_SUBCHANNEL_REF_REASON ""
62
+ #define GRPC_SUBCHANNEL_REF_MUTATE_EXTRA_ARGS
63
+ #define GRPC_SUBCHANNEL_REF_MUTATE_PURPOSE(x)
71
64
  #endif
72
65
 
73
66
  namespace grpc_core {
74
67
 
68
+ class SubchannelCall;
69
+
75
70
  class ConnectedSubchannel : public RefCounted<ConnectedSubchannel> {
76
71
  public:
77
72
  struct CallArgs {
@@ -87,8 +82,7 @@ class ConnectedSubchannel : public RefCounted<ConnectedSubchannel> {
87
82
 
88
83
  ConnectedSubchannel(
89
84
  grpc_channel_stack* channel_stack, const grpc_channel_args* args,
90
- grpc_core::RefCountedPtr<grpc_core::channelz::SubchannelNode>
91
- channelz_subchannel,
85
+ RefCountedPtr<channelz::SubchannelNode> channelz_subchannel,
92
86
  intptr_t socket_uuid);
93
87
  ~ConnectedSubchannel();
94
88
 
@@ -96,7 +90,8 @@ class ConnectedSubchannel : public RefCounted<ConnectedSubchannel> {
96
90
  grpc_connectivity_state* state,
97
91
  grpc_closure* closure);
98
92
  void Ping(grpc_closure* on_initiate, grpc_closure* on_ack);
99
- grpc_error* CreateCall(const CallArgs& args, grpc_subchannel_call** call);
93
+ RefCountedPtr<SubchannelCall> CreateCall(const CallArgs& args,
94
+ grpc_error** error);
100
95
 
101
96
  grpc_channel_stack* channel_stack() const { return channel_stack_; }
102
97
  const grpc_channel_args* args() const { return args_; }
@@ -112,107 +107,202 @@ class ConnectedSubchannel : public RefCounted<ConnectedSubchannel> {
112
107
  grpc_channel_args* args_;
113
108
  // ref counted pointer to the channelz node in this connected subchannel's
114
109
  // owning subchannel.
115
- grpc_core::RefCountedPtr<grpc_core::channelz::SubchannelNode>
116
- channelz_subchannel_;
110
+ RefCountedPtr<channelz::SubchannelNode> channelz_subchannel_;
117
111
  // uuid of this subchannel's socket. 0 if this subchannel is not connected.
118
112
  const intptr_t socket_uuid_;
119
113
  };
120
114
 
121
- } // namespace grpc_core
115
+ // Implements the interface of RefCounted<>.
116
+ class SubchannelCall {
117
+ public:
118
+ SubchannelCall(RefCountedPtr<ConnectedSubchannel> connected_subchannel,
119
+ const ConnectedSubchannel::CallArgs& args)
120
+ : connected_subchannel_(std::move(connected_subchannel)),
121
+ deadline_(args.deadline) {}
122
+
123
+ // Continues processing a transport stream op batch.
124
+ void StartTransportStreamOpBatch(grpc_transport_stream_op_batch* batch);
125
+
126
+ // Returns a pointer to the parent data associated with the subchannel call.
127
+ // The data will be of the size specified in \a parent_data_size field of
128
+ // the args passed to \a ConnectedSubchannel::CreateCall().
129
+ void* GetParentData();
122
130
 
123
- grpc_subchannel* grpc_subchannel_ref(
124
- grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
125
- grpc_subchannel* grpc_subchannel_ref_from_weak_ref(
126
- grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
127
- void grpc_subchannel_unref(
128
- grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
129
- grpc_subchannel* grpc_subchannel_weak_ref(
130
- grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
131
- void grpc_subchannel_weak_unref(
132
- grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
133
- grpc_subchannel_call* grpc_subchannel_call_ref(
134
- grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
135
- void grpc_subchannel_call_unref(
136
- grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
137
-
138
- grpc_core::channelz::SubchannelNode* grpc_subchannel_get_channelz_node(
139
- grpc_subchannel* subchannel);
140
-
141
- intptr_t grpc_subchannel_get_child_socket_uuid(grpc_subchannel* subchannel);
142
-
143
- /** Returns a pointer to the parent data associated with \a subchannel_call.
144
- The data will be of the size specified in \a parent_data_size
145
- field of the args passed to \a grpc_connected_subchannel_create_call(). */
146
- void* grpc_connected_subchannel_call_get_parent_data(
147
- grpc_subchannel_call* subchannel_call);
148
-
149
- /** poll the current connectivity state of a channel */
150
- grpc_connectivity_state grpc_subchannel_check_connectivity(
151
- grpc_subchannel* channel, grpc_error** error, bool inhibit_health_checking);
152
-
153
- /** Calls notify when the connectivity state of a channel becomes different
154
- from *state. Updates *state with the new state of the channel. */
155
- void grpc_subchannel_notify_on_state_change(
156
- grpc_subchannel* channel, grpc_pollset_set* interested_parties,
157
- grpc_connectivity_state* state, grpc_closure* notify,
158
- bool inhibit_health_checks);
159
-
160
- /** retrieve the grpc_core::ConnectedSubchannel - or nullptr if not connected
161
- * (which may happen before it initially connects or during transient failures)
162
- * */
163
- grpc_core::RefCountedPtr<grpc_core::ConnectedSubchannel>
164
- grpc_subchannel_get_connected_subchannel(grpc_subchannel* c);
165
-
166
- /** return the subchannel index key for \a subchannel */
167
- const grpc_subchannel_key* grpc_subchannel_get_key(
168
- const grpc_subchannel* subchannel);
169
-
170
- // Resets the connection backoff of the subchannel.
171
- // TODO(roth): Move connection backoff out of subchannels and up into LB
172
- // policy code (probably by adding a SubchannelGroup between
173
- // SubchannelList and SubchannelData), at which point this method can
174
- // go away.
175
- void grpc_subchannel_reset_backoff(grpc_subchannel* subchannel);
176
-
177
- /** continue processing a transport op */
178
- void grpc_subchannel_call_process_op(grpc_subchannel_call* subchannel_call,
179
- grpc_transport_stream_op_batch* op);
180
-
181
- /** Must be called once per call. Sets the 'then_schedule_closure' argument for
182
- call stack destruction. */
183
- void grpc_subchannel_call_set_cleanup_closure(
184
- grpc_subchannel_call* subchannel_call, grpc_closure* closure);
185
-
186
- grpc_call_stack* grpc_subchannel_call_get_call_stack(
187
- grpc_subchannel_call* subchannel_call);
188
-
189
- struct grpc_subchannel_args {
190
- /* When updating this struct, also update subchannel_index.c */
191
-
192
- /** Channel filters for this channel - wrapped factories will likely
193
- want to mutate this */
194
- const grpc_channel_filter** filters;
195
- /** The number of filters in the above array */
196
- size_t filter_count;
197
- /** Channel arguments to be supplied to the newly created channel */
198
- const grpc_channel_args* args;
131
+ // Returns the call stack of the subchannel call.
132
+ grpc_call_stack* GetCallStack();
133
+
134
+ // Sets the 'then_schedule_closure' argument for call stack destruction.
135
+ // Must be called once per call.
136
+ void SetAfterCallStackDestroy(grpc_closure* closure);
137
+
138
+ // Interface of RefCounted<>.
139
+ RefCountedPtr<SubchannelCall> Ref() GRPC_MUST_USE_RESULT;
140
+ RefCountedPtr<SubchannelCall> Ref(const DebugLocation& location,
141
+ const char* reason) GRPC_MUST_USE_RESULT;
142
+ // When refcount drops to 0, destroys itself and the associated call stack,
143
+ // but does NOT free the memory because it's in the call arena.
144
+ void Unref();
145
+ void Unref(const DebugLocation& location, const char* reason);
146
+
147
+ static void Destroy(void* arg, grpc_error* error);
148
+
149
+ private:
150
+ // Allow RefCountedPtr<> to access IncrementRefCount().
151
+ template <typename T>
152
+ friend class RefCountedPtr;
153
+
154
+ // If channelz is enabled, intercepts recv_trailing so that we may check the
155
+ // status and associate it to a subchannel.
156
+ void MaybeInterceptRecvTrailingMetadata(
157
+ grpc_transport_stream_op_batch* batch);
158
+
159
+ static void RecvTrailingMetadataReady(void* arg, grpc_error* error);
160
+
161
+ // Interface of RefCounted<>.
162
+ void IncrementRefCount();
163
+ void IncrementRefCount(const DebugLocation& location, const char* reason);
164
+
165
+ RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
166
+ grpc_closure* after_call_stack_destroy_ = nullptr;
167
+ // State needed to support channelz interception of recv trailing metadata.
168
+ grpc_closure recv_trailing_metadata_ready_;
169
+ grpc_closure* original_recv_trailing_metadata_ = nullptr;
170
+ grpc_metadata_batch* recv_trailing_metadata_ = nullptr;
171
+ grpc_millis deadline_;
199
172
  };
200
173
 
201
- /** create a subchannel given a connector */
202
- grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
203
- const grpc_subchannel_args* args);
174
+ // A subchannel that knows how to connect to exactly one target address. It
175
+ // provides a target for load balancing.
176
+ class Subchannel {
177
+ public:
178
+ // The ctor and dtor are not intended to use directly.
179
+ Subchannel(SubchannelKey* key, grpc_connector* connector,
180
+ const grpc_channel_args* args);
181
+ ~Subchannel();
182
+
183
+ // Creates a subchannel given \a connector and \a args.
184
+ static Subchannel* Create(grpc_connector* connector,
185
+ const grpc_channel_args* args);
204
186
 
205
- /// Sets \a addr from \a args.
206
- void grpc_get_subchannel_address_arg(const grpc_channel_args* args,
207
- grpc_resolved_address* addr);
187
+ // Strong and weak refcounting.
188
+ Subchannel* Ref(GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
189
+ void Unref(GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
190
+ Subchannel* WeakRef(GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
191
+ void WeakUnref(GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
192
+ Subchannel* RefFromWeakRef(GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
208
193
 
209
- const char* grpc_subchannel_get_target(grpc_subchannel* subchannel);
194
+ intptr_t GetChildSocketUuid();
210
195
 
211
- /// Returns the URI string for the address to connect to.
212
- const char* grpc_get_subchannel_address_uri_arg(const grpc_channel_args* args);
196
+ // Gets the string representing the subchannel address.
197
+ // Caller doesn't take ownership.
198
+ const char* GetTargetAddress();
213
199
 
214
- /// Returns a new channel arg encoding the subchannel address as a string.
215
- /// Caller is responsible for freeing the string.
216
- grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr);
200
+ // Gets the connected subchannel - or nullptr if not connected (which may
201
+ // happen before it initially connects or during transient failures).
202
+ RefCountedPtr<ConnectedSubchannel> connected_subchannel();
203
+
204
+ channelz::SubchannelNode* channelz_node();
205
+
206
+ // Polls the current connectivity state of the subchannel.
207
+ grpc_connectivity_state CheckConnectivity(grpc_error** error,
208
+ bool inhibit_health_checking);
209
+
210
+ // When the connectivity state of the subchannel changes from \a *state,
211
+ // invokes \a notify and updates \a *state with the new state.
212
+ void NotifyOnStateChange(grpc_pollset_set* interested_parties,
213
+ grpc_connectivity_state* state, grpc_closure* notify,
214
+ bool inhibit_health_checking);
215
+
216
+ // Resets the connection backoff of the subchannel.
217
+ // TODO(roth): Move connection backoff out of subchannels and up into LB
218
+ // policy code (probably by adding a SubchannelGroup between
219
+ // SubchannelList and SubchannelData), at which point this method can
220
+ // go away.
221
+ void ResetBackoff();
222
+
223
+ // Returns a new channel arg encoding the subchannel address as a URI
224
+ // string. Caller is responsible for freeing the string.
225
+ static grpc_arg CreateSubchannelAddressArg(const grpc_resolved_address* addr);
226
+
227
+ // Returns the URI string from the subchannel address arg in \a args.
228
+ static const char* GetUriFromSubchannelAddressArg(
229
+ const grpc_channel_args* args);
230
+
231
+ // Sets \a addr from the subchannel address arg in \a args.
232
+ static void GetAddressFromSubchannelAddressArg(const grpc_channel_args* args,
233
+ grpc_resolved_address* addr);
234
+
235
+ private:
236
+ struct ExternalStateWatcher;
237
+ class ConnectedSubchannelStateWatcher;
238
+
239
+ // Sets the subchannel's connectivity state to \a state.
240
+ void SetConnectivityStateLocked(grpc_connectivity_state state,
241
+ grpc_error* error, const char* reason);
242
+
243
+ // Methods for connection.
244
+ void MaybeStartConnectingLocked();
245
+ static void OnRetryAlarm(void* arg, grpc_error* error);
246
+ void ContinueConnectingLocked();
247
+ static void OnConnectingFinished(void* arg, grpc_error* error);
248
+ bool PublishTransportLocked();
249
+ void Disconnect();
250
+
251
+ gpr_atm RefMutate(gpr_atm delta,
252
+ int barrier GRPC_SUBCHANNEL_REF_MUTATE_EXTRA_ARGS);
253
+
254
+ // The subchannel pool this subchannel is in.
255
+ RefCountedPtr<SubchannelPoolInterface> subchannel_pool_;
256
+ // TODO(juanlishen): Consider using args_ as key_ directly.
257
+ // Subchannel key that identifies this subchannel in the subchannel pool.
258
+ SubchannelKey* key_;
259
+ // Channel args.
260
+ grpc_channel_args* args_;
261
+ // pollset_set tracking who's interested in a connection being setup.
262
+ grpc_pollset_set* pollset_set_;
263
+ // Protects the other members.
264
+ gpr_mu mu_;
265
+ // Refcount
266
+ // - lower INTERNAL_REF_BITS bits are for internal references:
267
+ // these do not keep the subchannel open.
268
+ // - upper remaining bits are for public references: these do
269
+ // keep the subchannel open
270
+ gpr_atm ref_pair_;
271
+
272
+ // Connection states.
273
+ grpc_connector* connector_ = nullptr;
274
+ // Set during connection.
275
+ grpc_connect_out_args connecting_result_;
276
+ grpc_closure on_connecting_finished_;
277
+ // Active connection, or null.
278
+ RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
279
+ OrphanablePtr<ConnectedSubchannelStateWatcher> connected_subchannel_watcher_;
280
+ bool connecting_ = false;
281
+ bool disconnected_ = false;
282
+
283
+ // Connectivity state tracking.
284
+ grpc_connectivity_state_tracker state_tracker_;
285
+ grpc_connectivity_state_tracker state_and_health_tracker_;
286
+ UniquePtr<char> health_check_service_name_;
287
+ ExternalStateWatcher* external_state_watcher_list_ = nullptr;
288
+
289
+ // Backoff state.
290
+ BackOff backoff_;
291
+ grpc_millis next_attempt_deadline_;
292
+ grpc_millis min_connect_timeout_ms_;
293
+ bool backoff_begun_ = false;
294
+
295
+ // Retry alarm.
296
+ grpc_timer retry_alarm_;
297
+ grpc_closure on_retry_alarm_;
298
+ bool have_retry_alarm_ = false;
299
+ // reset_backoff() was called while alarm was pending.
300
+ bool retry_immediately_ = false;
301
+
302
+ // Channelz tracking.
303
+ RefCountedPtr<channelz::SubchannelNode> channelz_node_;
304
+ };
305
+
306
+ } // namespace grpc_core
217
307
 
218
308
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_H */
@@ -0,0 +1,97 @@
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
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
22
+
23
+ #include "src/core/lib/gpr/useful.h"
24
+
25
+ // The subchannel pool to reuse subchannels.
26
+ #define GRPC_ARG_SUBCHANNEL_POOL "grpc.subchannel_pool"
27
+ // The subchannel key ID that is only used in test to make each key unique.
28
+ #define GRPC_ARG_SUBCHANNEL_KEY_TEST_ONLY_ID "grpc.subchannel_key_test_only_id"
29
+
30
+ namespace grpc_core {
31
+
32
+ TraceFlag grpc_subchannel_pool_trace(false, "subchannel_pool");
33
+
34
+ SubchannelKey::SubchannelKey(const grpc_channel_args* args) {
35
+ Init(args, grpc_channel_args_normalize);
36
+ }
37
+
38
+ SubchannelKey::~SubchannelKey() {
39
+ grpc_channel_args_destroy(const_cast<grpc_channel_args*>(args_));
40
+ }
41
+
42
+ SubchannelKey::SubchannelKey(const SubchannelKey& other) {
43
+ Init(other.args_, grpc_channel_args_copy);
44
+ }
45
+
46
+ SubchannelKey& SubchannelKey::operator=(const SubchannelKey& other) {
47
+ grpc_channel_args_destroy(const_cast<grpc_channel_args*>(args_));
48
+ Init(other.args_, grpc_channel_args_copy);
49
+ return *this;
50
+ }
51
+
52
+ int SubchannelKey::Cmp(const SubchannelKey& other) const {
53
+ return grpc_channel_args_compare(args_, other.args_);
54
+ }
55
+
56
+ void SubchannelKey::Init(
57
+ const grpc_channel_args* args,
58
+ grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) {
59
+ args_ = copy_channel_args(args);
60
+ }
61
+
62
+ namespace {
63
+
64
+ void* arg_copy(void* p) {
65
+ auto* subchannel_pool = static_cast<SubchannelPoolInterface*>(p);
66
+ subchannel_pool->Ref().release();
67
+ return p;
68
+ }
69
+
70
+ void arg_destroy(void* p) {
71
+ auto* subchannel_pool = static_cast<SubchannelPoolInterface*>(p);
72
+ subchannel_pool->Unref();
73
+ }
74
+
75
+ int arg_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
76
+
77
+ const grpc_arg_pointer_vtable subchannel_pool_arg_vtable = {
78
+ arg_copy, arg_destroy, arg_cmp};
79
+
80
+ } // namespace
81
+
82
+ grpc_arg SubchannelPoolInterface::CreateChannelArg(
83
+ SubchannelPoolInterface* subchannel_pool) {
84
+ return grpc_channel_arg_pointer_create(
85
+ const_cast<char*>(GRPC_ARG_SUBCHANNEL_POOL), subchannel_pool,
86
+ &subchannel_pool_arg_vtable);
87
+ }
88
+
89
+ SubchannelPoolInterface*
90
+ SubchannelPoolInterface::GetSubchannelPoolFromChannelArgs(
91
+ const grpc_channel_args* args) {
92
+ const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_SUBCHANNEL_POOL);
93
+ if (arg == nullptr || arg->type != GRPC_ARG_POINTER) return nullptr;
94
+ return static_cast<SubchannelPoolInterface*>(arg->value.pointer.p);
95
+ }
96
+
97
+ } // namespace grpc_core