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
@@ -53,14 +53,12 @@ typedef struct grpc_pollset grpc_pollset;
|
|
53
53
|
typedef struct grpc_pollset_worker grpc_pollset_worker;
|
54
54
|
|
55
55
|
size_t grpc_pollset_size(void);
|
56
|
+
/* Initialize a pollset: assumes *pollset contains all zeros */
|
56
57
|
void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu);
|
57
58
|
/* Begin shutting down the pollset, and call closure when done.
|
58
59
|
* pollset's mutex must be held */
|
59
60
|
void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
60
61
|
grpc_closure *closure);
|
61
|
-
/** Reset the pollset to its initial state (perhaps with some cached objects);
|
62
|
-
* must have been previously shutdown */
|
63
|
-
void grpc_pollset_reset(grpc_pollset *pollset);
|
64
62
|
void grpc_pollset_destroy(grpc_pollset *pollset);
|
65
63
|
|
66
64
|
/* Do some work on a pollset.
|
@@ -44,7 +44,8 @@
|
|
44
44
|
typedef struct grpc_pollset_set grpc_pollset_set;
|
45
45
|
|
46
46
|
grpc_pollset_set *grpc_pollset_set_create(void);
|
47
|
-
void grpc_pollset_set_destroy(
|
47
|
+
void grpc_pollset_set_destroy(grpc_exec_ctx *exec_ctx,
|
48
|
+
grpc_pollset_set *pollset_set);
|
48
49
|
void grpc_pollset_set_add_pollset(grpc_exec_ctx *exec_ctx,
|
49
50
|
grpc_pollset_set *pollset_set,
|
50
51
|
grpc_pollset *pollset);
|
@@ -41,7 +41,8 @@ grpc_pollset_set* grpc_pollset_set_create(void) {
|
|
41
41
|
return (grpc_pollset_set*)((intptr_t)0xdeafbeef);
|
42
42
|
}
|
43
43
|
|
44
|
-
void grpc_pollset_set_destroy(
|
44
|
+
void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx,
|
45
|
+
grpc_pollset_set* pollset_set) {}
|
45
46
|
|
46
47
|
void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx,
|
47
48
|
grpc_pollset_set* pollset_set,
|
@@ -42,7 +42,8 @@ grpc_pollset_set* grpc_pollset_set_create(void) {
|
|
42
42
|
return (grpc_pollset_set*)((intptr_t)0xdeafbeef);
|
43
43
|
}
|
44
44
|
|
45
|
-
void grpc_pollset_set_destroy(
|
45
|
+
void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx,
|
46
|
+
grpc_pollset_set* pollset_set) {}
|
46
47
|
|
47
48
|
void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx,
|
48
49
|
grpc_pollset_set* pollset_set,
|
@@ -39,6 +39,7 @@
|
|
39
39
|
|
40
40
|
#include <string.h>
|
41
41
|
|
42
|
+
#include <grpc/support/alloc.h>
|
42
43
|
#include <grpc/support/log.h>
|
43
44
|
#include <grpc/support/sync.h>
|
44
45
|
|
@@ -57,24 +58,40 @@ int grpc_pollset_work_run_loop;
|
|
57
58
|
|
58
59
|
gpr_mu grpc_polling_mu;
|
59
60
|
|
61
|
+
/* This is used solely to kick the uv loop, by setting a callback to be run
|
62
|
+
immediately in the next loop iteration.
|
63
|
+
Note: In the future, if there is a bug that involves missing wakeups in the
|
64
|
+
future, try adding a uv_async_t to kick the loop differently */
|
65
|
+
uv_timer_t *dummy_uv_handle;
|
66
|
+
|
60
67
|
size_t grpc_pollset_size() { return sizeof(grpc_pollset); }
|
61
68
|
|
69
|
+
void dummy_timer_cb(uv_timer_t *handle) {}
|
70
|
+
|
71
|
+
void dummy_handle_close_cb(uv_handle_t *handle) { gpr_free(handle); }
|
72
|
+
|
62
73
|
void grpc_pollset_global_init(void) {
|
63
74
|
gpr_mu_init(&grpc_polling_mu);
|
75
|
+
dummy_uv_handle = gpr_malloc(sizeof(uv_timer_t));
|
76
|
+
uv_timer_init(uv_default_loop(), dummy_uv_handle);
|
64
77
|
grpc_pollset_work_run_loop = 1;
|
65
78
|
}
|
66
79
|
|
67
|
-
void grpc_pollset_global_shutdown(void) {
|
80
|
+
void grpc_pollset_global_shutdown(void) {
|
81
|
+
gpr_mu_destroy(&grpc_polling_mu);
|
82
|
+
uv_close((uv_handle_t *)dummy_uv_handle, dummy_handle_close_cb);
|
83
|
+
}
|
84
|
+
|
85
|
+
static void timer_run_cb(uv_timer_t *timer) {}
|
86
|
+
|
87
|
+
static void timer_close_cb(uv_handle_t *handle) { handle->data = (void *)1; }
|
68
88
|
|
69
89
|
void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu) {
|
70
90
|
*mu = &grpc_polling_mu;
|
71
|
-
memset(pollset, 0, sizeof(grpc_pollset));
|
72
91
|
uv_timer_init(uv_default_loop(), &pollset->timer);
|
73
92
|
pollset->shutting_down = 0;
|
74
93
|
}
|
75
94
|
|
76
|
-
static void timer_close_cb(uv_handle_t *handle) { handle->data = (void *)1; }
|
77
|
-
|
78
95
|
void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
79
96
|
grpc_closure *closure) {
|
80
97
|
GPR_ASSERT(!pollset->shutting_down);
|
@@ -82,6 +99,9 @@ void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
|
82
99
|
if (grpc_pollset_work_run_loop) {
|
83
100
|
// Drain any pending UV callbacks without blocking
|
84
101
|
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
|
102
|
+
} else {
|
103
|
+
// kick the loop once
|
104
|
+
uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0);
|
85
105
|
}
|
86
106
|
grpc_closure_sched(exec_ctx, closure, GRPC_ERROR_NONE);
|
87
107
|
}
|
@@ -97,13 +117,6 @@ void grpc_pollset_destroy(grpc_pollset *pollset) {
|
|
97
117
|
}
|
98
118
|
}
|
99
119
|
|
100
|
-
void grpc_pollset_reset(grpc_pollset *pollset) {
|
101
|
-
GPR_ASSERT(pollset->shutting_down);
|
102
|
-
pollset->shutting_down = 0;
|
103
|
-
}
|
104
|
-
|
105
|
-
static void timer_run_cb(uv_timer_t *timer) {}
|
106
|
-
|
107
120
|
grpc_error *grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
108
121
|
grpc_pollset_worker **worker_hdl,
|
109
122
|
gpr_timespec now, gpr_timespec deadline) {
|
@@ -136,6 +149,7 @@ grpc_error *grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
|
136
149
|
|
137
150
|
grpc_error *grpc_pollset_kick(grpc_pollset *pollset,
|
138
151
|
grpc_pollset_worker *specific_worker) {
|
152
|
+
uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0);
|
139
153
|
return GRPC_ERROR_NONE;
|
140
154
|
}
|
141
155
|
|
@@ -98,7 +98,6 @@ size_t grpc_pollset_size(void) { return sizeof(grpc_pollset); }
|
|
98
98
|
|
99
99
|
void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu) {
|
100
100
|
*mu = &grpc_polling_mu;
|
101
|
-
memset(pollset, 0, sizeof(*pollset));
|
102
101
|
pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].next =
|
103
102
|
pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].prev =
|
104
103
|
&pollset->root_worker;
|
@@ -117,16 +116,6 @@ void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
|
117
116
|
|
118
117
|
void grpc_pollset_destroy(grpc_pollset *pollset) {}
|
119
118
|
|
120
|
-
void grpc_pollset_reset(grpc_pollset *pollset) {
|
121
|
-
GPR_ASSERT(pollset->shutting_down);
|
122
|
-
GPR_ASSERT(
|
123
|
-
!has_workers(&pollset->root_worker, GRPC_POLLSET_WORKER_LINK_POLLSET));
|
124
|
-
pollset->shutting_down = 0;
|
125
|
-
pollset->is_iocp_worker = 0;
|
126
|
-
pollset->kicked_without_pollers = 0;
|
127
|
-
pollset->on_shutdown = NULL;
|
128
|
-
}
|
129
|
-
|
130
119
|
grpc_error *grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
131
120
|
grpc_pollset_worker **worker_hdl,
|
132
121
|
gpr_timespec now, gpr_timespec deadline) {
|
@@ -40,6 +40,7 @@
|
|
40
40
|
#include <grpc/support/host_port.h>
|
41
41
|
#include <grpc/support/log.h>
|
42
42
|
#include <grpc/support/string_util.h>
|
43
|
+
#include <grpc/support/useful.h>
|
43
44
|
|
44
45
|
#include "src/core/lib/iomgr/closure.h"
|
45
46
|
#include "src/core/lib/iomgr/error.h"
|
@@ -54,8 +55,36 @@ typedef struct request {
|
|
54
55
|
grpc_closure *on_done;
|
55
56
|
grpc_resolved_addresses **addresses;
|
56
57
|
struct addrinfo *hints;
|
58
|
+
char *host;
|
59
|
+
char *port;
|
57
60
|
} request;
|
58
61
|
|
62
|
+
static int retry_named_port_failure(int status, request *r,
|
63
|
+
uv_getaddrinfo_cb getaddrinfo_cb) {
|
64
|
+
if (status != 0) {
|
65
|
+
// This loop is copied from resolve_address_posix.c
|
66
|
+
char *svc[][2] = {{"http", "80"}, {"https", "443"}};
|
67
|
+
for (size_t i = 0; i < GPR_ARRAY_SIZE(svc); i++) {
|
68
|
+
if (strcmp(r->port, svc[i][0]) == 0) {
|
69
|
+
int retry_status;
|
70
|
+
uv_getaddrinfo_t *req = gpr_malloc(sizeof(uv_getaddrinfo_t));
|
71
|
+
req->data = r;
|
72
|
+
retry_status = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_cb,
|
73
|
+
r->host, svc[i][1], r->hints);
|
74
|
+
if (retry_status < 0 || getaddrinfo_cb == NULL) {
|
75
|
+
// The callback will not be called
|
76
|
+
gpr_free(req);
|
77
|
+
}
|
78
|
+
return retry_status;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
/* If this function calls uv_getaddrinfo, it will return that function's
|
83
|
+
return value. That function only returns numbers <=0, so we can safely
|
84
|
+
return 1 to indicate that we never retried */
|
85
|
+
return 1;
|
86
|
+
}
|
87
|
+
|
59
88
|
static grpc_error *handle_addrinfo_result(int status, struct addrinfo *result,
|
60
89
|
grpc_resolved_addresses **addresses) {
|
61
90
|
struct addrinfo *resp;
|
@@ -97,13 +126,21 @@ static void getaddrinfo_callback(uv_getaddrinfo_t *req, int status,
|
|
97
126
|
request *r = (request *)req->data;
|
98
127
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
|
99
128
|
grpc_error *error;
|
129
|
+
int retry_status;
|
130
|
+
|
131
|
+
gpr_free(req);
|
132
|
+
retry_status = retry_named_port_failure(status, r, getaddrinfo_callback);
|
133
|
+
if (retry_status == 0) {
|
134
|
+
// The request is being retried. Nothing should be done here
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
/* Either no retry was attempted, or the retry failed. Either way, the
|
138
|
+
original error probably has more interesting information */
|
100
139
|
error = handle_addrinfo_result(status, res, r->addresses);
|
101
140
|
grpc_closure_sched(&exec_ctx, r->on_done, error);
|
102
141
|
grpc_exec_ctx_finish(&exec_ctx);
|
103
|
-
|
104
142
|
gpr_free(r->hints);
|
105
143
|
gpr_free(r);
|
106
|
-
gpr_free(req);
|
107
144
|
uv_freeaddrinfo(res);
|
108
145
|
}
|
109
146
|
|
@@ -143,6 +180,7 @@ static grpc_error *blocking_resolve_address_impl(
|
|
143
180
|
uv_getaddrinfo_t req;
|
144
181
|
int s;
|
145
182
|
grpc_error *err;
|
183
|
+
int retry_status;
|
146
184
|
|
147
185
|
req.addrinfo = NULL;
|
148
186
|
|
@@ -158,6 +196,12 @@ static grpc_error *blocking_resolve_address_impl(
|
|
158
196
|
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
|
159
197
|
|
160
198
|
s = uv_getaddrinfo(uv_default_loop(), &req, NULL, host, port, &hints);
|
199
|
+
request r = {
|
200
|
+
.addresses = addresses, .hints = &hints, .host = host, .port = port};
|
201
|
+
retry_status = retry_named_port_failure(s, &r, NULL);
|
202
|
+
if (retry_status <= 0) {
|
203
|
+
s = retry_status;
|
204
|
+
}
|
161
205
|
err = handle_addrinfo_result(s, req.addrinfo, addresses);
|
162
206
|
|
163
207
|
done:
|
@@ -200,6 +244,8 @@ static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
|
200
244
|
r = gpr_malloc(sizeof(request));
|
201
245
|
r->on_done = on_done;
|
202
246
|
r->addresses = addrs;
|
247
|
+
r->host = host;
|
248
|
+
r->port = port;
|
203
249
|
req = gpr_malloc(sizeof(uv_getaddrinfo_t));
|
204
250
|
req->data = r;
|
205
251
|
|
@@ -222,6 +268,8 @@ static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
|
222
268
|
gpr_free(r);
|
223
269
|
gpr_free(req);
|
224
270
|
gpr_free(hints);
|
271
|
+
gpr_free(host);
|
272
|
+
gpr_free(port);
|
225
273
|
}
|
226
274
|
}
|
227
275
|
|
@@ -33,6 +33,8 @@
|
|
33
33
|
|
34
34
|
#include "src/core/lib/iomgr/resource_quota.h"
|
35
35
|
|
36
|
+
#include <limits.h>
|
37
|
+
#include <stdint.h>
|
36
38
|
#include <string.h>
|
37
39
|
|
38
40
|
#include <grpc/support/alloc.h>
|
@@ -44,6 +46,8 @@
|
|
44
46
|
|
45
47
|
int grpc_resource_quota_trace = 0;
|
46
48
|
|
49
|
+
#define MEMORY_USAGE_ESTIMATION_MAX 65536
|
50
|
+
|
47
51
|
/* Internal linked list pointers for a resource user */
|
48
52
|
typedef struct {
|
49
53
|
grpc_resource_user *next;
|
@@ -126,9 +130,12 @@ struct grpc_resource_quota {
|
|
126
130
|
/* refcount */
|
127
131
|
gpr_refcount refs;
|
128
132
|
|
133
|
+
/* estimate of current memory usage
|
134
|
+
scaled to the range [0..RESOURCE_USAGE_ESTIMATION_MAX] */
|
135
|
+
gpr_atm memory_usage_estimation;
|
136
|
+
|
129
137
|
/* Master combiner lock: all activity on a quota executes under this combiner
|
130
|
-
* (so no mutex is needed for this data structure)
|
131
|
-
*/
|
138
|
+
* (so no mutex is needed for this data structure) */
|
132
139
|
grpc_combiner *combiner;
|
133
140
|
/* Size of the resource quota */
|
134
141
|
int64_t size;
|
@@ -269,6 +276,16 @@ static void rq_step_sched(grpc_exec_ctx *exec_ctx,
|
|
269
276
|
GRPC_ERROR_NONE);
|
270
277
|
}
|
271
278
|
|
279
|
+
/* update the atomically available resource estimate - use no barriers since
|
280
|
+
timeliness of delivery really doesn't matter much */
|
281
|
+
static void rq_update_estimate(grpc_resource_quota *resource_quota) {
|
282
|
+
gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation,
|
283
|
+
(gpr_atm)((1.0 -
|
284
|
+
((double)resource_quota->free_pool) /
|
285
|
+
((double)resource_quota->size)) *
|
286
|
+
MEMORY_USAGE_ESTIMATION_MAX));
|
287
|
+
}
|
288
|
+
|
272
289
|
/* returns true if all allocations are completed */
|
273
290
|
static bool rq_alloc(grpc_exec_ctx *exec_ctx,
|
274
291
|
grpc_resource_quota *resource_quota) {
|
@@ -281,6 +298,7 @@ static bool rq_alloc(grpc_exec_ctx *exec_ctx,
|
|
281
298
|
int64_t amt = -resource_user->free_pool;
|
282
299
|
resource_user->free_pool = 0;
|
283
300
|
resource_quota->free_pool -= amt;
|
301
|
+
rq_update_estimate(resource_quota);
|
284
302
|
if (grpc_resource_quota_trace) {
|
285
303
|
gpr_log(GPR_DEBUG, "RQ %s %s: grant alloc %" PRId64
|
286
304
|
" bytes; rq_free_pool -> %" PRId64,
|
@@ -315,6 +333,7 @@ static bool rq_reclaim_from_per_user_free_pool(
|
|
315
333
|
int64_t amt = resource_user->free_pool;
|
316
334
|
resource_user->free_pool = 0;
|
317
335
|
resource_quota->free_pool += amt;
|
336
|
+
rq_update_estimate(resource_quota);
|
318
337
|
if (grpc_resource_quota_trace) {
|
319
338
|
gpr_log(GPR_DEBUG, "RQ %s %s: reclaim_from_per_user_free_pool %" PRId64
|
320
339
|
" bytes; rq_free_pool -> %" PRId64,
|
@@ -378,11 +397,15 @@ static void ru_slice_unref(grpc_exec_ctx *exec_ctx, void *p) {
|
|
378
397
|
}
|
379
398
|
}
|
380
399
|
|
400
|
+
static const grpc_slice_refcount_vtable ru_slice_vtable = {
|
401
|
+
ru_slice_ref, ru_slice_unref, grpc_slice_default_eq_impl,
|
402
|
+
grpc_slice_default_hash_impl};
|
403
|
+
|
381
404
|
static grpc_slice ru_slice_create(grpc_resource_user *resource_user,
|
382
405
|
size_t size) {
|
383
406
|
ru_slice_refcount *rc = gpr_malloc(sizeof(ru_slice_refcount) + size);
|
384
|
-
rc->base.
|
385
|
-
rc->base.
|
407
|
+
rc->base.vtable = &ru_slice_vtable;
|
408
|
+
rc->base.sub_refcount = &rc->base;
|
386
409
|
gpr_ref_init(&rc->refs, 1);
|
387
410
|
rc->resource_user = resource_user;
|
388
411
|
rc->size = size;
|
@@ -527,6 +550,7 @@ static void rq_resize(grpc_exec_ctx *exec_ctx, void *args, grpc_error *error) {
|
|
527
550
|
int64_t delta = a->size - a->resource_quota->size;
|
528
551
|
a->resource_quota->size += delta;
|
529
552
|
a->resource_quota->free_pool += delta;
|
553
|
+
rq_update_estimate(a->resource_quota);
|
530
554
|
rq_step_sched(exec_ctx, a->resource_quota);
|
531
555
|
grpc_resource_quota_unref_internal(exec_ctx, a->resource_quota);
|
532
556
|
gpr_free(a);
|
@@ -553,6 +577,7 @@ grpc_resource_quota *grpc_resource_quota_create(const char *name) {
|
|
553
577
|
resource_quota->size = INT64_MAX;
|
554
578
|
resource_quota->step_scheduled = false;
|
555
579
|
resource_quota->reclaiming = false;
|
580
|
+
gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation, 0);
|
556
581
|
if (name != NULL) {
|
557
582
|
resource_quota->name = gpr_strdup(name);
|
558
583
|
} else {
|
@@ -574,7 +599,7 @@ grpc_resource_quota *grpc_resource_quota_create(const char *name) {
|
|
574
599
|
void grpc_resource_quota_unref_internal(grpc_exec_ctx *exec_ctx,
|
575
600
|
grpc_resource_quota *resource_quota) {
|
576
601
|
if (gpr_unref(&resource_quota->refs)) {
|
577
|
-
|
602
|
+
GRPC_COMBINER_UNREF(exec_ctx, resource_quota->combiner, "resource_quota");
|
578
603
|
gpr_free(resource_quota->name);
|
579
604
|
gpr_free(resource_quota);
|
580
605
|
}
|
@@ -598,6 +623,13 @@ void grpc_resource_quota_ref(grpc_resource_quota *resource_quota) {
|
|
598
623
|
grpc_resource_quota_ref_internal(resource_quota);
|
599
624
|
}
|
600
625
|
|
626
|
+
double grpc_resource_quota_get_memory_pressure(
|
627
|
+
grpc_resource_quota *resource_quota) {
|
628
|
+
return ((double)(gpr_atm_no_barrier_load(
|
629
|
+
&resource_quota->memory_usage_estimation))) /
|
630
|
+
((double)MEMORY_USAGE_ESTIMATION_MAX);
|
631
|
+
}
|
632
|
+
|
601
633
|
/* Public API */
|
602
634
|
void grpc_resource_quota_resize(grpc_resource_quota *resource_quota,
|
603
635
|
size_t size) {
|
@@ -804,12 +836,10 @@ void grpc_resource_user_finish_reclamation(grpc_exec_ctx *exec_ctx,
|
|
804
836
|
void grpc_resource_user_slice_allocator_init(
|
805
837
|
grpc_resource_user_slice_allocator *slice_allocator,
|
806
838
|
grpc_resource_user *resource_user, grpc_iomgr_cb_func cb, void *p) {
|
807
|
-
grpc_closure_init(
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
&slice_allocator->on_done, cb, p,
|
812
|
-
grpc_combiner_scheduler(resource_user->resource_quota->combiner, false));
|
839
|
+
grpc_closure_init(&slice_allocator->on_allocated, ru_allocated_slices,
|
840
|
+
slice_allocator, grpc_schedule_on_exec_ctx);
|
841
|
+
grpc_closure_init(&slice_allocator->on_done, cb, p,
|
842
|
+
grpc_schedule_on_exec_ctx);
|
813
843
|
slice_allocator->resource_user = resource_user;
|
814
844
|
}
|
815
845
|
|
@@ -84,6 +84,12 @@ void grpc_resource_quota_unref_internal(grpc_exec_ctx *exec_ctx,
|
|
84
84
|
grpc_resource_quota *grpc_resource_quota_from_channel_args(
|
85
85
|
const grpc_channel_args *channel_args);
|
86
86
|
|
87
|
+
/* Return a number indicating current memory pressure:
|
88
|
+
0.0 ==> no memory usage
|
89
|
+
1.0 ==> maximum memory usage */
|
90
|
+
double grpc_resource_quota_get_memory_pressure(
|
91
|
+
grpc_resource_quota *resource_quota);
|
92
|
+
|
87
93
|
typedef struct grpc_resource_user grpc_resource_user;
|
88
94
|
|
89
95
|
grpc_resource_user *grpc_resource_user_create(
|
@@ -162,6 +162,7 @@ int grpc_sockaddr_to_string(char **out,
|
|
162
162
|
char ntop_buf[INET6_ADDRSTRLEN];
|
163
163
|
const void *ip = NULL;
|
164
164
|
int port;
|
165
|
+
uint32_t sin6_scope_id = 0;
|
165
166
|
int ret;
|
166
167
|
|
167
168
|
*out = NULL;
|
@@ -177,10 +178,19 @@ int grpc_sockaddr_to_string(char **out,
|
|
177
178
|
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
|
178
179
|
ip = &addr6->sin6_addr;
|
179
180
|
port = ntohs(addr6->sin6_port);
|
181
|
+
sin6_scope_id = addr6->sin6_scope_id;
|
180
182
|
}
|
181
183
|
if (ip != NULL &&
|
182
184
|
grpc_inet_ntop(addr->sa_family, ip, ntop_buf, sizeof(ntop_buf)) != NULL) {
|
183
|
-
|
185
|
+
if (sin6_scope_id != 0) {
|
186
|
+
char *host_with_scope;
|
187
|
+
/* Enclose sin6_scope_id with the format defined in RFC 6784 section 2. */
|
188
|
+
gpr_asprintf(&host_with_scope, "%s%%25%" PRIu32, ntop_buf, sin6_scope_id);
|
189
|
+
ret = gpr_join_host_port(out, host_with_scope, port);
|
190
|
+
gpr_free(host_with_scope);
|
191
|
+
} else {
|
192
|
+
ret = gpr_join_host_port(out, ntop_buf, port);
|
193
|
+
}
|
184
194
|
} else {
|
185
195
|
ret = gpr_asprintf(out, "(sockaddr family=%d)", addr->sa_family);
|
186
196
|
}
|
@@ -190,31 +200,37 @@ int grpc_sockaddr_to_string(char **out,
|
|
190
200
|
}
|
191
201
|
|
192
202
|
char *grpc_sockaddr_to_uri(const grpc_resolved_address *resolved_addr) {
|
193
|
-
char *temp;
|
194
|
-
char *result;
|
195
203
|
grpc_resolved_address addr_normalized;
|
196
|
-
const struct sockaddr *addr;
|
197
|
-
|
198
204
|
if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) {
|
199
205
|
resolved_addr = &addr_normalized;
|
200
206
|
}
|
207
|
+
const char *scheme = grpc_sockaddr_get_uri_scheme(resolved_addr);
|
208
|
+
if (scheme == NULL || strcmp("unix", scheme) == 0) {
|
209
|
+
return grpc_sockaddr_to_uri_unix_if_possible(resolved_addr);
|
210
|
+
}
|
211
|
+
char *path = NULL;
|
212
|
+
char *uri_str = NULL;
|
213
|
+
if (grpc_sockaddr_to_string(&path, resolved_addr,
|
214
|
+
false /* suppress errors */) &&
|
215
|
+
scheme != NULL) {
|
216
|
+
gpr_asprintf(&uri_str, "%s:%s", scheme, path);
|
217
|
+
}
|
218
|
+
gpr_free(path);
|
219
|
+
return uri_str != NULL ? uri_str : NULL;
|
220
|
+
}
|
201
221
|
|
202
|
-
|
203
|
-
|
222
|
+
const char *grpc_sockaddr_get_uri_scheme(
|
223
|
+
const grpc_resolved_address *resolved_addr) {
|
224
|
+
const struct sockaddr *addr = (const struct sockaddr *)resolved_addr->addr;
|
204
225
|
switch (addr->sa_family) {
|
205
226
|
case AF_INET:
|
206
|
-
|
207
|
-
gpr_asprintf(&result, "ipv4:%s", temp);
|
208
|
-
gpr_free(temp);
|
209
|
-
return result;
|
227
|
+
return "ipv4";
|
210
228
|
case AF_INET6:
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
return result;
|
215
|
-
default:
|
216
|
-
return grpc_sockaddr_to_uri_unix_if_possible(resolved_addr);
|
229
|
+
return "ipv6";
|
230
|
+
case AF_UNIX:
|
231
|
+
return "unix";
|
217
232
|
}
|
233
|
+
return NULL;
|
218
234
|
}
|
219
235
|
|
220
236
|
int grpc_sockaddr_get_port(const grpc_resolved_address *resolved_addr) {
|