grpc 1.20.0 → 1.21.0

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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +500 -29
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/grpc_types.h +10 -7
  6. data/include/grpc/impl/codegen/port_platform.h +11 -1
  7. data/include/grpc/impl/codegen/slice.h +1 -21
  8. data/include/grpc/impl/codegen/status.h +2 -1
  9. data/include/grpc/slice.h +1 -1
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
  11. data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
  12. data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
  14. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
  15. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
  16. data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
  17. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  18. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
  21. data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
  32. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  45. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  46. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
  47. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
  48. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
  49. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
  50. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
  51. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
  52. data/src/core/ext/filters/client_channel/service_config.cc +247 -27
  53. data/src/core/ext/filters/client_channel/service_config.h +119 -166
  54. data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
  55. data/src/core/ext/filters/client_channel/subchannel.h +7 -7
  56. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  57. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  58. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  59. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  60. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  61. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  62. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  63. data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
  64. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  65. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
  68. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
  70. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
  71. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
  75. data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
  76. data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
  77. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  78. data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
  79. data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
  80. data/src/core/lib/channel/channel_args.cc +0 -101
  81. data/src/core/lib/channel/channel_args.h +0 -37
  82. data/src/core/lib/channel/channel_stack.h +9 -5
  83. data/src/core/lib/channel/channelz_registry.cc +1 -1
  84. data/src/core/lib/channel/connected_channel.cc +2 -2
  85. data/src/core/lib/channel/context.h +3 -0
  86. data/src/core/lib/channel/handshaker.cc +4 -4
  87. data/src/core/lib/channel/handshaker.h +1 -1
  88. data/src/core/lib/compression/compression_args.cc +127 -0
  89. data/src/core/lib/compression/compression_args.h +55 -0
  90. data/src/core/lib/debug/trace.cc +13 -7
  91. data/src/core/lib/debug/trace.h +12 -0
  92. data/src/core/lib/gpr/arena.h +13 -9
  93. data/src/core/lib/gpr/env.h +2 -5
  94. data/src/core/lib/gpr/env_linux.cc +6 -1
  95. data/src/core/lib/gpr/env_posix.cc +5 -0
  96. data/src/core/lib/gpr/env_windows.cc +7 -5
  97. data/src/core/lib/gpr/log.cc +9 -13
  98. data/src/core/lib/gpr/string.cc +12 -6
  99. data/src/core/lib/gpr/string.h +4 -2
  100. data/src/core/lib/gpr/time_posix.cc +13 -0
  101. data/src/core/lib/gprpp/arena.cc +103 -0
  102. data/src/core/lib/gprpp/arena.h +121 -0
  103. data/src/core/lib/gprpp/fork.cc +12 -29
  104. data/src/core/lib/gprpp/global_config.h +87 -0
  105. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  106. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  107. data/src/core/lib/gprpp/global_config_env.h +131 -0
  108. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  109. data/src/core/lib/gprpp/map.h +419 -0
  110. data/src/core/lib/gprpp/optional.h +1 -0
  111. data/src/core/lib/gprpp/orphanable.h +2 -2
  112. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  113. data/src/core/lib/gprpp/ref_counted.h +18 -2
  114. data/src/core/lib/gprpp/sync.h +126 -0
  115. data/src/core/lib/http/parser.cc +1 -1
  116. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  117. data/src/core/lib/iomgr/call_combiner.h +75 -82
  118. data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
  119. data/src/core/lib/iomgr/cfstream_handle.h +82 -0
  120. data/src/core/lib/iomgr/combiner.h +1 -1
  121. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  122. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  123. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  124. data/src/core/lib/iomgr/error.h +23 -0
  125. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  126. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  127. data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
  128. data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
  129. data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
  130. data/src/core/lib/iomgr/ev_posix.cc +15 -13
  131. data/src/core/lib/iomgr/ev_posix.h +4 -1
  132. data/src/core/lib/iomgr/executor.cc +13 -9
  133. data/src/core/lib/iomgr/fork_posix.cc +0 -1
  134. data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
  135. data/src/core/lib/iomgr/iomgr.cc +6 -5
  136. data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
  137. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  138. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  139. data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
  140. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  141. data/src/core/lib/iomgr/port.h +11 -0
  142. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  143. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  144. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  145. data/src/core/lib/iomgr/socket_windows.h +8 -0
  146. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  147. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  148. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  149. data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
  150. data/src/core/lib/iomgr/tcp_custom.cc +9 -9
  151. data/src/core/lib/iomgr/tcp_posix.cc +41 -41
  152. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
  153. data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
  154. data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
  155. data/src/core/lib/iomgr/tcp_windows.cc +7 -9
  156. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  157. data/src/core/lib/iomgr/timer_manager.cc +12 -11
  158. data/src/core/lib/profiling/basic_timers.cc +10 -4
  159. data/src/core/lib/security/context/security_context.cc +6 -7
  160. data/src/core/lib/security/context/security_context.h +3 -4
  161. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
  162. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
  163. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  164. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
  165. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  166. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  167. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
  168. data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
  169. data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
  170. data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
  171. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  172. data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
  173. data/src/core/lib/slice/slice.cc +99 -116
  174. data/src/core/lib/slice/slice_buffer.cc +5 -0
  175. data/src/core/lib/slice/slice_intern.cc +38 -95
  176. data/src/core/lib/slice/slice_internal.h +200 -2
  177. data/src/core/lib/surface/api_trace.h +1 -1
  178. data/src/core/lib/surface/call.cc +41 -35
  179. data/src/core/lib/surface/call.h +7 -2
  180. data/src/core/lib/surface/call_details.cc +0 -1
  181. data/src/core/lib/surface/completion_queue.cc +36 -27
  182. data/src/core/lib/surface/init.cc +3 -4
  183. data/src/core/lib/surface/lame_client.cc +1 -1
  184. data/src/core/lib/surface/server.cc +18 -25
  185. data/src/core/lib/surface/version.cc +1 -1
  186. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  187. data/src/core/lib/transport/bdp_estimator.h +2 -2
  188. data/src/core/lib/transport/connectivity_state.cc +10 -40
  189. data/src/core/lib/transport/connectivity_state.h +0 -8
  190. data/src/core/lib/transport/error_utils.cc +12 -0
  191. data/src/core/lib/transport/metadata.cc +206 -278
  192. data/src/core/lib/transport/metadata.h +205 -10
  193. data/src/core/lib/transport/static_metadata.cc +108 -116
  194. data/src/core/lib/transport/static_metadata.h +1 -2
  195. data/src/core/lib/transport/status_metadata.cc +3 -3
  196. data/src/core/lib/transport/transport.cc +29 -66
  197. data/src/core/lib/transport/transport.h +36 -8
  198. data/src/core/lib/transport/transport_impl.h +1 -1
  199. data/src/core/tsi/fake_transport_security.cc +4 -4
  200. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  201. data/src/core/tsi/ssl_transport_security.cc +1 -1
  202. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  203. data/src/ruby/lib/grpc/errors.rb +22 -3
  204. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  205. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  206. data/src/ruby/lib/grpc/version.rb +1 -1
  207. data/src/ruby/spec/errors_spec.rb +141 -0
  208. metadata +57 -33
  209. data/src/core/lib/gpr/arena.cc +0 -192
@@ -220,7 +220,7 @@ static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) {
220
220
  GRPC_LOG_IF_ERROR("getpeername error", err);
221
221
  GRPC_ERROR_UNREF(err);
222
222
  }
223
- if (grpc_tcp_trace.enabled()) {
223
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
224
224
  if (peer_name_string) {
225
225
  gpr_log(GPR_INFO, "SERVER_CONNECT: %p accepted connection: %s",
226
226
  sp->server, peer_name_string);
@@ -372,7 +372,7 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s,
372
372
  addr = &wildcard;
373
373
  }
374
374
 
375
- if (grpc_tcp_trace.enabled()) {
375
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
376
376
  char* port_string;
377
377
  grpc_sockaddr_to_string(&port_string, addr, 0);
378
378
  const char* str = grpc_error_string(error);
@@ -418,7 +418,7 @@ static void tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets,
418
418
  (void)pollsets;
419
419
  (void)pollset_count;
420
420
  GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD();
421
- if (grpc_tcp_trace.enabled()) {
421
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
422
422
  gpr_log(GPR_INFO, "SERVER_START %p", server);
423
423
  }
424
424
  GPR_ASSERT(on_accept_cb);
@@ -217,12 +217,25 @@ static void on_read(void* arg, grpc_error* err) {
217
217
  }
218
218
  }
219
219
 
220
+ /* For UNIX sockets, the accept call might not fill up the member sun_path
221
+ * of sockaddr_un, so explicitly call getsockname to get it. */
222
+ if (grpc_is_unix_socket(&addr)) {
223
+ memset(&addr, 0, sizeof(addr));
224
+ addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage));
225
+ if (getsockname(fd, reinterpret_cast<struct sockaddr*>(addr.addr),
226
+ &(addr.len)) < 0) {
227
+ gpr_log(GPR_ERROR, "Failed getsockname: %s", strerror(errno));
228
+ close(fd);
229
+ goto error;
230
+ }
231
+ }
232
+
220
233
  grpc_set_socket_no_sigpipe_if_possible(fd);
221
234
 
222
235
  addr_str = grpc_sockaddr_to_uri(&addr);
223
236
  gpr_asprintf(&name, "tcp-server-connection:%s", addr_str);
224
237
 
225
- if (grpc_tcp_trace.enabled()) {
238
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
226
239
  gpr_log(GPR_INFO, "SERVER_CONNECT: incoming connection: %s", addr_str);
227
240
  }
228
241
 
@@ -255,7 +255,7 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) {
255
255
  }
256
256
 
257
257
  sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
258
- WSA_FLAG_OVERLAPPED);
258
+ grpc_get_default_wsa_socket_flags());
259
259
  if (sock == INVALID_SOCKET) {
260
260
  error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket");
261
261
  goto failure;
@@ -493,7 +493,7 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s,
493
493
  }
494
494
 
495
495
  sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
496
- WSA_FLAG_OVERLAPPED);
496
+ grpc_get_default_wsa_socket_flags());
497
497
  if (sock == INVALID_SOCKET) {
498
498
  error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket");
499
499
  goto done;
@@ -74,18 +74,16 @@ static grpc_error* set_dualstack(SOCKET sock) {
74
74
  : GRPC_WSA_ERROR(WSAGetLastError(), "setsockopt(IPV6_V6ONLY)");
75
75
  }
76
76
 
77
- static grpc_error* enable_loopback_fast_path(SOCKET sock) {
77
+ static grpc_error* enable_socket_low_latency(SOCKET sock) {
78
78
  int status;
79
- uint32_t param = 1;
80
- DWORD ret;
81
- status = WSAIoctl(sock, /*SIO_LOOPBACK_FAST_PATH==*/_WSAIOW(IOC_VENDOR, 16),
82
- &param, sizeof(param), NULL, 0, &ret, 0, 0);
79
+ BOOL param = TRUE;
80
+ status = ::setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
81
+ reinterpret_cast<char*>(&param), sizeof(param));
83
82
  if (status == SOCKET_ERROR) {
84
83
  status = WSAGetLastError();
85
84
  }
86
- return status == 0 || status == WSAEOPNOTSUPP
87
- ? GRPC_ERROR_NONE
88
- : GRPC_WSA_ERROR(status, "WSAIoctl(SIO_LOOPBACK_FAST_PATH)");
85
+ return status == 0 ? GRPC_ERROR_NONE
86
+ : GRPC_WSA_ERROR(status, "setsockopt(TCP_NODELAY)");
89
87
  }
90
88
 
91
89
  grpc_error* grpc_tcp_prepare_socket(SOCKET sock) {
@@ -94,7 +92,7 @@ grpc_error* grpc_tcp_prepare_socket(SOCKET sock) {
94
92
  if (err != GRPC_ERROR_NONE) return err;
95
93
  err = set_dualstack(sock);
96
94
  if (err != GRPC_ERROR_NONE) return err;
97
- err = enable_loopback_fast_path(sock);
95
+ err = enable_socket_low_latency(sock);
98
96
  if (err != GRPC_ERROR_NONE) return err;
99
97
  return GRPC_ERROR_NONE;
100
98
  }
@@ -361,7 +361,7 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
361
361
  timer->hash_table_next = nullptr;
362
362
  #endif
363
363
 
364
- if (grpc_timer_trace.enabled()) {
364
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
365
365
  gpr_log(GPR_INFO, "TIMER %p: SET %" PRId64 " now %" PRId64 " call %p[%p]",
366
366
  timer, deadline, grpc_core::ExecCtx::Get()->Now(), closure,
367
367
  closure->cb);
@@ -397,7 +397,7 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
397
397
  timer->heap_index = INVALID_HEAP_INDEX;
398
398
  list_join(&shard->list, timer);
399
399
  }
400
- if (grpc_timer_trace.enabled()) {
400
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
401
401
  gpr_log(GPR_INFO,
402
402
  " .. add to shard %d with queue_deadline_cap=%" PRId64
403
403
  " => is_first_timer=%s",
@@ -419,7 +419,7 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
419
419
  grpc_timer_check. */
420
420
  if (is_first_timer) {
421
421
  gpr_mu_lock(&g_shared_mutables.mu);
422
- if (grpc_timer_trace.enabled()) {
422
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
423
423
  gpr_log(GPR_INFO, " .. old shard min_deadline=%" PRId64,
424
424
  shard->min_deadline);
425
425
  }
@@ -463,7 +463,7 @@ static void timer_cancel(grpc_timer* timer) {
463
463
 
464
464
  timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)];
465
465
  gpr_mu_lock(&shard->mu);
466
- if (grpc_timer_trace.enabled()) {
466
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
467
467
  gpr_log(GPR_INFO, "TIMER %p: CANCEL pending=%s", timer,
468
468
  timer->pending ? "true" : "false");
469
469
  }
@@ -487,7 +487,7 @@ static void timer_cancel(grpc_timer* timer) {
487
487
  /* Rebalances the timer shard by computing a new 'queue_deadline_cap' and moving
488
488
  all relevant timers in shard->list (i.e timers with deadlines earlier than
489
489
  'queue_deadline_cap') into into shard->heap.
490
- Returns 'true' if shard->heap has atleast ONE element
490
+ Returns 'true' if shard->heap has at least ONE element
491
491
  REQUIRES: shard->mu locked */
492
492
  static bool refill_heap(timer_shard* shard, grpc_millis now) {
493
493
  /* Compute the new queue window width and bound by the limits: */
@@ -504,7 +504,7 @@ static bool refill_heap(timer_shard* shard, grpc_millis now) {
504
504
  saturating_add(GPR_MAX(now, shard->queue_deadline_cap),
505
505
  static_cast<grpc_millis>(deadline_delta * 1000.0));
506
506
 
507
- if (grpc_timer_check_trace.enabled()) {
507
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
508
508
  gpr_log(GPR_INFO, " .. shard[%d]->queue_deadline_cap --> %" PRId64,
509
509
  static_cast<int>(shard - g_shards), shard->queue_deadline_cap);
510
510
  }
@@ -512,7 +512,7 @@ static bool refill_heap(timer_shard* shard, grpc_millis now) {
512
512
  next = timer->next;
513
513
 
514
514
  if (timer->deadline < shard->queue_deadline_cap) {
515
- if (grpc_timer_check_trace.enabled()) {
515
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
516
516
  gpr_log(GPR_INFO, " .. add timer with deadline %" PRId64 " to heap",
517
517
  timer->deadline);
518
518
  }
@@ -529,7 +529,7 @@ static bool refill_heap(timer_shard* shard, grpc_millis now) {
529
529
  static grpc_timer* pop_one(timer_shard* shard, grpc_millis now) {
530
530
  grpc_timer* timer;
531
531
  for (;;) {
532
- if (grpc_timer_check_trace.enabled()) {
532
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
533
533
  gpr_log(GPR_INFO, " .. shard[%d]: heap_empty=%s",
534
534
  static_cast<int>(shard - g_shards),
535
535
  grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false");
@@ -539,13 +539,13 @@ static grpc_timer* pop_one(timer_shard* shard, grpc_millis now) {
539
539
  if (!refill_heap(shard, now)) return nullptr;
540
540
  }
541
541
  timer = grpc_timer_heap_top(&shard->heap);
542
- if (grpc_timer_check_trace.enabled()) {
542
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
543
543
  gpr_log(GPR_INFO,
544
544
  " .. check top timer deadline=%" PRId64 " now=%" PRId64,
545
545
  timer->deadline, now);
546
546
  }
547
547
  if (timer->deadline > now) return nullptr;
548
- if (grpc_timer_trace.enabled()) {
548
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
549
549
  gpr_log(GPR_INFO, "TIMER %p: FIRE %" PRId64 "ms late via %s scheduler",
550
550
  timer, now - timer->deadline,
551
551
  timer->closure->scheduler->vtable->name);
@@ -569,7 +569,7 @@ static size_t pop_timers(timer_shard* shard, grpc_millis now,
569
569
  }
570
570
  *new_min_deadline = compute_min_deadline(shard);
571
571
  gpr_mu_unlock(&shard->mu);
572
- if (grpc_timer_check_trace.enabled()) {
572
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
573
573
  gpr_log(GPR_INFO, " .. shard[%d] popped %" PRIdPTR,
574
574
  static_cast<int>(shard - g_shards), n);
575
575
  }
@@ -606,7 +606,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_millis now,
606
606
  gpr_mu_lock(&g_shared_mutables.mu);
607
607
  result = GRPC_TIMERS_CHECKED_AND_EMPTY;
608
608
 
609
- if (grpc_timer_check_trace.enabled()) {
609
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
610
610
  gpr_log(GPR_INFO, " .. shard[%d]->min_deadline = %" PRId64,
611
611
  static_cast<int>(g_shard_queue[0] - g_shards),
612
612
  g_shard_queue[0]->min_deadline);
@@ -624,7 +624,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_millis now,
624
624
  result = GRPC_TIMERS_FIRED;
625
625
  }
626
626
 
627
- if (grpc_timer_check_trace.enabled()) {
627
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
628
628
  gpr_log(GPR_INFO,
629
629
  " .. result --> %d"
630
630
  ", shard[%d]->min_deadline %" PRId64 " --> %" PRId64
@@ -691,7 +691,7 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
691
691
  if (next != nullptr) {
692
692
  *next = GPR_MIN(*next, min_timer);
693
693
  }
694
- if (grpc_timer_check_trace.enabled()) {
694
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
695
695
  gpr_log(GPR_INFO, "TIMER CHECK SKIP: now=%" PRId64 " min_timer=%" PRId64,
696
696
  now, min_timer);
697
697
  }
@@ -704,7 +704,7 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
704
704
  : GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system");
705
705
 
706
706
  // tracing
707
- if (grpc_timer_check_trace.enabled()) {
707
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
708
708
  char* next_str;
709
709
  if (next == nullptr) {
710
710
  next_str = gpr_strdup("NULL");
@@ -728,7 +728,7 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
728
728
  grpc_timer_check_result r =
729
729
  run_some_expired_timers(now, next, shutdown_error);
730
730
  // tracing
731
- if (grpc_timer_check_trace.enabled()) {
731
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
732
732
  char* next_str;
733
733
  if (next == nullptr) {
734
734
  next_str = gpr_strdup("NULL");
@@ -90,7 +90,7 @@ static void start_timer_thread_and_unlock(void) {
90
90
  ++g_waiter_count;
91
91
  ++g_thread_count;
92
92
  gpr_mu_unlock(&g_mu);
93
- if (grpc_timer_check_trace.enabled()) {
93
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
94
94
  gpr_log(GPR_INFO, "Spawn timer thread");
95
95
  }
96
96
  completed_thread* ct =
@@ -126,7 +126,7 @@ static void run_some_timers() {
126
126
  // if there's no thread waiting with a timeout, kick an existing untimed
127
127
  // waiter so that the next deadline is not missed
128
128
  if (!g_has_timed_waiter) {
129
- if (grpc_timer_check_trace.enabled()) {
129
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
130
130
  gpr_log(GPR_INFO, "kick untimed waiter");
131
131
  }
132
132
  gpr_cv_signal(&g_cv_wait);
@@ -134,7 +134,7 @@ static void run_some_timers() {
134
134
  gpr_mu_unlock(&g_mu);
135
135
  }
136
136
  // without our lock, flush the exec_ctx
137
- if (grpc_timer_check_trace.enabled()) {
137
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
138
138
  gpr_log(GPR_INFO, "flush exec_ctx");
139
139
  }
140
140
  grpc_core::ExecCtx::Get()->Flush();
@@ -189,7 +189,7 @@ static bool wait_until(grpc_millis next) {
189
189
  g_has_timed_waiter = true;
190
190
  g_timed_waiter_deadline = next;
191
191
 
192
- if (grpc_timer_check_trace.enabled()) {
192
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
193
193
  grpc_millis wait_time = next - grpc_core::ExecCtx::Get()->Now();
194
194
  gpr_log(GPR_INFO, "sleep for a %" PRId64 " milliseconds", wait_time);
195
195
  }
@@ -198,7 +198,8 @@ static bool wait_until(grpc_millis next) {
198
198
  }
199
199
  }
200
200
 
201
- if (grpc_timer_check_trace.enabled() && next == GRPC_MILLIS_INF_FUTURE) {
201
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace) &&
202
+ next == GRPC_MILLIS_INF_FUTURE) {
202
203
  gpr_log(GPR_INFO, "sleep until kicked");
203
204
  }
204
205
 
@@ -210,7 +211,7 @@ static bool wait_until(grpc_millis next) {
210
211
  gpr_cv_wait(&g_cv_wait, &g_mu,
211
212
  grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC));
212
213
 
213
- if (grpc_timer_check_trace.enabled()) {
214
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
214
215
  gpr_log(GPR_INFO, "wait ended: was_timed:%d kicked:%d",
215
216
  my_timed_waiter_generation == g_timed_waiter_generation,
216
217
  g_kicked);
@@ -255,7 +256,7 @@ static void timer_main_loop() {
255
256
 
256
257
  Consequently, we can just sleep forever here and be happy at some
257
258
  saved wakeup cycles. */
258
- if (grpc_timer_check_trace.enabled()) {
259
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
259
260
  gpr_log(GPR_INFO, "timers not checked: expect another thread to");
260
261
  }
261
262
  next = GRPC_MILLIS_INF_FUTURE;
@@ -281,7 +282,7 @@ static void timer_thread_cleanup(completed_thread* ct) {
281
282
  ct->next = g_completed_threads;
282
283
  g_completed_threads = ct;
283
284
  gpr_mu_unlock(&g_mu);
284
- if (grpc_timer_check_trace.enabled()) {
285
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
285
286
  gpr_log(GPR_INFO, "End timer thread");
286
287
  }
287
288
  }
@@ -327,18 +328,18 @@ void grpc_timer_manager_init(void) {
327
328
 
328
329
  static void stop_threads(void) {
329
330
  gpr_mu_lock(&g_mu);
330
- if (grpc_timer_check_trace.enabled()) {
331
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
331
332
  gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded);
332
333
  }
333
334
  if (g_threaded) {
334
335
  g_threaded = false;
335
336
  gpr_cv_broadcast(&g_cv_wait);
336
- if (grpc_timer_check_trace.enabled()) {
337
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
337
338
  gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count);
338
339
  }
339
340
  while (g_thread_count > 0) {
340
341
  gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
341
- if (grpc_timer_check_trace.enabled()) {
342
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
342
343
  gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count);
343
344
  }
344
345
  gc_completed_threads();
@@ -31,7 +31,8 @@
31
31
  #include <stdio.h>
32
32
  #include <string.h>
33
33
 
34
- #include "src/core/lib/gpr/env.h"
34
+ #include "src/core/lib/gprpp/global_config.h"
35
+ #include "src/core/lib/profiling/timers.h"
35
36
 
36
37
  typedef enum { BEGIN = '{', END = '}', MARK = '.' } marker_type;
37
38
 
@@ -74,11 +75,16 @@ static __thread int g_thread_id;
74
75
  static int g_next_thread_id;
75
76
  static int g_writing_enabled = 1;
76
77
 
78
+ GPR_GLOBAL_CONFIG_DEFINE_STRING(grpc_latency_trace, "latency_trace.txt",
79
+ "Output file name for latency trace")
80
+
77
81
  static const char* output_filename() {
78
82
  if (output_filename_or_null == NULL) {
79
- output_filename_or_null = gpr_getenv("LATENCY_TRACE");
80
- if (output_filename_or_null == NULL ||
81
- strlen(output_filename_or_null) == 0) {
83
+ grpc_core::UniquePtr<char> value =
84
+ GPR_GLOBAL_CONFIG_GET(grpc_latency_trace);
85
+ if (strlen(value.get()) > 0) {
86
+ output_filename_or_null = value.release();
87
+ } else {
82
88
  output_filename_or_null = "latency_trace.txt";
83
89
  }
84
90
  }
@@ -21,8 +21,8 @@
21
21
  #include <string.h>
22
22
 
23
23
  #include "src/core/lib/channel/channel_args.h"
24
- #include "src/core/lib/gpr/arena.h"
25
24
  #include "src/core/lib/gpr/string.h"
25
+ #include "src/core/lib/gprpp/arena.h"
26
26
  #include "src/core/lib/gprpp/ref_counted.h"
27
27
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
28
28
  #include "src/core/lib/security/context/security_context.h"
@@ -102,9 +102,9 @@ grpc_client_security_context::~grpc_client_security_context() {
102
102
  }
103
103
 
104
104
  grpc_client_security_context* grpc_client_security_context_create(
105
- gpr_arena* arena, grpc_call_credentials* creds) {
106
- return new (gpr_arena_alloc(arena, sizeof(grpc_client_security_context)))
107
- grpc_client_security_context(creds != nullptr ? creds->Ref() : nullptr);
105
+ grpc_core::Arena* arena, grpc_call_credentials* creds) {
106
+ return arena->New<grpc_client_security_context>(
107
+ creds != nullptr ? creds->Ref() : nullptr);
108
108
  }
109
109
 
110
110
  void grpc_client_security_context_destroy(void* ctx) {
@@ -123,9 +123,8 @@ grpc_server_security_context::~grpc_server_security_context() {
123
123
  }
124
124
 
125
125
  grpc_server_security_context* grpc_server_security_context_create(
126
- gpr_arena* arena) {
127
- return new (gpr_arena_alloc(arena, sizeof(grpc_server_security_context)))
128
- grpc_server_security_context();
126
+ grpc_core::Arena* arena) {
127
+ return arena->New<grpc_server_security_context>();
129
128
  }
130
129
 
131
130
  void grpc_server_security_context_destroy(void* ctx) {
@@ -21,6 +21,7 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include "src/core/lib/gprpp/arena.h"
24
25
  #include "src/core/lib/gprpp/ref_counted.h"
25
26
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
26
27
  #include "src/core/lib/iomgr/pollset.h"
@@ -28,8 +29,6 @@
28
29
 
29
30
  extern grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount;
30
31
 
31
- struct gpr_arena;
32
-
33
32
  /* --- grpc_auth_context ---
34
33
 
35
34
  High level authentication context object. Can optionally be chained. */
@@ -121,7 +120,7 @@ struct grpc_client_security_context {
121
120
  };
122
121
 
123
122
  grpc_client_security_context* grpc_client_security_context_create(
124
- gpr_arena* arena, grpc_call_credentials* creds);
123
+ grpc_core::Arena* arena, grpc_call_credentials* creds);
125
124
  void grpc_client_security_context_destroy(void* ctx);
126
125
 
127
126
  /* --- grpc_server_security_context ---
@@ -137,7 +136,7 @@ struct grpc_server_security_context {
137
136
  };
138
137
 
139
138
  grpc_server_security_context* grpc_server_security_context_create(
140
- gpr_arena* arena);
139
+ grpc_core::Arena* arena);
141
140
  void grpc_server_security_context_destroy(void* ctx);
142
141
 
143
142
  /* --- Channel args for auth context --- */
@@ -160,7 +160,7 @@ static char* redact_private_key(const char* json_key) {
160
160
 
161
161
  grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
162
162
  const char* json_key, gpr_timespec token_lifetime, void* reserved) {
163
- if (grpc_api_trace.enabled()) {
163
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_api_trace)) {
164
164
  char* clean_json = redact_private_key(json_key);
165
165
  gpr_log(GPR_INFO,
166
166
  "grpc_service_account_jwt_access_credentials_create("
@@ -624,9 +624,8 @@ static int verify_jwt_signature(EVP_PKEY* key, const char* alg,
624
624
  gpr_log(GPR_ERROR, "EVP_DigestVerifyUpdate failed.");
625
625
  goto end;
626
626
  }
627
- if (EVP_DigestVerifyFinal(
628
- md_ctx, const_cast<uint8_t*>(GRPC_SLICE_START_PTR(signature)),
629
- GRPC_SLICE_LENGTH(signature)) != 1) {
627
+ if (EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(signature),
628
+ GRPC_SLICE_LENGTH(signature)) != 1) {
630
629
  gpr_log(GPR_ERROR, "JWT signature verification failed.");
631
630
  goto end;
632
631
  }