grpc 1.1.2 → 1.2.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.
- checksums.yaml +4 -4
- data/Makefile +1257 -404
- data/etc/roots.pem +189 -102
- data/include/grpc/census.h +7 -7
- data/include/grpc/compression.h +4 -4
- data/include/grpc/grpc.h +13 -7
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
- data/include/grpc/impl/codegen/grpc_types.h +39 -30
- data/include/grpc/impl/codegen/slice.h +24 -6
- data/include/grpc/impl/codegen/sync.h +8 -0
- data/include/grpc/load_reporting.h +63 -0
- data/include/grpc/slice.h +37 -1
- data/include/grpc/slice_buffer.h +7 -0
- data/include/grpc/support/alloc.h +3 -0
- data/include/grpc/support/useful.h +3 -0
- data/src/core/ext/census/gen/census.pb.h +1 -1
- data/src/core/ext/census/gen/trace_context.pb.c +9 -36
- data/src/core/ext/census/gen/trace_context.pb.h +20 -26
- data/src/core/ext/census/grpc_filter.c +3 -5
- data/src/core/ext/census/trace_context.c +1 -1
- data/src/core/ext/census/trace_context.h +3 -0
- data/src/core/ext/census/trace_label.h +61 -0
- data/src/core/ext/census/trace_propagation.h +63 -0
- data/src/core/ext/census/trace_status.h +45 -0
- data/src/core/ext/census/trace_string.h +50 -0
- data/src/core/ext/census/tracing.c +31 -11
- data/src/core/ext/census/tracing.h +124 -0
- data/src/core/ext/client_channel/client_channel.c +456 -368
- data/src/core/ext/client_channel/client_channel.h +4 -0
- data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
- data/src/core/ext/client_channel/connector.c +3 -3
- data/src/core/ext/client_channel/connector.h +4 -3
- data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
- data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
- data/src/core/ext/client_channel/http_proxy.c +125 -0
- data/src/core/ext/client_channel/http_proxy.h +39 -0
- data/src/core/ext/client_channel/lb_policy.c +56 -35
- data/src/core/ext/client_channel/lb_policy.h +46 -39
- data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
- data/src/core/ext/client_channel/parse_address.c +32 -6
- data/src/core/ext/client_channel/proxy_mapper.c +63 -0
- data/src/core/ext/client_channel/proxy_mapper.h +89 -0
- data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
- data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
- data/src/core/ext/client_channel/resolver.c +16 -9
- data/src/core/ext/client_channel/resolver.h +23 -12
- data/src/core/ext/client_channel/resolver_factory.h +1 -0
- data/src/core/ext/client_channel/resolver_registry.c +15 -11
- data/src/core/ext/client_channel/resolver_registry.h +5 -3
- data/src/core/ext/client_channel/subchannel.c +44 -27
- data/src/core/ext/client_channel/subchannel.h +6 -2
- data/src/core/ext/client_channel/uri_parser.c +26 -14
- data/src/core/ext/client_channel/uri_parser.h +3 -1
- data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
- data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
- data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
- data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
- data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
- data/src/core/ext/load_reporting/load_reporting.c +20 -0
- data/src/core/ext/load_reporting/load_reporting.h +1 -16
- data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
- data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
- data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
- data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
- data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
- data/src/core/lib/channel/channel_stack.c +14 -44
- data/src/core/lib/channel/channel_stack.h +10 -17
- data/src/core/lib/channel/channel_stack_builder.c +2 -3
- data/src/core/lib/channel/compress_filter.c +54 -46
- data/src/core/lib/channel/connected_channel.c +4 -4
- data/src/core/lib/channel/connected_channel.h +5 -0
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/deadline_filter.c +61 -61
- data/src/core/lib/channel/deadline_filter.h +8 -5
- data/src/core/lib/channel/handshaker.c +47 -7
- data/src/core/lib/channel/handshaker.h +21 -3
- data/src/core/lib/channel/http_client_filter.c +149 -99
- data/src/core/lib/channel/http_server_filter.c +163 -147
- data/src/core/lib/channel/message_size_filter.c +15 -10
- data/src/core/lib/compression/algorithm_metadata.h +4 -4
- data/src/core/lib/compression/compression.c +17 -23
- data/src/core/lib/http/httpcli.c +3 -2
- data/src/core/lib/http/httpcli.h +2 -1
- data/src/core/lib/http/httpcli_security_connector.c +2 -3
- data/src/core/lib/http/parser.c +2 -2
- data/src/core/lib/iomgr/closure.c +6 -3
- data/src/core/lib/iomgr/closure.h +4 -2
- data/src/core/lib/iomgr/combiner.c +35 -5
- data/src/core/lib/iomgr/combiner.h +21 -2
- data/src/core/lib/iomgr/endpoint.c +3 -2
- data/src/core/lib/iomgr/endpoint.h +3 -2
- data/src/core/lib/iomgr/error.c +60 -94
- data/src/core/lib/iomgr/error.h +7 -10
- data/src/core/lib/iomgr/error_internal.h +54 -0
- data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
- data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
- data/src/core/lib/iomgr/ev_posix.c +7 -8
- data/src/core/lib/iomgr/ev_posix.h +4 -4
- data/src/core/lib/iomgr/exec_ctx.c +11 -6
- data/src/core/lib/iomgr/exec_ctx.h +11 -14
- data/src/core/lib/iomgr/executor.c +2 -2
- data/src/core/lib/iomgr/load_file.c +1 -1
- data/src/core/lib/iomgr/network_status_tracker.c +5 -81
- data/src/core/lib/iomgr/pollset.h +1 -3
- data/src/core/lib/iomgr/pollset_set.h +2 -1
- data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
- data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
- data/src/core/lib/iomgr/pollset_uv.c +25 -11
- data/src/core/lib/iomgr/pollset_windows.c +0 -11
- data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
- data/src/core/lib/iomgr/resource_quota.c +41 -11
- data/src/core/lib/iomgr/resource_quota.h +6 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
- data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
- data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
- data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
- data/src/core/lib/iomgr/tcp_posix.c +4 -5
- data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
- data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
- data/src/core/lib/iomgr/tcp_uv.c +11 -5
- data/src/core/lib/iomgr/tcp_windows.c +20 -7
- data/src/core/lib/iomgr/timer_generic.c +15 -22
- data/src/core/lib/iomgr/timer_generic.h +1 -1
- data/src/core/lib/iomgr/timer_uv.c +10 -6
- data/src/core/lib/iomgr/timer_uv.h +1 -1
- data/src/core/lib/iomgr/udp_server.c +45 -6
- data/src/core/lib/iomgr/udp_server.h +7 -1
- data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
- data/src/core/lib/json/json.c +1 -2
- data/src/core/lib/profiling/basic_timers.c +17 -3
- data/src/core/lib/security/context/security_context.c +3 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
- data/src/core/lib/security/credentials/credentials.c +48 -2
- data/src/core/lib/security/credentials/credentials.h +13 -0
- data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
- data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
- data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
- data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
- data/src/core/lib/security/transport/client_auth_filter.c +72 -47
- data/src/core/lib/security/transport/lb_targets_info.c +70 -0
- data/src/core/lib/security/transport/lb_targets_info.h +47 -0
- data/src/core/lib/security/transport/secure_endpoint.c +3 -3
- data/src/core/lib/security/transport/security_connector.c +125 -28
- data/src/core/lib/security/transport/security_connector.h +4 -3
- data/src/core/lib/security/transport/security_handshaker.c +13 -9
- data/src/core/lib/security/transport/server_auth_filter.c +31 -40
- data/src/core/lib/security/util/b64.c +1 -1
- data/src/core/lib/slice/slice.c +110 -20
- data/src/core/lib/slice/slice_buffer.c +92 -39
- data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
- data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
- data/src/core/lib/slice/slice_intern.c +346 -0
- data/src/core/lib/slice/slice_internal.h +15 -0
- data/src/core/lib/slice/slice_string_helpers.c +5 -0
- data/src/core/lib/slice/slice_string_helpers.h +5 -0
- data/src/core/lib/support/alloc.c +26 -1
- data/src/core/lib/support/cmdline.c +2 -4
- data/src/core/lib/support/cpu_posix.c +2 -7
- data/src/core/lib/support/histogram.c +1 -2
- data/src/core/lib/support/log_posix.c +8 -4
- data/src/core/lib/support/spinlock.h +52 -0
- data/src/core/lib/support/subprocess_posix.c +1 -2
- data/src/core/lib/support/sync.c +7 -1
- data/src/core/lib/support/sync_posix.c +9 -0
- data/src/core/lib/support/time_windows.c +7 -1
- data/src/core/lib/surface/call.c +647 -629
- data/src/core/lib/surface/call.h +4 -1
- data/src/core/lib/surface/call_details.c +8 -2
- data/src/core/lib/surface/call_log_batch.c +17 -6
- data/src/core/lib/surface/channel.c +49 -59
- data/src/core/lib/surface/channel.h +5 -6
- data/src/core/lib/surface/completion_queue.c +16 -45
- data/src/core/lib/surface/completion_queue.h +0 -3
- data/src/core/lib/surface/init.c +6 -2
- data/src/core/lib/surface/init_secure.c +1 -1
- data/src/core/lib/surface/lame_client.c +14 -4
- data/src/core/lib/surface/server.c +79 -82
- data/src/core/lib/surface/validate_metadata.c +46 -15
- data/src/core/lib/surface/validate_metadata.h +43 -0
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.c +104 -0
- data/src/core/lib/transport/bdp_estimator.h +76 -0
- data/src/core/lib/transport/connectivity_state.c +33 -13
- data/src/core/lib/transport/connectivity_state.h +15 -5
- data/src/core/lib/transport/error_utils.c +124 -0
- data/src/core/lib/transport/error_utils.h +56 -0
- data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
- data/src/core/lib/transport/metadata.c +259 -503
- data/src/core/lib/transport/metadata.h +69 -68
- data/src/core/lib/transport/metadata_batch.c +183 -63
- data/src/core/lib/transport/metadata_batch.h +50 -26
- data/src/core/lib/transport/pid_controller.c +28 -8
- data/src/core/lib/transport/pid_controller.h +15 -2
- data/src/core/lib/transport/service_config.c +21 -18
- data/src/core/lib/transport/service_config.h +5 -5
- data/src/core/lib/transport/static_metadata.c +753 -112
- data/src/core/lib/transport/static_metadata.h +403 -264
- data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
- data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
- data/src/core/lib/transport/timeout_encoding.c +11 -9
- data/src/core/lib/transport/timeout_encoding.h +3 -1
- data/src/core/lib/transport/transport.c +47 -87
- data/src/core/lib/transport/transport.h +20 -25
- data/src/core/lib/transport/transport_op_string.c +7 -19
- data/src/core/lib/tsi/fake_transport_security.c +2 -4
- data/src/core/lib/tsi/ssl_transport_security.c +7 -16
- data/src/core/lib/tsi/transport_security.c +2 -4
- data/src/ruby/ext/grpc/extconf.rb +4 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
- data/src/ruby/ext/grpc/rb_call.c +47 -46
- data/src/ruby/ext/grpc/rb_channel.c +21 -6
- data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
- data/src/ruby/ext/grpc/rb_server.c +6 -4
- data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +33 -9
@@ -67,6 +67,7 @@
|
|
67
67
|
#include "src/core/ext/client_channel/subchannel.h"
|
68
68
|
#include "src/core/lib/channel/channel_args.h"
|
69
69
|
#include "src/core/lib/debug/trace.h"
|
70
|
+
#include "src/core/lib/iomgr/combiner.h"
|
70
71
|
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
71
72
|
#include "src/core/lib/transport/connectivity_state.h"
|
72
73
|
#include "src/core/lib/transport/static_metadata.h"
|
@@ -134,7 +135,6 @@ typedef struct {
|
|
134
135
|
struct round_robin_lb_policy {
|
135
136
|
/** base policy: must be first */
|
136
137
|
grpc_lb_policy base;
|
137
|
-
gpr_mu mu;
|
138
138
|
|
139
139
|
/** total number of addresses received at creation time */
|
140
140
|
size_t num_addresses;
|
@@ -213,8 +213,7 @@ static void advance_last_picked_locked(round_robin_lb_policy *p) {
|
|
213
213
|
* csc to the list of ready subchannels. */
|
214
214
|
static ready_list *add_connected_sc_locked(round_robin_lb_policy *p,
|
215
215
|
subchannel_data *sd) {
|
216
|
-
ready_list *new_elem =
|
217
|
-
memset(new_elem, 0, sizeof(ready_list));
|
216
|
+
ready_list *new_elem = gpr_zalloc(sizeof(ready_list));
|
218
217
|
new_elem->subchannel = sd->subchannel;
|
219
218
|
new_elem->user_data = sd->user_data;
|
220
219
|
if (p->ready_list.prev == NULL) {
|
@@ -293,7 +292,6 @@ static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
|
|
293
292
|
|
294
293
|
grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker);
|
295
294
|
gpr_free(p->subchannels);
|
296
|
-
gpr_mu_destroy(&p->mu);
|
297
295
|
|
298
296
|
elem = p->ready_list.next;
|
299
297
|
while (elem != NULL && elem != &p->ready_list) {
|
@@ -309,12 +307,11 @@ static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
|
|
309
307
|
gpr_free(p);
|
310
308
|
}
|
311
309
|
|
312
|
-
static void
|
310
|
+
static void rr_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
|
313
311
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
314
312
|
pending_pick *pp;
|
315
313
|
size_t i;
|
316
314
|
|
317
|
-
gpr_mu_lock(&p->mu);
|
318
315
|
if (grpc_lb_round_robin_trace) {
|
319
316
|
gpr_log(GPR_DEBUG, "Shutting down Round Robin policy at %p", (void *)pol);
|
320
317
|
}
|
@@ -335,15 +332,13 @@ static void rr_shutdown(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
|
|
335
332
|
grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, NULL, NULL,
|
336
333
|
&sd->connectivity_changed_closure);
|
337
334
|
}
|
338
|
-
gpr_mu_unlock(&p->mu);
|
339
335
|
}
|
340
336
|
|
341
|
-
static void
|
342
|
-
|
343
|
-
|
337
|
+
static void rr_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
338
|
+
grpc_connected_subchannel **target,
|
339
|
+
grpc_error *error) {
|
344
340
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
345
341
|
pending_pick *pp;
|
346
|
-
gpr_mu_lock(&p->mu);
|
347
342
|
pp = p->pending_picks;
|
348
343
|
p->pending_picks = NULL;
|
349
344
|
while (pp != NULL) {
|
@@ -360,17 +355,15 @@ static void rr_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
|
360
355
|
}
|
361
356
|
pp = next;
|
362
357
|
}
|
363
|
-
gpr_mu_unlock(&p->mu);
|
364
358
|
GRPC_ERROR_UNREF(error);
|
365
359
|
}
|
366
360
|
|
367
|
-
static void
|
368
|
-
|
369
|
-
|
370
|
-
|
361
|
+
static void rr_cancel_picks_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
362
|
+
uint32_t initial_metadata_flags_mask,
|
363
|
+
uint32_t initial_metadata_flags_eq,
|
364
|
+
grpc_error *error) {
|
371
365
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
372
366
|
pending_pick *pp;
|
373
|
-
gpr_mu_lock(&p->mu);
|
374
367
|
pp = p->pending_picks;
|
375
368
|
p->pending_picks = NULL;
|
376
369
|
while (pp != NULL) {
|
@@ -388,11 +381,11 @@ static void rr_cancel_picks(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
|
388
381
|
}
|
389
382
|
pp = next;
|
390
383
|
}
|
391
|
-
gpr_mu_unlock(&p->mu);
|
392
384
|
GRPC_ERROR_UNREF(error);
|
393
385
|
}
|
394
386
|
|
395
|
-
static void
|
387
|
+
static void start_picking_locked(grpc_exec_ctx *exec_ctx,
|
388
|
+
round_robin_lb_policy *p) {
|
396
389
|
size_t i;
|
397
390
|
p->started_picking = 1;
|
398
391
|
|
@@ -411,23 +404,20 @@ static void start_picking(grpc_exec_ctx *exec_ctx, round_robin_lb_policy *p) {
|
|
411
404
|
}
|
412
405
|
}
|
413
406
|
|
414
|
-
static void
|
407
|
+
static void rr_exit_idle_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
|
415
408
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
416
|
-
gpr_mu_lock(&p->mu);
|
417
409
|
if (!p->started_picking) {
|
418
|
-
|
410
|
+
start_picking_locked(exec_ctx, p);
|
419
411
|
}
|
420
|
-
gpr_mu_unlock(&p->mu);
|
421
412
|
}
|
422
413
|
|
423
|
-
static int
|
424
|
-
|
425
|
-
|
426
|
-
|
414
|
+
static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
415
|
+
const grpc_lb_policy_pick_args *pick_args,
|
416
|
+
grpc_connected_subchannel **target, void **user_data,
|
417
|
+
grpc_closure *on_complete) {
|
427
418
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
428
419
|
pending_pick *pp;
|
429
420
|
ready_list *selected;
|
430
|
-
gpr_mu_lock(&p->mu);
|
431
421
|
|
432
422
|
if (grpc_lb_round_robin_trace) {
|
433
423
|
gpr_log(GPR_INFO, "Round Robin %p trying to pick", (void *)pol);
|
@@ -449,12 +439,11 @@ static int rr_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
|
449
439
|
}
|
450
440
|
/* only advance the last picked pointer if the selection was used */
|
451
441
|
advance_last_picked_locked(p);
|
452
|
-
gpr_mu_unlock(&p->mu);
|
453
442
|
return 1;
|
454
443
|
} else {
|
455
444
|
/* no pick currently available. Save for later in list of pending picks */
|
456
445
|
if (!p->started_picking) {
|
457
|
-
|
446
|
+
start_picking_locked(exec_ctx, p);
|
458
447
|
}
|
459
448
|
pp = gpr_malloc(sizeof(*pp));
|
460
449
|
pp->next = p->pending_picks;
|
@@ -463,7 +452,6 @@ static int rr_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
|
463
452
|
pp->initial_metadata_flags = pick_args->initial_metadata_flags;
|
464
453
|
pp->user_data = user_data;
|
465
454
|
p->pending_picks = pp;
|
466
|
-
gpr_mu_unlock(&p->mu);
|
467
455
|
return 0;
|
468
456
|
}
|
469
457
|
}
|
@@ -538,17 +526,15 @@ static grpc_connectivity_state update_lb_connectivity_status(
|
|
538
526
|
return sd->curr_connectivity_state;
|
539
527
|
}
|
540
528
|
|
541
|
-
static void
|
542
|
-
|
529
|
+
static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
530
|
+
grpc_error *error) {
|
543
531
|
subchannel_data *sd = arg;
|
544
532
|
round_robin_lb_policy *p = sd->policy;
|
545
533
|
pending_pick *pp;
|
546
534
|
|
547
535
|
GRPC_ERROR_REF(error);
|
548
|
-
gpr_mu_lock(&p->mu);
|
549
536
|
|
550
537
|
if (p->shutdown) {
|
551
|
-
gpr_mu_unlock(&p->mu);
|
552
538
|
GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &p->base, "rr_connectivity");
|
553
539
|
GRPC_ERROR_UNREF(error);
|
554
540
|
return;
|
@@ -645,56 +631,51 @@ static void rr_connectivity_changed(grpc_exec_ctx *exec_ctx, void *arg,
|
|
645
631
|
GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &p->base, "rr_connectivity");
|
646
632
|
break;
|
647
633
|
}
|
648
|
-
gpr_mu_unlock(&p->mu);
|
649
634
|
GRPC_ERROR_UNREF(error);
|
650
635
|
}
|
651
636
|
|
652
|
-
static grpc_connectivity_state
|
653
|
-
|
654
|
-
grpc_error **error) {
|
637
|
+
static grpc_connectivity_state rr_check_connectivity_locked(
|
638
|
+
grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, grpc_error **error) {
|
655
639
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
656
|
-
|
657
|
-
gpr_mu_lock(&p->mu);
|
658
|
-
st = grpc_connectivity_state_check(&p->state_tracker, error);
|
659
|
-
gpr_mu_unlock(&p->mu);
|
660
|
-
return st;
|
640
|
+
return grpc_connectivity_state_get(&p->state_tracker, error);
|
661
641
|
}
|
662
642
|
|
663
|
-
static void
|
664
|
-
|
665
|
-
|
666
|
-
|
643
|
+
static void rr_notify_on_state_change_locked(grpc_exec_ctx *exec_ctx,
|
644
|
+
grpc_lb_policy *pol,
|
645
|
+
grpc_connectivity_state *current,
|
646
|
+
grpc_closure *notify) {
|
667
647
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
668
|
-
gpr_mu_lock(&p->mu);
|
669
648
|
grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker,
|
670
649
|
current, notify);
|
671
|
-
gpr_mu_unlock(&p->mu);
|
672
650
|
}
|
673
651
|
|
674
|
-
static void
|
675
|
-
|
652
|
+
static void rr_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
|
653
|
+
grpc_closure *closure) {
|
676
654
|
round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
|
677
655
|
ready_list *selected;
|
678
656
|
grpc_connected_subchannel *target;
|
679
|
-
gpr_mu_lock(&p->mu);
|
680
657
|
if ((selected = peek_next_connected_locked(p))) {
|
681
|
-
gpr_mu_unlock(&p->mu);
|
682
658
|
target = GRPC_CONNECTED_SUBCHANNEL_REF(
|
683
659
|
grpc_subchannel_get_connected_subchannel(selected->subchannel),
|
684
660
|
"rr_picked");
|
685
661
|
grpc_connected_subchannel_ping(exec_ctx, target, closure);
|
686
662
|
GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, target, "rr_picked");
|
687
663
|
} else {
|
688
|
-
gpr_mu_unlock(&p->mu);
|
689
664
|
grpc_closure_sched(exec_ctx, closure,
|
690
665
|
GRPC_ERROR_CREATE("Round Robin not connected"));
|
691
666
|
}
|
692
667
|
}
|
693
668
|
|
694
669
|
static const grpc_lb_policy_vtable round_robin_lb_policy_vtable = {
|
695
|
-
rr_destroy,
|
696
|
-
|
697
|
-
|
670
|
+
rr_destroy,
|
671
|
+
rr_shutdown_locked,
|
672
|
+
rr_pick_locked,
|
673
|
+
rr_cancel_pick_locked,
|
674
|
+
rr_cancel_picks_locked,
|
675
|
+
rr_ping_one_locked,
|
676
|
+
rr_exit_idle_locked,
|
677
|
+
rr_check_connectivity_locked,
|
678
|
+
rr_notify_on_state_change_locked};
|
698
679
|
|
699
680
|
static void round_robin_factory_ref(grpc_lb_policy_factory *factory) {}
|
700
681
|
|
@@ -717,12 +698,10 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx,
|
|
717
698
|
}
|
718
699
|
if (num_addrs == 0) return NULL;
|
719
700
|
|
720
|
-
round_robin_lb_policy *p =
|
721
|
-
memset(p, 0, sizeof(*p));
|
701
|
+
round_robin_lb_policy *p = gpr_zalloc(sizeof(*p));
|
722
702
|
|
723
703
|
p->num_addresses = num_addrs;
|
724
|
-
p->subchannels =
|
725
|
-
memset(p->subchannels, 0, sizeof(*p->subchannels) * num_addrs);
|
704
|
+
p->subchannels = gpr_zalloc(sizeof(*p->subchannels) * num_addrs);
|
726
705
|
|
727
706
|
grpc_subchannel_args sc_args;
|
728
707
|
size_t subchannel_idx = 0;
|
@@ -739,11 +718,17 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx,
|
|
739
718
|
sc_args.args = new_args;
|
740
719
|
grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel(
|
741
720
|
exec_ctx, args->client_channel_factory, &sc_args);
|
721
|
+
if (grpc_lb_round_robin_trace) {
|
722
|
+
char *address_uri =
|
723
|
+
grpc_sockaddr_to_uri(&addresses->addresses[i].address);
|
724
|
+
gpr_log(GPR_DEBUG, "Created subchannel %p for address uri %s",
|
725
|
+
(void *)subchannel, address_uri);
|
726
|
+
gpr_free(address_uri);
|
727
|
+
}
|
742
728
|
grpc_channel_args_destroy(exec_ctx, new_args);
|
743
729
|
|
744
730
|
if (subchannel != NULL) {
|
745
|
-
subchannel_data *sd =
|
746
|
-
memset(sd, 0, sizeof(*sd));
|
731
|
+
subchannel_data *sd = gpr_zalloc(sizeof(*sd));
|
747
732
|
p->subchannels[subchannel_idx] = sd;
|
748
733
|
sd->policy = p;
|
749
734
|
sd->index = subchannel_idx;
|
@@ -755,7 +740,8 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx,
|
|
755
740
|
}
|
756
741
|
++subchannel_idx;
|
757
742
|
grpc_closure_init(&sd->connectivity_changed_closure,
|
758
|
-
|
743
|
+
rr_connectivity_changed_locked, sd,
|
744
|
+
grpc_combiner_scheduler(args->combiner, false));
|
759
745
|
}
|
760
746
|
}
|
761
747
|
if (subchannel_idx == 0) {
|
@@ -772,7 +758,7 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx,
|
|
772
758
|
p->ready_list.next = NULL;
|
773
759
|
p->ready_list_last_pick = &p->ready_list;
|
774
760
|
|
775
|
-
grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable);
|
761
|
+
grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable, args->combiner);
|
776
762
|
grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE,
|
777
763
|
"round_robin");
|
778
764
|
|
@@ -780,7 +766,6 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx,
|
|
780
766
|
gpr_log(GPR_DEBUG, "Created RR policy at %p with %lu subchannels",
|
781
767
|
(void *)p, (unsigned long)p->num_subchannels);
|
782
768
|
}
|
783
|
-
gpr_mu_init(&p->mu);
|
784
769
|
return &p->base;
|
785
770
|
}
|
786
771
|
|
@@ -34,14 +34,34 @@
|
|
34
34
|
#include <limits.h>
|
35
35
|
#include <string.h>
|
36
36
|
|
37
|
+
#include <grpc/load_reporting.h>
|
37
38
|
#include <grpc/support/alloc.h>
|
38
39
|
#include <grpc/support/sync.h>
|
39
40
|
|
40
41
|
#include "src/core/ext/load_reporting/load_reporting.h"
|
41
42
|
#include "src/core/ext/load_reporting/load_reporting_filter.h"
|
42
43
|
#include "src/core/lib/channel/channel_stack_builder.h"
|
44
|
+
#include "src/core/lib/slice/slice_internal.h"
|
45
|
+
#include "src/core/lib/surface/call.h"
|
43
46
|
#include "src/core/lib/surface/channel_init.h"
|
44
47
|
|
48
|
+
static void destroy_lr_cost_context(void *c) {
|
49
|
+
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
|
50
|
+
grpc_load_reporting_cost_context *cost_ctx = c;
|
51
|
+
for (size_t i = 0; i < cost_ctx->values_count; ++i) {
|
52
|
+
grpc_slice_unref_internal(&exec_ctx, cost_ctx->values[i]);
|
53
|
+
}
|
54
|
+
grpc_exec_ctx_finish(&exec_ctx);
|
55
|
+
gpr_free(cost_ctx->values);
|
56
|
+
gpr_free(cost_ctx);
|
57
|
+
}
|
58
|
+
|
59
|
+
void grpc_call_set_load_reporting_cost_context(
|
60
|
+
grpc_call *call, grpc_load_reporting_cost_context *ctx) {
|
61
|
+
grpc_call_context_set(call, GRPC_CONTEXT_LR_COST, ctx,
|
62
|
+
destroy_lr_cost_context);
|
63
|
+
}
|
64
|
+
|
45
65
|
static bool is_load_reporting_enabled(const grpc_channel_args *a) {
|
46
66
|
if (a == NULL) return false;
|
47
67
|
for (size_t i = 0; i < a->num_args; i++) {
|
@@ -35,23 +35,8 @@
|
|
35
35
|
#define GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_H
|
36
36
|
|
37
37
|
#include <grpc/impl/codegen/grpc_types.h>
|
38
|
-
#include "src/core/lib/channel/channel_stack.h"
|
39
|
-
|
40
|
-
/** Metadata key for the gRPC LB load balancer token.
|
41
|
-
*
|
42
|
-
* The value corresponding to this key is an opaque token that is given to the
|
43
|
-
* frontend as part of each pick; the frontend sends this token to the backend
|
44
|
-
* in each request it sends when using that pick. The token is used by the
|
45
|
-
* backend to verify the request and to allow the backend to report load to the
|
46
|
-
* gRPC LB system. */
|
47
|
-
#define GRPC_LB_TOKEN_MD_KEY "lb-token"
|
48
38
|
|
49
|
-
|
50
|
-
*
|
51
|
-
* The value corresponding to this key is an opaque binary blob reported by the
|
52
|
-
* backend as part of its trailing metadata containing cost information for the
|
53
|
-
* call. */
|
54
|
-
#define GRPC_LB_COST_MD_KEY "lb-cost-bin"
|
39
|
+
#include "src/core/lib/channel/channel_stack.h"
|
55
40
|
|
56
41
|
/** Identifiers for the invocation point of the users LR callback */
|
57
42
|
typedef enum grpc_load_reporting_source {
|
@@ -31,23 +31,27 @@
|
|
31
31
|
*
|
32
32
|
*/
|
33
33
|
|
34
|
+
#include <string.h>
|
35
|
+
|
36
|
+
#include <grpc/load_reporting.h>
|
34
37
|
#include <grpc/support/alloc.h>
|
35
38
|
#include <grpc/support/log.h>
|
36
39
|
#include <grpc/support/string_util.h>
|
37
40
|
#include <grpc/support/sync.h>
|
38
|
-
#include <string.h>
|
39
41
|
|
40
42
|
#include "src/core/ext/load_reporting/load_reporting.h"
|
41
43
|
#include "src/core/ext/load_reporting/load_reporting_filter.h"
|
42
44
|
#include "src/core/lib/channel/channel_args.h"
|
43
45
|
#include "src/core/lib/profiling/timers.h"
|
46
|
+
#include "src/core/lib/slice/slice_internal.h"
|
44
47
|
#include "src/core/lib/transport/static_metadata.h"
|
45
48
|
|
46
49
|
typedef struct call_data {
|
47
50
|
intptr_t id; /**< an id unique to the call */
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
bool have_initial_md_string;
|
52
|
+
grpc_slice initial_md_string;
|
53
|
+
bool have_service_method;
|
54
|
+
grpc_slice service_method;
|
51
55
|
|
52
56
|
/* stores the recv_initial_metadata op's ready closure, which we wrap with our
|
53
57
|
* own (on_initial_md_ready) in order to capture the incoming initial metadata
|
@@ -63,42 +67,28 @@ typedef struct channel_data {
|
|
63
67
|
intptr_t id; /**< an id unique to the channel */
|
64
68
|
} channel_data;
|
65
69
|
|
66
|
-
typedef struct {
|
67
|
-
grpc_call_element *elem;
|
68
|
-
grpc_exec_ctx *exec_ctx;
|
69
|
-
} recv_md_filter_args;
|
70
|
-
|
71
|
-
static grpc_mdelem *recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data,
|
72
|
-
grpc_mdelem *md) {
|
73
|
-
recv_md_filter_args *a = user_data;
|
74
|
-
grpc_call_element *elem = a->elem;
|
75
|
-
call_data *calld = elem->call_data;
|
76
|
-
|
77
|
-
if (md->key == GRPC_MDSTR_PATH) {
|
78
|
-
calld->service_method = grpc_mdstr_as_c_string(md->value);
|
79
|
-
} else if (md->key == GRPC_MDSTR_LB_TOKEN) {
|
80
|
-
calld->initial_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value));
|
81
|
-
return NULL;
|
82
|
-
}
|
83
|
-
|
84
|
-
return md;
|
85
|
-
}
|
86
|
-
|
87
70
|
static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data,
|
88
71
|
grpc_error *err) {
|
89
72
|
grpc_call_element *elem = user_data;
|
90
73
|
call_data *calld = elem->call_data;
|
91
74
|
|
92
75
|
if (err == GRPC_ERROR_NONE) {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
if (calld->service_method == NULL) {
|
76
|
+
if (calld->recv_initial_metadata->idx.named.path != NULL) {
|
77
|
+
calld->service_method = grpc_slice_ref_internal(
|
78
|
+
GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md));
|
79
|
+
calld->have_service_method = true;
|
80
|
+
} else {
|
99
81
|
err =
|
100
82
|
grpc_error_add_child(err, GRPC_ERROR_CREATE("Missing :path header"));
|
101
83
|
}
|
84
|
+
if (calld->recv_initial_metadata->idx.named.lb_token != NULL) {
|
85
|
+
calld->initial_md_string = grpc_slice_ref_internal(
|
86
|
+
GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md));
|
87
|
+
calld->have_initial_md_string = true;
|
88
|
+
grpc_metadata_batch_remove(
|
89
|
+
exec_ctx, calld->recv_initial_metadata,
|
90
|
+
calld->recv_initial_metadata->idx.named.lb_token);
|
91
|
+
}
|
102
92
|
} else {
|
103
93
|
GRPC_ERROR_REF(err);
|
104
94
|
}
|
@@ -110,10 +100,8 @@ static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data,
|
|
110
100
|
/* Constructor for call_data */
|
111
101
|
static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
|
112
102
|
grpc_call_element *elem,
|
113
|
-
grpc_call_element_args *args) {
|
103
|
+
const grpc_call_element_args *args) {
|
114
104
|
call_data *calld = elem->call_data;
|
115
|
-
memset(calld, 0, sizeof(call_data));
|
116
|
-
|
117
105
|
calld->id = (intptr_t)args->call_stack;
|
118
106
|
grpc_closure_init(&calld->on_initial_md_ready, on_initial_md_ready, elem,
|
119
107
|
grpc_schedule_on_exec_ctx);
|
@@ -149,8 +137,12 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
|
|
149
137
|
calld->service_method};
|
150
138
|
*/
|
151
139
|
|
152
|
-
|
153
|
-
|
140
|
+
if (calld->have_initial_md_string) {
|
141
|
+
grpc_slice_unref_internal(exec_ctx, calld->initial_md_string);
|
142
|
+
}
|
143
|
+
if (calld->have_service_method) {
|
144
|
+
grpc_slice_unref_internal(exec_ctx, calld->service_method);
|
145
|
+
}
|
154
146
|
}
|
155
147
|
|
156
148
|
/* Constructor for channel_data */
|
@@ -160,8 +152,6 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx,
|
|
160
152
|
GPR_ASSERT(!args->is_last);
|
161
153
|
|
162
154
|
channel_data *chand = elem->channel_data;
|
163
|
-
memset(chand, 0, sizeof(channel_data));
|
164
|
-
|
165
155
|
chand->id = (intptr_t)args->channel_stack;
|
166
156
|
|
167
157
|
/* TODO(dgq): do something with the data
|
@@ -193,19 +183,6 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
|
|
193
183
|
*/
|
194
184
|
}
|
195
185
|
|
196
|
-
static grpc_mdelem *lr_trailing_md_filter(grpc_exec_ctx *exec_ctx,
|
197
|
-
void *user_data, grpc_mdelem *md) {
|
198
|
-
grpc_call_element *elem = user_data;
|
199
|
-
call_data *calld = elem->call_data;
|
200
|
-
|
201
|
-
if (md->key == GRPC_MDSTR_LB_COST_BIN) {
|
202
|
-
calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value));
|
203
|
-
return NULL;
|
204
|
-
}
|
205
|
-
|
206
|
-
return md;
|
207
|
-
}
|
208
|
-
|
209
186
|
static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx,
|
210
187
|
grpc_call_element *elem,
|
211
188
|
grpc_transport_stream_op *op) {
|
@@ -217,9 +194,6 @@ static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx,
|
|
217
194
|
/* substitute our callback for the higher callback */
|
218
195
|
calld->ops_recv_initial_metadata_ready = op->recv_initial_metadata_ready;
|
219
196
|
op->recv_initial_metadata_ready = &calld->on_initial_md_ready;
|
220
|
-
} else if (op->send_trailing_metadata) {
|
221
|
-
grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata,
|
222
|
-
lr_trailing_md_filter, elem);
|
223
197
|
}
|
224
198
|
grpc_call_next_op(exec_ctx, elem, op);
|
225
199
|
|