Revert "Implement TraceFlag::Log (#26954)" (#27145)

This reverts commit 4d2b979b75.
pull/27148/head
Craig Tiller 4 years ago committed by GitHub
parent ab57f03b30
commit f2f60f7716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 1
      build_autogenerated.yaml
  3. 2
      gRPC-C++.podspec
  4. 2
      gRPC-Core.podspec
  5. 1
      grpc.gemspec
  6. 1
      package.xml
  7. 449
      src/core/ext/filters/client_channel/client_channel.cc
  8. 53
      src/core/ext/filters/client_channel/health/health_check_client.cc
  9. 65
      src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc
  10. 105
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  11. 75
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  12. 198
      src/core/ext/filters/client_channel/lb_policy/priority/priority.cc
  13. 60
      src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc
  14. 79
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  15. 110
      src/core/ext/filters/client_channel/lb_policy/subchannel_list.h
  16. 132
      src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc
  17. 78
      src/core/ext/filters/client_channel/lb_policy/xds/cds.cc
  18. 91
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc
  19. 113
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc
  20. 116
      src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc
  21. 54
      src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc
  22. 463
      src/core/ext/filters/client_channel/retry_filter.cc
  23. 20
      src/core/ext/filters/client_channel/subchannel.cc
  24. 31
      src/core/ext/filters/fault_injection/fault_injection_filter.cc
  25. 76
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  26. 15
      src/core/ext/transport/chttp2/transport/frame_settings.cc
  27. 5
      src/core/ext/transport/chttp2/transport/hpack_encoder.cc
  28. 4
      src/core/ext/transport/chttp2/transport/hpack_parser.cc
  29. 9
      src/core/ext/transport/chttp2/transport/hpack_table.cc
  30. 9
      src/core/ext/transport/chttp2/transport/parsing.cc
  31. 14
      src/core/ext/transport/chttp2/transport/stream_lists.cc
  32. 49
      src/core/ext/transport/chttp2/transport/writing.cc
  33. 184
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  34. 6
      src/core/ext/xds/xds_api.cc
  35. 338
      src/core/ext/xds/xds_client.cc
  36. 53
      src/core/ext/xds/xds_client_stats.cc
  37. 10
      src/core/ext/xds/xds_server_config_fetcher.cc
  38. 43
      src/core/lib/channel/handshaker.cc
  39. 12
      src/core/lib/debug/trace.h
  40. 11
      src/core/lib/gpr/log_android.cc
  41. 25
      src/core/lib/gpr/log_internal.h
  42. 10
      src/core/lib/gpr/log_linux.cc
  43. 20
      src/core/lib/gpr/log_posix.cc
  44. 18
      src/core/lib/gpr/log_windows.cc
  45. 7
      src/core/lib/http/parser.cc
  46. 96
      src/core/lib/iomgr/call_combiner.cc
  47. 14
      src/core/lib/iomgr/call_combiner.h
  48. 12
      src/core/lib/iomgr/cfstream_handle.cc
  49. 13
      src/core/lib/iomgr/closure.h
  50. 69
      src/core/lib/iomgr/combiner.cc
  51. 44
      src/core/lib/iomgr/endpoint_cfstream.cc
  52. 39
      src/core/lib/iomgr/error.cc
  53. 6
      src/core/lib/iomgr/ev_apple.cc
  54. 132
      src/core/lib/iomgr/ev_epoll1_linux.cc
  55. 193
      src/core/lib/iomgr/ev_epollex_linux.cc
  56. 47
      src/core/lib/iomgr/ev_poll_posix.cc
  57. 6
      src/core/lib/iomgr/ev_posix.cc
  58. 6
      src/core/lib/iomgr/ev_posix.h
  59. 18
      src/core/lib/iomgr/event_engine/closure.cc
  60. 15
      src/core/lib/iomgr/exec_ctx.cc
  61. 22
      src/core/lib/iomgr/lockfree_event.cc
  62. 132
      src/core/lib/iomgr/resource_quota.cc
  63. 12
      src/core/lib/iomgr/socket_utils_common_posix.cc
  64. 17
      src/core/lib/iomgr/tcp_client_cfstream.cc
  65. 14
      src/core/lib/iomgr/tcp_client_custom.cc
  66. 21
      src/core/lib/iomgr/tcp_client_posix.cc
  67. 28
      src/core/lib/iomgr/tcp_custom.cc
  68. 116
      src/core/lib/iomgr/tcp_posix.cc
  69. 18
      src/core/lib/iomgr/tcp_server_custom.cc
  70. 13
      src/core/lib/iomgr/tcp_server_posix.cc
  71. 16
      src/core/lib/iomgr/tcp_windows.cc
  72. 106
      src/core/lib/iomgr/timer_generic.cc
  73. 44
      src/core/lib/iomgr/timer_manager.cc
  74. 50
      src/core/lib/iomgr/work_serializer.cc
  75. 11
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  76. 68
      src/core/lib/security/credentials/plugin/plugin_credentials.cc
  77. 7
      src/core/lib/surface/call.cc
  78. 4
      src/core/lib/surface/server.cc
  79. 24
      src/core/lib/transport/bdp_estimator.cc
  80. 14
      src/core/lib/transport/bdp_estimator.h
  81. 72
      src/core/lib/transport/connectivity_state.cc
  82. 16
      src/core/lib/transport/transport.h
  83. 24
      src/core/tsi/fake_transport_security.cc
  84. 8
      test/core/handshake/client_ssl.cc
  85. 1
      tools/doxygen/Doxyfile.c++.internal
  86. 1
      tools/doxygen/Doxyfile.core.internal

@ -672,7 +672,6 @@ grpc_cc_library(
hdrs = [ hdrs = [
"src/core/lib/gpr/alloc.h", "src/core/lib/gpr/alloc.h",
"src/core/lib/gpr/env.h", "src/core/lib/gpr/env.h",
"src/core/lib/gpr/log_internal.h",
"src/core/lib/gpr/murmur_hash.h", "src/core/lib/gpr/murmur_hash.h",
"src/core/lib/gpr/spinlock.h", "src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/string.h", "src/core/lib/gpr/string.h",

@ -313,7 +313,6 @@ libs:
- src/core/ext/upb-generated/google/rpc/status.upb.h - src/core/ext/upb-generated/google/rpc/status.upb.h
- src/core/lib/gpr/alloc.h - src/core/lib/gpr/alloc.h
- src/core/lib/gpr/env.h - src/core/lib/gpr/env.h
- src/core/lib/gpr/log_internal.h
- src/core/lib/gpr/murmur_hash.h - src/core/lib/gpr/murmur_hash.h
- src/core/lib/gpr/spinlock.h - src/core/lib/gpr/spinlock.h
- src/core/lib/gpr/string.h - src/core/lib/gpr/string.h

2
gRPC-C++.podspec generated

@ -535,7 +535,6 @@ Pod::Spec.new do |s|
'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/event_engine/sockaddr.h',
'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/log_internal.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h', 'src/core/lib/gpr/string.h',
@ -1202,7 +1201,6 @@ Pod::Spec.new do |s|
'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/event_engine/sockaddr.h',
'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/log_internal.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h', 'src/core/lib/gpr/string.h',

2
gRPC-Core.podspec generated

@ -886,7 +886,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_internal.h',
'src/core/lib/gpr/log_linux.cc', 'src/core/lib/gpr/log_linux.cc',
'src/core/lib/gpr/log_posix.cc', 'src/core/lib/gpr/log_posix.cc',
'src/core/lib/gpr/log_windows.cc', 'src/core/lib/gpr/log_windows.cc',
@ -1791,7 +1790,6 @@ Pod::Spec.new do |s|
'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/event_engine/sockaddr.h',
'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/log_internal.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h', 'src/core/lib/gpr/string.h',

1
grpc.gemspec generated

@ -799,7 +799,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/env_windows.cc ) s.files += %w( src/core/lib/gpr/env_windows.cc )
s.files += %w( src/core/lib/gpr/log.cc ) s.files += %w( src/core/lib/gpr/log.cc )
s.files += %w( src/core/lib/gpr/log_android.cc ) s.files += %w( src/core/lib/gpr/log_android.cc )
s.files += %w( src/core/lib/gpr/log_internal.h )
s.files += %w( src/core/lib/gpr/log_linux.cc ) s.files += %w( src/core/lib/gpr/log_linux.cc )
s.files += %w( src/core/lib/gpr/log_posix.cc ) s.files += %w( src/core/lib/gpr/log_posix.cc )
s.files += %w( src/core/lib/gpr/log_windows.cc ) s.files += %w( src/core/lib/gpr/log_windows.cc )

1
package.xml generated

@ -779,7 +779,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_internal.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_linux.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_linux.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_posix.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_windows.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_windows.cc" role="src" />

@ -353,9 +353,11 @@ class DynamicTerminationFilter::CallData {
args, pollent, nullptr, args, pollent, nullptr,
service_config_call_data->call_dispatch_controller(), service_config_call_data->call_dispatch_controller(),
/*is_transparent_retry=*/false); /*is_transparent_retry=*/false);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p dynamic_termination_calld=%p: create lb_call=%p", gpr_log(GPR_INFO,
chand, client_channel, calld->lb_call_.get()); "chand=%p dynamic_termination_calld=%p: create lb_call=%p", chand,
client_channel, calld->lb_call_.get());
}
} }
private: private:
@ -406,8 +408,9 @@ class ClientChannel::ResolverResultHandler : public Resolver::ResultHandler {
} }
~ResolverResultHandler() override { ~ResolverResultHandler() override {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: resolver shutdown complete", chand_); gpr_log(GPR_INFO, "chand=%p: resolver shutdown complete", chand_);
}
GRPC_CHANNEL_STACK_UNREF(chand_->owning_stack_, "ResolverResultHandler"); GRPC_CHANNEL_STACK_UNREF(chand_->owning_stack_, "ResolverResultHandler");
} }
@ -448,9 +451,11 @@ class ClientChannel::SubchannelWrapper : public SubchannelInterface {
chand_(chand), chand_(chand),
subchannel_(std::move(subchannel)), subchannel_(std::move(subchannel)),
health_check_service_name_(std::move(health_check_service_name)) { health_check_service_name_(std::move(health_check_service_name)) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: creating subchannel wrapper %p for subchannel %p", gpr_log(GPR_INFO,
chand, this, subchannel_.get()); "chand=%p: creating subchannel wrapper %p for subchannel %p",
chand, this, subchannel_.get());
}
GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "SubchannelWrapper"); GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "SubchannelWrapper");
auto* subchannel_node = subchannel_->channelz_node(); auto* subchannel_node = subchannel_->channelz_node();
if (subchannel_node != nullptr) { if (subchannel_node != nullptr) {
@ -466,10 +471,11 @@ class ClientChannel::SubchannelWrapper : public SubchannelInterface {
} }
~SubchannelWrapper() override { ~SubchannelWrapper() override {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: destroying subchannel wrapper %p for subchannel %p", chand_, "chand=%p: destroying subchannel wrapper %p for subchannel %p",
this, subchannel_.get()); chand_, this, subchannel_.get());
}
chand_->subchannel_wrappers_.erase(this); chand_->subchannel_wrappers_.erase(this);
auto* subchannel_node = subchannel_->channelz_node(); auto* subchannel_node = subchannel_->channelz_node();
if (subchannel_node != nullptr) { if (subchannel_node != nullptr) {
@ -531,12 +537,13 @@ class ClientChannel::SubchannelWrapper : public SubchannelInterface {
void UpdateHealthCheckServiceName( void UpdateHealthCheckServiceName(
absl::optional<std::string> health_check_service_name) { absl::optional<std::string> health_check_service_name) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: subchannel wrapper %p: updating health check service " "chand=%p: subchannel wrapper %p: updating health check service "
"name from \"%s\" to \"%s\"", "name from \"%s\" to \"%s\"",
chand_, this, health_check_service_name_->c_str(), chand_, this, health_check_service_name_->c_str(),
health_check_service_name->c_str()); health_check_service_name->c_str());
}
for (auto& p : watcher_map_) { for (auto& p : watcher_map_) {
WatcherWrapper*& watcher_wrapper = p.second; WatcherWrapper*& watcher_wrapper = p.second;
// Cancel the current watcher and create a new one using the new // Cancel the current watcher and create a new one using the new
@ -616,11 +623,12 @@ class ClientChannel::SubchannelWrapper : public SubchannelInterface {
} }
void OnConnectivityStateChange() override { void OnConnectivityStateChange() override {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: connectivity change for subchannel wrapper %p " "chand=%p: connectivity change for subchannel wrapper %p "
"subchannel %p; hopping into work_serializer", "subchannel %p; hopping into work_serializer",
parent_->chand_, parent_.get(), parent_->subchannel_.get()); parent_->chand_, parent_.get(), parent_->subchannel_.get());
}
Ref().release(); // ref owned by lambda Ref().release(); // ref owned by lambda
parent_->chand_->work_serializer_->Run( parent_->chand_->work_serializer_->Run(
[this]() [this]()
@ -650,13 +658,14 @@ class ClientChannel::SubchannelWrapper : public SubchannelInterface {
private: private:
void ApplyUpdateInControlPlaneWorkSerializer() void ApplyUpdateInControlPlaneWorkSerializer()
ABSL_EXCLUSIVE_LOCKS_REQUIRED(parent_->chand_->work_serializer_) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(parent_->chand_->work_serializer_) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: processing connectivity change in work serializer " "chand=%p: processing connectivity change in work serializer "
"for subchannel wrapper %p subchannel %p " "for subchannel wrapper %p subchannel %p "
"watcher=%p", "watcher=%p",
parent_->chand_, parent_.get(), parent_->subchannel_.get(), parent_->chand_, parent_.get(), parent_->subchannel_.get(),
watcher_.get()); watcher_.get());
}
ConnectivityStateChange state_change = PopConnectivityStateChange(); ConnectivityStateChange state_change = PopConnectivityStateChange();
absl::optional<absl::Cord> keepalive_throttling = absl::optional<absl::Cord> keepalive_throttling =
state_change.status.GetPayload(kKeepaliveThrottlingKey); state_change.status.GetPayload(kKeepaliveThrottlingKey);
@ -666,9 +675,10 @@ class ClientChannel::SubchannelWrapper : public SubchannelInterface {
&new_keepalive_time)) { &new_keepalive_time)) {
if (new_keepalive_time > parent_->chand_->keepalive_time_) { if (new_keepalive_time > parent_->chand_->keepalive_time_) {
parent_->chand_->keepalive_time_ = new_keepalive_time; parent_->chand_->keepalive_time_ = new_keepalive_time;
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: throttling keepalive time to %d", gpr_log(GPR_INFO, "chand=%p: throttling keepalive time to %d",
parent_->chand_, parent_->chand_->keepalive_time_); parent_->chand_, parent_->chand_->keepalive_time_);
}
// Propagate the new keepalive time to all subchannels. This is so // Propagate the new keepalive time to all subchannels. This is so
// that new transports created by any subchannel (and not just the // that new transports created by any subchannel (and not just the
// subchannel that received the GOAWAY), use the new keepalive time. // subchannel that received the GOAWAY), use the new keepalive time.
@ -995,8 +1005,9 @@ class ClientChannel::ClientChannelControlHelper
void RequestReresolution() override void RequestReresolution() override
ABSL_EXCLUSIVE_LOCKS_REQUIRED(chand_->work_serializer_) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(chand_->work_serializer_) {
if (chand_->resolver_ == nullptr) return; // Shutting down. if (chand_->resolver_ == nullptr) return; // Shutting down.
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: started name re-resolving", chand_); gpr_log(GPR_INFO, "chand=%p: started name re-resolving", chand_);
}
chand_->resolver_->RequestReresolutionLocked(); chand_->resolver_->RequestReresolutionLocked();
} }
@ -1078,9 +1089,10 @@ ClientChannel::ClientChannel(grpc_channel_element_args* args,
state_tracker_("client_channel", GRPC_CHANNEL_IDLE), state_tracker_("client_channel", GRPC_CHANNEL_IDLE),
subchannel_pool_(GetSubchannelPool(args->channel_args)), subchannel_pool_(GetSubchannelPool(args->channel_args)),
disconnect_error_(GRPC_ERROR_NONE) { disconnect_error_(GRPC_ERROR_NONE) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: creating client_channel for channel stack %p", this, gpr_log(GPR_INFO, "chand=%p: creating client_channel for channel stack %p",
owning_stack_); this, owning_stack_);
}
// Start backup polling. // Start backup polling.
grpc_client_channel_start_backup_polling(interested_parties_); grpc_client_channel_start_backup_polling(interested_parties_);
// Check client channel factory. // Check client channel factory.
@ -1139,8 +1151,9 @@ ClientChannel::ClientChannel(grpc_channel_element_args* args,
} }
ClientChannel::~ClientChannel() { ClientChannel::~ClientChannel() {
grpc_client_channel_routing_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
"chand=%p: destroying channel", this); gpr_log(GPR_INFO, "chand=%p: destroying channel", this);
}
DestroyResolverAndLbPolicyLocked(); DestroyResolverAndLbPolicyLocked();
grpc_channel_args_destroy(channel_args_); grpc_channel_args_destroy(channel_args_);
GRPC_ERROR_UNREF(resolver_transient_failure_error_); GRPC_ERROR_UNREF(resolver_transient_failure_error_);
@ -1211,8 +1224,9 @@ RefCountedPtr<LoadBalancingPolicy::Config> ChooseLbPolicy(
void ClientChannel::OnResolverResultChangedLocked(Resolver::Result result) { void ClientChannel::OnResolverResultChangedLocked(Resolver::Result result) {
// Handle race conditions. // Handle race conditions.
if (resolver_ == nullptr) return; if (resolver_ == nullptr) return;
grpc_client_channel_routing_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
"chand=%p: got resolver result", this); gpr_log(GPR_INFO, "chand=%p: got resolver result", this);
}
// We only want to trace the address resolution in the follow cases: // We only want to trace the address resolution in the follow cases:
// (a) Address resolution resulted in service config change. // (a) Address resolution resulted in service config change.
// (b) Address resolution that causes number of backends to go from // (b) Address resolution that causes number of backends to go from
@ -1240,17 +1254,19 @@ void ClientChannel::OnResolverResultChangedLocked(Resolver::Result result) {
RefCountedPtr<ServiceConfig> service_config; RefCountedPtr<ServiceConfig> service_config;
RefCountedPtr<ConfigSelector> config_selector; RefCountedPtr<ConfigSelector> config_selector;
if (result.service_config_error != GRPC_ERROR_NONE) { if (result.service_config_error != GRPC_ERROR_NONE) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: resolver returned service config error: %s", this, gpr_log(GPR_INFO, "chand=%p: resolver returned service config error: %s",
grpc_error_std_string(result.service_config_error).c_str()); this, grpc_error_std_string(result.service_config_error).c_str());
}
// If the service config was invalid, then fallback to the // If the service config was invalid, then fallback to the
// previously returned service config. // previously returned service config.
if (saved_service_config_ != nullptr) { if (saved_service_config_ != nullptr) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: resolver returned invalid service config. " "chand=%p: resolver returned invalid service config. "
"Continuing to use previous service config.", "Continuing to use previous service config.",
this); this);
}
service_config = saved_service_config_; service_config = saved_service_config_;
config_selector = saved_config_selector_; config_selector = saved_config_selector_;
} else { } else {
@ -1262,11 +1278,12 @@ void ClientChannel::OnResolverResultChangedLocked(Resolver::Result result) {
} }
} else if (result.service_config == nullptr) { } else if (result.service_config == nullptr) {
// Resolver did not return any service config. // Resolver did not return any service config.
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: resolver returned no service config. Using default " "chand=%p: resolver returned no service config. Using default "
"service config for channel.", "service config for channel.",
this); this);
}
service_config = default_service_config_; service_config = default_service_config_;
} else { } else {
// Use ServiceConfig and ConfigSelector returned by resolver. // Use ServiceConfig and ConfigSelector returned by resolver.
@ -1295,9 +1312,8 @@ void ClientChannel::OnResolverResultChangedLocked(Resolver::Result result) {
UpdateServiceConfigInControlPlaneLocked( UpdateServiceConfigInControlPlaneLocked(
std::move(service_config), std::move(config_selector), std::move(service_config), std::move(config_selector),
parsed_service_config, lb_policy_config->name()); parsed_service_config, lb_policy_config->name());
} else { } else if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
grpc_client_channel_routing_trace.Log( gpr_log(GPR_INFO, "chand=%p: service config not changed", this);
GPR_INFO, "chand=%p: service config not changed", this);
} }
// Create or update LB policy, as needed. // Create or update LB policy, as needed.
CreateOrUpdateLbPolicyLocked(std::move(lb_policy_config), CreateOrUpdateLbPolicyLocked(std::move(lb_policy_config),
@ -1329,9 +1345,10 @@ void ClientChannel::OnResolverErrorLocked(grpc_error_handle error) {
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
return; return;
} }
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: resolver transient failure: %s", this, gpr_log(GPR_INFO, "chand=%p: resolver transient failure: %s", this,
grpc_error_std_string(error).c_str()); grpc_error_std_string(error).c_str());
}
// If we already have an LB policy from a previous resolution // If we already have an LB policy from a previous resolution
// result, then we continue to let it set the connectivity state. // result, then we continue to let it set the connectivity state.
// Otherwise, we go into TRANSIENT_FAILURE. // Otherwise, we go into TRANSIENT_FAILURE.
@ -1382,8 +1399,10 @@ void ClientChannel::CreateOrUpdateLbPolicyLocked(
lb_policy_ = CreateLbPolicyLocked(*update_args.args); lb_policy_ = CreateLbPolicyLocked(*update_args.args);
} }
// Update the policy. // Update the policy.
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: Updating child policy %p", this, lb_policy_.get()); gpr_log(GPR_INFO, "chand=%p: Updating child policy %p", this,
lb_policy_.get());
}
lb_policy_->UpdateLocked(std::move(update_args)); lb_policy_->UpdateLocked(std::move(update_args));
} }
@ -1398,8 +1417,10 @@ OrphanablePtr<LoadBalancingPolicy> ClientChannel::CreateLbPolicyLocked(
OrphanablePtr<LoadBalancingPolicy> lb_policy = OrphanablePtr<LoadBalancingPolicy> lb_policy =
MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args), MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
&grpc_client_channel_routing_trace); &grpc_client_channel_routing_trace);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: created new LB policy %p", this, lb_policy.get()); gpr_log(GPR_INFO, "chand=%p: created new LB policy %p", this,
lb_policy.get());
}
grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(), grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
interested_parties_); interested_parties_);
return lb_policy; return lb_policy;
@ -1436,9 +1457,11 @@ void ClientChannel::UpdateServiceConfigInControlPlaneLocked(
const char* lb_policy_name) { const char* lb_policy_name) {
UniquePtr<char> service_config_json( UniquePtr<char> service_config_json(
gpr_strdup(service_config->json_string().c_str())); gpr_strdup(service_config->json_string().c_str()));
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: resolver returned updated service config: \"%s\"", gpr_log(GPR_INFO,
this, service_config_json.get()); "chand=%p: resolver returned updated service config: \"%s\"", this,
service_config_json.get());
}
// Save service config. // Save service config.
saved_service_config_ = std::move(service_config); saved_service_config_ = std::move(service_config);
// Update health check service name if needed. // Update health check service name if needed.
@ -1461,9 +1484,10 @@ void ClientChannel::UpdateServiceConfigInControlPlaneLocked(
} }
// Save config selector. // Save config selector.
saved_config_selector_ = std::move(config_selector); saved_config_selector_ = std::move(config_selector);
grpc_client_channel_routing_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
"chand=%p: using ConfigSelector %p", gpr_log(GPR_INFO, "chand=%p: using ConfigSelector %p", this,
this, saved_config_selector_.get()); saved_config_selector_.get());
}
} }
void ClientChannel::UpdateServiceConfigInDataPlaneLocked() { void ClientChannel::UpdateServiceConfigInDataPlaneLocked() {
@ -1471,9 +1495,10 @@ void ClientChannel::UpdateServiceConfigInDataPlaneLocked() {
RefCountedPtr<ServiceConfig> service_config = saved_service_config_; RefCountedPtr<ServiceConfig> service_config = saved_service_config_;
// Grab ref to config selector. Use default if resolver didn't supply one. // Grab ref to config selector. Use default if resolver didn't supply one.
RefCountedPtr<ConfigSelector> config_selector = saved_config_selector_; RefCountedPtr<ConfigSelector> config_selector = saved_config_selector_;
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: switching to ConfigSelector %p", this, gpr_log(GPR_INFO, "chand=%p: switching to ConfigSelector %p", this,
saved_config_selector_.get()); saved_config_selector_.get());
}
if (config_selector == nullptr) { if (config_selector == nullptr) {
config_selector = config_selector =
MakeRefCounted<DefaultConfigSelector>(saved_service_config_); MakeRefCounted<DefaultConfigSelector>(saved_service_config_);
@ -1543,8 +1568,9 @@ void ClientChannel::UpdateServiceConfigInDataPlaneLocked() {
} }
void ClientChannel::CreateResolverLocked() { void ClientChannel::CreateResolverLocked() {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: starting name resolution", this); gpr_log(GPR_INFO, "chand=%p: starting name resolution", this);
}
resolver_ = ResolverRegistry::CreateResolver( resolver_ = ResolverRegistry::CreateResolver(
target_uri_.get(), channel_args_, interested_parties_, work_serializer_, target_uri_.get(), channel_args_, interested_parties_, work_serializer_,
absl::make_unique<ResolverResultHandler>(this)); absl::make_unique<ResolverResultHandler>(this));
@ -1555,19 +1581,23 @@ void ClientChannel::CreateResolverLocked() {
GRPC_CHANNEL_CONNECTING, absl::Status(), "started resolving", GRPC_CHANNEL_CONNECTING, absl::Status(), "started resolving",
absl::make_unique<LoadBalancingPolicy::QueuePicker>(nullptr)); absl::make_unique<LoadBalancingPolicy::QueuePicker>(nullptr));
resolver_->StartLocked(); resolver_->StartLocked();
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: created resolver=%p", this, resolver_.get()); gpr_log(GPR_INFO, "chand=%p: created resolver=%p", this, resolver_.get());
}
} }
void ClientChannel::DestroyResolverAndLbPolicyLocked() { void ClientChannel::DestroyResolverAndLbPolicyLocked() {
if (resolver_ != nullptr) { if (resolver_ != nullptr) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: shutting down resolver=%p", this, resolver_.get()); gpr_log(GPR_INFO, "chand=%p: shutting down resolver=%p", this,
resolver_.get());
}
resolver_.reset(); resolver_.reset();
if (lb_policy_ != nullptr) { if (lb_policy_ != nullptr) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p: shutting down lb_policy=%p", this, gpr_log(GPR_INFO, "chand=%p: shutting down lb_policy=%p", this,
lb_policy_.get()); lb_policy_.get());
}
grpc_pollset_set_del_pollset_set(lb_policy_->interested_parties(), grpc_pollset_set_del_pollset_set(lb_policy_->interested_parties(),
interested_parties_); interested_parties_);
lb_policy_.reset(); lb_policy_.reset();
@ -1620,11 +1650,12 @@ void ClientChannel::UpdateStateAndPickerLocked(
MutexLock lock(&data_plane_mu_); MutexLock lock(&data_plane_mu_);
// Handle subchannel updates. // Handle subchannel updates.
for (auto& p : pending_subchannel_updates_) { for (auto& p : pending_subchannel_updates_) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p: updating subchannel wrapper %p data plane " "chand=%p: updating subchannel wrapper %p data plane "
"connected_subchannel to %p", "connected_subchannel to %p",
this, p.first.get(), p.second.get()); this, p.first.get(), p.second.get());
}
// Note: We do not remove the entry from pending_subchannel_updates_ // Note: We do not remove the entry from pending_subchannel_updates_
// here, since this would unref the subchannel wrapper; instead, // here, since this would unref the subchannel wrapper; instead,
// we wait until we've released the lock to clear the map. // we wait until we've released the lock to clear the map.
@ -1755,9 +1786,10 @@ void ClientChannel::StartTransportOpLocked(grpc_transport_op* op) {
} }
// Disconnect or enter IDLE. // Disconnect or enter IDLE.
if (op->disconnect_with_error != GRPC_ERROR_NONE) { if (op->disconnect_with_error != GRPC_ERROR_NONE) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p: disconnect_with_error: %s", this, gpr_log(GPR_INFO, "chand=%p: disconnect_with_error: %s", this,
grpc_error_std_string(op->disconnect_with_error).c_str()); grpc_error_std_string(op->disconnect_with_error).c_str());
}
DestroyResolverAndLbPolicyLocked(); DestroyResolverAndLbPolicyLocked();
intptr_t value; intptr_t value;
if (grpc_error_get_int(op->disconnect_with_error, if (grpc_error_get_int(op->disconnect_with_error,
@ -1904,8 +1936,9 @@ ClientChannel::CallData::CallData(grpc_call_element* elem,
owning_call_(args.call_stack), owning_call_(args.call_stack),
call_combiner_(args.call_combiner), call_combiner_(args.call_combiner),
call_context_(args.context) { call_context_(args.context) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p calld=%p: created call", &chand, this); gpr_log(GPR_INFO, "chand=%p calld=%p: created call", &chand, this);
}
} }
ClientChannel::CallData::~CallData() { ClientChannel::CallData::~CallData() {
@ -1958,9 +1991,10 @@ void ClientChannel::CallData::StartTransportStreamOpBatch(
// Note that once we have done so, we do not need to acquire the channel's // Note that once we have done so, we do not need to acquire the channel's
// resolution mutex, which is more efficient (especially for streaming calls). // resolution mutex, which is more efficient (especially for streaming calls).
if (calld->dynamic_call_ != nullptr) { if (calld->dynamic_call_ != nullptr) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p calld=%p: starting batch on dynamic_call=%p", chand, gpr_log(GPR_INFO, "chand=%p calld=%p: starting batch on dynamic_call=%p",
calld, calld->dynamic_call_.get()); chand, calld, calld->dynamic_call_.get());
}
calld->dynamic_call_->StartTransportStreamOpBatch(batch); calld->dynamic_call_->StartTransportStreamOpBatch(batch);
return; return;
} }
@ -1968,9 +2002,11 @@ void ClientChannel::CallData::StartTransportStreamOpBatch(
// //
// If we've previously been cancelled, immediately fail any new batches. // If we've previously been cancelled, immediately fail any new batches.
if (GPR_UNLIKELY(calld->cancel_error_ != GRPC_ERROR_NONE)) { if (GPR_UNLIKELY(calld->cancel_error_ != GRPC_ERROR_NONE)) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p calld=%p: failing batch with error: %s", chand, gpr_log(GPR_INFO, "chand=%p calld=%p: failing batch with error: %s",
calld, grpc_error_std_string(calld->cancel_error_).c_str()); chand, calld,
grpc_error_std_string(calld->cancel_error_).c_str());
}
// Note: This will release the call combiner. // Note: This will release the call combiner.
grpc_transport_stream_op_batch_finish_with_failure( grpc_transport_stream_op_batch_finish_with_failure(
batch, GRPC_ERROR_REF(calld->cancel_error_), calld->call_combiner_); batch, GRPC_ERROR_REF(calld->cancel_error_), calld->call_combiner_);
@ -1986,9 +2022,10 @@ void ClientChannel::CallData::StartTransportStreamOpBatch(
GRPC_ERROR_UNREF(calld->cancel_error_); GRPC_ERROR_UNREF(calld->cancel_error_);
calld->cancel_error_ = calld->cancel_error_ =
GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error); GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error);
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p calld=%p: recording cancel_error=%s", chand, calld, gpr_log(GPR_INFO, "chand=%p calld=%p: recording cancel_error=%s", chand,
grpc_error_std_string(calld->cancel_error_).c_str()); calld, grpc_error_std_string(calld->cancel_error_).c_str());
}
// Fail all pending batches. // Fail all pending batches.
calld->PendingBatchesFail(elem, GRPC_ERROR_REF(calld->cancel_error_), calld->PendingBatchesFail(elem, GRPC_ERROR_REF(calld->cancel_error_),
NoYieldCallCombiner); NoYieldCallCombiner);
@ -2003,17 +2040,20 @@ void ClientChannel::CallData::StartTransportStreamOpBatch(
// channel's resolution mutex to apply the service config to the call, // channel's resolution mutex to apply the service config to the call,
// after which we will create a dynamic call. // after which we will create a dynamic call.
if (GPR_LIKELY(batch->send_initial_metadata)) { if (GPR_LIKELY(batch->send_initial_metadata)) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p: grabbing resolution mutex to apply service " "chand=%p calld=%p: grabbing resolution mutex to apply service "
"config", "config",
chand, calld); chand, calld);
}
CheckResolution(elem, GRPC_ERROR_NONE); CheckResolution(elem, GRPC_ERROR_NONE);
} else { } else {
// For all other batches, release the call combiner. // For all other batches, release the call combiner.
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p calld=%p: saved batch, yielding call combiner", gpr_log(GPR_INFO,
chand, calld); "chand=%p calld=%p: saved batch, yielding call combiner", chand,
calld);
}
GRPC_CALL_COMBINER_STOP(calld->call_combiner_, GRPC_CALL_COMBINER_STOP(calld->call_combiner_,
"batch does not include send_initial_metadata"); "batch does not include send_initial_metadata");
} }
@ -2048,9 +2088,11 @@ void ClientChannel::CallData::PendingBatchesAdd(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
ClientChannel* chand = static_cast<ClientChannel*>(elem->channel_data); ClientChannel* chand = static_cast<ClientChannel*>(elem->channel_data);
const size_t idx = GetBatchIndex(batch); const size_t idx = GetBatchIndex(batch);
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p calld=%p: adding pending batch at index %" PRIuPTR, gpr_log(GPR_INFO,
chand, this, idx); "chand=%p calld=%p: adding pending batch at index %" PRIuPTR, chand,
this, idx);
}
grpc_transport_stream_op_batch*& pending = pending_batches_[idx]; grpc_transport_stream_op_batch*& pending = pending_batches_[idx];
GPR_ASSERT(pending == nullptr); GPR_ASSERT(pending == nullptr);
pending = batch; pending = batch;
@ -2168,12 +2210,13 @@ class ClientChannel::CallData::ResolverQueuedCallCanceller {
auto* calld = static_cast<CallData*>(self->elem_->call_data); auto* calld = static_cast<CallData*>(self->elem_->call_data);
{ {
MutexLock lock(&chand->resolution_mu_); MutexLock lock(&chand->resolution_mu_);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p: cancelling resolver queued pick: " "chand=%p calld=%p: cancelling resolver queued pick: "
"error=%s self=%p calld->resolver_pick_canceller=%p", "error=%s self=%p calld->resolver_pick_canceller=%p",
chand, calld, grpc_error_std_string(error).c_str(), self, chand, calld, grpc_error_std_string(error).c_str(), self,
calld->resolver_call_canceller_); calld->resolver_call_canceller_);
}
if (calld->resolver_call_canceller_ == self && error != GRPC_ERROR_NONE) { if (calld->resolver_call_canceller_ == self && error != GRPC_ERROR_NONE) {
// Remove pick from list of queued picks. // Remove pick from list of queued picks.
calld->MaybeRemoveCallFromResolverQueuedCallsLocked(self->elem_); calld->MaybeRemoveCallFromResolverQueuedCallsLocked(self->elem_);
@ -2194,9 +2237,11 @@ void ClientChannel::CallData::MaybeRemoveCallFromResolverQueuedCallsLocked(
grpc_call_element* elem) { grpc_call_element* elem) {
if (!queued_pending_resolver_result_) return; if (!queued_pending_resolver_result_) return;
auto* chand = static_cast<ClientChannel*>(elem->channel_data); auto* chand = static_cast<ClientChannel*>(elem->channel_data);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p calld=%p: removing from resolver queued picks list", gpr_log(GPR_INFO,
chand, this); "chand=%p calld=%p: removing from resolver queued picks list",
chand, this);
}
chand->RemoveResolverQueuedCall(&resolver_queued_call_, pollent_); chand->RemoveResolverQueuedCall(&resolver_queued_call_, pollent_);
queued_pending_resolver_result_ = false; queued_pending_resolver_result_ = false;
// Lame the call combiner canceller. // Lame the call combiner canceller.
@ -2207,9 +2252,10 @@ void ClientChannel::CallData::MaybeAddCallToResolverQueuedCallsLocked(
grpc_call_element* elem) { grpc_call_element* elem) {
if (queued_pending_resolver_result_) return; if (queued_pending_resolver_result_) return;
auto* chand = static_cast<ClientChannel*>(elem->channel_data); auto* chand = static_cast<ClientChannel*>(elem->channel_data);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p calld=%p: adding to resolver queued picks list", gpr_log(GPR_INFO, "chand=%p calld=%p: adding to resolver queued picks list",
chand, this); chand, this);
}
queued_pending_resolver_result_ = true; queued_pending_resolver_result_ = true;
resolver_queued_call_.elem = elem; resolver_queued_call_.elem = elem;
chand->AddResolverQueuedCall(&resolver_queued_call_, pollent_); chand->AddResolverQueuedCall(&resolver_queued_call_, pollent_);
@ -2220,9 +2266,10 @@ void ClientChannel::CallData::MaybeAddCallToResolverQueuedCallsLocked(
grpc_error_handle ClientChannel::CallData::ApplyServiceConfigToCallLocked( grpc_error_handle ClientChannel::CallData::ApplyServiceConfigToCallLocked(
grpc_call_element* elem, grpc_metadata_batch* initial_metadata) { grpc_call_element* elem, grpc_metadata_batch* initial_metadata) {
ClientChannel* chand = static_cast<ClientChannel*>(elem->channel_data); ClientChannel* chand = static_cast<ClientChannel*>(elem->channel_data);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p calld=%p: applying service config to call", chand, gpr_log(GPR_INFO, "chand=%p calld=%p: applying service config to call",
this); chand, this);
}
ConfigSelector* config_selector = chand->config_selector_.get(); ConfigSelector* config_selector = chand->config_selector_.get();
if (config_selector != nullptr) { if (config_selector != nullptr) {
// Use the ConfigSelector to determine the config for the call. // Use the ConfigSelector to determine the config for the call.
@ -2314,9 +2361,11 @@ void ClientChannel::CallData::ResolutionDone(void* arg,
ClientChannel* chand = static_cast<ClientChannel*>(elem->channel_data); ClientChannel* chand = static_cast<ClientChannel*>(elem->channel_data);
CallData* calld = static_cast<CallData*>(elem->call_data); CallData* calld = static_cast<CallData*>(elem->call_data);
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p calld=%p: error applying config to call: error=%s", gpr_log(GPR_INFO,
chand, calld, grpc_error_std_string(error).c_str()); "chand=%p calld=%p: error applying config to call: error=%s",
chand, calld, grpc_error_std_string(error).c_str());
}
calld->PendingBatchesFail(elem, GRPC_ERROR_REF(error), YieldCallCombiner); calld->PendingBatchesFail(elem, GRPC_ERROR_REF(error), YieldCallCombiner);
return; return;
} }
@ -2413,15 +2462,19 @@ void ClientChannel::CallData::CreateDynamicCall(grpc_call_element* elem) {
call_combiner_}; call_combiner_};
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
DynamicFilters* channel_stack = args.channel_stack.get(); DynamicFilters* channel_stack = args.channel_stack.get();
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(
"chand=%p calld=%p: creating dynamic call stack on channel_stack=%p", GPR_INFO,
chand, this, channel_stack); "chand=%p calld=%p: creating dynamic call stack on channel_stack=%p",
chand, this, channel_stack);
}
dynamic_call_ = channel_stack->CreateCall(std::move(args), &error); dynamic_call_ = channel_stack->CreateCall(std::move(args), &error);
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p calld=%p: failed to create dynamic call: error=%s", gpr_log(GPR_INFO,
chand, this, grpc_error_std_string(error).c_str()); "chand=%p calld=%p: failed to create dynamic call: error=%s",
chand, this, grpc_error_std_string(error).c_str());
}
PendingBatchesFail(elem, error, YieldCallCombiner); PendingBatchesFail(elem, error, YieldCallCombiner);
return; return;
} }
@ -2614,9 +2667,11 @@ size_t ClientChannel::LoadBalancedCall::GetBatchIndex(
void ClientChannel::LoadBalancedCall::PendingBatchesAdd( void ClientChannel::LoadBalancedCall::PendingBatchesAdd(
grpc_transport_stream_op_batch* batch) { grpc_transport_stream_op_batch* batch) {
const size_t idx = GetBatchIndex(batch); const size_t idx = GetBatchIndex(batch);
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p lb_call=%p: adding pending batch at index %" PRIuPTR, gpr_log(GPR_INFO,
chand_, this, idx); "chand=%p lb_call=%p: adding pending batch at index %" PRIuPTR,
chand_, this, idx);
}
GPR_ASSERT(pending_batches_[idx] == nullptr); GPR_ASSERT(pending_batches_[idx] == nullptr);
pending_batches_[idx] = batch; pending_batches_[idx] = batch;
} }
@ -2773,9 +2828,11 @@ void ClientChannel::LoadBalancedCall::StartTransportStreamOpBatch(
// the channel's data plane mutex, which is more efficient (especially for // the channel's data plane mutex, which is more efficient (especially for
// streaming calls). // streaming calls).
if (subchannel_call_ != nullptr) { if (subchannel_call_ != nullptr) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p lb_call=%p: starting batch on subchannel_call=%p", gpr_log(GPR_INFO,
chand_, this, subchannel_call_.get()); "chand=%p lb_call=%p: starting batch on subchannel_call=%p",
chand_, this, subchannel_call_.get());
}
subchannel_call_->StartTransportStreamOpBatch(batch); subchannel_call_->StartTransportStreamOpBatch(batch);
return; return;
} }
@ -2783,9 +2840,10 @@ void ClientChannel::LoadBalancedCall::StartTransportStreamOpBatch(
// //
// If we've previously been cancelled, immediately fail any new batches. // If we've previously been cancelled, immediately fail any new batches.
if (GPR_UNLIKELY(cancel_error_ != GRPC_ERROR_NONE)) { if (GPR_UNLIKELY(cancel_error_ != GRPC_ERROR_NONE)) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p lb_call=%p: failing batch with error: %s", chand_, gpr_log(GPR_INFO, "chand=%p lb_call=%p: failing batch with error: %s",
this, grpc_error_std_string(cancel_error_).c_str()); chand_, this, grpc_error_std_string(cancel_error_).c_str());
}
// Note: This will release the call combiner. // Note: This will release the call combiner.
grpc_transport_stream_op_batch_finish_with_failure( grpc_transport_stream_op_batch_finish_with_failure(
batch, GRPC_ERROR_REF(cancel_error_), call_combiner_); batch, GRPC_ERROR_REF(cancel_error_), call_combiner_);
@ -2800,9 +2858,10 @@ void ClientChannel::LoadBalancedCall::StartTransportStreamOpBatch(
// error to the caller when the first batch does get passed down. // error to the caller when the first batch does get passed down.
GRPC_ERROR_UNREF(cancel_error_); GRPC_ERROR_UNREF(cancel_error_);
cancel_error_ = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error); cancel_error_ = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error);
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p lb_call=%p: recording cancel_error=%s", chand_, gpr_log(GPR_INFO, "chand=%p lb_call=%p: recording cancel_error=%s",
this, grpc_error_std_string(cancel_error_).c_str()); chand_, this, grpc_error_std_string(cancel_error_).c_str());
}
// Fail all pending batches. // Fail all pending batches.
PendingBatchesFail(GRPC_ERROR_REF(cancel_error_), NoYieldCallCombiner); PendingBatchesFail(GRPC_ERROR_REF(cancel_error_), NoYieldCallCombiner);
// Note: This will release the call combiner. // Note: This will release the call combiner.
@ -2815,16 +2874,19 @@ void ClientChannel::LoadBalancedCall::StartTransportStreamOpBatch(
// For batches containing a send_initial_metadata op, acquire the // For batches containing a send_initial_metadata op, acquire the
// channel's data plane mutex to pick a subchannel. // channel's data plane mutex to pick a subchannel.
if (GPR_LIKELY(batch->send_initial_metadata)) { if (GPR_LIKELY(batch->send_initial_metadata)) {
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p lb_call=%p: grabbing data plane mutex to perform pick", "chand=%p lb_call=%p: grabbing data plane mutex to perform pick",
chand_, this); chand_, this);
}
PickSubchannel(this, GRPC_ERROR_NONE); PickSubchannel(this, GRPC_ERROR_NONE);
} else { } else {
// For all other batches, release the call combiner. // For all other batches, release the call combiner.
grpc_client_channel_call_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_call_trace)) {
GPR_INFO, "chand=%p lb_call=%p: saved batch, yielding call combiner", gpr_log(GPR_INFO,
chand_, this); "chand=%p lb_call=%p: saved batch, yielding call combiner",
chand_, this);
}
GRPC_CALL_COMBINER_STOP(call_combiner_, GRPC_CALL_COMBINER_STOP(call_combiner_,
"batch does not include send_initial_metadata"); "batch does not include send_initial_metadata");
} }
@ -2927,10 +2989,11 @@ void ClientChannel::LoadBalancedCall::CreateSubchannelCall() {
call_context_, call_combiner_}; call_context_, call_combiner_};
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
subchannel_call_ = SubchannelCall::Create(std::move(call_args), &error); subchannel_call_ = SubchannelCall::Create(std::move(call_args), &error);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: create subchannel_call=%p: error=%s", gpr_log(GPR_INFO,
chand_, this, subchannel_call_.get(), "chand=%p lb_call=%p: create subchannel_call=%p: error=%s", chand_,
grpc_error_std_string(error).c_str()); this, subchannel_call_.get(), grpc_error_std_string(error).c_str());
}
if (on_call_destruction_complete_ != nullptr) { if (on_call_destruction_complete_ != nullptr) {
subchannel_call_->SetAfterCallStackDestroy(on_call_destruction_complete_); subchannel_call_->SetAfterCallStackDestroy(on_call_destruction_complete_);
on_call_destruction_complete_ = nullptr; on_call_destruction_complete_ = nullptr;
@ -2965,12 +3028,13 @@ class ClientChannel::LoadBalancedCall::LbQueuedCallCanceller {
auto* chand = lb_call->chand_; auto* chand = lb_call->chand_;
{ {
MutexLock lock(&chand->data_plane_mu_); MutexLock lock(&chand->data_plane_mu_);
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p lb_call=%p: cancelling queued pick: " "chand=%p lb_call=%p: cancelling queued pick: "
"error=%s self=%p calld->pick_canceller=%p", "error=%s self=%p calld->pick_canceller=%p",
chand, lb_call, grpc_error_std_string(error).c_str(), self, chand, lb_call, grpc_error_std_string(error).c_str(), self,
lb_call->lb_call_canceller_); lb_call->lb_call_canceller_);
}
if (lb_call->lb_call_canceller_ == self && error != GRPC_ERROR_NONE) { if (lb_call->lb_call_canceller_ == self && error != GRPC_ERROR_NONE) {
lb_call->call_dispatch_controller_->Commit(); lb_call->call_dispatch_controller_->Commit();
// Remove pick from list of queued picks. // Remove pick from list of queued picks.
@ -2990,9 +3054,10 @@ class ClientChannel::LoadBalancedCall::LbQueuedCallCanceller {
void ClientChannel::LoadBalancedCall::MaybeRemoveCallFromLbQueuedCallsLocked() { void ClientChannel::LoadBalancedCall::MaybeRemoveCallFromLbQueuedCallsLocked() {
if (!queued_pending_lb_pick_) return; if (!queued_pending_lb_pick_) return;
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: removing from queued picks list", chand_, gpr_log(GPR_INFO, "chand=%p lb_call=%p: removing from queued picks list",
this); chand_, this);
}
chand_->RemoveLbQueuedCall(&queued_call_, pollent_); chand_->RemoveLbQueuedCall(&queued_call_, pollent_);
queued_pending_lb_pick_ = false; queued_pending_lb_pick_ = false;
// Lame the call combiner canceller. // Lame the call combiner canceller.
@ -3001,9 +3066,10 @@ void ClientChannel::LoadBalancedCall::MaybeRemoveCallFromLbQueuedCallsLocked() {
void ClientChannel::LoadBalancedCall::MaybeAddCallToLbQueuedCallsLocked() { void ClientChannel::LoadBalancedCall::MaybeAddCallToLbQueuedCallsLocked() {
if (queued_pending_lb_pick_) return; if (queued_pending_lb_pick_) return;
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: adding to queued picks list", chand_, gpr_log(GPR_INFO, "chand=%p lb_call=%p: adding to queued picks list",
this); chand_, this);
}
queued_pending_lb_pick_ = true; queued_pending_lb_pick_ = true;
queued_call_.lb_call = this; queued_call_.lb_call = this;
chand_->AddLbQueuedCall(&queued_call_, pollent_); chand_->AddLbQueuedCall(&queued_call_, pollent_);
@ -3021,9 +3087,11 @@ void ClientChannel::LoadBalancedCall::PickDone(void* arg,
grpc_error_handle error) { grpc_error_handle error) {
auto* self = static_cast<LoadBalancedCall*>(arg); auto* self = static_cast<LoadBalancedCall*>(arg);
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: failed to pick subchannel: error=%s", gpr_log(GPR_INFO,
self->chand_, self, grpc_error_std_string(error).c_str()); "chand=%p lb_call=%p: failed to pick subchannel: error=%s",
self->chand_, self, grpc_error_std_string(error).c_str());
}
self->PendingBatchesFail(GRPC_ERROR_REF(error), YieldCallCombiner); self->PendingBatchesFail(GRPC_ERROR_REF(error), YieldCallCombiner);
return; return;
} }
@ -3069,10 +3137,11 @@ bool ClientChannel::LoadBalancedCall::PickSubchannelLocked(
// CompletePick // CompletePick
[this](LoadBalancingPolicy::PickResult::Complete* complete_pick) [this](LoadBalancingPolicy::PickResult::Complete* complete_pick)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p lb_call=%p: LB pick succeeded: subchannel=%p", chand_, "chand=%p lb_call=%p: LB pick succeeded: subchannel=%p",
this, complete_pick->subchannel.get()); chand_, this, complete_pick->subchannel.get());
}
GPR_ASSERT(complete_pick->subchannel != nullptr); GPR_ASSERT(complete_pick->subchannel != nullptr);
// Grab a ref to the connected subchannel while we're still // Grab a ref to the connected subchannel while we're still
// holding the data plane mutex. // holding the data plane mutex.
@ -3087,8 +3156,10 @@ bool ClientChannel::LoadBalancedCall::PickSubchannelLocked(
// QueuePick // QueuePick
[this](LoadBalancingPolicy::PickResult::Queue* /*queue_pick*/) [this](LoadBalancingPolicy::PickResult::Queue* /*queue_pick*/)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: LB pick queued", chand_, this); gpr_log(GPR_INFO, "chand=%p lb_call=%p: LB pick queued", chand_,
this);
}
MaybeAddCallToLbQueuedCallsLocked(); MaybeAddCallToLbQueuedCallsLocked();
return false; return false;
}, },
@ -3096,9 +3167,10 @@ bool ClientChannel::LoadBalancedCall::PickSubchannelLocked(
[this, send_initial_metadata_flags, [this, send_initial_metadata_flags,
&error](LoadBalancingPolicy::PickResult::Fail* fail_pick) &error](LoadBalancingPolicy::PickResult::Fail* fail_pick)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: LB pick failed: %s", chand_, gpr_log(GPR_INFO, "chand=%p lb_call=%p: LB pick failed: %s",
this, fail_pick->status.ToString().c_str()); chand_, this, fail_pick->status.ToString().c_str());
}
// If we're shutting down, fail all RPCs. // If we're shutting down, fail all RPCs.
grpc_error_handle disconnect_error = chand_->disconnect_error(); grpc_error_handle disconnect_error = chand_->disconnect_error();
if (disconnect_error != GRPC_ERROR_NONE) { if (disconnect_error != GRPC_ERROR_NONE) {
@ -3126,9 +3198,10 @@ bool ClientChannel::LoadBalancedCall::PickSubchannelLocked(
// DropPick // DropPick
[this, &error](LoadBalancingPolicy::PickResult::Drop* drop_pick) [this, &error](LoadBalancingPolicy::PickResult::Drop* drop_pick)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) { ABSL_EXCLUSIVE_LOCKS_REQUIRED(&ClientChannel::data_plane_mu_) {
grpc_client_channel_routing_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
GPR_INFO, "chand=%p lb_call=%p: LB pick dropped: %s", chand_, gpr_log(GPR_INFO, "chand=%p lb_call=%p: LB pick dropped: %s",
this, drop_pick->status.ToString().c_str()); chand_, this, drop_pick->status.ToString().c_str());
}
*error = *error =
grpc_error_set_int(absl_status_to_grpc_error(drop_pick->status), grpc_error_set_int(absl_status_to_grpc_error(drop_pick->status),
GRPC_ERROR_INT_LB_POLICY_DROP, 1); GRPC_ERROR_INT_LB_POLICY_DROP, 1);

@ -68,16 +68,18 @@ HealthCheckClient::HealthCheckClient(
.set_jitter(HEALTH_CHECK_RECONNECT_JITTER) .set_jitter(HEALTH_CHECK_RECONNECT_JITTER)
.set_max_backoff(HEALTH_CHECK_RECONNECT_MAX_BACKOFF_SECONDS * .set_max_backoff(HEALTH_CHECK_RECONNECT_MAX_BACKOFF_SECONDS *
1000)) { 1000)) {
grpc_health_check_client_trace.Log(GPR_INFO, "created HealthCheckClient %p", if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
this); gpr_log(GPR_INFO, "created HealthCheckClient %p", this);
}
GRPC_CLOSURE_INIT(&retry_timer_callback_, OnRetryTimer, this, GRPC_CLOSURE_INIT(&retry_timer_callback_, OnRetryTimer, this,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
StartCall(); StartCall();
} }
HealthCheckClient::~HealthCheckClient() { HealthCheckClient::~HealthCheckClient() {
grpc_health_check_client_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
"destroying HealthCheckClient %p", this); gpr_log(GPR_INFO, "destroying HealthCheckClient %p", this);
}
} }
void HealthCheckClient::SetHealthStatus(grpc_connectivity_state state, void HealthCheckClient::SetHealthStatus(grpc_connectivity_state state,
@ -88,9 +90,10 @@ void HealthCheckClient::SetHealthStatus(grpc_connectivity_state state,
void HealthCheckClient::SetHealthStatusLocked(grpc_connectivity_state state, void HealthCheckClient::SetHealthStatusLocked(grpc_connectivity_state state,
const char* reason) { const char* reason) {
grpc_health_check_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
GPR_INFO, "HealthCheckClient %p: setting state=%s reason=%s", this, gpr_log(GPR_INFO, "HealthCheckClient %p: setting state=%s reason=%s", this,
ConnectivityStateName(state), reason); ConnectivityStateName(state), reason);
}
if (watcher_ != nullptr) { if (watcher_ != nullptr) {
watcher_->Notify(state, watcher_->Notify(state,
state == GRPC_CHANNEL_TRANSIENT_FAILURE state == GRPC_CHANNEL_TRANSIENT_FAILURE
@ -100,8 +103,9 @@ void HealthCheckClient::SetHealthStatusLocked(grpc_connectivity_state state,
} }
void HealthCheckClient::Orphan() { void HealthCheckClient::Orphan() {
grpc_health_check_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
GPR_INFO, "HealthCheckClient %p: shutting down", this); gpr_log(GPR_INFO, "HealthCheckClient %p: shutting down", this);
}
{ {
MutexLock lock(&mu_); MutexLock lock(&mu_);
shutting_down_ = true; shutting_down_ = true;
@ -124,9 +128,10 @@ void HealthCheckClient::StartCallLocked() {
GPR_ASSERT(call_state_ == nullptr); GPR_ASSERT(call_state_ == nullptr);
SetHealthStatusLocked(GRPC_CHANNEL_CONNECTING, "starting health watch"); SetHealthStatusLocked(GRPC_CHANNEL_CONNECTING, "starting health watch");
call_state_ = MakeOrphanable<CallState>(Ref(), interested_parties_); call_state_ = MakeOrphanable<CallState>(Ref(), interested_parties_);
grpc_health_check_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
GPR_INFO, "HealthCheckClient %p: created CallState %p", this, gpr_log(GPR_INFO, "HealthCheckClient %p: created CallState %p", this,
call_state_.get()); call_state_.get());
}
call_state_->StartCall(); call_state_->StartCall();
} }
@ -159,8 +164,10 @@ void HealthCheckClient::OnRetryTimer(void* arg, grpc_error_handle error) {
self->retry_timer_callback_pending_ = false; self->retry_timer_callback_pending_ = false;
if (!self->shutting_down_ && error == GRPC_ERROR_NONE && if (!self->shutting_down_ && error == GRPC_ERROR_NONE &&
self->call_state_ == nullptr) { self->call_state_ == nullptr) {
grpc_health_check_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
GPR_INFO, "HealthCheckClient %p: restarting health check call", self); gpr_log(GPR_INFO, "HealthCheckClient %p: restarting health check call",
self);
}
self->StartCallLocked(); self->StartCallLocked();
} }
} }
@ -250,9 +257,10 @@ HealthCheckClient::CallState::CallState(
payload_(context_) {} payload_(context_) {}
HealthCheckClient::CallState::~CallState() { HealthCheckClient::CallState::~CallState() {
grpc_health_check_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
GPR_INFO, "HealthCheckClient %p: destroying CallState %p", gpr_log(GPR_INFO, "HealthCheckClient %p: destroying CallState %p",
health_check_client_.get(), this); health_check_client_.get(), this);
}
for (size_t i = 0; i < GRPC_CONTEXT_COUNT; i++) { for (size_t i = 0; i < GRPC_CONTEXT_COUNT; i++) {
if (context_[i].destroy != nullptr) { if (context_[i].destroy != nullptr) {
context_[i].destroy(context_[i].value); context_[i].destroy(context_[i].value);
@ -554,11 +562,12 @@ void HealthCheckClient::CallState::RecvTrailingMetadataReady(
status = grpc_get_status_code_from_metadata( status = grpc_get_status_code_from_metadata(
self->recv_trailing_metadata_.idx.named.grpc_status->md); self->recv_trailing_metadata_.idx.named.grpc_status->md);
} }
grpc_health_check_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"HealthCheckClient %p CallState %p: health watch failed with " "HealthCheckClient %p CallState %p: health watch failed with "
"status %d", "status %d",
self->health_check_client_.get(), self, status); self->health_check_client_.get(), self, status);
}
// Clean up. // Clean up.
grpc_metadata_batch_destroy(&self->recv_trailing_metadata_); grpc_metadata_batch_destroy(&self->recv_trailing_metadata_);
// For status UNIMPLEMENTED, give up and assume always healthy. // For status UNIMPLEMENTED, give up and assume always healthy.

@ -53,12 +53,13 @@ class ChildPolicyHandler::Helper
// it reports something other than CONNECTING, at which point we swap it // it reports something other than CONNECTING, at which point we swap it
// into place. // into place.
if (CalledByPendingChild()) { if (CalledByPendingChild()) {
parent_->tracer_->Log( if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
GPR_INFO, gpr_log(GPR_INFO,
"[child_policy_handler %p] helper %p: pending child policy %p " "[child_policy_handler %p] helper %p: pending child policy %p "
"reports state=%s (%s)", "reports state=%s (%s)",
parent_.get(), this, child_, ConnectivityStateName(state), parent_.get(), this, child_, ConnectivityStateName(state),
status.ToString().c_str()); status.ToString().c_str());
}
if (state == GRPC_CHANNEL_CONNECTING) return; if (state == GRPC_CHANNEL_CONNECTING) return;
grpc_pollset_set_del_pollset_set( grpc_pollset_set_del_pollset_set(
parent_->child_policy_->interested_parties(), parent_->child_policy_->interested_parties(),
@ -82,9 +83,10 @@ class ChildPolicyHandler::Helper
? parent_->pending_child_policy_.get() ? parent_->pending_child_policy_.get()
: parent_->child_policy_.get(); : parent_->child_policy_.get();
if (child_ != latest_child_policy) return; if (child_ != latest_child_policy) return;
parent_->tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*(parent_->tracer_))) {
"[child_policy_handler %p] started name re-resolving", gpr_log(GPR_INFO, "[child_policy_handler %p] started name re-resolving",
parent_.get()); parent_.get());
}
parent_->channel_control_helper()->RequestReresolution(); parent_->channel_control_helper()->RequestReresolution();
} }
@ -117,20 +119,25 @@ class ChildPolicyHandler::Helper
// //
void ChildPolicyHandler::ShutdownLocked() { void ChildPolicyHandler::ShutdownLocked() {
tracer_->Log(GPR_INFO, "[child_policy_handler %p] shutting down", this); if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
gpr_log(GPR_INFO, "[child_policy_handler %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
if (child_policy_ != nullptr) { if (child_policy_ != nullptr) {
tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
"[child_policy_handler %p] shutting down lb_policy %p", this, gpr_log(GPR_INFO, "[child_policy_handler %p] shutting down lb_policy %p",
child_policy_.get()); this, child_policy_.get());
}
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(), grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
interested_parties()); interested_parties());
child_policy_.reset(); child_policy_.reset();
} }
if (pending_child_policy_ != nullptr) { if (pending_child_policy_ != nullptr) {
tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
"[child_policy_handler %p] shutting down pending lb_policy %p", gpr_log(GPR_INFO,
this, pending_child_policy_.get()); "[child_policy_handler %p] shutting down pending lb_policy %p",
this, pending_child_policy_.get());
}
grpc_pollset_set_del_pollset_set( grpc_pollset_set_del_pollset_set(
pending_child_policy_->interested_parties(), interested_parties()); pending_child_policy_->interested_parties(), interested_parties());
pending_child_policy_.reset(); pending_child_policy_.reset();
@ -203,9 +210,11 @@ void ChildPolicyHandler::UpdateLocked(UpdateArgs args) {
// that there's an upper bound on the amount of time it takes us to // that there's an upper bound on the amount of time it takes us to
// switch to the new policy, even if the new policy stays in // switch to the new policy, even if the new policy stays in
// CONNECTING for a very long period of time. // CONNECTING for a very long period of time.
tracer_->Log( if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
GPR_INFO, "[child_policy_handler %p] creating new %schild policy %s", gpr_log(GPR_INFO,
this, child_policy_ == nullptr ? "" : "pending ", args.config->name()); "[child_policy_handler %p] creating new %schild policy %s", this,
child_policy_ == nullptr ? "" : "pending ", args.config->name());
}
auto& lb_policy = auto& lb_policy =
child_policy_ == nullptr ? child_policy_ : pending_child_policy_; child_policy_ == nullptr ? child_policy_ : pending_child_policy_;
lb_policy = CreateChildPolicy(args.config->name(), *args.args); lb_policy = CreateChildPolicy(args.config->name(), *args.args);
@ -220,10 +229,12 @@ void ChildPolicyHandler::UpdateLocked(UpdateArgs args) {
} }
GPR_ASSERT(policy_to_update != nullptr); GPR_ASSERT(policy_to_update != nullptr);
// Update the policy. // Update the policy.
tracer_->Log( if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
GPR_INFO, "[child_policy_handler %p] updating %schild policy %p", this, gpr_log(GPR_INFO, "[child_policy_handler %p] updating %schild policy %p",
policy_to_update == pending_child_policy_.get() ? "pending " : "", this,
policy_to_update); policy_to_update == pending_child_policy_.get() ? "pending " : "",
policy_to_update);
}
policy_to_update->UpdateLocked(std::move(args)); policy_to_update->UpdateLocked(std::move(args));
} }
@ -260,9 +271,11 @@ OrphanablePtr<LoadBalancingPolicy> ChildPolicyHandler::CreateChildPolicy(
return nullptr; return nullptr;
} }
helper->set_child(lb_policy.get()); helper->set_child(lb_policy.get());
tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
"[child_policy_handler %p] created new LB policy \"%s\" (%p)", gpr_log(GPR_INFO,
this, child_policy_name, lb_policy.get()); "[child_policy_handler %p] created new LB policy \"%s\" (%p)", this,
child_policy_name, lb_policy.get());
}
channel_control_helper()->AddTraceEvent( channel_control_helper()->AddTraceEvent(
ChannelControlHelper::TRACE_INFO, ChannelControlHelper::TRACE_INFO,
absl::StrCat("Created new LB policy \"", child_policy_name, "\"")); absl::StrCat("Created new LB policy \"", child_policy_name, "\""));

@ -709,12 +709,14 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
parent_->lb_calld_->client_stats() != nullptr) { parent_->lb_calld_->client_stats() != nullptr) {
client_stats = parent_->lb_calld_->client_stats()->Ref(); client_stats = parent_->lb_calld_->client_stats()->Ref();
} }
grpc_lb_glb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
"[grpclb %p helper %p] state=%s (%s) wrapping child " gpr_log(GPR_INFO,
"picker %p (serverlist=%p, client_stats=%p)", "[grpclb %p helper %p] state=%s (%s) wrapping child "
parent_.get(), this, ConnectivityStateName(state), "picker %p (serverlist=%p, client_stats=%p)",
status.ToString().c_str(), picker.get(), parent_.get(), this, ConnectivityStateName(state),
serverlist.get(), client_stats.get()); status.ToString().c_str(), picker.get(), serverlist.get(),
client_stats.get());
}
parent_->channel_control_helper()->UpdateState( parent_->channel_control_helper()->UpdateState(
state, status, state, status,
absl::make_unique<Picker>(std::move(serverlist), std::move(picker), absl::make_unique<Picker>(std::move(serverlist), std::move(picker),
@ -815,9 +817,10 @@ void GrpcLb::BalancerCallState::Orphan() {
void GrpcLb::BalancerCallState::StartQuery() { void GrpcLb::BalancerCallState::StartQuery() {
GPR_ASSERT(lb_call_ != nullptr); GPR_ASSERT(lb_call_ != nullptr);
grpc_lb_glb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
"[grpclb %p] lb_calld=%p: Starting LB call %p", gpr_log(GPR_INFO, "[grpclb %p] lb_calld=%p: Starting LB call %p",
grpclb_policy_.get(), this, lb_call_); grpclb_policy_.get(), this, lb_call_);
}
// Create the ops. // Create the ops.
grpc_call_error call_error; grpc_call_error call_error;
grpc_op ops[3]; grpc_op ops[3];
@ -1059,18 +1062,18 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() {
if (response.client_stats_report_interval != 0) { if (response.client_stats_report_interval != 0) {
client_stats_report_interval_ = client_stats_report_interval_ =
GPR_MAX(GPR_MS_PER_SEC, response.client_stats_report_interval); GPR_MAX(GPR_MS_PER_SEC, response.client_stats_report_interval);
grpc_lb_glb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[grpclb %p] lb_calld=%p: Received initial LB response " "[grpclb %p] lb_calld=%p: Received initial LB response "
"message; client load reporting interval = %" PRId64 "message; client load reporting interval = %" PRId64
" milliseconds", " milliseconds",
grpclb_policy(), this, client_stats_report_interval_); grpclb_policy(), this, client_stats_report_interval_);
} else { }
grpc_lb_glb_trace.Log( } else if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[grpclb %p] lb_calld=%p: Received initial LB response " "[grpclb %p] lb_calld=%p: Received initial LB response "
"message; client load reporting NOT enabled", "message; client load reporting NOT enabled",
grpclb_policy(), this); grpclb_policy(), this);
} }
seen_initial_response_ = true; seen_initial_response_ = true;
break; break;
@ -1079,12 +1082,14 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() {
GPR_ASSERT(lb_call_ != nullptr); GPR_ASSERT(lb_call_ != nullptr);
auto serverlist_wrapper = auto serverlist_wrapper =
MakeRefCounted<Serverlist>(std::move(response.serverlist)); MakeRefCounted<Serverlist>(std::move(response.serverlist));
grpc_lb_glb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[grpclb %p] lb_calld=%p: Serverlist with %" PRIuPTR "[grpclb %p] lb_calld=%p: Serverlist with %" PRIuPTR
" servers received:\n%s", " servers received:\n%s",
grpclb_policy(), this, serverlist_wrapper->serverlist().size(), grpclb_policy(), this,
serverlist_wrapper->AsText().c_str()); serverlist_wrapper->serverlist().size(),
serverlist_wrapper->AsText().c_str());
}
seen_serverlist_ = true; seen_serverlist_ = true;
// Start sending client load report only after we start using the // Start sending client load report only after we start using the
// serverlist returned from the current LB call. // serverlist returned from the current LB call.
@ -1097,11 +1102,12 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() {
// Check if the serverlist differs from the previous one. // Check if the serverlist differs from the previous one.
if (grpclb_policy()->serverlist_ != nullptr && if (grpclb_policy()->serverlist_ != nullptr &&
*grpclb_policy()->serverlist_ == *serverlist_wrapper) { *grpclb_policy()->serverlist_ == *serverlist_wrapper) {
grpc_lb_glb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[grpclb %p] lb_calld=%p: Incoming server list identical " "[grpclb %p] lb_calld=%p: Incoming server list identical "
"to current, ignoring.", "to current, ignoring.",
grpclb_policy(), this); grpclb_policy(), this);
}
} else { // New serverlist. } else { // New serverlist.
// Dispose of the fallback. // Dispose of the fallback.
// TODO(roth): Ideally, we should stay in fallback mode until we // TODO(roth): Ideally, we should stay in fallback mode until we
@ -1339,9 +1345,11 @@ GrpcLb::GrpcLb(Args args)
absl::StatusOr<URI> uri = URI::Parse(server_uri); absl::StatusOr<URI> uri = URI::Parse(server_uri);
GPR_ASSERT(uri.ok() && !uri->path().empty()); GPR_ASSERT(uri.ok() && !uri->path().empty());
server_name_ = std::string(absl::StripPrefix(uri->path(), "/")); server_name_ = std::string(absl::StripPrefix(uri->path(), "/"));
grpc_lb_glb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
GPR_INFO, "[grpclb %p] Will use '%s' as the server name for LB request.", gpr_log(GPR_INFO,
this, server_name_.c_str()); "[grpclb %p] Will use '%s' as the server name for LB request.",
this, server_name_.c_str());
}
// Record LB call timeout. // Record LB call timeout.
arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS); arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS);
lb_call_timeout_ms_ = grpc_channel_arg_get_integer(arg, {0, 0, INT_MAX}); lb_call_timeout_ms_ = grpc_channel_arg_get_integer(arg, {0, 0, INT_MAX});
@ -1500,9 +1508,11 @@ void GrpcLb::StartBalancerCallLocked() {
// Init the LB call data. // Init the LB call data.
GPR_ASSERT(lb_calld_ == nullptr); GPR_ASSERT(lb_calld_ == nullptr);
lb_calld_ = MakeOrphanable<BalancerCallState>(Ref()); lb_calld_ = MakeOrphanable<BalancerCallState>(Ref());
grpc_lb_glb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
GPR_INFO, "[grpclb %p] Query for backends (lb_channel: %p, lb_calld: %p)", gpr_log(GPR_INFO,
this, lb_channel_, lb_calld_.get()); "[grpclb %p] Query for backends (lb_channel: %p, lb_calld: %p)",
this, lb_channel_, lb_calld_.get());
}
lb_calld_->StartQuery(); lb_calld_->StartQuery();
} }
@ -1541,8 +1551,9 @@ void GrpcLb::OnBalancerCallRetryTimer(void* arg, grpc_error_handle error) {
void GrpcLb::OnBalancerCallRetryTimerLocked(grpc_error_handle error) { void GrpcLb::OnBalancerCallRetryTimerLocked(grpc_error_handle error) {
retry_timer_callback_pending_ = false; retry_timer_callback_pending_ = false;
if (!shutting_down_ && error == GRPC_ERROR_NONE && lb_calld_ == nullptr) { if (!shutting_down_ && error == GRPC_ERROR_NONE && lb_calld_ == nullptr) {
grpc_lb_glb_trace.Log(GPR_INFO, "[grpclb %p] Restarting call to LB server", if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
this); gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", this);
}
StartBalancerCallLocked(); StartBalancerCallLocked();
} }
Unref(DEBUG_LOCATION, "on_balancer_call_retry_timer"); Unref(DEBUG_LOCATION, "on_balancer_call_retry_timer");
@ -1624,9 +1635,10 @@ OrphanablePtr<LoadBalancingPolicy> GrpcLb::CreateChildPolicyLocked(
OrphanablePtr<LoadBalancingPolicy> lb_policy = OrphanablePtr<LoadBalancingPolicy> lb_policy =
MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args), MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
&grpc_lb_glb_trace); &grpc_lb_glb_trace);
grpc_lb_glb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
"[grpclb %p] Created new child policy handler (%p)", gpr_log(GPR_INFO, "[grpclb %p] Created new child policy handler (%p)", this,
this, lb_policy.get()); lb_policy.get());
}
// Add the gRPC LB's interested_parties pollset_set to that of the newly // Add the gRPC LB's interested_parties pollset_set to that of the newly
// created child policy. This will make the child policy progress upon // created child policy. This will make the child policy progress upon
// activity on gRPC LB, which in turn is tied to the application's call. // activity on gRPC LB, which in turn is tied to the application's call.
@ -1661,9 +1673,10 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
child_policy_ = CreateChildPolicyLocked(update_args.args); child_policy_ = CreateChildPolicyLocked(update_args.args);
} }
// Update the policy. // Update the policy.
grpc_lb_glb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
"[grpclb %p] Updating child policy handler %p", this, gpr_log(GPR_INFO, "[grpclb %p] Updating child policy handler %p", this,
child_policy_.get()); child_policy_.get());
}
child_policy_->UpdateLocked(std::move(update_args)); child_policy_->UpdateLocked(std::move(update_args));
} }

@ -140,17 +140,23 @@ class PickFirst : public LoadBalancingPolicy {
}; };
PickFirst::PickFirst(Args args) : LoadBalancingPolicy(std::move(args)) { PickFirst::PickFirst(Args args) : LoadBalancingPolicy(std::move(args)) {
grpc_lb_pick_first_trace.Log(GPR_INFO, "Pick First %p created.", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
gpr_log(GPR_INFO, "Pick First %p created.", this);
}
} }
PickFirst::~PickFirst() { PickFirst::~PickFirst() {
grpc_lb_pick_first_trace.Log(GPR_INFO, "Destroying Pick First %p", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
gpr_log(GPR_INFO, "Destroying Pick First %p", this);
}
GPR_ASSERT(subchannel_list_ == nullptr); GPR_ASSERT(subchannel_list_ == nullptr);
GPR_ASSERT(latest_pending_subchannel_list_ == nullptr); GPR_ASSERT(latest_pending_subchannel_list_ == nullptr);
} }
void PickFirst::ShutdownLocked() { void PickFirst::ShutdownLocked() {
grpc_lb_pick_first_trace.Log(GPR_INFO, "Pick First %p Shutting down", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
gpr_log(GPR_INFO, "Pick First %p Shutting down", this);
}
shutdown_ = true; shutdown_ = true;
subchannel_list_.reset(); subchannel_list_.reset();
latest_pending_subchannel_list_.reset(); latest_pending_subchannel_list_.reset();
@ -159,7 +165,9 @@ void PickFirst::ShutdownLocked() {
void PickFirst::ExitIdleLocked() { void PickFirst::ExitIdleLocked() {
if (shutdown_) return; if (shutdown_) return;
if (idle_) { if (idle_) {
grpc_lb_pick_first_trace.Log(GPR_INFO, "Pick First %p exiting idle", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
gpr_log(GPR_INFO, "Pick First %p exiting idle", this);
}
idle_ = false; idle_ = false;
AttemptToConnectUsingLatestUpdateArgsLocked(); AttemptToConnectUsingLatestUpdateArgsLocked();
} }
@ -226,11 +234,13 @@ void PickFirst::AttemptToConnectUsingLatestUpdateArgsLocked() {
// We do have a selected subchannel (which means it's READY), so keep // We do have a selected subchannel (which means it's READY), so keep
// using it until one of the subchannels in the new list reports READY. // using it until one of the subchannels in the new list reports READY.
if (latest_pending_subchannel_list_ != nullptr) { if (latest_pending_subchannel_list_ != nullptr) {
grpc_lb_pick_first_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"Pick First %p Shutting down latest pending subchannel list " "Pick First %p Shutting down latest pending subchannel list "
"%p, about to be replaced by newer latest %p", "%p, about to be replaced by newer latest %p",
this, latest_pending_subchannel_list_.get(), subchannel_list.get()); this, latest_pending_subchannel_list_.get(),
subchannel_list.get());
}
} }
latest_pending_subchannel_list_ = std::move(subchannel_list); latest_pending_subchannel_list_ = std::move(subchannel_list);
// If we're not in IDLE state, start trying to connect to the first // If we're not in IDLE state, start trying to connect to the first
@ -247,9 +257,11 @@ void PickFirst::AttemptToConnectUsingLatestUpdateArgsLocked() {
} }
void PickFirst::UpdateLocked(UpdateArgs args) { void PickFirst::UpdateLocked(UpdateArgs args) {
grpc_lb_pick_first_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
GPR_INFO, "Pick First %p received update with %" PRIuPTR " addresses", gpr_log(GPR_INFO,
this, args.addresses.size()); "Pick First %p received update with %" PRIuPTR " addresses", this,
args.addresses.size());
}
// Update the latest_update_args_ // Update the latest_update_args_
grpc_arg new_arg = grpc_channel_arg_integer_create( grpc_arg new_arg = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1); const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1);
@ -275,20 +287,22 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
GPR_ASSERT(connectivity_state != GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(connectivity_state != GRPC_CHANNEL_SHUTDOWN);
// Handle updates for the currently selected subchannel. // Handle updates for the currently selected subchannel.
if (p->selected_ == this) { if (p->selected_ == this) {
grpc_lb_pick_first_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"Pick First %p selected subchannel connectivity changed to %s", p, "Pick First %p selected subchannel connectivity changed to %s", p,
ConnectivityStateName(connectivity_state)); ConnectivityStateName(connectivity_state));
}
// If the new state is anything other than READY and there is a // If the new state is anything other than READY and there is a
// pending update, switch to the pending update. // pending update, switch to the pending update.
if (connectivity_state != GRPC_CHANNEL_READY && if (connectivity_state != GRPC_CHANNEL_READY &&
p->latest_pending_subchannel_list_ != nullptr) { p->latest_pending_subchannel_list_ != nullptr) {
grpc_lb_pick_first_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"Pick First %p promoting pending subchannel list %p to " "Pick First %p promoting pending subchannel list %p to "
"replace %p", "replace %p",
p, p->latest_pending_subchannel_list_.get(), p, p->latest_pending_subchannel_list_.get(),
p->subchannel_list_.get()); p->subchannel_list_.get());
}
p->selected_ = nullptr; p->selected_ = nullptr;
CancelConnectivityWatchLocked( CancelConnectivityWatchLocked(
"selected subchannel failed; switching to pending update"); "selected subchannel failed; switching to pending update");
@ -413,16 +427,19 @@ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
subchannel_list() == p->latest_pending_subchannel_list_.get()); subchannel_list() == p->latest_pending_subchannel_list_.get());
// Case 2. Promote p->latest_pending_subchannel_list_ to p->subchannel_list_. // Case 2. Promote p->latest_pending_subchannel_list_ to p->subchannel_list_.
if (subchannel_list() == p->latest_pending_subchannel_list_.get()) { if (subchannel_list() == p->latest_pending_subchannel_list_.get()) {
grpc_lb_pick_first_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"Pick First %p promoting pending subchannel list %p to " "Pick First %p promoting pending subchannel list %p to "
"replace %p", "replace %p",
p, p->latest_pending_subchannel_list_.get(), p->subchannel_list_.get()); p, p->latest_pending_subchannel_list_.get(),
p->subchannel_list_.get());
}
p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_); p->subchannel_list_ = std::move(p->latest_pending_subchannel_list_);
} }
// Cases 1 and 2. // Cases 1 and 2.
grpc_lb_pick_first_trace.Log(GPR_INFO, "Pick First %p selected subchannel %p", if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) {
p, subchannel()); gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p, subchannel());
}
p->selected_ = this; p->selected_ = this;
p->channel_control_helper()->UpdateState( p->channel_control_helper()->UpdateState(
GRPC_CHANNEL_READY, absl::Status(), GRPC_CHANNEL_READY, absl::Status(),

@ -246,17 +246,22 @@ PriorityLb::PriorityLb(Args args)
child_failover_timeout_ms_(grpc_channel_args_find_integer( child_failover_timeout_ms_(grpc_channel_args_find_integer(
args.args, GRPC_ARG_PRIORITY_FAILOVER_TIMEOUT_MS, args.args, GRPC_ARG_PRIORITY_FAILOVER_TIMEOUT_MS,
{kDefaultChildFailoverTimeoutMs, 0, INT_MAX})) { {kDefaultChildFailoverTimeoutMs, 0, INT_MAX})) {
grpc_lb_priority_trace.Log(GPR_INFO, "[priority_lb %p] created", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
gpr_log(GPR_INFO, "[priority_lb %p] created", this);
}
} }
PriorityLb::~PriorityLb() { PriorityLb::~PriorityLb() {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, "[priority_lb %p] destroying priority LB policy", this); gpr_log(GPR_INFO, "[priority_lb %p] destroying priority LB policy", this);
}
grpc_channel_args_destroy(args_); grpc_channel_args_destroy(args_);
} }
void PriorityLb::ShutdownLocked() { void PriorityLb::ShutdownLocked() {
grpc_lb_priority_trace.Log(GPR_INFO, "[priority_lb %p] shutting down", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
gpr_log(GPR_INFO, "[priority_lb %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
children_.clear(); children_.clear();
} }
@ -264,10 +269,11 @@ void PriorityLb::ShutdownLocked() {
void PriorityLb::ExitIdleLocked() { void PriorityLb::ExitIdleLocked() {
if (current_priority_ != UINT32_MAX) { if (current_priority_ != UINT32_MAX) {
const std::string& child_name = config_->priorities()[current_priority_]; const std::string& child_name = config_->priorities()[current_priority_];
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] exiting IDLE for current priority %d child %s", this, "[priority_lb %p] exiting IDLE for current priority %d child %s",
current_priority_, child_name.c_str()); this, current_priority_, child_name.c_str());
}
children_[child_name]->ExitIdleLocked(); children_[child_name]->ExitIdleLocked();
} }
} }
@ -277,8 +283,9 @@ void PriorityLb::ResetBackoffLocked() {
} }
void PriorityLb::UpdateLocked(UpdateArgs args) { void PriorityLb::UpdateLocked(UpdateArgs args) {
grpc_lb_priority_trace.Log(GPR_INFO, "[priority_lb %p] received update", if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
this); gpr_log(GPR_INFO, "[priority_lb %p] received update", this);
}
// Save current child. // Save current child.
if (current_priority_ != UINT32_MAX) { if (current_priority_ != UINT32_MAX) {
const std::string& child_name = config_->priorities()[current_priority_]; const std::string& child_name = config_->priorities()[current_priority_];
@ -329,11 +336,12 @@ void PriorityLb::HandleChildConnectivityStateChangeLocked(
// Special case for the child that was the current child before the // Special case for the child that was the current child before the
// most recent update. // most recent update.
if (child == current_child_from_before_update_) { if (child == current_child_from_before_update_) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] state update for current child from before " "[priority_lb %p] state update for current child from before "
"config update", "config update",
this); this);
}
if (child->connectivity_state() == GRPC_CHANNEL_READY || if (child->connectivity_state() == GRPC_CHANNEL_READY ||
child->connectivity_state() == GRPC_CHANNEL_IDLE) { child->connectivity_state() == GRPC_CHANNEL_IDLE) {
// If it's still READY or IDLE, we stick with this child, so pass // If it's still READY or IDLE, we stick with this child, so pass
@ -354,11 +362,12 @@ void PriorityLb::HandleChildConnectivityStateChangeLocked(
} }
// Otherwise, find the child's priority. // Otherwise, find the child's priority.
uint32_t child_priority = GetChildPriorityLocked(child->name()); uint32_t child_priority = GetChildPriorityLocked(child->name());
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] state update for priority %u, child %s, current " "[priority_lb %p] state update for priority %u, child %s, current "
"priority %u", "priority %u",
this, child_priority, child->name().c_str(), current_priority_); this, child_priority, child->name().c_str(), current_priority_);
}
// Ignore priorities not in the current config. // Ignore priorities not in the current config.
if (child_priority == UINT32_MAX) return; if (child_priority == UINT32_MAX) return;
// Ignore lower-than-current priorities. // Ignore lower-than-current priorities.
@ -410,9 +419,10 @@ void PriorityLb::TryNextPriorityLocked(bool report_connecting) {
++priority) { ++priority) {
// If the child for the priority does not exist yet, create it. // If the child for the priority does not exist yet, create it.
const std::string& child_name = config_->priorities()[priority]; const std::string& child_name = config_->priorities()[priority];
grpc_lb_priority_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
"[priority_lb %p] trying priority %u, child %s", gpr_log(GPR_INFO, "[priority_lb %p] trying priority %u, child %s", this,
this, priority, child_name.c_str()); priority, child_name.c_str());
}
auto& child = children_[child_name]; auto& child = children_[child_name];
if (child == nullptr) { if (child == nullptr) {
if (report_connecting) { if (report_connecting) {
@ -439,11 +449,12 @@ void PriorityLb::TryNextPriorityLocked(bool report_connecting) {
// Child is not READY or IDLE. // Child is not READY or IDLE.
// If its failover timer is still pending, give it time to fire. // If its failover timer is still pending, give it time to fire.
if (child->failover_timer_callback_pending()) { if (child->failover_timer_callback_pending()) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] priority %u, child %s: child still " "[priority_lb %p] priority %u, child %s: child still "
"attempting to connect, will wait", "attempting to connect, will wait",
this, priority, child_name.c_str()); this, priority, child_name.c_str());
}
if (report_connecting) { if (report_connecting) {
channel_control_helper()->UpdateState( channel_control_helper()->UpdateState(
GRPC_CHANNEL_CONNECTING, absl::Status(), GRPC_CHANNEL_CONNECTING, absl::Status(),
@ -454,11 +465,12 @@ void PriorityLb::TryNextPriorityLocked(bool report_connecting) {
// Child has been failing for a while. Move on to the next priority. // Child has been failing for a while. Move on to the next priority.
} }
// If there are no more priorities to try, report TRANSIENT_FAILURE. // If there are no more priorities to try, report TRANSIENT_FAILURE.
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] no priority reachable, putting channel in " "[priority_lb %p] no priority reachable, putting channel in "
"TRANSIENT_FAILURE", "TRANSIENT_FAILURE",
this); this);
}
current_child_from_before_update_ = nullptr; current_child_from_before_update_ = nullptr;
absl::Status status = absl::UnavailableError("no ready priority"); absl::Status status = absl::UnavailableError("no ready priority");
channel_control_helper()->UpdateState( channel_control_helper()->UpdateState(
@ -467,9 +479,10 @@ void PriorityLb::TryNextPriorityLocked(bool report_connecting) {
} }
void PriorityLb::SelectPriorityLocked(uint32_t priority) { void PriorityLb::SelectPriorityLocked(uint32_t priority) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, "[priority_lb %p] selected priority %u, child %s", this, gpr_log(GPR_INFO, "[priority_lb %p] selected priority %u, child %s", this,
priority, config_->priorities()[priority].c_str()); priority, config_->priorities()[priority].c_str());
}
current_priority_ = priority; current_priority_ = priority;
current_child_from_before_update_ = nullptr; current_child_from_before_update_ = nullptr;
// Deactivate lower priorities. // Deactivate lower priorities.
@ -492,9 +505,10 @@ void PriorityLb::SelectPriorityLocked(uint32_t priority) {
PriorityLb::ChildPriority::ChildPriority( PriorityLb::ChildPriority::ChildPriority(
RefCountedPtr<PriorityLb> priority_policy, std::string name) RefCountedPtr<PriorityLb> priority_policy, std::string name)
: priority_policy_(std::move(priority_policy)), name_(std::move(name)) { : priority_policy_(std::move(priority_policy)), name_(std::move(name)) {
grpc_lb_priority_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
"[priority_lb %p] creating child %s (%p)", gpr_log(GPR_INFO, "[priority_lb %p] creating child %s (%p)",
priority_policy_.get(), name_.c_str(), this); priority_policy_.get(), name_.c_str(), this);
}
GRPC_CLOSURE_INIT(&on_failover_timer_, OnFailoverTimer, this, GRPC_CLOSURE_INIT(&on_failover_timer_, OnFailoverTimer, this,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&on_deactivation_timer_, OnDeactivationTimer, this, GRPC_CLOSURE_INIT(&on_deactivation_timer_, OnDeactivationTimer, this,
@ -504,9 +518,10 @@ PriorityLb::ChildPriority::ChildPriority(
} }
void PriorityLb::ChildPriority::Orphan() { void PriorityLb::ChildPriority::Orphan() {
grpc_lb_priority_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
"[priority_lb %p] child %s (%p): orphaned", gpr_log(GPR_INFO, "[priority_lb %p] child %s (%p): orphaned",
priority_policy_.get(), name_.c_str(), this); priority_policy_.get(), name_.c_str(), this);
}
MaybeCancelFailoverTimerLocked(); MaybeCancelFailoverTimerLocked();
if (deactivation_timer_callback_pending_) { if (deactivation_timer_callback_pending_) {
grpc_timer_cancel(&deactivation_timer_); grpc_timer_cancel(&deactivation_timer_);
@ -529,9 +544,10 @@ void PriorityLb::ChildPriority::UpdateLocked(
RefCountedPtr<LoadBalancingPolicy::Config> config, RefCountedPtr<LoadBalancingPolicy::Config> config,
bool ignore_reresolution_requests) { bool ignore_reresolution_requests) {
if (priority_policy_->shutting_down_) return; if (priority_policy_->shutting_down_) return;
grpc_lb_priority_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
"[priority_lb %p] child %s (%p): start update", gpr_log(GPR_INFO, "[priority_lb %p] child %s (%p): start update",
priority_policy_.get(), name_.c_str(), this); priority_policy_.get(), name_.c_str(), this);
}
ignore_reresolution_requests_ = ignore_reresolution_requests; ignore_reresolution_requests_ = ignore_reresolution_requests;
// Create policy if needed. // Create policy if needed.
if (child_policy_ == nullptr) { if (child_policy_ == nullptr) {
@ -543,10 +559,11 @@ void PriorityLb::ChildPriority::UpdateLocked(
update_args.addresses = priority_policy_->addresses_[name_]; update_args.addresses = priority_policy_->addresses_[name_];
update_args.args = grpc_channel_args_copy(priority_policy_->args_); update_args.args = grpc_channel_args_copy(priority_policy_->args_);
// Update the policy. // Update the policy.
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): updating child policy handler %p", "[priority_lb %p] child %s (%p): updating child policy handler %p",
priority_policy_.get(), name_.c_str(), this, child_policy_.get()); priority_policy_.get(), name_.c_str(), this, child_policy_.get());
}
child_policy_->UpdateLocked(std::move(update_args)); child_policy_->UpdateLocked(std::move(update_args));
} }
@ -561,11 +578,12 @@ PriorityLb::ChildPriority::CreateChildPolicyLocked(
OrphanablePtr<LoadBalancingPolicy> lb_policy = OrphanablePtr<LoadBalancingPolicy> lb_policy =
MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args), MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
&grpc_lb_priority_trace); &grpc_lb_priority_trace);
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): created new child policy " "[priority_lb %p] child %s (%p): created new child policy "
"handler %p", "handler %p",
priority_policy_.get(), name_.c_str(), this, lb_policy.get()); priority_policy_.get(), name_.c_str(), this, lb_policy.get());
}
// Add the parent's interested_parties pollset_set to that of the newly // Add the parent's interested_parties pollset_set to that of the newly
// created child policy. This will make the child policy progress upon // created child policy. This will make the child policy progress upon
// activity on the parent LB, which in turn is tied to the application's call. // activity on the parent LB, which in turn is tied to the application's call.
@ -589,11 +607,13 @@ void PriorityLb::ChildPriority::ResetBackoffLocked() {
void PriorityLb::ChildPriority::OnConnectivityStateUpdateLocked( void PriorityLb::ChildPriority::OnConnectivityStateUpdateLocked(
grpc_connectivity_state state, const absl::Status& status, grpc_connectivity_state state, const absl::Status& status,
std::unique_ptr<SubchannelPicker> picker) { std::unique_ptr<SubchannelPicker> picker) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): state update: %s (%s) picker %p", "[priority_lb %p] child %s (%p): state update: %s (%s) picker %p",
priority_policy_.get(), name_.c_str(), this, ConnectivityStateName(state), priority_policy_.get(), name_.c_str(), this,
status.ToString().c_str(), picker.get()); ConnectivityStateName(state), status.ToString().c_str(),
picker.get());
}
// Store the state and picker. // Store the state and picker.
connectivity_state_ = state; connectivity_state_ = state;
connectivity_status_ = status; connectivity_status_ = status;
@ -607,11 +627,12 @@ void PriorityLb::ChildPriority::OnConnectivityStateUpdateLocked(
} }
void PriorityLb::ChildPriority::StartFailoverTimerLocked() { void PriorityLb::ChildPriority::StartFailoverTimerLocked() {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): starting failover timer for %d ms", "[priority_lb %p] child %s (%p): starting failover timer for %d ms",
priority_policy_.get(), name_.c_str(), this, priority_policy_.get(), name_.c_str(), this,
priority_policy_->child_failover_timeout_ms_); priority_policy_->child_failover_timeout_ms_);
}
Ref(DEBUG_LOCATION, "ChildPriority+OnFailoverTimerLocked").release(); Ref(DEBUG_LOCATION, "ChildPriority+OnFailoverTimerLocked").release();
grpc_timer_init( grpc_timer_init(
&failover_timer_, &failover_timer_,
@ -622,9 +643,11 @@ void PriorityLb::ChildPriority::StartFailoverTimerLocked() {
void PriorityLb::ChildPriority::MaybeCancelFailoverTimerLocked() { void PriorityLb::ChildPriority::MaybeCancelFailoverTimerLocked() {
if (failover_timer_callback_pending_) { if (failover_timer_callback_pending_) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, "[priority_lb %p] child %s (%p): cancelling failover timer", gpr_log(GPR_INFO,
priority_policy_.get(), name_.c_str(), this); "[priority_lb %p] child %s (%p): cancelling failover timer",
priority_policy_.get(), name_.c_str(), this);
}
grpc_timer_cancel(&failover_timer_); grpc_timer_cancel(&failover_timer_);
failover_timer_callback_pending_ = false; failover_timer_callback_pending_ = false;
} }
@ -641,11 +664,12 @@ void PriorityLb::ChildPriority::OnFailoverTimer(void* arg,
void PriorityLb::ChildPriority::OnFailoverTimerLocked(grpc_error_handle error) { void PriorityLb::ChildPriority::OnFailoverTimerLocked(grpc_error_handle error) {
if (error == GRPC_ERROR_NONE && failover_timer_callback_pending_ && if (error == GRPC_ERROR_NONE && failover_timer_callback_pending_ &&
!priority_policy_->shutting_down_) { !priority_policy_->shutting_down_) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): failover timer fired, " "[priority_lb %p] child %s (%p): failover timer fired, "
"reporting TRANSIENT_FAILURE", "reporting TRANSIENT_FAILURE",
priority_policy_.get(), name_.c_str(), this); priority_policy_.get(), name_.c_str(), this);
}
failover_timer_callback_pending_ = false; failover_timer_callback_pending_ = false;
OnConnectivityStateUpdateLocked( OnConnectivityStateUpdateLocked(
GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_CHANNEL_TRANSIENT_FAILURE,
@ -659,11 +683,13 @@ void PriorityLb::ChildPriority::OnFailoverTimerLocked(grpc_error_handle error) {
void PriorityLb::ChildPriority::DeactivateLocked() { void PriorityLb::ChildPriority::DeactivateLocked() {
// If already deactivated, don't do it again. // If already deactivated, don't do it again.
if (deactivation_timer_callback_pending_) return; if (deactivation_timer_callback_pending_) return;
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): deactivating -- will remove in %d " "[priority_lb %p] child %s (%p): deactivating -- will remove in %d "
"ms.", "ms.",
priority_policy_.get(), name_.c_str(), this, kChildRetentionIntervalMs); priority_policy_.get(), name_.c_str(), this,
kChildRetentionIntervalMs);
}
MaybeCancelFailoverTimerLocked(); MaybeCancelFailoverTimerLocked();
// Start a timer to delete the child. // Start a timer to delete the child.
Ref(DEBUG_LOCATION, "ChildPriority+timer").release(); Ref(DEBUG_LOCATION, "ChildPriority+timer").release();
@ -675,9 +701,10 @@ void PriorityLb::ChildPriority::DeactivateLocked() {
void PriorityLb::ChildPriority::MaybeReactivateLocked() { void PriorityLb::ChildPriority::MaybeReactivateLocked() {
if (deactivation_timer_callback_pending_) { if (deactivation_timer_callback_pending_) {
grpc_lb_priority_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
"[priority_lb %p] child %s (%p): reactivating", gpr_log(GPR_INFO, "[priority_lb %p] child %s (%p): reactivating",
priority_policy_.get(), name_.c_str(), this); priority_policy_.get(), name_.c_str(), this);
}
deactivation_timer_callback_pending_ = false; deactivation_timer_callback_pending_ = false;
grpc_timer_cancel(&deactivation_timer_); grpc_timer_cancel(&deactivation_timer_);
} }
@ -696,11 +723,12 @@ void PriorityLb::ChildPriority::OnDeactivationTimerLocked(
grpc_error_handle error) { grpc_error_handle error) {
if (error == GRPC_ERROR_NONE && deactivation_timer_callback_pending_ && if (error == GRPC_ERROR_NONE && deactivation_timer_callback_pending_ &&
!priority_policy_->shutting_down_) { !priority_policy_->shutting_down_) {
grpc_lb_priority_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_priority_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[priority_lb %p] child %s (%p): deactivation timer fired, " "[priority_lb %p] child %s (%p): deactivation timer fired, "
"deleting child", "deleting child",
priority_policy_.get(), name_.c_str(), this); priority_policy_.get(), name_.c_str(), this);
}
deactivation_timer_callback_pending_ = false; deactivation_timer_callback_pending_ = false;
priority_policy_->DeleteChild(this); priority_policy_->DeleteChild(this);
} }

@ -371,11 +371,12 @@ RingHash::Picker::Picker(RefCountedPtr<RingHash> parent,
[](const RingEntry& lhs, const RingEntry& rhs) -> bool { [](const RingEntry& lhs, const RingEntry& rhs) -> bool {
return lhs.hash < rhs.hash; return lhs.hash < rhs.hash;
}); });
grpc_lb_ring_hash_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[RH %p picker %p] created picker from subchannel_list=%p " "[RH %p picker %p] created picker from subchannel_list=%p "
"with %" PRIuPTR " ring entries", "with %" PRIuPTR " ring entries",
parent_.get(), this, subchannel_list, ring_.size()); parent_.get(), this, subchannel_list, ring_.size());
}
} }
RingHash::PickResult RingHash::Picker::Pick(PickArgs args) { RingHash::PickResult RingHash::Picker::Pick(PickArgs args) {
@ -577,14 +578,16 @@ bool RingHash::RingHashSubchannelList::UpdateRingHashConnectivityStateLocked() {
void RingHash::RingHashSubchannelData::UpdateConnectivityStateLocked( void RingHash::RingHashSubchannelData::UpdateConnectivityStateLocked(
grpc_connectivity_state connectivity_state) { grpc_connectivity_state connectivity_state) {
RingHash* p = static_cast<RingHash*>(subchannel_list()->policy()); RingHash* p = static_cast<RingHash*>(subchannel_list()->policy());
grpc_lb_ring_hash_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
GPR_INFO, gpr_log(
"[RR %p] connectivity changed for subchannel %p, subchannel_list %p " GPR_INFO,
"(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s", "[RR %p] connectivity changed for subchannel %p, subchannel_list %p "
p, subchannel(), subchannel_list(), Index(), "(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s",
subchannel_list()->num_subchannels(), p, subchannel(), subchannel_list(), Index(),
ConnectivityStateName(last_connectivity_state_), subchannel_list()->num_subchannels(),
ConnectivityStateName(connectivity_state)); ConnectivityStateName(last_connectivity_state_),
ConnectivityStateName(connectivity_state));
}
// Decide what state to report for aggregation purposes. // Decide what state to report for aggregation purposes.
// If we haven't seen a failure since the last time we were in state // If we haven't seen a failure since the last time we were in state
// READY, then we report the state change as-is. However, once we do see // READY, then we report the state change as-is. However, once we do see
@ -618,11 +621,12 @@ void RingHash::RingHashSubchannelData::ProcessConnectivityChangeLocked(
// loop of re-resolution. // loop of re-resolution.
// Also attempt to reconnect. // Also attempt to reconnect.
if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
grpc_lb_ring_hash_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[RR %p] Subchannel %p has gone into TRANSIENT_FAILURE. " "[RR %p] Subchannel %p has gone into TRANSIENT_FAILURE. "
"Requesting re-resolution", "Requesting re-resolution",
p, subchannel()); p, subchannel());
}
p->channel_control_helper()->RequestReresolution(); p->channel_control_helper()->RequestReresolution();
} }
// Update state counters. // Update state counters.
@ -658,17 +662,22 @@ void RingHash::RingHashSubchannelData::ProcessConnectivityChangeLocked(
// //
RingHash::RingHash(Args args) : LoadBalancingPolicy(std::move(args)) { RingHash::RingHash(Args args) : LoadBalancingPolicy(std::move(args)) {
grpc_lb_ring_hash_trace.Log(GPR_INFO, "[RH %p] Created", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
gpr_log(GPR_INFO, "[RH %p] Created", this);
}
} }
RingHash::~RingHash() { RingHash::~RingHash() {
grpc_lb_ring_hash_trace.Log(GPR_INFO, "[RH %p] Destroying Ring Hash policy", if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
this); gpr_log(GPR_INFO, "[RH %p] Destroying Ring Hash policy", this);
}
GPR_ASSERT(subchannel_list_ == nullptr); GPR_ASSERT(subchannel_list_ == nullptr);
} }
void RingHash::ShutdownLocked() { void RingHash::ShutdownLocked() {
grpc_lb_ring_hash_trace.Log(GPR_INFO, "[RH %p] Shutting down", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
gpr_log(GPR_INFO, "[RH %p] Shutting down", this);
}
shutdown_ = true; shutdown_ = true;
subchannel_list_.reset(); subchannel_list_.reset();
} }
@ -676,9 +685,10 @@ void RingHash::ShutdownLocked() {
void RingHash::ResetBackoffLocked() { subchannel_list_->ResetBackoffLocked(); } void RingHash::ResetBackoffLocked() { subchannel_list_->ResetBackoffLocked(); }
void RingHash::UpdateLocked(UpdateArgs args) { void RingHash::UpdateLocked(UpdateArgs args) {
grpc_lb_ring_hash_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_ring_hash_trace)) {
GPR_INFO, "[RR %p] received update with %" PRIuPTR " addresses", this, gpr_log(GPR_INFO, "[RR %p] received update with %" PRIuPTR " addresses",
args.addresses.size()); this, args.addresses.size());
}
config_ = std::move(args.config); config_ = std::move(args.config);
// Filter out any address with weight 0. // Filter out any address with weight 0.
ServerAddressList addresses; ServerAddressList addresses;

@ -196,19 +196,23 @@ RoundRobin::Picker::Picker(RoundRobin* parent,
// TODO(roth): rand(3) is not thread-safe. This should be replaced with // TODO(roth): rand(3) is not thread-safe. This should be replaced with
// something better as part of https://github.com/grpc/grpc/issues/17891. // something better as part of https://github.com/grpc/grpc/issues/17891.
last_picked_index_ = rand() % subchannels_.size(); last_picked_index_ = rand() % subchannels_.size();
grpc_lb_round_robin_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[RR %p picker %p] created picker from subchannel_list=%p " "[RR %p picker %p] created picker from subchannel_list=%p "
"with %" PRIuPTR " READY subchannels; last_picked_index_=%" PRIuPTR, "with %" PRIuPTR " READY subchannels; last_picked_index_=%" PRIuPTR,
parent_, this, subchannel_list, subchannels_.size(), last_picked_index_); parent_, this, subchannel_list, subchannels_.size(),
last_picked_index_);
}
} }
RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs /*args*/) { RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs /*args*/) {
last_picked_index_ = (last_picked_index_ + 1) % subchannels_.size(); last_picked_index_ = (last_picked_index_ + 1) % subchannels_.size();
grpc_lb_round_robin_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
GPR_INFO, "[RR %p picker %p] returning index %" PRIuPTR ", subchannel=%p", gpr_log(GPR_INFO,
parent_, this, last_picked_index_, "[RR %p picker %p] returning index %" PRIuPTR ", subchannel=%p",
subchannels_[last_picked_index_].get()); parent_, this, last_picked_index_,
subchannels_[last_picked_index_].get());
}
return PickResult::Complete(subchannels_[last_picked_index_]); return PickResult::Complete(subchannels_[last_picked_index_]);
} }
@ -217,18 +221,23 @@ RoundRobin::PickResult RoundRobin::Picker::Pick(PickArgs /*args*/) {
// //
RoundRobin::RoundRobin(Args args) : LoadBalancingPolicy(std::move(args)) { RoundRobin::RoundRobin(Args args) : LoadBalancingPolicy(std::move(args)) {
grpc_lb_round_robin_trace.Log(GPR_INFO, "[RR %p] Created", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
gpr_log(GPR_INFO, "[RR %p] Created", this);
}
} }
RoundRobin::~RoundRobin() { RoundRobin::~RoundRobin() {
grpc_lb_round_robin_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
"[RR %p] Destroying Round Robin policy", this); gpr_log(GPR_INFO, "[RR %p] Destroying Round Robin policy", this);
}
GPR_ASSERT(subchannel_list_ == nullptr); GPR_ASSERT(subchannel_list_ == nullptr);
GPR_ASSERT(latest_pending_subchannel_list_ == nullptr); GPR_ASSERT(latest_pending_subchannel_list_ == nullptr);
} }
void RoundRobin::ShutdownLocked() { void RoundRobin::ShutdownLocked() {
grpc_lb_round_robin_trace.Log(GPR_INFO, "[RR %p] Shutting down", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
gpr_log(GPR_INFO, "[RR %p] Shutting down", this);
}
shutdown_ = true; shutdown_ = true;
subchannel_list_.reset(); subchannel_list_.reset();
latest_pending_subchannel_list_.reset(); latest_pending_subchannel_list_.reset();
@ -359,14 +368,16 @@ void RoundRobin::RoundRobinSubchannelList::
void RoundRobin::RoundRobinSubchannelData::UpdateConnectivityStateLocked( void RoundRobin::RoundRobinSubchannelData::UpdateConnectivityStateLocked(
grpc_connectivity_state connectivity_state) { grpc_connectivity_state connectivity_state) {
RoundRobin* p = static_cast<RoundRobin*>(subchannel_list()->policy()); RoundRobin* p = static_cast<RoundRobin*>(subchannel_list()->policy());
grpc_lb_round_robin_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
GPR_INFO, gpr_log(
"[RR %p] connectivity changed for subchannel %p, subchannel_list %p " GPR_INFO,
"(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s", "[RR %p] connectivity changed for subchannel %p, subchannel_list %p "
p, subchannel(), subchannel_list(), Index(), "(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s",
subchannel_list()->num_subchannels(), p, subchannel(), subchannel_list(), Index(),
ConnectivityStateName(last_connectivity_state_), subchannel_list()->num_subchannels(),
ConnectivityStateName(connectivity_state)); ConnectivityStateName(last_connectivity_state_),
ConnectivityStateName(connectivity_state));
}
// Decide what state to report for aggregation purposes. // Decide what state to report for aggregation purposes.
// If we haven't seen a failure since the last time we were in state // If we haven't seen a failure since the last time we were in state
// READY, then we report the state change as-is. However, once we do see // READY, then we report the state change as-is. However, once we do see
@ -400,11 +411,12 @@ void RoundRobin::RoundRobinSubchannelData::ProcessConnectivityChangeLocked(
// loop of re-resolution. // loop of re-resolution.
// Also attempt to reconnect. // Also attempt to reconnect.
if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
grpc_lb_round_robin_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[RR %p] Subchannel %p has gone into TRANSIENT_FAILURE. " "[RR %p] Subchannel %p has gone into TRANSIENT_FAILURE. "
"Requesting re-resolution", "Requesting re-resolution",
p, subchannel()); p, subchannel());
}
p->channel_control_helper()->RequestReresolution(); p->channel_control_helper()->RequestReresolution();
subchannel()->AttemptToConnect(); subchannel()->AttemptToConnect();
} }
@ -415,14 +427,17 @@ void RoundRobin::RoundRobinSubchannelData::ProcessConnectivityChangeLocked(
} }
void RoundRobin::UpdateLocked(UpdateArgs args) { void RoundRobin::UpdateLocked(UpdateArgs args) {
grpc_lb_round_robin_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
GPR_INFO, "[RR %p] received update with %" PRIuPTR " addresses", this, gpr_log(GPR_INFO, "[RR %p] received update with %" PRIuPTR " addresses",
args.addresses.size()); this, args.addresses.size());
}
// Replace latest_pending_subchannel_list_. // Replace latest_pending_subchannel_list_.
if (latest_pending_subchannel_list_ != nullptr) { if (latest_pending_subchannel_list_ != nullptr) {
grpc_lb_round_robin_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_round_robin_trace)) {
GPR_INFO, "[RR %p] Shutting down previous pending subchannel list %p", gpr_log(GPR_INFO,
this, latest_pending_subchannel_list_.get()); "[RR %p] Shutting down previous pending subchannel list %p", this,
latest_pending_subchannel_list_.get());
}
} }
latest_pending_subchannel_list_ = MakeOrphanable<RoundRobinSubchannelList>( latest_pending_subchannel_list_ = MakeOrphanable<RoundRobinSubchannelList>(
this, &grpc_lb_round_robin_trace, std::move(args.addresses), *args.args); this, &grpc_lb_round_robin_trace, std::move(args.addresses), *args.args);

@ -239,16 +239,18 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, SubchannelDataType>::Watcher:: void SubchannelData<SubchannelListType, SubchannelDataType>::Watcher::
OnConnectivityStateChange(grpc_connectivity_state new_state) { OnConnectivityStateChange(grpc_connectivity_state new_state) {
subchannel_list_->tracer()->Log( if (GRPC_TRACE_FLAG_ENABLED(*subchannel_list_->tracer())) {
GPR_INFO, gpr_log(GPR_INFO,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): connectivity changed: state=%s, " " (subchannel %p): connectivity changed: state=%s, "
"shutting_down=%d, pending_watcher=%p", "shutting_down=%d, pending_watcher=%p",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_.get(), subchannel_data_->Index(), subchannel_list_.get(), subchannel_data_->Index(),
subchannel_list_->num_subchannels(), subchannel_data_->subchannel_.get(), subchannel_list_->num_subchannels(),
ConnectivityStateName(new_state), subchannel_list_->shutting_down(), subchannel_data_->subchannel_.get(),
subchannel_data_->pending_watcher_); ConnectivityStateName(new_state), subchannel_list_->shutting_down(),
subchannel_data_->pending_watcher_);
}
if (!subchannel_list_->shutting_down() && if (!subchannel_list_->shutting_down() &&
subchannel_data_->pending_watcher_ != nullptr) { subchannel_data_->pending_watcher_ != nullptr) {
subchannel_data_->connectivity_state_ = new_state; subchannel_data_->connectivity_state_ = new_state;
@ -281,13 +283,14 @@ template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, SubchannelDataType>:: void SubchannelData<SubchannelListType, SubchannelDataType>::
UnrefSubchannelLocked(const char* reason) { UnrefSubchannelLocked(const char* reason) {
if (subchannel_ != nullptr) { if (subchannel_ != nullptr) {
subchannel_list_->tracer()->Log( if (GRPC_TRACE_FLAG_ENABLED(*subchannel_list_->tracer())) {
GPR_INFO, gpr_log(GPR_INFO,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): unreffing subchannel (%s)", " (subchannel %p): unreffing subchannel (%s)",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_->num_subchannels(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_.get(), reason); subchannel_.get(), reason);
}
subchannel_.reset(); subchannel_.reset();
} }
} }
@ -303,13 +306,14 @@ void SubchannelData<SubchannelListType,
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, void SubchannelData<SubchannelListType,
SubchannelDataType>::StartConnectivityWatchLocked() { SubchannelDataType>::StartConnectivityWatchLocked() {
subchannel_list_->tracer()->Log( if (GRPC_TRACE_FLAG_ENABLED(*subchannel_list_->tracer())) {
GPR_INFO, gpr_log(GPR_INFO,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): starting watch (from %s)", " (subchannel %p): starting watch (from %s)",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_->num_subchannels(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_.get(), ConnectivityStateName(connectivity_state_)); subchannel_.get(), ConnectivityStateName(connectivity_state_));
}
GPR_ASSERT(pending_watcher_ == nullptr); GPR_ASSERT(pending_watcher_ == nullptr);
pending_watcher_ = pending_watcher_ =
new Watcher(this, subchannel_list()->Ref(DEBUG_LOCATION, "Watcher")); new Watcher(this, subchannel_list()->Ref(DEBUG_LOCATION, "Watcher"));
@ -322,13 +326,14 @@ void SubchannelData<SubchannelListType,
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelData<SubchannelListType, SubchannelDataType>:: void SubchannelData<SubchannelListType, SubchannelDataType>::
CancelConnectivityWatchLocked(const char* reason) { CancelConnectivityWatchLocked(const char* reason) {
subchannel_list_->tracer()->Log( if (GRPC_TRACE_FLAG_ENABLED(*subchannel_list_->tracer())) {
GPR_INFO, gpr_log(GPR_INFO,
"[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR
" (subchannel %p): canceling connectivity watch (%s)", " (subchannel %p): canceling connectivity watch (%s)",
subchannel_list_->tracer()->name(), subchannel_list_->policy(), subchannel_list_->tracer()->name(), subchannel_list_->policy(),
subchannel_list_, Index(), subchannel_list_->num_subchannels(), subchannel_list_, Index(), subchannel_list_->num_subchannels(),
subchannel_.get(), reason); subchannel_.get(), reason);
}
if (pending_watcher_ != nullptr) { if (pending_watcher_ != nullptr) {
subchannel_->CancelConnectivityStateWatch(pending_watcher_); subchannel_->CancelConnectivityStateWatch(pending_watcher_);
pending_watcher_ = nullptr; pending_watcher_ = nullptr;
@ -354,10 +359,11 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
GRPC_TRACE_FLAG_ENABLED(*tracer) ? "SubchannelList" : nullptr), GRPC_TRACE_FLAG_ENABLED(*tracer) ? "SubchannelList" : nullptr),
policy_(policy), policy_(policy),
tracer_(tracer) { tracer_(tracer) {
tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
"[%s %p] Creating subchannel list %p for %" PRIuPTR gpr_log(GPR_INFO,
" subchannels", "[%s %p] Creating subchannel list %p for %" PRIuPTR " subchannels",
tracer_->name(), policy, this, addresses.size()); tracer_->name(), policy, this, addresses.size());
}
subchannels_.reserve(addresses.size()); subchannels_.reserve(addresses.size());
// Create a subchannel for each address. // Create a subchannel for each address.
for (ServerAddress address : addresses) { for (ServerAddress address : addresses) {
@ -365,31 +371,39 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
helper->CreateSubchannel(address, args); helper->CreateSubchannel(address, args);
if (subchannel == nullptr) { if (subchannel == nullptr) {
// Subchannel could not be created. // Subchannel could not be created.
tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
"[%s %p] could not create subchannel for address %s, " gpr_log(GPR_INFO,
"ignoring", "[%s %p] could not create subchannel for address %s, "
tracer_->name(), policy_, address.ToString().c_str()); "ignoring",
tracer_->name(), policy_, address.ToString().c_str());
}
continue; continue;
} }
tracer_->Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
"[%s %p] subchannel list %p index %" PRIuPTR gpr_log(GPR_INFO,
": Created subchannel %p for address %s", "[%s %p] subchannel list %p index %" PRIuPTR
tracer_->name(), policy_, this, subchannels_.size(), ": Created subchannel %p for address %s",
subchannel.get(), address.ToString().c_str()); tracer_->name(), policy_, this, subchannels_.size(),
subchannel.get(), address.ToString().c_str());
}
subchannels_.emplace_back(this, std::move(address), std::move(subchannel)); subchannels_.emplace_back(this, std::move(address), std::move(subchannel));
} }
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
SubchannelList<SubchannelListType, SubchannelDataType>::~SubchannelList() { SubchannelList<SubchannelListType, SubchannelDataType>::~SubchannelList() {
tracer_->Log(GPR_INFO, "[%s %p] Destroying subchannel_list %p", if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
tracer_->name(), policy_, this); gpr_log(GPR_INFO, "[%s %p] Destroying subchannel_list %p", tracer_->name(),
policy_, this);
}
} }
template <typename SubchannelListType, typename SubchannelDataType> template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelList<SubchannelListType, SubchannelDataType>::ShutdownLocked() { void SubchannelList<SubchannelListType, SubchannelDataType>::ShutdownLocked() {
tracer_->Log(GPR_INFO, "[%s %p] Shutting down subchannel_list %p", if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
tracer_->name(), policy_, this); gpr_log(GPR_INFO, "[%s %p] Shutting down subchannel_list %p",
tracer_->name(), policy_, this);
}
GPR_ASSERT(!shutting_down_); GPR_ASSERT(!shutting_down_);
shutting_down_ = true; shutting_down_ = true;
for (size_t i = 0; i < subchannels_.size(); i++) { for (size_t i = 0; i < subchannels_.size(); i++) {

@ -240,19 +240,23 @@ WeightedTargetLb::PickResult WeightedTargetLb::WeightedPicker::Pick(
WeightedTargetLb::WeightedTargetLb(Args args) WeightedTargetLb::WeightedTargetLb(Args args)
: LoadBalancingPolicy(std::move(args)) { : LoadBalancingPolicy(std::move(args)) {
grpc_lb_weighted_target_trace.Log(GPR_INFO, "[weighted_target_lb %p] created", if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
this); gpr_log(GPR_INFO, "[weighted_target_lb %p] created", this);
}
} }
WeightedTargetLb::~WeightedTargetLb() { WeightedTargetLb::~WeightedTargetLb() {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] destroying weighted_target LB policy", gpr_log(GPR_INFO,
this); "[weighted_target_lb %p] destroying weighted_target LB policy",
this);
}
} }
void WeightedTargetLb::ShutdownLocked() { void WeightedTargetLb::ShutdownLocked() {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] shutting down", this); gpr_log(GPR_INFO, "[weighted_target_lb %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
targets_.clear(); targets_.clear();
} }
@ -263,8 +267,9 @@ void WeightedTargetLb::ResetBackoffLocked() {
void WeightedTargetLb::UpdateLocked(UpdateArgs args) { void WeightedTargetLb::UpdateLocked(UpdateArgs args) {
if (shutting_down_) return; if (shutting_down_) return;
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] Received update", this); gpr_log(GPR_INFO, "[weighted_target_lb %p] Received update", this);
}
// Update config. // Update config.
config_ = std::move(args.config); config_ = std::move(args.config);
// Deactivate the targets not in the new config. // Deactivate the targets not in the new config.
@ -302,11 +307,12 @@ void WeightedTargetLb::UpdateLocked(UpdateArgs args) {
} }
void WeightedTargetLb::UpdateStateLocked() { void WeightedTargetLb::UpdateStateLocked() {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[weighted_target_lb %p] scanning children to determine " "[weighted_target_lb %p] scanning children to determine "
"connectivity state", "connectivity state",
this); this);
}
// Construct a new picker which maintains a map of all child pickers // Construct a new picker which maintains a map of all child pickers
// that are ready. Each child is represented by a portion of the range // that are ready. Each child is represented by a portion of the range
// proportional to its weight, such that the total range is the sum of the // proportional to its weight, such that the total range is the sum of the
@ -325,11 +331,13 @@ void WeightedTargetLb::UpdateStateLocked() {
if (config_->target_map().find(child_name) == config_->target_map().end()) { if (config_->target_map().find(child_name) == config_->target_map().end()) {
continue; continue;
} }
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[weighted_target_lb %p] child=%s state=%s weight=%d picker=%p", this, "[weighted_target_lb %p] child=%s state=%s weight=%d picker=%p",
child_name.c_str(), ConnectivityStateName(child->connectivity_state()), this, child_name.c_str(),
child->weight(), child->picker_wrapper().get()); ConnectivityStateName(child->connectivity_state()),
child->weight(), child->picker_wrapper().get());
}
switch (child->connectivity_state()) { switch (child->connectivity_state()) {
case GRPC_CHANNEL_READY: { case GRPC_CHANNEL_READY: {
end += child->weight(); end += child->weight();
@ -363,9 +371,10 @@ void WeightedTargetLb::UpdateStateLocked() {
} else { } else {
connectivity_state = GRPC_CHANNEL_TRANSIENT_FAILURE; connectivity_state = GRPC_CHANNEL_TRANSIENT_FAILURE;
} }
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] connectivity changed to %s", this, gpr_log(GPR_INFO, "[weighted_target_lb %p] connectivity changed to %s",
ConnectivityStateName(connectivity_state)); this, ConnectivityStateName(connectivity_state));
}
std::unique_ptr<SubchannelPicker> picker; std::unique_ptr<SubchannelPicker> picker;
absl::Status status; absl::Status status;
switch (connectivity_state) { switch (connectivity_state) {
@ -394,25 +403,29 @@ WeightedTargetLb::WeightedChild::WeightedChild(
RefCountedPtr<WeightedTargetLb> weighted_target_policy, RefCountedPtr<WeightedTargetLb> weighted_target_policy,
const std::string& name) const std::string& name)
: weighted_target_policy_(std::move(weighted_target_policy)), name_(name) { : weighted_target_policy_(std::move(weighted_target_policy)), name_(name) {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] created WeightedChild %p for %s", gpr_log(GPR_INFO, "[weighted_target_lb %p] created WeightedChild %p for %s",
weighted_target_policy_.get(), this, name_.c_str()); weighted_target_policy_.get(), this, name_.c_str());
}
GRPC_CLOSURE_INIT(&on_delayed_removal_timer_, OnDelayedRemovalTimer, this, GRPC_CLOSURE_INIT(&on_delayed_removal_timer_, OnDelayedRemovalTimer, this,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
} }
WeightedTargetLb::WeightedChild::~WeightedChild() { WeightedTargetLb::WeightedChild::~WeightedChild() {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] WeightedChild %p %s: destroying child", gpr_log(GPR_INFO,
weighted_target_policy_.get(), this, name_.c_str()); "[weighted_target_lb %p] WeightedChild %p %s: destroying child",
weighted_target_policy_.get(), this, name_.c_str());
}
weighted_target_policy_.reset(DEBUG_LOCATION, "WeightedChild"); weighted_target_policy_.reset(DEBUG_LOCATION, "WeightedChild");
} }
void WeightedTargetLb::WeightedChild::Orphan() { void WeightedTargetLb::WeightedChild::Orphan() {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[weighted_target_lb %p] WeightedChild %p %s: shutting down child", "[weighted_target_lb %p] WeightedChild %p %s: shutting down child",
weighted_target_policy_.get(), this, name_.c_str()); weighted_target_policy_.get(), this, name_.c_str());
}
// Remove the child policy's interested_parties pollset_set from the // Remove the child policy's interested_parties pollset_set from the
// xDS policy. // xDS policy.
grpc_pollset_set_del_pollset_set( grpc_pollset_set_del_pollset_set(
@ -441,11 +454,13 @@ WeightedTargetLb::WeightedChild::CreateChildPolicyLocked(
OrphanablePtr<LoadBalancingPolicy> lb_policy = OrphanablePtr<LoadBalancingPolicy> lb_policy =
MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args), MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
&grpc_lb_weighted_target_trace); &grpc_lb_weighted_target_trace);
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[weighted_target_lb %p] WeightedChild %p %s: Created new child " "[weighted_target_lb %p] WeightedChild %p %s: Created new child "
"policy handler %p", "policy handler %p",
weighted_target_policy_.get(), this, name_.c_str(), lb_policy.get()); weighted_target_policy_.get(), this, name_.c_str(),
lb_policy.get());
}
// Add the xDS's interested_parties pollset_set to that of the newly created // Add the xDS's interested_parties pollset_set to that of the newly created
// child policy. This will make the child policy progress upon activity on // child policy. This will make the child policy progress upon activity on
// xDS LB, which in turn is tied to the application's call. // xDS LB, which in turn is tied to the application's call.
@ -463,9 +478,11 @@ void WeightedTargetLb::WeightedChild::UpdateLocked(
weight_ = config.weight; weight_ = config.weight;
// Reactivate if needed. // Reactivate if needed.
if (delayed_removal_timer_callback_pending_) { if (delayed_removal_timer_callback_pending_) {
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] WeightedChild %p %s: reactivating", gpr_log(GPR_INFO,
weighted_target_policy_.get(), this, name_.c_str()); "[weighted_target_lb %p] WeightedChild %p %s: reactivating",
weighted_target_policy_.get(), this, name_.c_str());
}
delayed_removal_timer_callback_pending_ = false; delayed_removal_timer_callback_pending_ = false;
grpc_timer_cancel(&delayed_removal_timer_); grpc_timer_cancel(&delayed_removal_timer_);
} }
@ -479,11 +496,13 @@ void WeightedTargetLb::WeightedChild::UpdateLocked(
update_args.addresses = std::move(addresses); update_args.addresses = std::move(addresses);
update_args.args = grpc_channel_args_copy(args); update_args.args = grpc_channel_args_copy(args);
// Update the policy. // Update the policy.
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[weighted_target_lb %p] WeightedChild %p %s: Updating child " "[weighted_target_lb %p] WeightedChild %p %s: Updating child "
"policy handler %p", "policy handler %p",
weighted_target_policy_.get(), this, name_.c_str(), child_policy_.get()); weighted_target_policy_.get(), this, name_.c_str(),
child_policy_.get());
}
child_policy_->UpdateLocked(std::move(update_args)); child_policy_->UpdateLocked(std::move(update_args));
} }
@ -496,13 +515,14 @@ void WeightedTargetLb::WeightedChild::OnConnectivityStateUpdateLocked(
std::unique_ptr<SubchannelPicker> picker) { std::unique_ptr<SubchannelPicker> picker) {
// Cache the picker in the WeightedChild. // Cache the picker in the WeightedChild.
picker_wrapper_ = MakeRefCounted<ChildPickerWrapper>(std::move(picker)); picker_wrapper_ = MakeRefCounted<ChildPickerWrapper>(std::move(picker));
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[weighted_target_lb %p] WeightedChild %p %s: connectivity " "[weighted_target_lb %p] WeightedChild %p %s: connectivity "
"state update: state=%s (%s) picker_wrapper=%p", "state update: state=%s (%s) picker_wrapper=%p",
weighted_target_policy_.get(), this, name_.c_str(), weighted_target_policy_.get(), this, name_.c_str(),
ConnectivityStateName(state), status.ToString().c_str(), ConnectivityStateName(state), status.ToString().c_str(),
picker_wrapper_.get()); picker_wrapper_.get());
}
// If the child reports IDLE, immediately tell it to exit idle. // If the child reports IDLE, immediately tell it to exit idle.
if (state == GRPC_CHANNEL_IDLE) child_policy_->ExitIdleLocked(); if (state == GRPC_CHANNEL_IDLE) child_policy_->ExitIdleLocked();
// Decide what state to report for aggregation purposes. // Decide what state to report for aggregation purposes.
@ -526,9 +546,11 @@ void WeightedTargetLb::WeightedChild::OnConnectivityStateUpdateLocked(
void WeightedTargetLb::WeightedChild::DeactivateLocked() { void WeightedTargetLb::WeightedChild::DeactivateLocked() {
// If already deactivated, don't do that again. // If already deactivated, don't do that again.
if (weight_ == 0) return; if (weight_ == 0) return;
grpc_lb_weighted_target_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_weighted_target_trace)) {
GPR_INFO, "[weighted_target_lb %p] WeightedChild %p %s: deactivating", gpr_log(GPR_INFO,
weighted_target_policy_.get(), this, name_.c_str()); "[weighted_target_lb %p] WeightedChild %p %s: deactivating",
weighted_target_policy_.get(), this, name_.c_str());
}
// Set the child weight to 0 so that future picker won't contain this child. // Set the child weight to 0 so that future picker won't contain this child.
weight_ = 0; weight_ = 0;
// Start a timer to delete the child. // Start a timer to delete the child.

@ -243,18 +243,21 @@ void CdsLb::Helper::UpdateState(grpc_connectivity_state state,
const absl::Status& status, const absl::Status& status,
std::unique_ptr<SubchannelPicker> picker) { std::unique_ptr<SubchannelPicker> picker) {
if (parent_->shutting_down_ || parent_->child_policy_ == nullptr) return; if (parent_->shutting_down_ || parent_->child_policy_ == nullptr) return;
grpc_cds_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
GPR_INFO, "[cdslb %p] state updated by child: %s message_state: (%s)", gpr_log(GPR_INFO,
this, ConnectivityStateName(state), status.ToString().c_str()); "[cdslb %p] state updated by child: %s message_state: (%s)", this,
ConnectivityStateName(state), status.ToString().c_str());
}
parent_->channel_control_helper()->UpdateState(state, status, parent_->channel_control_helper()->UpdateState(state, status,
std::move(picker)); std::move(picker));
} }
void CdsLb::Helper::RequestReresolution() { void CdsLb::Helper::RequestReresolution() {
if (parent_->shutting_down_) return; if (parent_->shutting_down_) return;
grpc_cds_lb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
"[cdslb %p] Re-resolution requested from child policy.", gpr_log(GPR_INFO, "[cdslb %p] Re-resolution requested from child policy.",
parent_.get()); parent_.get());
}
parent_->channel_control_helper()->RequestReresolution(); parent_->channel_control_helper()->RequestReresolution();
} }
@ -270,23 +273,30 @@ void CdsLb::Helper::AddTraceEvent(TraceSeverity severity,
CdsLb::CdsLb(RefCountedPtr<XdsClient> xds_client, Args args) CdsLb::CdsLb(RefCountedPtr<XdsClient> xds_client, Args args)
: LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) { : LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) {
grpc_cds_lb_trace.Log(GPR_INFO, "[cdslb %p] created -- using xds client %p", if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
this, xds_client_.get()); gpr_log(GPR_INFO, "[cdslb %p] created -- using xds client %p", this,
xds_client_.get());
}
} }
CdsLb::~CdsLb() { CdsLb::~CdsLb() {
grpc_cds_lb_trace.Log(GPR_INFO, "[cdslb %p] destroying cds LB policy", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
gpr_log(GPR_INFO, "[cdslb %p] destroying cds LB policy", this);
}
} }
void CdsLb::ShutdownLocked() { void CdsLb::ShutdownLocked() {
grpc_cds_lb_trace.Log(GPR_INFO, "[cdslb %p] shutting down", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
gpr_log(GPR_INFO, "[cdslb %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
MaybeDestroyChildPolicyLocked(); MaybeDestroyChildPolicyLocked();
if (xds_client_ != nullptr) { if (xds_client_ != nullptr) {
for (auto& watcher : watchers_) { for (auto& watcher : watchers_) {
grpc_cds_lb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
"[cdslb %p] cancelling watch for cluster %s", this, gpr_log(GPR_INFO, "[cdslb %p] cancelling watch for cluster %s", this,
watcher.first.c_str()); watcher.first.c_str());
}
CancelClusterDataWatch(watcher.first, watcher.second.watcher, CancelClusterDataWatch(watcher.first, watcher.second.watcher,
/*delay_unsubscription=*/false); /*delay_unsubscription=*/false);
} }
@ -317,8 +327,10 @@ void CdsLb::UpdateLocked(UpdateArgs args) {
// Update config. // Update config.
auto old_config = std::move(config_); auto old_config = std::move(config_);
config_ = std::move(args.config); config_ = std::move(args.config);
grpc_cds_lb_trace.Log(GPR_INFO, "[cdslb %p] received update: cluster=%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
this, config_->cluster().c_str()); gpr_log(GPR_INFO, "[cdslb %p] received update: cluster=%s", this,
config_->cluster().c_str());
}
// Update args. // Update args.
grpc_channel_args_destroy(args_); grpc_channel_args_destroy(args_);
args_ = args.args; args_ = args.args;
@ -327,9 +339,10 @@ void CdsLb::UpdateLocked(UpdateArgs args) {
if (old_config == nullptr || old_config->cluster() != config_->cluster()) { if (old_config == nullptr || old_config->cluster() != config_->cluster()) {
if (old_config != nullptr) { if (old_config != nullptr) {
for (auto& watcher : watchers_) { for (auto& watcher : watchers_) {
grpc_cds_lb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
"[cdslb %p] cancelling watch for cluster %s", gpr_log(GPR_INFO, "[cdslb %p] cancelling watch for cluster %s", this,
this, watcher.first.c_str()); watcher.first.c_str());
}
CancelClusterDataWatch(watcher.first, watcher.second.watcher, CancelClusterDataWatch(watcher.first, watcher.second.watcher,
/*delay_unsubscription=*/true); /*delay_unsubscription=*/true);
} }
@ -357,8 +370,10 @@ bool CdsLb::GenerateDiscoveryMechanismForCluster(
// Create a new watcher if needed. // Create a new watcher if needed.
if (state.watcher == nullptr) { if (state.watcher == nullptr) {
auto watcher = absl::make_unique<ClusterWatcher>(Ref(), name); auto watcher = absl::make_unique<ClusterWatcher>(Ref(), name);
grpc_cds_lb_trace.Log(GPR_INFO, "[cdslb %p] starting watch for cluster %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
this, name.c_str()); gpr_log(GPR_INFO, "[cdslb %p] starting watch for cluster %s", this,
name.c_str());
}
state.watcher = watcher.get(); state.watcher = watcher.get();
xds_client_->WatchClusterData(name, std::move(watcher)); xds_client_->WatchClusterData(name, std::move(watcher));
return false; return false;
@ -406,10 +421,12 @@ bool CdsLb::GenerateDiscoveryMechanismForCluster(
void CdsLb::OnClusterChanged(const std::string& name, void CdsLb::OnClusterChanged(const std::string& name,
XdsApi::CdsUpdate cluster_data) { XdsApi::CdsUpdate cluster_data) {
grpc_cds_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
GPR_INFO, gpr_log(
"[cdslb %p] received CDS update for cluster %s from xds client %p: %s", GPR_INFO,
this, name.c_str(), xds_client_.get(), cluster_data.ToString().c_str()); "[cdslb %p] received CDS update for cluster %s from xds client %p: %s",
this, name.c_str(), xds_client_.get(), cluster_data.ToString().c_str());
}
// Store the update in the map if we are still interested in watching this // Store the update in the map if we are still interested in watching this
// cluster (i.e., it is not cancelled already). // cluster (i.e., it is not cancelled already).
// If we've already deleted this entry, then this is an update notification // If we've already deleted this entry, then this is an update notification
@ -479,8 +496,10 @@ void CdsLb::OnClusterChanged(const std::string& name,
} }
grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(), grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(),
interested_parties()); interested_parties());
grpc_cds_lb_trace.Log(GPR_INFO, "[cdslb %p] created child policy %s (%p)", if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
this, config->name(), child_policy_.get()); gpr_log(GPR_INFO, "[cdslb %p] created child policy %s (%p)", this,
config->name(), child_policy_.get());
}
} }
// Update child policy. // Update child policy.
UpdateArgs args; UpdateArgs args;
@ -500,9 +519,10 @@ void CdsLb::OnClusterChanged(const std::string& name,
++it; ++it;
continue; continue;
} }
grpc_cds_lb_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
"[cdslb %p] cancelling watch for cluster %s", this, gpr_log(GPR_INFO, "[cdslb %p] cancelling watch for cluster %s", this,
cluster_name.c_str()); cluster_name.c_str());
}
CancelClusterDataWatch(cluster_name, it->second.watcher, CancelClusterDataWatch(cluster_name, it->second.watcher,
/*delay_unsubscription=*/false); /*delay_unsubscription=*/false);
it = watchers_.erase(it); it = watchers_.erase(it);

@ -275,9 +275,10 @@ XdsClusterImplLb::Picker::Picker(XdsClusterImplLb* xds_cluster_impl_lb,
drop_config_(xds_cluster_impl_lb->config_->drop_config()), drop_config_(xds_cluster_impl_lb->config_->drop_config()),
drop_stats_(xds_cluster_impl_lb->drop_stats_), drop_stats_(xds_cluster_impl_lb->drop_stats_),
picker_(std::move(picker)) { picker_(std::move(picker)) {
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, "[xds_cluster_impl_lb %p] constructed new picker %p", gpr_log(GPR_INFO, "[xds_cluster_impl_lb %p] constructed new picker %p",
xds_cluster_impl_lb, this); xds_cluster_impl_lb, this);
}
} }
LoadBalancingPolicy::PickResult XdsClusterImplLb::Picker::Pick( LoadBalancingPolicy::PickResult XdsClusterImplLb::Picker::Pick(
@ -358,20 +359,24 @@ LoadBalancingPolicy::PickResult XdsClusterImplLb::Picker::Pick(
XdsClusterImplLb::XdsClusterImplLb(RefCountedPtr<XdsClient> xds_client, XdsClusterImplLb::XdsClusterImplLb(RefCountedPtr<XdsClient> xds_client,
Args args) Args args)
: LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) { : LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) {
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, "[xds_cluster_impl_lb %p] created -- using xds client %p", this, gpr_log(GPR_INFO, "[xds_cluster_impl_lb %p] created -- using xds client %p",
xds_client_.get()); this, xds_client_.get());
}
} }
XdsClusterImplLb::~XdsClusterImplLb() { XdsClusterImplLb::~XdsClusterImplLb() {
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_impl_lb %p] destroying xds_cluster_impl LB policy", this); "[xds_cluster_impl_lb %p] destroying xds_cluster_impl LB policy",
this);
}
} }
void XdsClusterImplLb::ShutdownLocked() { void XdsClusterImplLb::ShutdownLocked() {
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, "[xds_cluster_impl_lb %p] shutting down", this); gpr_log(GPR_INFO, "[xds_cluster_impl_lb %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
// Remove the child policy's interested_parties pollset_set from the // Remove the child policy's interested_parties pollset_set from the
// xDS policy. // xDS policy.
@ -398,8 +403,9 @@ void XdsClusterImplLb::ResetBackoffLocked() {
} }
void XdsClusterImplLb::UpdateLocked(UpdateArgs args) { void XdsClusterImplLb::UpdateLocked(UpdateArgs args) {
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, "[xds_cluster_impl_lb %p] Received update", this); gpr_log(GPR_INFO, "[xds_cluster_impl_lb %p] Received update", this);
}
// Update config. // Update config.
const bool is_initial_update = config_ == nullptr; const bool is_initial_update = config_ == nullptr;
auto old_config = std::move(config_); auto old_config = std::move(config_);
@ -436,12 +442,13 @@ void XdsClusterImplLb::MaybeUpdatePickerLocked() {
// whether) the child has reported. // whether) the child has reported.
if (config_->drop_config() != nullptr && config_->drop_config()->drop_all()) { if (config_->drop_config() != nullptr && config_->drop_config()->drop_all()) {
auto drop_picker = absl::make_unique<Picker>(this, picker_); auto drop_picker = absl::make_unique<Picker>(this, picker_);
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_impl_lb %p] updating connectivity (drop all): " "[xds_cluster_impl_lb %p] updating connectivity (drop all): "
"state=READY " "state=READY "
"picker=%p", "picker=%p",
this, drop_picker.get()); this, drop_picker.get());
}
channel_control_helper()->UpdateState(GRPC_CHANNEL_READY, absl::Status(), channel_control_helper()->UpdateState(GRPC_CHANNEL_READY, absl::Status(),
std::move(drop_picker)); std::move(drop_picker));
return; return;
@ -449,13 +456,14 @@ void XdsClusterImplLb::MaybeUpdatePickerLocked() {
// Otherwise, update only if we have a child picker. // Otherwise, update only if we have a child picker.
if (picker_ != nullptr) { if (picker_ != nullptr) {
auto drop_picker = absl::make_unique<Picker>(this, picker_); auto drop_picker = absl::make_unique<Picker>(this, picker_);
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_impl_lb %p] updating connectivity: state=%s " "[xds_cluster_impl_lb %p] updating connectivity: state=%s "
"status=(%s) " "status=(%s) "
"picker=%p", "picker=%p",
this, ConnectivityStateName(state_), status_.ToString().c_str(), this, ConnectivityStateName(state_), status_.ToString().c_str(),
drop_picker.get()); drop_picker.get());
}
channel_control_helper()->UpdateState(state_, status_, channel_control_helper()->UpdateState(state_, status_,
std::move(drop_picker)); std::move(drop_picker));
} }
@ -471,9 +479,11 @@ OrphanablePtr<LoadBalancingPolicy> XdsClusterImplLb::CreateChildPolicyLocked(
OrphanablePtr<LoadBalancingPolicy> lb_policy = OrphanablePtr<LoadBalancingPolicy> lb_policy =
MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args), MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
&grpc_xds_cluster_impl_lb_trace); &grpc_xds_cluster_impl_lb_trace);
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, "[xds_cluster_impl_lb %p] Created new child policy handler %p", gpr_log(GPR_INFO,
this, lb_policy.get()); "[xds_cluster_impl_lb %p] Created new child policy handler %p",
this, lb_policy.get());
}
// Add our interested_parties pollset_set to that of the newly created // Add our interested_parties pollset_set to that of the newly created
// child policy. This will make the child policy progress upon activity on // child policy. This will make the child policy progress upon activity on
// this policy, which in turn is tied to the application's call. // this policy, which in turn is tied to the application's call.
@ -497,9 +507,11 @@ void XdsClusterImplLb::UpdateChildPolicyLocked(ServerAddressList addresses,
const_cast<char*>(config_->cluster_name().c_str())); const_cast<char*>(config_->cluster_name().c_str()));
update_args.args = grpc_channel_args_copy_and_add(args, &cluster_arg, 1); update_args.args = grpc_channel_args_copy_and_add(args, &cluster_arg, 1);
// Update the policy. // Update the policy.
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, "[xds_cluster_impl_lb %p] Updating child policy handler %p", gpr_log(GPR_INFO,
this, child_policy_.get()); "[xds_cluster_impl_lb %p] Updating child policy handler %p", this,
child_policy_.get());
}
child_policy_->UpdateLocked(std::move(update_args)); child_policy_->UpdateLocked(std::move(update_args));
} }
@ -542,13 +554,14 @@ void XdsClusterImplLb::Helper::UpdateState(
grpc_connectivity_state state, const absl::Status& status, grpc_connectivity_state state, const absl::Status& status,
std::unique_ptr<SubchannelPicker> picker) { std::unique_ptr<SubchannelPicker> picker) {
if (xds_cluster_impl_policy_->shutting_down_) return; if (xds_cluster_impl_policy_->shutting_down_) return;
grpc_xds_cluster_impl_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_impl_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_impl_lb %p] child connectivity state update: " "[xds_cluster_impl_lb %p] child connectivity state update: "
"state=%s (%s) " "state=%s (%s) "
"picker=%p", "picker=%p",
xds_cluster_impl_policy_.get(), ConnectivityStateName(state), xds_cluster_impl_policy_.get(), ConnectivityStateName(state),
status.ToString().c_str(), picker.get()); status.ToString().c_str(), picker.get());
}
// Save the state and picker. // Save the state and picker.
xds_cluster_impl_policy_->state_ = state; xds_cluster_impl_policy_->state_ = state;
xds_cluster_impl_policy_->status_ = status; xds_cluster_impl_policy_->status_ = status;

@ -224,15 +224,18 @@ XdsClusterManagerLb::XdsClusterManagerLb(Args args)
: LoadBalancingPolicy(std::move(args)) {} : LoadBalancingPolicy(std::move(args)) {}
XdsClusterManagerLb::~XdsClusterManagerLb() { XdsClusterManagerLb::~XdsClusterManagerLb() {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(
"[xds_cluster_manager_lb %p] destroying xds_cluster_manager LB policy", GPR_INFO,
this); "[xds_cluster_manager_lb %p] destroying xds_cluster_manager LB policy",
this);
}
} }
void XdsClusterManagerLb::ShutdownLocked() { void XdsClusterManagerLb::ShutdownLocked() {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, "[xds_cluster_manager_lb %p] shutting down", this); gpr_log(GPR_INFO, "[xds_cluster_manager_lb %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
children_.clear(); children_.clear();
} }
@ -247,8 +250,9 @@ void XdsClusterManagerLb::ResetBackoffLocked() {
void XdsClusterManagerLb::UpdateLocked(UpdateArgs args) { void XdsClusterManagerLb::UpdateLocked(UpdateArgs args) {
if (shutting_down_) return; if (shutting_down_) return;
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, "[xds_cluster_manager_lb %p] Received update", this); gpr_log(GPR_INFO, "[xds_cluster_manager_lb %p] Received update", this);
}
// Update config. // Update config.
config_ = std::move(args.config); config_ = std::move(args.config);
// Deactivate the children not in the new config. // Deactivate the children not in the new config.
@ -322,20 +326,22 @@ void XdsClusterManagerLb::UpdateStateLocked() {
} else { } else {
connectivity_state = GRPC_CHANNEL_TRANSIENT_FAILURE; connectivity_state = GRPC_CHANNEL_TRANSIENT_FAILURE;
} }
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, "[xds_cluster_manager_lb %p] connectivity changed to %s", this, gpr_log(GPR_INFO, "[xds_cluster_manager_lb %p] connectivity changed to %s",
ConnectivityStateName(connectivity_state)); this, ConnectivityStateName(connectivity_state));
}
ClusterPicker::ClusterMap cluster_map; ClusterPicker::ClusterMap cluster_map;
for (const auto& p : config_->cluster_map()) { for (const auto& p : config_->cluster_map()) {
const std::string& cluster_name = p.first; const std::string& cluster_name = p.first;
RefCountedPtr<ChildPickerWrapper>& child_picker = cluster_map[cluster_name]; RefCountedPtr<ChildPickerWrapper>& child_picker = cluster_map[cluster_name];
child_picker = children_[cluster_name]->picker_wrapper(); child_picker = children_[cluster_name]->picker_wrapper();
if (child_picker == nullptr) { if (child_picker == nullptr) {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_manager_lb %p] child %s has not yet returned a " "[xds_cluster_manager_lb %p] child %s has not yet returned a "
"picker; creating a QueuePicker.", "picker; creating a QueuePicker.",
this, cluster_name.c_str()); this, cluster_name.c_str());
}
child_picker = MakeRefCounted<ChildPickerWrapper>( child_picker = MakeRefCounted<ChildPickerWrapper>(
cluster_name, cluster_name,
absl::make_unique<QueuePicker>(Ref(DEBUG_LOCATION, "QueuePicker"))); absl::make_unique<QueuePicker>(Ref(DEBUG_LOCATION, "QueuePicker")));
@ -361,28 +367,32 @@ XdsClusterManagerLb::ClusterChild::ClusterChild(
const std::string& name) const std::string& name)
: xds_cluster_manager_policy_(std::move(xds_cluster_manager_policy)), : xds_cluster_manager_policy_(std::move(xds_cluster_manager_policy)),
name_(name) { name_(name) {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, "[xds_cluster_manager_lb %p] created ClusterChild %p for %s", gpr_log(GPR_INFO,
xds_cluster_manager_policy_.get(), this, name_.c_str()); "[xds_cluster_manager_lb %p] created ClusterChild %p for %s",
xds_cluster_manager_policy_.get(), this, name_.c_str());
}
GRPC_CLOSURE_INIT(&on_delayed_removal_timer_, OnDelayedRemovalTimer, this, GRPC_CLOSURE_INIT(&on_delayed_removal_timer_, OnDelayedRemovalTimer, this,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
} }
XdsClusterManagerLb::ClusterChild::~ClusterChild() { XdsClusterManagerLb::ClusterChild::~ClusterChild() {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_manager_lb %p] ClusterChild %p: destroying " "[xds_cluster_manager_lb %p] ClusterChild %p: destroying "
"child", "child",
xds_cluster_manager_policy_.get(), this); xds_cluster_manager_policy_.get(), this);
}
xds_cluster_manager_policy_.reset(DEBUG_LOCATION, "ClusterChild"); xds_cluster_manager_policy_.reset(DEBUG_LOCATION, "ClusterChild");
} }
void XdsClusterManagerLb::ClusterChild::Orphan() { void XdsClusterManagerLb::ClusterChild::Orphan() {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_manager_lb %p] ClusterChild %p %s: " "[xds_cluster_manager_lb %p] ClusterChild %p %s: "
"shutting down child", "shutting down child",
xds_cluster_manager_policy_.get(), this, name_.c_str()); xds_cluster_manager_policy_.get(), this, name_.c_str());
}
// Remove the child policy's interested_parties pollset_set from the // Remove the child policy's interested_parties pollset_set from the
// xDS policy. // xDS policy.
grpc_pollset_set_del_pollset_set( grpc_pollset_set_del_pollset_set(
@ -411,12 +421,14 @@ XdsClusterManagerLb::ClusterChild::CreateChildPolicyLocked(
OrphanablePtr<LoadBalancingPolicy> lb_policy = OrphanablePtr<LoadBalancingPolicy> lb_policy =
MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args), MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
&grpc_xds_cluster_manager_lb_trace); &grpc_xds_cluster_manager_lb_trace);
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_manager_lb %p] ClusterChild %p %s: Created " "[xds_cluster_manager_lb %p] ClusterChild %p %s: Created "
"new child " "new child "
"policy handler %p", "policy handler %p",
xds_cluster_manager_policy_.get(), this, name_.c_str(), lb_policy.get()); xds_cluster_manager_policy_.get(), this, name_.c_str(),
lb_policy.get());
}
// Add the xDS's interested_parties pollset_set to that of the newly created // Add the xDS's interested_parties pollset_set to that of the newly created
// child policy. This will make the child policy progress upon activity on // child policy. This will make the child policy progress upon activity on
// xDS LB, which in turn is tied to the application's call. // xDS LB, which in turn is tied to the application's call.
@ -446,13 +458,14 @@ void XdsClusterManagerLb::ClusterChild::UpdateLocked(
update_args.addresses = addresses; update_args.addresses = addresses;
update_args.args = grpc_channel_args_copy(args); update_args.args = grpc_channel_args_copy(args);
// Update the policy. // Update the policy.
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_manager_lb %p] ClusterChild %p %s: " "[xds_cluster_manager_lb %p] ClusterChild %p %s: "
"Updating child " "Updating child "
"policy handler %p", "policy handler %p",
xds_cluster_manager_policy_.get(), this, name_.c_str(), xds_cluster_manager_policy_.get(), this, name_.c_str(),
child_policy_.get()); child_policy_.get());
}
child_policy_->UpdateLocked(std::move(update_args)); child_policy_->UpdateLocked(std::move(update_args));
} }
@ -514,13 +527,15 @@ XdsClusterManagerLb::ClusterChild::Helper::CreateSubchannel(
void XdsClusterManagerLb::ClusterChild::Helper::UpdateState( void XdsClusterManagerLb::ClusterChild::Helper::UpdateState(
grpc_connectivity_state state, const absl::Status& status, grpc_connectivity_state state, const absl::Status& status,
std::unique_ptr<SubchannelPicker> picker) { std::unique_ptr<SubchannelPicker> picker) {
grpc_xds_cluster_manager_lb_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_cluster_manager_lb_trace)) {
GPR_INFO, gpr_log(
"[xds_cluster_manager_lb %p] child %s: received update: state=%s (%s) " GPR_INFO,
"picker=%p", "[xds_cluster_manager_lb %p] child %s: received update: state=%s (%s) "
xds_cluster_manager_child_->xds_cluster_manager_policy_.get(), "picker=%p",
xds_cluster_manager_child_->name_.c_str(), ConnectivityStateName(state), xds_cluster_manager_child_->xds_cluster_manager_policy_.get(),
status.ToString().c_str(), picker.get()); xds_cluster_manager_child_->name_.c_str(), ConnectivityStateName(state),
status.ToString().c_str(), picker.get());
}
if (xds_cluster_manager_child_->xds_cluster_manager_policy_->shutting_down_) { if (xds_cluster_manager_child_->xds_cluster_manager_policy_->shutting_down_) {
return; return;
} }

@ -369,12 +369,13 @@ void XdsClusterResolverLb::Helper::UpdateState(
xds_cluster_resolver_policy_->child_policy_ == nullptr) { xds_cluster_resolver_policy_->child_policy_ == nullptr) {
return; return;
} }
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] child policy updated state=%s (%s) " "[xds_cluster_resolver_lb %p] child policy updated state=%s (%s) "
"picker=%p", "picker=%p",
xds_cluster_resolver_policy_.get(), ConnectivityStateName(state), xds_cluster_resolver_policy_.get(), ConnectivityStateName(state),
status.ToString().c_str(), picker.get()); status.ToString().c_str(), picker.get());
}
xds_cluster_resolver_policy_->channel_control_helper()->UpdateState( xds_cluster_resolver_policy_->channel_control_helper()->UpdateState(
state, status, std::move(picker)); state, status, std::move(picker));
} }
@ -391,11 +392,12 @@ void XdsClusterResolverLb::Helper::AddTraceEvent(TraceSeverity severity,
// //
void XdsClusterResolverLb::EdsDiscoveryMechanism::Start() { void XdsClusterResolverLb::EdsDiscoveryMechanism::Start() {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] eds discovery mechanism %" PRIuPTR "[xds_cluster_resolver_lb %p] eds discovery mechanism %" PRIuPTR
":%p starting xds watch for %s", ":%p starting xds watch for %s",
parent(), index(), this, std::string(GetEdsResourceName()).c_str()); parent(), index(), this, std::string(GetEdsResourceName()).c_str());
}
auto watcher = absl::make_unique<EndpointWatcher>( auto watcher = absl::make_unique<EndpointWatcher>(
Ref(DEBUG_LOCATION, "EdsDiscoveryMechanism")); Ref(DEBUG_LOCATION, "EdsDiscoveryMechanism"));
watcher_ = watcher.get(); watcher_ = watcher.get();
@ -404,11 +406,12 @@ void XdsClusterResolverLb::EdsDiscoveryMechanism::Start() {
} }
void XdsClusterResolverLb::EdsDiscoveryMechanism::Orphan() { void XdsClusterResolverLb::EdsDiscoveryMechanism::Orphan() {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] eds discovery mechanism %" PRIuPTR "[xds_cluster_resolver_lb %p] eds discovery mechanism %" PRIuPTR
":%p cancelling xds watch for %s", ":%p cancelling xds watch for %s",
parent(), index(), this, std::string(GetEdsResourceName()).c_str()); parent(), index(), this, std::string(GetEdsResourceName()).c_str());
}
parent()->xds_client_->CancelEndpointDataWatch(GetEdsResourceName(), parent()->xds_client_->CancelEndpointDataWatch(GetEdsResourceName(),
watcher_); watcher_);
Unref(); Unref();
@ -506,19 +509,22 @@ void XdsClusterResolverLb::LogicalDNSDiscoveryMechanism::Start() {
return; return;
} }
resolver_->StartLocked(); resolver_->StartLocked();
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] logical DNS discovery mechanism " "[xds_cluster_resolver_lb %p] logical DNS discovery mechanism "
"%" PRIuPTR ":%p starting dns resolver %p", "%" PRIuPTR ":%p starting dns resolver %p",
parent(), index(), this, resolver_.get()); parent(), index(), this, resolver_.get());
}
} }
void XdsClusterResolverLb::LogicalDNSDiscoveryMechanism::Orphan() { void XdsClusterResolverLb::LogicalDNSDiscoveryMechanism::Orphan() {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(
"[xds_cluster_resolver_lb %p] logical DNS discovery mechanism %" PRIuPTR GPR_INFO,
":%p shutting down dns resolver %p", "[xds_cluster_resolver_lb %p] logical DNS discovery mechanism %" PRIuPTR
parent(), index(), this, resolver_.get()); ":%p shutting down dns resolver %p",
parent(), index(), this, resolver_.get());
}
resolver_.reset(); resolver_.reset();
Unref(); Unref();
} }
@ -558,11 +564,12 @@ XdsClusterResolverLb::XdsClusterResolverLb(RefCountedPtr<XdsClient> xds_client,
xds_client_(std::move(xds_client)), xds_client_(std::move(xds_client)),
server_name_(std::move(server_name)), server_name_(std::move(server_name)),
is_xds_uri_(is_xds_uri) { is_xds_uri_(is_xds_uri) {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] created -- xds_client=%p, " "[xds_cluster_resolver_lb %p] created -- xds_client=%p, "
"server_name=%s, is_xds_uri=%d", "server_name=%s, is_xds_uri=%d",
this, xds_client_.get(), server_name_.c_str(), is_xds_uri_); this, xds_client_.get(), server_name_.c_str(), is_xds_uri_);
}
// EDS-only flow. // EDS-only flow.
if (!is_xds_uri_) { if (!is_xds_uri_) {
// Setup channelz linkage. // Setup channelz linkage.
@ -579,16 +586,18 @@ XdsClusterResolverLb::XdsClusterResolverLb(RefCountedPtr<XdsClient> xds_client,
} }
XdsClusterResolverLb::~XdsClusterResolverLb() { XdsClusterResolverLb::~XdsClusterResolverLb() {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] destroying xds_cluster_resolver LB " "[xds_cluster_resolver_lb %p] destroying xds_cluster_resolver LB "
"policy", "policy",
this); this);
}
} }
void XdsClusterResolverLb::ShutdownLocked() { void XdsClusterResolverLb::ShutdownLocked() {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, "[xds_cluster_resolver_lb %p] shutting down", this); gpr_log(GPR_INFO, "[xds_cluster_resolver_lb %p] shutting down", this);
}
shutting_down_ = true; shutting_down_ = true;
MaybeDestroyChildPolicyLocked(); MaybeDestroyChildPolicyLocked();
discovery_mechanisms_.clear(); discovery_mechanisms_.clear();
@ -619,8 +628,9 @@ void XdsClusterResolverLb::MaybeDestroyChildPolicyLocked() {
} }
void XdsClusterResolverLb::UpdateLocked(UpdateArgs args) { void XdsClusterResolverLb::UpdateLocked(UpdateArgs args) {
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, "[xds_cluster_resolver_lb %p] Received update", this); gpr_log(GPR_INFO, "[xds_cluster_resolver_lb %p] Received update", this);
}
const bool is_initial_update = args_ == nullptr; const bool is_initial_update = args_ == nullptr;
// Update config. // Update config.
auto old_config = std::move(config_); auto old_config = std::move(config_);
@ -675,11 +685,12 @@ void XdsClusterResolverLb::ExitIdleLocked() {
void XdsClusterResolverLb::OnEndpointChanged(size_t index, void XdsClusterResolverLb::OnEndpointChanged(size_t index,
XdsApi::EdsUpdate update) { XdsApi::EdsUpdate update) {
if (shutting_down_) return; if (shutting_down_) return;
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_cluster_resolver_lb %p] Received update from xds client" "[xds_cluster_resolver_lb %p] Received update from xds client"
" for discovery mechanism %" PRIuPTR "", " for discovery mechanism %" PRIuPTR "",
this, index); this, index);
}
// We need at least one priority for each discovery mechanism, just so that we // We need at least one priority for each discovery mechanism, just so that we
// have a child in which to create the xds_cluster_impl policy. This ensures // have a child in which to create the xds_cluster_impl policy. This ensures
// that we properly handle the case of a discovery mechanism dropping 100% of // that we properly handle the case of a discovery mechanism dropping 100% of
@ -1037,9 +1048,10 @@ void XdsClusterResolverLb::UpdateChildPolicyLocked() {
if (child_policy_ == nullptr) { if (child_policy_ == nullptr) {
child_policy_ = CreateChildPolicyLocked(update_args.args); child_policy_ = CreateChildPolicyLocked(update_args.args);
} }
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, "[xds_cluster_resolver_lb %p] Updating child policy %p", this, gpr_log(GPR_INFO, "[xds_cluster_resolver_lb %p] Updating child policy %p",
child_policy_.get()); this, child_policy_.get());
}
child_policy_->UpdateLocked(std::move(update_args)); child_policy_->UpdateLocked(std::move(update_args));
} }
@ -1070,9 +1082,11 @@ XdsClusterResolverLb::CreateChildPolicyLocked(const grpc_channel_args* args) {
"[xds_cluster_resolver_lb %p] failure creating child policy", this); "[xds_cluster_resolver_lb %p] failure creating child policy", this);
return nullptr; return nullptr;
} }
grpc_lb_xds_cluster_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_xds_cluster_resolver_trace)) {
GPR_INFO, "[xds_cluster_resolver_lb %p]: Created new child policy %p", gpr_log(GPR_INFO,
this, lb_policy.get()); "[xds_cluster_resolver_lb %p]: Created new child policy %p", this,
lb_policy.get());
}
// Add our interested_parties pollset_set to that of the newly created // Add our interested_parties pollset_set to that of the newly created
// child policy. This will make the child policy progress upon activity on // child policy. This will make the child policy progress upon activity on
// this policy, which in turn is tied to the application's call. // this policy, which in turn is tied to the application's call.

@ -56,14 +56,17 @@ class XdsResolver : public Resolver {
server_name_(absl::StripPrefix(args.uri.path(), "/")), server_name_(absl::StripPrefix(args.uri.path(), "/")),
args_(grpc_channel_args_copy(args.args)), args_(grpc_channel_args_copy(args.args)),
interested_parties_(args.pollset_set) { interested_parties_(args.pollset_set) {
grpc_xds_resolver_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
"[xds_resolver %p] created for server name %s", gpr_log(GPR_INFO, "[xds_resolver %p] created for server name %s", this,
this, server_name_.c_str()); server_name_.c_str());
}
} }
~XdsResolver() override { ~XdsResolver() override {
grpc_channel_args_destroy(args_); grpc_channel_args_destroy(args_);
grpc_xds_resolver_trace.Log(GPR_INFO, "[xds_resolver %p] destroyed", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
gpr_log(GPR_INFO, "[xds_resolver %p] destroyed", this);
}
} }
void StartLocked() override; void StartLocked() override;
@ -367,9 +370,10 @@ bool XdsResolver::XdsConfigSelector::Route::operator==(
XdsResolver::XdsConfigSelector::XdsConfigSelector( XdsResolver::XdsConfigSelector::XdsConfigSelector(
RefCountedPtr<XdsResolver> resolver, grpc_error_handle* error) RefCountedPtr<XdsResolver> resolver, grpc_error_handle* error)
: resolver_(std::move(resolver)) { : resolver_(std::move(resolver)) {
grpc_xds_resolver_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
"[xds_resolver %p] creating XdsConfigSelector %p", gpr_log(GPR_INFO, "[xds_resolver %p] creating XdsConfigSelector %p",
resolver_.get(), this); resolver_.get(), this);
}
// 1. Construct the route table // 1. Construct the route table
// 2 Update resolver's cluster state map // 2 Update resolver's cluster state map
// 3. Construct cluster list to hold on to entries in the cluster state // 3. Construct cluster list to hold on to entries in the cluster state
@ -381,9 +385,10 @@ XdsResolver::XdsConfigSelector::XdsConfigSelector(
// invalid data. // invalid data.
route_table_.reserve(resolver_->current_virtual_host_.routes.size()); route_table_.reserve(resolver_->current_virtual_host_.routes.size());
for (auto& route : resolver_->current_virtual_host_.routes) { for (auto& route : resolver_->current_virtual_host_.routes) {
grpc_xds_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
GPR_INFO, "[xds_resolver %p] XdsConfigSelector %p: route: %s", gpr_log(GPR_INFO, "[xds_resolver %p] XdsConfigSelector %p: route: %s",
resolver_.get(), this, route.ToString().c_str()); resolver_.get(), this, route.ToString().c_str());
}
route_table_.emplace_back(); route_table_.emplace_back();
auto& route_entry = route_table_.back(); auto& route_entry = route_table_.back();
route_entry.route = route; route_entry.route = route;
@ -431,9 +436,10 @@ XdsResolver::XdsConfigSelector::XdsConfigSelector(
} }
XdsResolver::XdsConfigSelector::~XdsConfigSelector() { XdsResolver::XdsConfigSelector::~XdsConfigSelector() {
grpc_xds_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
GPR_INFO, "[xds_resolver %p] destroying XdsConfigSelector %p", gpr_log(GPR_INFO, "[xds_resolver %p] destroying XdsConfigSelector %p",
resolver_.get(), this); resolver_.get(), this);
}
clusters_.clear(); clusters_.clear();
resolver_->MaybeRemoveUnusedClusters(); resolver_->MaybeRemoveUnusedClusters();
} }
@ -775,8 +781,9 @@ void XdsResolver::StartLocked() {
} }
void XdsResolver::ShutdownLocked() { void XdsResolver::ShutdownLocked() {
grpc_xds_resolver_trace.Log(GPR_INFO, "[xds_resolver %p] shutting down", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
this); gpr_log(GPR_INFO, "[xds_resolver %p] shutting down", this);
}
if (xds_client_ != nullptr) { if (xds_client_ != nullptr) {
if (listener_watcher_ != nullptr) { if (listener_watcher_ != nullptr) {
xds_client_->CancelListenerDataWatch(server_name_, listener_watcher_, xds_client_->CancelListenerDataWatch(server_name_, listener_watcher_,
@ -799,8 +806,9 @@ void XdsResolver::ShutdownLocked() {
} }
void XdsResolver::OnListenerUpdate(XdsApi::LdsUpdate listener) { void XdsResolver::OnListenerUpdate(XdsApi::LdsUpdate listener) {
grpc_xds_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
GPR_INFO, "[xds_resolver %p] received updated listener data", this); gpr_log(GPR_INFO, "[xds_resolver %p] received updated listener data", this);
}
if (listener.http_connection_manager.route_config_name != if (listener.http_connection_manager.route_config_name !=
route_config_name_) { route_config_name_) {
if (route_config_watcher_ != nullptr) { if (route_config_watcher_ != nullptr) {
@ -833,8 +841,9 @@ void XdsResolver::OnListenerUpdate(XdsApi::LdsUpdate listener) {
} }
void XdsResolver::OnRouteConfigUpdate(XdsApi::RdsUpdate rds_update) { void XdsResolver::OnRouteConfigUpdate(XdsApi::RdsUpdate rds_update) {
grpc_xds_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
GPR_INFO, "[xds_resolver %p] received updated route config", this); gpr_log(GPR_INFO, "[xds_resolver %p] received updated route config", this);
}
// Find the relevant VirtualHost from the RouteConfiguration. // Find the relevant VirtualHost from the RouteConfiguration.
XdsApi::RdsUpdate::VirtualHost* vhost = XdsApi::RdsUpdate::VirtualHost* vhost =
rds_update.FindVirtualHostForDomain(server_name_); rds_update.FindVirtualHostForDomain(server_name_);
@ -923,9 +932,10 @@ void XdsResolver::GenerateResult() {
OnError(error); OnError(error);
return; return;
} }
grpc_xds_resolver_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_resolver_trace)) {
GPR_INFO, "[xds_resolver %p] generated service config: %s", this, gpr_log(GPR_INFO, "[xds_resolver %p] generated service config: %s", this,
result.service_config->json_string().c_str()); result.service_config->json_string().c_str());
}
grpc_arg new_args[] = { grpc_arg new_args[] = {
xds_client_->MakeChannelArg(), xds_client_->MakeChannelArg(),
config_selector->MakeChannelArg(), config_selector->MakeChannelArg(),

@ -676,20 +676,23 @@ RetryFilter::CallData::CallAttempt::CallAttempt(CallData* calld)
seen_recv_trailing_metadata_from_surface_(false), seen_recv_trailing_metadata_from_surface_(false),
abandoned_(false) { abandoned_(false) {
lb_call_ = calld->CreateLoadBalancedCall(&attempt_dispatch_controller_); lb_call_ = calld->CreateLoadBalancedCall(&attempt_dispatch_controller_);
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: create lb_call=%p", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: create lb_call=%p",
calld->chand_, calld, this, lb_call_.get()); calld->chand_, calld, this, lb_call_.get());
}
// If per_attempt_recv_timeout is set, start a timer. // If per_attempt_recv_timeout is set, start a timer.
if (calld->retry_policy_ != nullptr && if (calld->retry_policy_ != nullptr &&
calld->retry_policy_->per_attempt_recv_timeout().has_value()) { calld->retry_policy_->per_attempt_recv_timeout().has_value()) {
grpc_millis per_attempt_recv_deadline = grpc_millis per_attempt_recv_deadline =
ExecCtx::Get()->Now() + ExecCtx::Get()->Now() +
*calld->retry_policy_->per_attempt_recv_timeout(); *calld->retry_policy_->per_attempt_recv_timeout();
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: per-attempt timeout in %" PRId64 " ms", "chand=%p calld=%p attempt=%p: per-attempt timeout in %" PRId64
calld->chand_, calld, this, " ms",
*calld->retry_policy_->per_attempt_recv_timeout()); calld->chand_, calld, this,
*calld->retry_policy_->per_attempt_recv_timeout());
}
// Schedule retry after computed delay. // Schedule retry after computed delay.
GRPC_CLOSURE_INIT(&on_per_attempt_recv_timer_, OnPerAttemptRecvTimer, this, GRPC_CLOSURE_INIT(&on_per_attempt_recv_timer_, OnPerAttemptRecvTimer, this,
nullptr); nullptr);
@ -702,9 +705,10 @@ RetryFilter::CallData::CallAttempt::CallAttempt(CallData* calld)
} }
RetryFilter::CallData::CallAttempt::~CallAttempt() { RetryFilter::CallData::CallAttempt::~CallAttempt() {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: destroying call attempt", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: destroying call attempt",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
} }
void RetryFilter::CallData::CallAttempt::FreeCachedSendOpDataAfterCommit() { void RetryFilter::CallData::CallAttempt::FreeCachedSendOpDataAfterCommit() {
@ -767,11 +771,12 @@ void RetryFilter::CallData::CallAttempt::MaybeSwitchToFastPath() {
// yet seen that op from the surface, we can't switch yet. // yet seen that op from the surface, we can't switch yet.
if (recv_trailing_metadata_internal_batch_ != nullptr) return; if (recv_trailing_metadata_internal_batch_ != nullptr) return;
// Switch to fast path. // Switch to fast path.
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: retry state no longer needed; " "chand=%p calld=%p attempt=%p: retry state no longer needed; "
"moving LB call to parent and unreffing the call attempt", "moving LB call to parent and unreffing the call attempt",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
calld_->committed_call_ = std::move(lb_call_); calld_->committed_call_ = std::move(lb_call_);
calld_->call_attempt_.reset(DEBUG_LOCATION, "MaybeSwitchToFastPath"); calld_->call_attempt_.reset(DEBUG_LOCATION, "MaybeSwitchToFastPath");
} }
@ -785,11 +790,12 @@ RetryFilter::CallData::CallAttempt::MaybeCreateBatchForReplay() {
// send_initial_metadata. // send_initial_metadata.
if (calld_->seen_send_initial_metadata_ && !started_send_initial_metadata_ && if (calld_->seen_send_initial_metadata_ && !started_send_initial_metadata_ &&
!calld_->pending_send_initial_metadata_) { !calld_->pending_send_initial_metadata_) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: replaying previously completed " "chand=%p calld=%p attempt=%p: replaying previously completed "
"send_initial_metadata op", "send_initial_metadata op",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
replay_batch_data = CreateBatch(1, true /* set_on_complete */); replay_batch_data = CreateBatch(1, true /* set_on_complete */);
replay_batch_data->AddRetriableSendInitialMetadataOp(); replay_batch_data->AddRetriableSendInitialMetadataOp();
} }
@ -798,11 +804,12 @@ RetryFilter::CallData::CallAttempt::MaybeCreateBatchForReplay() {
if (started_send_message_count_ < calld_->send_messages_.size() && if (started_send_message_count_ < calld_->send_messages_.size() &&
started_send_message_count_ == completed_send_message_count_ && started_send_message_count_ == completed_send_message_count_ &&
!calld_->pending_send_message_) { !calld_->pending_send_message_) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: replaying previously completed " "chand=%p calld=%p attempt=%p: replaying previously completed "
"send_message op", "send_message op",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
if (replay_batch_data == nullptr) { if (replay_batch_data == nullptr) {
replay_batch_data = CreateBatch(1, true /* set_on_complete */); replay_batch_data = CreateBatch(1, true /* set_on_complete */);
} }
@ -816,11 +823,12 @@ RetryFilter::CallData::CallAttempt::MaybeCreateBatchForReplay() {
started_send_message_count_ == calld_->send_messages_.size() && started_send_message_count_ == calld_->send_messages_.size() &&
!started_send_trailing_metadata_ && !started_send_trailing_metadata_ &&
!calld_->pending_send_trailing_metadata_) { !calld_->pending_send_trailing_metadata_) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: replaying previously completed " "chand=%p calld=%p attempt=%p: replaying previously completed "
"send_trailing_metadata op", "send_trailing_metadata op",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
if (replay_batch_data == nullptr) { if (replay_batch_data == nullptr) {
replay_batch_data = CreateBatch(1, true /* set_on_complete */); replay_batch_data = CreateBatch(1, true /* set_on_complete */);
} }
@ -845,10 +853,11 @@ void StartBatchInCallCombiner(void* arg, grpc_error_handle /*ignored*/) {
void RetryFilter::CallData::CallAttempt::AddClosureForBatch( void RetryFilter::CallData::CallAttempt::AddClosureForBatch(
grpc_transport_stream_op_batch* batch, const char* reason, grpc_transport_stream_op_batch* batch, const char* reason,
CallCombinerClosureList* closures) { CallCombinerClosureList* closures) {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: adding batch (%s): %s", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: adding batch (%s): %s",
calld_->chand_, calld_, this, reason, calld_->chand_, calld_, this, reason,
grpc_transport_stream_op_batch_string(batch).c_str()); grpc_transport_stream_op_batch_string(batch).c_str());
}
batch->handler_private.extra_arg = lb_call_.get(); batch->handler_private.extra_arg = lb_call_.get();
GRPC_CLOSURE_INIT(&batch->handler_private.closure, StartBatchInCallCombiner, GRPC_CLOSURE_INIT(&batch->handler_private.closure, StartBatchInCallCombiner,
batch, grpc_schedule_on_exec_ctx); batch, grpc_schedule_on_exec_ctx);
@ -857,11 +866,12 @@ void RetryFilter::CallData::CallAttempt::AddClosureForBatch(
void RetryFilter::CallData::CallAttempt:: void RetryFilter::CallData::CallAttempt::
AddBatchForInternalRecvTrailingMetadata(CallCombinerClosureList* closures) { AddBatchForInternalRecvTrailingMetadata(CallCombinerClosureList* closures) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: call failed but " "chand=%p calld=%p attempt=%p: call failed but "
"recv_trailing_metadata not started; starting it internally", "recv_trailing_metadata not started; starting it internally",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
// Create batch_data with 2 refs, since this batch will be unreffed twice: // Create batch_data with 2 refs, since this batch will be unreffed twice:
// once for the recv_trailing_metadata_ready callback when the batch // once for the recv_trailing_metadata_ready callback when the batch
// completes, and again when we actually get a recv_trailing_metadata // completes, and again when we actually get a recv_trailing_metadata
@ -1033,19 +1043,22 @@ void RetryFilter::CallData::CallAttempt::AddRetriableBatches(
} }
void RetryFilter::CallData::CallAttempt::StartRetriableBatches() { void RetryFilter::CallData::CallAttempt::StartRetriableBatches() {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p attempt=%p: constructing retriable batches", gpr_log(GPR_INFO,
calld_->chand_, calld_, this); "chand=%p calld=%p attempt=%p: constructing retriable batches",
calld_->chand_, calld_, this);
}
// Construct list of closures to execute, one for each pending batch. // Construct list of closures to execute, one for each pending batch.
CallCombinerClosureList closures; CallCombinerClosureList closures;
AddRetriableBatches(&closures); AddRetriableBatches(&closures);
// Note: This will yield the call combiner. // Note: This will yield the call combiner.
// Start batches on LB call. // Start batches on LB call.
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: starting %" PRIuPTR gpr_log(GPR_INFO,
" retriable batches on lb_call=%p", "chand=%p calld=%p attempt=%p: starting %" PRIuPTR
calld_->chand_, calld_, this, closures.size(), " retriable batches on lb_call=%p",
lb_call_.get()); calld_->chand_, calld_, this, closures.size(), lb_call_.get());
}
closures.RunClosures(calld_->call_combiner_); closures.RunClosures(calld_->call_combiner_);
} }
@ -1070,18 +1083,21 @@ bool RetryFilter::CallData::CallAttempt::ShouldRetry(
if (calld_->retry_throttle_data_ != nullptr) { if (calld_->retry_throttle_data_ != nullptr) {
calld_->retry_throttle_data_->RecordSuccess(); calld_->retry_throttle_data_->RecordSuccess();
} }
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: call succeeded", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: call succeeded",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
return false; return false;
} }
// Status is not OK. Check whether the status is retryable. // Status is not OK. Check whether the status is retryable.
if (!calld_->retry_policy_->retryable_status_codes().Contains(*status)) { if (!calld_->retry_policy_->retryable_status_codes().Contains(*status)) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: status %s not configured as " "chand=%p calld=%p attempt=%p: status %s not configured as "
"retryable", "retryable",
calld_->chand_, calld_, this, grpc_status_code_to_string(*status)); calld_->chand_, calld_, this,
grpc_status_code_to_string(*status));
}
return false; return false;
} }
} }
@ -1094,25 +1110,30 @@ bool RetryFilter::CallData::CallAttempt::ShouldRetry(
// checks, so that we don't fail to record failures due to other factors. // checks, so that we don't fail to record failures due to other factors.
if (calld_->retry_throttle_data_ != nullptr && if (calld_->retry_throttle_data_ != nullptr &&
!calld_->retry_throttle_data_->RecordFailure()) { !calld_->retry_throttle_data_->RecordFailure()) {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: retries throttled", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: retries throttled",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
return false; return false;
} }
// Check whether the call is committed. // Check whether the call is committed.
if (calld_->retry_committed_) { if (calld_->retry_committed_) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p attempt=%p: retries already committed", gpr_log(GPR_INFO,
calld_->chand_, calld_, this); "chand=%p calld=%p attempt=%p: retries already committed",
calld_->chand_, calld_, this);
}
return false; return false;
} }
// Check whether we have retries remaining. // Check whether we have retries remaining.
++calld_->num_attempts_completed_; ++calld_->num_attempts_completed_;
if (calld_->num_attempts_completed_ >= if (calld_->num_attempts_completed_ >=
calld_->retry_policy_->max_attempts()) { calld_->retry_policy_->max_attempts()) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p attempt=%p: exceeded %d retry attempts", gpr_log(
calld_->chand_, calld_, this, calld_->retry_policy_->max_attempts()); GPR_INFO, "chand=%p calld=%p attempt=%p: exceeded %d retry attempts",
calld_->chand_, calld_, this, calld_->retry_policy_->max_attempts());
}
return false; return false;
} }
// Check server push-back. // Check server push-back.
@ -1120,17 +1141,20 @@ bool RetryFilter::CallData::CallAttempt::ShouldRetry(
// If the value is "-1" or any other unparseable string, we do not retry. // If the value is "-1" or any other unparseable string, we do not retry.
uint32_t ms; uint32_t ms;
if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(*server_pushback_md), &ms)) { if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(*server_pushback_md), &ms)) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: not retrying due to server " "chand=%p calld=%p attempt=%p: not retrying due to server "
"push-back", "push-back",
calld_->chand_, calld_, this); calld_->chand_, calld_, this);
}
return false; return false;
} else { } else {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(
"chand=%p calld=%p attempt=%p: server push-back: retry in %u ms", GPR_INFO,
calld_->chand_, calld_, this, ms); "chand=%p calld=%p attempt=%p: server push-back: retry in %u ms",
calld_->chand_, calld_, this, ms);
}
*server_pushback_ms = static_cast<grpc_millis>(ms); *server_pushback_ms = static_cast<grpc_millis>(ms);
} }
} }
@ -1138,10 +1162,12 @@ bool RetryFilter::CallData::CallAttempt::ShouldRetry(
auto* service_config_call_data = static_cast<ServiceConfigCallData*>( auto* service_config_call_data = static_cast<ServiceConfigCallData*>(
calld_->call_context_[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value); calld_->call_context_[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
if (!service_config_call_data->call_dispatch_controller()->ShouldRetry()) { if (!service_config_call_data->call_dispatch_controller()->ShouldRetry()) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(
"chand=%p calld=%p attempt=%p: call dispatch controller denied retry", GPR_INFO,
calld_->chand_, calld_, this); "chand=%p calld=%p attempt=%p: call dispatch controller denied retry",
calld_->chand_, calld_, this);
}
return false; return false;
} }
// We should retry. // We should retry.
@ -1192,12 +1218,14 @@ void RetryFilter::CallData::CallAttempt::OnPerAttemptRecvTimerLocked(
void* arg, grpc_error_handle error) { void* arg, grpc_error_handle error) {
auto* call_attempt = static_cast<CallAttempt*>(arg); auto* call_attempt = static_cast<CallAttempt*>(arg);
auto* calld = call_attempt->calld_; auto* calld = call_attempt->calld_;
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: perAttemptRecvTimeout timer fired: " "chand=%p calld=%p attempt=%p: perAttemptRecvTimeout timer fired: "
"error=%s, per_attempt_recv_timer_pending_=%d", "error=%s, per_attempt_recv_timer_pending_=%d",
calld->chand_, calld, call_attempt, grpc_error_std_string(error).c_str(), calld->chand_, calld, call_attempt,
call_attempt->per_attempt_recv_timer_pending_); grpc_error_std_string(error).c_str(),
call_attempt->per_attempt_recv_timer_pending_);
}
CallCombinerClosureList closures; CallCombinerClosureList closures;
if (error == GRPC_ERROR_NONE && if (error == GRPC_ERROR_NONE &&
call_attempt->per_attempt_recv_timer_pending_) { call_attempt->per_attempt_recv_timer_pending_) {
@ -1233,10 +1261,12 @@ void RetryFilter::CallData::CallAttempt::OnPerAttemptRecvTimerLocked(
void RetryFilter::CallData::CallAttempt::MaybeCancelPerAttemptRecvTimer() { void RetryFilter::CallData::CallAttempt::MaybeCancelPerAttemptRecvTimer() {
if (per_attempt_recv_timer_pending_) { if (per_attempt_recv_timer_pending_) {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: cancelling " gpr_log(GPR_INFO,
"perAttemptRecvTimeout timer", "chand=%p calld=%p attempt=%p: cancelling "
calld_->chand_, calld_, this); "perAttemptRecvTimeout timer",
calld_->chand_, calld_, this);
}
per_attempt_recv_timer_pending_ = false; per_attempt_recv_timer_pending_ = false;
grpc_timer_cancel(&per_attempt_recv_timer_); grpc_timer_cancel(&per_attempt_recv_timer_);
} }
@ -1252,10 +1282,11 @@ RetryFilter::CallData::CallAttempt::BatchData::BatchData(
GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace) ? "BatchData" : nullptr, GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace) ? "BatchData" : nullptr,
refcount), refcount),
call_attempt_(std::move(attempt)) { call_attempt_(std::move(attempt)) {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: creating batch %p", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: creating batch %p",
call_attempt_->calld_->chand_, call_attempt_->calld_, call_attempt_->calld_->chand_, call_attempt_->calld_,
call_attempt_.get(), this); call_attempt_.get(), this);
}
// We hold a ref to the call stack for every batch sent on a call attempt. // We hold a ref to the call stack for every batch sent on a call attempt.
// This is because some batches on the call attempt may not complete // This is because some batches on the call attempt may not complete
// until after all of the batches are completed at the surface (because // until after all of the batches are completed at the surface (because
@ -1272,10 +1303,11 @@ RetryFilter::CallData::CallAttempt::BatchData::BatchData(
} }
RetryFilter::CallData::CallAttempt::BatchData::~BatchData() { RetryFilter::CallData::CallAttempt::BatchData::~BatchData() {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: destroying batch %p", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: destroying batch %p",
call_attempt_->calld_->chand_, call_attempt_->calld_, call_attempt_->calld_->chand_, call_attempt_->calld_,
call_attempt_.get(), this); call_attempt_.get(), this);
}
if (batch_.send_initial_metadata) { if (batch_.send_initial_metadata) {
grpc_metadata_batch_destroy(&call_attempt_->send_initial_metadata_); grpc_metadata_batch_destroy(&call_attempt_->send_initial_metadata_);
} }
@ -1356,11 +1388,13 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvInitialMetadataReady(
RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg)); RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg));
CallAttempt* call_attempt = batch_data->call_attempt_.get(); CallAttempt* call_attempt = batch_data->call_attempt_.get();
CallData* calld = call_attempt->calld_; CallData* calld = call_attempt->calld_;
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p batch_data=%p: " gpr_log(GPR_INFO,
"got recv_initial_metadata_ready, error=%s", "chand=%p calld=%p attempt=%p batch_data=%p: "
calld->chand_, calld, call_attempt, batch_data.get(), "got recv_initial_metadata_ready, error=%s",
grpc_error_std_string(error).c_str()); calld->chand_, calld, call_attempt, batch_data.get(),
grpc_error_std_string(error).c_str());
}
call_attempt->completed_recv_initial_metadata_ = true; call_attempt->completed_recv_initial_metadata_ = true;
// If this attempt has been abandoned, then we're not going to use the // If this attempt has been abandoned, then we're not going to use the
// result of this recv_initial_metadata op, so do nothing. // result of this recv_initial_metadata op, so do nothing.
@ -1381,10 +1415,12 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvInitialMetadataReady(
if (GPR_UNLIKELY((call_attempt->trailing_metadata_available_ || if (GPR_UNLIKELY((call_attempt->trailing_metadata_available_ ||
error != GRPC_ERROR_NONE) && error != GRPC_ERROR_NONE) &&
!call_attempt->completed_recv_trailing_metadata_)) { !call_attempt->completed_recv_trailing_metadata_)) {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: deferring " gpr_log(GPR_INFO,
"recv_initial_metadata_ready (Trailers-Only)", "chand=%p calld=%p attempt=%p: deferring "
calld->chand_, calld, call_attempt); "recv_initial_metadata_ready (Trailers-Only)",
calld->chand_, calld, call_attempt);
}
call_attempt->recv_initial_metadata_ready_deferred_batch_ = call_attempt->recv_initial_metadata_ready_deferred_batch_ =
std::move(batch_data); std::move(batch_data);
call_attempt->recv_initial_metadata_error_ = GRPC_ERROR_REF(error); call_attempt->recv_initial_metadata_error_ = GRPC_ERROR_REF(error);
@ -1451,11 +1487,13 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvMessageReady(
RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg)); RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg));
CallAttempt* call_attempt = batch_data->call_attempt_.get(); CallAttempt* call_attempt = batch_data->call_attempt_.get();
CallData* calld = call_attempt->calld_; CallData* calld = call_attempt->calld_;
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p batch_data=%p: " gpr_log(GPR_INFO,
"got recv_message_ready, error=%s", "chand=%p calld=%p attempt=%p batch_data=%p: "
calld->chand_, calld, call_attempt, batch_data.get(), "got recv_message_ready, error=%s",
grpc_error_std_string(error).c_str()); calld->chand_, calld, call_attempt, batch_data.get(),
grpc_error_std_string(error).c_str());
}
++call_attempt->completed_recv_message_count_; ++call_attempt->completed_recv_message_count_;
// If this attempt has been abandoned, then we're not going to use the // If this attempt has been abandoned, then we're not going to use the
// result of this recv_message op, so do nothing. // result of this recv_message op, so do nothing.
@ -1475,11 +1513,12 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvMessageReady(
if (GPR_UNLIKELY((call_attempt->recv_message_ == nullptr || if (GPR_UNLIKELY((call_attempt->recv_message_ == nullptr ||
error != GRPC_ERROR_NONE) && error != GRPC_ERROR_NONE) &&
!call_attempt->completed_recv_trailing_metadata_)) { !call_attempt->completed_recv_trailing_metadata_)) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: deferring recv_message_ready " "chand=%p calld=%p attempt=%p: deferring recv_message_ready "
"(nullptr message and recv_trailing_metadata pending)", "(nullptr message and recv_trailing_metadata pending)",
calld->chand_, calld, call_attempt); calld->chand_, calld, call_attempt);
}
call_attempt->recv_message_ready_deferred_batch_ = std::move(batch_data); call_attempt->recv_message_ready_deferred_batch_ = std::move(batch_data);
call_attempt->recv_message_error_ = GRPC_ERROR_REF(error); call_attempt->recv_message_error_ = GRPC_ERROR_REF(error);
CallCombinerClosureList closures; CallCombinerClosureList closures;
@ -1644,11 +1683,13 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvTrailingMetadataReady(
RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg)); RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg));
CallAttempt* call_attempt = batch_data->call_attempt_.get(); CallAttempt* call_attempt = batch_data->call_attempt_.get();
CallData* calld = call_attempt->calld_; CallData* calld = call_attempt->calld_;
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p batch_data=%p: " gpr_log(GPR_INFO,
"got recv_trailing_metadata_ready, error=%s", "chand=%p calld=%p attempt=%p batch_data=%p: "
calld->chand_, calld, call_attempt, batch_data.get(), "got recv_trailing_metadata_ready, error=%s",
grpc_error_std_string(error).c_str()); calld->chand_, calld, call_attempt, batch_data.get(),
grpc_error_std_string(error).c_str());
}
call_attempt->completed_recv_trailing_metadata_ = true; call_attempt->completed_recv_trailing_metadata_ = true;
// If this attempt has been abandoned, then we're not going to use the // If this attempt has been abandoned, then we're not going to use the
// result of this recv_trailing_metadata op, so do nothing. // result of this recv_trailing_metadata op, so do nothing.
@ -1668,11 +1709,13 @@ void RetryFilter::CallData::CallAttempt::BatchData::RecvTrailingMetadataReady(
bool is_lb_drop = false; bool is_lb_drop = false;
GetCallStatus(calld->deadline_, md_batch, GRPC_ERROR_REF(error), &status, GetCallStatus(calld->deadline_, md_batch, GRPC_ERROR_REF(error), &status,
&server_pushback_md, &is_lb_drop); &server_pushback_md, &is_lb_drop);
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(
"chand=%p calld=%p attempt=%p: call finished, status=%s is_lb_drop=%d", GPR_INFO,
calld->chand_, calld, call_attempt, grpc_status_code_to_string(status), "chand=%p calld=%p attempt=%p: call finished, status=%s is_lb_drop=%d",
is_lb_drop); calld->chand_, calld, call_attempt, grpc_status_code_to_string(status),
is_lb_drop);
}
// Check if we should retry. // Check if we should retry.
grpc_millis server_pushback_ms = -1; grpc_millis server_pushback_ms = -1;
if (call_attempt->ShouldRetry(status, is_lb_drop, server_pushback_md, if (call_attempt->ShouldRetry(status, is_lb_drop, server_pushback_md,
@ -1757,11 +1800,12 @@ void RetryFilter::CallData::CallAttempt::BatchData::
} }
} }
if (have_pending_send_ops) { if (have_pending_send_ops) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p: starting next batch for pending " "chand=%p calld=%p attempt=%p: starting next batch for pending "
"send op(s)", "send op(s)",
calld->chand_, calld, call_attempt_.get()); calld->chand_, calld, call_attempt_.get());
}
call_attempt_->AddRetriableBatches(closures); call_attempt_->AddRetriableBatches(closures);
} }
} }
@ -1771,13 +1815,14 @@ void RetryFilter::CallData::CallAttempt::BatchData::OnComplete(
RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg)); RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg));
CallAttempt* call_attempt = batch_data->call_attempt_.get(); CallAttempt* call_attempt = batch_data->call_attempt_.get();
CallData* calld = call_attempt->calld_; CallData* calld = call_attempt->calld_;
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p batch_data=%p: " "chand=%p calld=%p attempt=%p batch_data=%p: "
"got on_complete, error=%s, batch=%s", "got on_complete, error=%s, batch=%s",
calld->chand_, calld, call_attempt, batch_data.get(), calld->chand_, calld, call_attempt, batch_data.get(),
grpc_error_std_string(error).c_str(), grpc_error_std_string(error).c_str(),
grpc_transport_stream_op_batch_string(&batch_data->batch_).c_str()); grpc_transport_stream_op_batch_string(&batch_data->batch_).c_str());
}
// If this attempt has been abandoned, then we're not going to propagate // If this attempt has been abandoned, then we're not going to propagate
// the completion of this batch, so do nothing. // the completion of this batch, so do nothing.
if (call_attempt->abandoned_) { if (call_attempt->abandoned_) {
@ -1791,9 +1836,10 @@ void RetryFilter::CallData::CallAttempt::BatchData::OnComplete(
// recv_trailing_metadata comes back. // recv_trailing_metadata comes back.
if (GPR_UNLIKELY(!calld->retry_committed_ && error != GRPC_ERROR_NONE && if (GPR_UNLIKELY(!calld->retry_committed_ && error != GRPC_ERROR_NONE &&
!call_attempt->completed_recv_trailing_metadata_)) { !call_attempt->completed_recv_trailing_metadata_)) {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p attempt=%p: deferring on_complete", gpr_log(GPR_INFO, "chand=%p calld=%p attempt=%p: deferring on_complete",
calld->chand_, calld, call_attempt); calld->chand_, calld, call_attempt);
}
call_attempt->on_complete_deferred_batches_.emplace_back( call_attempt->on_complete_deferred_batches_.emplace_back(
std::move(batch_data), GRPC_ERROR_REF(error)); std::move(batch_data), GRPC_ERROR_REF(error));
CallCombinerClosureList closures; CallCombinerClosureList closures;
@ -1845,13 +1891,14 @@ void RetryFilter::CallData::CallAttempt::BatchData::OnCompleteForCancelOp(
RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg)); RefCountedPtr<BatchData> batch_data(static_cast<BatchData*>(arg));
CallAttempt* call_attempt = batch_data->call_attempt_.get(); CallAttempt* call_attempt = batch_data->call_attempt_.get();
CallData* calld = call_attempt->calld_; CallData* calld = call_attempt->calld_;
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p attempt=%p batch_data=%p: " "chand=%p calld=%p attempt=%p batch_data=%p: "
"got on_complete for cancel_stream batch, error=%s, batch=%s", "got on_complete for cancel_stream batch, error=%s, batch=%s",
calld->chand_, calld, call_attempt, batch_data.get(), calld->chand_, calld, call_attempt, batch_data.get(),
grpc_error_std_string(error).c_str(), grpc_error_std_string(error).c_str(),
grpc_transport_stream_op_batch_string(&batch_data->batch_).c_str()); grpc_transport_stream_op_batch_string(&batch_data->batch_).c_str());
}
GRPC_CALL_COMBINER_STOP( GRPC_CALL_COMBINER_STOP(
calld->call_combiner_, calld->call_combiner_,
"on_complete for internally generated cancel_stream op"); "on_complete for internally generated cancel_stream op");
@ -1913,12 +1960,14 @@ void RetryFilter::CallData::CallAttempt::BatchData::
void RetryFilter::CallData::CallAttempt::BatchData:: void RetryFilter::CallData::CallAttempt::BatchData::
AddRetriableSendMessageOp() { AddRetriableSendMessageOp() {
auto* calld = call_attempt_->calld_; auto* calld = call_attempt_->calld_;
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(
"chand=%p calld=%p attempt=%p: starting calld->send_messages[%" PRIuPTR GPR_INFO,
"]", "chand=%p calld=%p attempt=%p: starting calld->send_messages[%" PRIuPTR
calld->chand_, calld, call_attempt_.get(), "]",
call_attempt_->started_send_message_count_); calld->chand_, calld, call_attempt_.get(),
call_attempt_->started_send_message_count_);
}
ByteStreamCache* cache = ByteStreamCache* cache =
calld->send_messages_[call_attempt_->started_send_message_count_]; calld->send_messages_[call_attempt_->started_send_message_count_];
++call_attempt_->started_send_message_count_; ++call_attempt_->started_send_message_count_;
@ -2005,8 +2054,10 @@ grpc_error_handle RetryFilter::CallData::Init(
grpc_call_element* elem, const grpc_call_element_args* args) { grpc_call_element* elem, const grpc_call_element_args* args) {
auto* chand = static_cast<RetryFilter*>(elem->channel_data); auto* chand = static_cast<RetryFilter*>(elem->channel_data);
new (elem->call_data) CallData(chand, *args); new (elem->call_data) CallData(chand, *args);
grpc_retry_trace.Log(GPR_INFO, "chand=%p calld=%p: created call", chand, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
elem->call_data); gpr_log(GPR_INFO, "chand=%p calld=%p: created call", chand,
elem->call_data);
}
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
@ -2103,9 +2154,10 @@ void RetryFilter::CallData::StartTransportStreamOpBatch(
// Handle cancellation. // Handle cancellation.
if (GPR_UNLIKELY(batch->cancel_stream)) { if (GPR_UNLIKELY(batch->cancel_stream)) {
grpc_error_handle cancel_error = batch->payload->cancel_stream.cancel_error; grpc_error_handle cancel_error = batch->payload->cancel_stream.cancel_error;
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: cancelled from surface: %s", chand_, this, gpr_log(GPR_INFO, "chand=%p calld=%p: cancelled from surface: %s", chand_,
grpc_error_std_string(cancel_error).c_str()); this, grpc_error_std_string(cancel_error).c_str());
}
// If we have a current call attempt, commit the call, then send // If we have a current call attempt, commit the call, then send
// the cancellation down to that attempt. When the call fails, it // the cancellation down to that attempt. When the call fails, it
// will not be retried, because we have committed it here. // will not be retried, because we have committed it here.
@ -2123,8 +2175,10 @@ void RetryFilter::CallData::StartTransportStreamOpBatch(
} }
// Cancel retry timer. // Cancel retry timer.
if (retry_timer_pending_) { if (retry_timer_pending_) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: cancelling retry timer", chand_, this); gpr_log(GPR_INFO, "chand=%p calld=%p: cancelling retry timer", chand_,
this);
}
retry_timer_pending_ = false; // Lame timer callback. retry_timer_pending_ = false; // Lame timer callback.
grpc_timer_cancel(&retry_timer_); grpc_timer_cancel(&retry_timer_);
FreeAllCachedSendOpData(); FreeAllCachedSendOpData();
@ -2170,11 +2224,12 @@ void RetryFilter::CallData::StartTransportStreamOpBatch(
if (num_attempts_completed_ == 0 && retry_committed_ && if (num_attempts_completed_ == 0 && retry_committed_ &&
(retry_policy_ == nullptr || (retry_policy_ == nullptr ||
!retry_policy_->per_attempt_recv_timeout().has_value())) { !retry_policy_->per_attempt_recv_timeout().has_value())) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p: retry committed before first attempt; " "chand=%p calld=%p: retry committed before first attempt; "
"creating LB call", "creating LB call",
chand_, this); chand_, this);
}
PendingBatchClear(pending); PendingBatchClear(pending);
auto* service_config_call_data = static_cast<ServiceConfigCallData*>( auto* service_config_call_data = static_cast<ServiceConfigCallData*>(
call_context_[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value); call_context_[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
@ -2186,15 +2241,18 @@ void RetryFilter::CallData::StartTransportStreamOpBatch(
// Otherwise, create a call attempt. // Otherwise, create a call attempt.
// The attempt will automatically start any necessary replays or // The attempt will automatically start any necessary replays or
// pending batches. // pending batches.
grpc_retry_trace.Log(GPR_INFO, "chand=%p calld=%p: creating call attempt", if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
chand_, this); gpr_log(GPR_INFO, "chand=%p calld=%p: creating call attempt", chand_,
this);
}
CreateCallAttempt(); CreateCallAttempt();
return; return;
} }
// Send batches to call attempt. // Send batches to call attempt.
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p: starting batch on attempt=%p", gpr_log(GPR_INFO, "chand=%p calld=%p: starting batch on attempt=%p", chand_,
chand_, this, call_attempt_.get()); this, call_attempt_.get());
}
call_attempt_->StartRetriableBatches(); call_attempt_->StartRetriableBatches();
} }
@ -2263,23 +2321,27 @@ void RetryFilter::CallData::MaybeCacheSendOpsForBatch(PendingBatch* pending) {
} }
void RetryFilter::CallData::FreeCachedSendInitialMetadata() { void RetryFilter::CallData::FreeCachedSendInitialMetadata() {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p: destroying send_initial_metadata", gpr_log(GPR_INFO, "chand=%p calld=%p: destroying send_initial_metadata",
chand_, this); chand_, this);
}
grpc_metadata_batch_destroy(&send_initial_metadata_); grpc_metadata_batch_destroy(&send_initial_metadata_);
} }
void RetryFilter::CallData::FreeCachedSendMessage(size_t idx) { void RetryFilter::CallData::FreeCachedSendMessage(size_t idx) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: destroying send_messages[%" PRIuPTR "]", gpr_log(GPR_INFO,
chand_, this, idx); "chand=%p calld=%p: destroying send_messages[%" PRIuPTR "]", chand_,
this, idx);
}
send_messages_[idx]->Destroy(); send_messages_[idx]->Destroy();
} }
void RetryFilter::CallData::FreeCachedSendTrailingMetadata() { void RetryFilter::CallData::FreeCachedSendTrailingMetadata() {
grpc_retry_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
"chand=%p calld=%p: destroying send_trailing_metadata", gpr_log(GPR_INFO, "chand=%p calld=%p: destroying send_trailing_metadata",
chand_, this); chand_, this);
}
grpc_metadata_batch_destroy(&send_trailing_metadata_); grpc_metadata_batch_destroy(&send_trailing_metadata_);
} }
@ -2314,9 +2376,11 @@ size_t RetryFilter::CallData::GetBatchIndex(
RetryFilter::CallData::PendingBatch* RetryFilter::CallData::PendingBatchesAdd( RetryFilter::CallData::PendingBatch* RetryFilter::CallData::PendingBatchesAdd(
grpc_transport_stream_op_batch* batch) { grpc_transport_stream_op_batch* batch) {
const size_t idx = GetBatchIndex(batch); const size_t idx = GetBatchIndex(batch);
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: adding pending batch at index %" PRIuPTR, gpr_log(GPR_INFO,
chand_, this, idx); "chand=%p calld=%p: adding pending batch at index %" PRIuPTR,
chand_, this, idx);
}
PendingBatch* pending = &pending_batches_[idx]; PendingBatch* pending = &pending_batches_[idx];
GPR_ASSERT(pending->batch == nullptr); GPR_ASSERT(pending->batch == nullptr);
pending->batch = batch; pending->batch = batch;
@ -2343,9 +2407,11 @@ RetryFilter::CallData::PendingBatch* RetryFilter::CallData::PendingBatchesAdd(
// ops have already been sent, and we commit to that attempt. // ops have already been sent, and we commit to that attempt.
if (GPR_UNLIKELY(bytes_buffered_for_retry_ > if (GPR_UNLIKELY(bytes_buffered_for_retry_ >
chand_->per_rpc_retry_buffer_size_)) { chand_->per_rpc_retry_buffer_size_)) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: exceeded retry buffer size, committing", gpr_log(GPR_INFO,
chand_, this); "chand=%p calld=%p: exceeded retry buffer size, committing",
chand_, this);
}
RetryCommit(call_attempt_.get()); RetryCommit(call_attempt_.get());
} }
return pending; return pending;
@ -2377,8 +2443,10 @@ void RetryFilter::CallData::MaybeClearPendingBatch(PendingBatch* pending) {
(!batch->recv_trailing_metadata || (!batch->recv_trailing_metadata ||
batch->payload->recv_trailing_metadata.recv_trailing_metadata_ready == batch->payload->recv_trailing_metadata.recv_trailing_metadata_ready ==
nullptr)) { nullptr)) {
grpc_retry_trace.Log(GPR_INFO, "chand=%p calld=%p: clearing pending batch", if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
chand_, this); gpr_log(GPR_INFO, "chand=%p calld=%p: clearing pending batch", chand_,
this);
}
PendingBatchClear(pending); PendingBatchClear(pending);
} }
} }
@ -2431,9 +2499,11 @@ RetryFilter::CallData::PendingBatch* RetryFilter::CallData::PendingBatchFind(
PendingBatch* pending = &pending_batches_[i]; PendingBatch* pending = &pending_batches_[i];
grpc_transport_stream_op_batch* batch = pending->batch; grpc_transport_stream_op_batch* batch = pending->batch;
if (batch != nullptr && predicate(batch)) { if (batch != nullptr && predicate(batch)) {
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: %s pending batch at index %" PRIuPTR, gpr_log(GPR_INFO,
chand_, this, log_message, i); "chand=%p calld=%p: %s pending batch at index %" PRIuPTR,
chand_, this, log_message, i);
}
return pending; return pending;
} }
} }
@ -2447,8 +2517,9 @@ RetryFilter::CallData::PendingBatch* RetryFilter::CallData::PendingBatchFind(
void RetryFilter::CallData::RetryCommit(CallAttempt* call_attempt) { void RetryFilter::CallData::RetryCommit(CallAttempt* call_attempt) {
if (retry_committed_) return; if (retry_committed_) return;
retry_committed_ = true; retry_committed_ = true;
grpc_retry_trace.Log(GPR_INFO, "chand=%p calld=%p: committing retries", if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
chand_, this); gpr_log(GPR_INFO, "chand=%p calld=%p: committing retries", chand_, this);
}
if (call_attempt != nullptr) { if (call_attempt != nullptr) {
// If the call attempt's LB call has been committed, inform the call // If the call attempt's LB call has been committed, inform the call
// dispatch controller that the call has been committed. // dispatch controller that the call has been committed.
@ -2477,9 +2548,11 @@ void RetryFilter::CallData::StartRetryTimer(grpc_millis server_pushback_ms) {
} else { } else {
next_attempt_time = retry_backoff_.NextAttemptTime(); next_attempt_time = retry_backoff_.NextAttemptTime();
} }
grpc_retry_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_retry_trace)) {
GPR_INFO, "chand=%p calld=%p: retrying failed call in %" PRId64 " ms", gpr_log(GPR_INFO,
chand_, this, next_attempt_time - ExecCtx::Get()->Now()); "chand=%p calld=%p: retrying failed call in %" PRId64 " ms", chand_,
this, next_attempt_time - ExecCtx::Get()->Now());
}
// Schedule retry after computed delay. // Schedule retry after computed delay.
GRPC_CLOSURE_INIT(&retry_closure_, OnRetryTimer, this, nullptr); GRPC_CLOSURE_INIT(&retry_closure_, OnRetryTimer, this, nullptr);
GRPC_CALL_STACK_REF(owning_call_, "OnRetryTimer"); GRPC_CALL_STACK_REF(owning_call_, "OnRetryTimer");

@ -319,12 +319,13 @@ class Subchannel::ConnectedSubchannelStateWatcher
case GRPC_CHANNEL_TRANSIENT_FAILURE: case GRPC_CHANNEL_TRANSIENT_FAILURE:
case GRPC_CHANNEL_SHUTDOWN: { case GRPC_CHANNEL_SHUTDOWN: {
if (!c->disconnected_ && c->connected_subchannel_ != nullptr) { if (!c->disconnected_ && c->connected_subchannel_ != nullptr) {
grpc_trace_subchannel.Log( if (grpc_trace_subchannel.enabled()) {
GPR_INFO, gpr_log(GPR_INFO,
"Connected subchannel %p of subchannel %p has gone into " "Connected subchannel %p of subchannel %p has gone into "
"%s. Attempting to reconnect.", "%s. Attempting to reconnect.",
c->connected_subchannel_.get(), c, c->connected_subchannel_.get(), c,
ConnectivityStateName(new_state)); ConnectivityStateName(new_state));
}
c->connected_subchannel_.reset(); c->connected_subchannel_.reset();
if (c->channelz_node() != nullptr) { if (c->channelz_node() != nullptr) {
c->channelz_node()->SetChildSocket(nullptr); c->channelz_node()->SetChildSocket(nullptr);
@ -735,9 +736,10 @@ void Subchannel::ThrottleKeepaliveTime(int new_keepalive_time) {
// Only update the value if the new keepalive time is larger. // Only update the value if the new keepalive time is larger.
if (new_keepalive_time > keepalive_time_) { if (new_keepalive_time > keepalive_time_) {
keepalive_time_ = new_keepalive_time; keepalive_time_ = new_keepalive_time;
grpc_trace_subchannel.Log(GPR_INFO, if (grpc_trace_subchannel.enabled()) {
"Subchannel=%p: Throttling keepalive time to %d", gpr_log(GPR_INFO, "Subchannel=%p: Throttling keepalive time to %d", this,
this, new_keepalive_time); new_keepalive_time);
}
const grpc_arg arg_to_add = grpc_channel_arg_integer_create( const grpc_arg arg_to_add = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_KEEPALIVE_TIME_MS), new_keepalive_time); const_cast<char*>(GRPC_ARG_KEEPALIVE_TIME_MS), new_keepalive_time);
const char* arg_to_remove = GRPC_ARG_KEEPALIVE_TIME_MS; const char* arg_to_remove = GRPC_ARG_KEEPALIVE_TIME_MS;

@ -211,12 +211,13 @@ class CallData::ResumeBatchCanceller {
auto* calld = static_cast<CallData*>(self->elem_->call_data); auto* calld = static_cast<CallData*>(self->elem_->call_data);
{ {
MutexLock lock(&calld->delay_mu_); MutexLock lock(&calld->delay_mu_);
grpc_fault_injection_filter_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_fault_injection_filter_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p: cancelling schdueled pick: " "chand=%p calld=%p: cancelling schdueled pick: "
"error=%s self=%p calld->resume_batch_canceller_=%p", "error=%s self=%p calld->resume_batch_canceller_=%p",
chand, calld, grpc_error_std_string(error).c_str(), self, chand, calld, grpc_error_std_string(error).c_str(), self,
calld->resume_batch_canceller_); calld->resume_batch_canceller_);
}
if (error != GRPC_ERROR_NONE && calld->resume_batch_canceller_ == self) { if (error != GRPC_ERROR_NONE && calld->resume_batch_canceller_ == self) {
// Cancel the delayed pick. // Cancel the delayed pick.
calld->CancelDelayTimer(); calld->CancelDelayTimer();
@ -262,11 +263,12 @@ void CallData::StartTransportStreamOpBatch(
if (batch->send_initial_metadata) { if (batch->send_initial_metadata) {
calld->DecideWhetherToInjectFaults( calld->DecideWhetherToInjectFaults(
batch->payload->send_initial_metadata.send_initial_metadata); batch->payload->send_initial_metadata.send_initial_metadata);
grpc_fault_injection_filter_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_fault_injection_filter_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"chand=%p calld=%p: Fault injection triggered delay=%d abort=%d", "chand=%p calld=%p: Fault injection triggered delay=%d abort=%d",
elem->channel_data, calld, calld->delay_request_, elem->channel_data, calld, calld->delay_request_,
calld->abort_request_); calld->abort_request_);
}
if (calld->MaybeDelay()) { if (calld->MaybeDelay()) {
// Delay the batch, and pass down the batch in the scheduled closure. // Delay the batch, and pass down the batch in the scheduled closure.
calld->DelayBatch(elem, batch); calld->DelayBatch(elem, batch);
@ -443,9 +445,10 @@ void CallData::ResumeBatch(void* arg, grpc_error_handle error) {
calld->resume_batch_canceller_ == nullptr) { calld->resume_batch_canceller_ == nullptr) {
return; return;
} }
grpc_fault_injection_filter_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_fault_injection_filter_trace)) {
GPR_INFO, "chand=%p calld=%p: Resuming delayed stream op batch %p", gpr_log(GPR_INFO, "chand=%p calld=%p: Resuming delayed stream op batch %p",
elem->channel_data, calld, calld->delayed_batch_); elem->channel_data, calld, calld->delayed_batch_);
}
// Lame the canceller // Lame the canceller
calld->resume_batch_canceller_ = nullptr; calld->resume_batch_canceller_ = nullptr;
// Finish fault injection. // Finish fault injection.

@ -1216,17 +1216,19 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
return; return;
} }
closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT; closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT;
grpc_http_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
GPR_INFO, gpr_log(
"complete_closure_step: t=%p %p refs=%d flags=0x%04x desc=%s err=%s " GPR_INFO,
"write_state=%s", "complete_closure_step: t=%p %p refs=%d flags=0x%04x desc=%s err=%s "
t, closure, "write_state=%s",
static_cast<int>(closure->next_data.scratch / t, closure,
CLOSURE_BARRIER_FIRST_REF_BIT), static_cast<int>(closure->next_data.scratch /
static_cast<int>(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT),
CLOSURE_BARRIER_FIRST_REF_BIT), static_cast<int>(closure->next_data.scratch %
desc, grpc_error_std_string(error).c_str(), CLOSURE_BARRIER_FIRST_REF_BIT),
write_state_name(t->write_state)); desc, grpc_error_std_string(error).c_str(),
write_state_name(t->write_state));
}
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
if (closure->error_data.error == GRPC_ERROR_NONE) { if (closure->error_data.error == GRPC_ERROR_NONE) {
closure->error_data.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( closure->error_data.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
@ -1635,8 +1637,10 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
} }
} }
grpc_http_trace.Log(GPR_INFO, "perform_stream_op[s=%p]: %s", s, if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
grpc_transport_stream_op_batch_string(op).c_str()); gpr_log(GPR_INFO, "perform_stream_op[s=%p]: %s", s,
grpc_transport_stream_op_batch_string(op).c_str());
}
GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op"); GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op");
op->handler_private.extra_arg = gs; op->handler_private.extra_arg = gs;
@ -1829,8 +1833,10 @@ static void perform_transport_op_locked(void* stream_op,
static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) {
grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt);
grpc_http_trace.Log(GPR_INFO, "perform_transport_op[t=%p]: %s", t, if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
grpc_transport_op_string(op).c_str()); gpr_log(GPR_INFO, "perform_transport_op[t=%p]: %s", t,
grpc_transport_op_string(op).c_str());
}
op->handler_private.extra_arg = gt; op->handler_private.extra_arg = gt;
GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op"); GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op");
t->combiner->Run(GRPC_CLOSURE_INIT(&op->handler_private.closure, t->combiner->Run(GRPC_CLOSURE_INIT(&op->handler_private.closure,
@ -2620,9 +2626,10 @@ static void start_bdp_ping(void* tp, grpc_error_handle error) {
static void start_bdp_ping_locked(void* tp, grpc_error_handle error) { static void start_bdp_ping_locked(void* tp, grpc_error_handle error) {
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
grpc_http_trace.Log(GPR_INFO, "%s: Start BDP ping err=%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
t->peer_string.c_str(), gpr_log(GPR_INFO, "%s: Start BDP ping err=%s", t->peer_string.c_str(),
grpc_error_std_string(error).c_str()); grpc_error_std_string(error).c_str());
}
if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
return; return;
} }
@ -2643,9 +2650,10 @@ static void finish_bdp_ping(void* tp, grpc_error_handle error) {
static void finish_bdp_ping_locked(void* tp, grpc_error_handle error) { static void finish_bdp_ping_locked(void* tp, grpc_error_handle error) {
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
grpc_http_trace.Log(GPR_INFO, "%s: Complete BDP ping err=%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
t->peer_string.c_str(), gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s", t->peer_string.c_str(),
grpc_error_std_string(error).c_str()); grpc_error_std_string(error).c_str());
}
if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping");
return; return;
@ -3181,19 +3189,21 @@ static void benign_reclaimer_locked(void* arg, grpc_error_handle error) {
grpc_chttp2_stream_map_size(&t->stream_map) == 0) { grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
// Channel with no active streams: send a goaway to try and make it // Channel with no active streams: send a goaway to try and make it
// disconnect cleanly // disconnect cleanly
grpc_resource_quota_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
"HTTP2: %s - send goaway to free memory", gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory",
t->peer_string.c_str()); t->peer_string.c_str());
}
send_goaway(t, send_goaway(t,
grpc_error_set_int( grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
} else if (error == GRPC_ERROR_NONE) { } else if (error == GRPC_ERROR_NONE &&
grpc_resource_quota_trace.Log( GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
" streams", " streams",
t->peer_string.c_str(), grpc_chttp2_stream_map_size(&t->stream_map)); t->peer_string.c_str(),
grpc_chttp2_stream_map_size(&t->stream_map));
} }
t->benign_reclaimer_registered = false; t->benign_reclaimer_registered = false;
if (error != GRPC_ERROR_CANCELLED) { if (error != GRPC_ERROR_CANCELLED) {
@ -3216,8 +3226,10 @@ static void destructive_reclaimer_locked(void* arg, grpc_error_handle error) {
if (error == GRPC_ERROR_NONE && n > 0) { if (error == GRPC_ERROR_NONE && n > 0) {
grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>( grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(
grpc_chttp2_stream_map_rand(&t->stream_map)); grpc_chttp2_stream_map_rand(&t->stream_map));
grpc_resource_quota_trace.Log(GPR_INFO, "HTTP2: %s - abandon stream id %d", if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
t->peer_string.c_str(), s->id); gpr_log(GPR_INFO, "HTTP2: %s - abandon stream id %d",
t->peer_string.c_str(), s->id);
}
grpc_chttp2_cancel_stream( grpc_chttp2_cancel_stream(
t, s, t, s,
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),

@ -260,13 +260,14 @@ grpc_error_handle grpc_chttp2_settings_parser_parse(void* p,
} }
} }
parser->incoming_settings[id] = parser->value; parser->incoming_settings[id] = parser->value;
grpc_http_trace.Log(GPR_INFO, "CHTTP2:%s:%s: got setting %s = %d", if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
t->is_client ? "CLI" : "SVR", gpr_log(GPR_INFO, "CHTTP2:%s:%s: got setting %s = %d",
t->peer_string.c_str(), sp->name, parser->value); t->is_client ? "CLI" : "SVR", t->peer_string.c_str(),
} else { sp->name, parser->value);
grpc_http_trace.Log(GPR_ERROR, }
"CHTTP2: Ignoring unknown setting %d (value %d)", } else if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
parser->id, parser->value); gpr_log(GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)",
parser->id, parser->value);
} }
break; break;
} }

@ -633,8 +633,9 @@ void grpc_chttp2_hpack_compressor_set_max_table_size(
} }
} }
c->advertise_table_size_change = 1; c->advertise_table_size_change = 1;
grpc_http_trace.Log(GPR_INFO, "set max table size from encoder to %d", if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
max_table_size); gpr_log(GPR_INFO, "set max table size from encoder to %d", max_table_size);
}
} }
void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c, void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c,

@ -1184,7 +1184,9 @@ class HPackParser::Parser {
false); false);
} }
(*dynamic_table_updates_allowed_)--; (*dynamic_table_updates_allowed_)--;
grpc_trace_chttp2_hpack_parser.Log(GPR_INFO, "MAX TABLE SIZE: %d", *size); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", *size);
}
grpc_error_handle err = table_->SetCurrentTableSize(*size); grpc_error_handle err = table_->SetCurrentTableSize(*size);
if (err != GRPC_ERROR_NONE) { if (err != GRPC_ERROR_NONE) {
input_->SetError(err); input_->SetError(err);

@ -76,8 +76,9 @@ void HPackTable::SetMaxBytes(uint32_t max_bytes) {
if (max_bytes_ == max_bytes) { if (max_bytes_ == max_bytes) {
return; return;
} }
grpc_http_trace.Log(GPR_INFO, "Update hpack parser max size to %d", if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
max_bytes); gpr_log(GPR_INFO, "Update hpack parser max size to %d", max_bytes);
}
while (mem_used_ > max_bytes) { while (mem_used_ > max_bytes) {
EvictOne(); EvictOne();
} }
@ -95,7 +96,9 @@ grpc_error_handle HPackTable::SetCurrentTableSize(uint32_t bytes) {
max_bytes_) max_bytes_)
.c_str()); .c_str());
} }
grpc_http_trace.Log(GPR_INFO, "Update hpack parser table size to %d", bytes); if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_INFO, "Update hpack parser table size to %d", bytes);
}
while (mem_used_ > bytes) { while (mem_used_ > bytes) {
EvictOne(); EvictOne();
} }

@ -300,8 +300,9 @@ static grpc_error_handle init_frame_parser(grpc_chttp2_transport* t) {
case GRPC_CHTTP2_FRAME_GOAWAY: case GRPC_CHTTP2_FRAME_GOAWAY:
return init_goaway_parser(t); return init_goaway_parser(t);
default: default:
grpc_http_trace.Log(GPR_ERROR, "Unknown frame type %02x", if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
t->incoming_frame_type); gpr_log(GPR_ERROR, "Unknown frame type %02x", t->incoming_frame_type);
}
return init_non_header_skip_frame_parser(t); return init_non_header_skip_frame_parser(t);
} }
} }
@ -785,7 +786,9 @@ static grpc_error_handle parse_frame_slice(grpc_chttp2_transport* t,
if (GPR_LIKELY(err == GRPC_ERROR_NONE)) { if (GPR_LIKELY(err == GRPC_ERROR_NONE)) {
return err; return err;
} else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, &unused)) { } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, &unused)) {
grpc_http_trace.Log(GPR_ERROR, "%s", grpc_error_std_string(err).c_str()); if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_ERROR, "%s", grpc_error_std_string(err).c_str());
}
grpc_chttp2_parsing_become_skip_parser(t); grpc_chttp2_parsing_become_skip_parser(t);
if (s) { if (s) {
s->forced_close_error = err; s->forced_close_error = err;

@ -89,9 +89,10 @@ static void stream_list_remove(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
} else { } else {
t->lists[id].tail = s->links[id].prev; t->lists[id].tail = s->links[id].prev;
} }
grpc_trace_http2_stream_state.Log(GPR_INFO, "%p[%d][%s]: remove from %s", t, if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_http2_stream_state)) {
s->id, t->is_client ? "cli" : "svr", gpr_log(GPR_INFO, "%p[%d][%s]: remove from %s", t, s->id,
stream_list_id_string(id)); t->is_client ? "cli" : "svr", stream_list_id_string(id));
}
} }
static bool stream_list_maybe_remove(grpc_chttp2_transport* t, static bool stream_list_maybe_remove(grpc_chttp2_transport* t,
@ -120,9 +121,10 @@ static void stream_list_add_tail(grpc_chttp2_transport* t,
} }
t->lists[id].tail = s; t->lists[id].tail = s;
s->included[id] = 1; s->included[id] = 1;
grpc_trace_http2_stream_state.Log(GPR_INFO, "%p[%d][%s]: add to %s", t, s->id, if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_http2_stream_state)) {
t->is_client ? "cli" : "svr", gpr_log(GPR_INFO, "%p[%d][%s]: add to %s", t, s->id,
stream_list_id_string(id)); t->is_client ? "cli" : "svr", stream_list_id_string(id));
}
} }
static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s, static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s,

@ -159,29 +159,32 @@ static bool update_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s, static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
const char* staller) { const char* staller) {
grpc_flowctl_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_flowctl_trace)) {
GPR_DEBUG, gpr_log(
"%s:%p stream %d moved to stalled list by %s. This is FULLY expected " GPR_DEBUG,
"to happen in a healthy program that is not seeing flow control stalls." "%s:%p stream %d moved to stalled list by %s. This is FULLY expected "
" However, if you know that there are unwanted stalls, here is some " "to happen in a healthy program that is not seeing flow control stalls."
"helpful data: [fc:pending=%" PRIdPTR ":pending-compressed=%" PRIdPTR " However, if you know that there are unwanted stalls, here is some "
":flowed=%" PRId64 ":peer_initwin=%d:t_win=%" PRId64 "helpful data: [fc:pending=%" PRIdPTR ":pending-compressed=%" PRIdPTR
":s_win=%d:s_delta=%" PRId64 "]", ":flowed=%" PRId64 ":peer_initwin=%d:t_win=%" PRId64
t->peer_string.c_str(), t, s->id, staller, ":s_win=%d:s_delta=%" PRId64 "]",
s->flow_controlled_buffer.length, t->peer_string.c_str(), t, s->id, staller,
s->stream_compression_method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS s->flow_controlled_buffer.length,
? 0 s->stream_compression_method ==
: s->compressed_data_buffer.length, GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS
s->flow_controlled_bytes_flowed, ? 0
t->settings[GRPC_ACKED_SETTINGS] : s->compressed_data_buffer.length,
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE], s->flow_controlled_bytes_flowed,
t->flow_control->remote_window(), t->settings[GRPC_ACKED_SETTINGS]
static_cast<uint32_t> GPR_MAX( [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE],
0, t->flow_control->remote_window(),
s->flow_control->remote_window_delta() + static_cast<uint32_t> GPR_MAX(
(int64_t)t->settings[GRPC_PEER_SETTINGS] 0,
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]), s->flow_control->remote_window_delta() +
s->flow_control->remote_window_delta()); (int64_t)t->settings[GRPC_PEER_SETTINGS]
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]),
s->flow_control->remote_window_delta());
}
} }
/* How many bytes would we like to put on the wire during a single syscall */ /* How many bytes would we like to put on the wire during a single syscall */

@ -54,6 +54,10 @@
#define GRPC_FLUSH_READ_SIZE 4096 #define GRPC_FLUSH_READ_SIZE 4096
grpc_core::TraceFlag grpc_cronet_trace(false, "cronet"); grpc_core::TraceFlag grpc_cronet_trace(false, "cronet");
#define CRONET_LOG(...) \
do { \
if (grpc_cronet_trace.enabled()) gpr_log(__VA_ARGS__); \
} while (0)
enum e_op_result { enum e_op_result {
ACTION_TAKEN_WITH_CALLBACK, ACTION_TAKEN_WITH_CALLBACK,
@ -297,7 +301,7 @@ static void read_grpc_header(stream_obj* s) {
s->state.rs.remaining_bytes = GRPC_HEADER_SIZE_IN_BYTES; s->state.rs.remaining_bytes = GRPC_HEADER_SIZE_IN_BYTES;
s->state.rs.received_bytes = 0; s->state.rs.received_bytes = 0;
s->state.rs.compressed = false; s->state.rs.compressed = false;
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs);
bidirectional_stream_read(s->cbs, s->state.rs.read_buffer, bidirectional_stream_read(s->cbs, s->state.rs.read_buffer,
s->state.rs.remaining_bytes); s->state.rs.remaining_bytes);
} }
@ -337,8 +341,8 @@ static void add_to_storage(struct stream_obj* s,
if (op->recv_trailing_metadata) { if (op->recv_trailing_metadata) {
s->state.pending_recv_trailing_metadata = true; s->state.pending_recv_trailing_metadata = true;
} }
grpc_cronet_trace.Log(GPR_DEBUG, "adding new op %p. %d in the queue.", new_op, CRONET_LOG(GPR_DEBUG, "adding new op %p. %d in the queue.", new_op,
storage->num_pending_ops); storage->num_pending_ops);
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
} }
@ -355,20 +359,19 @@ static void remove_from_storage(struct stream_obj* s,
s->storage.head = oas->next; s->storage.head = oas->next;
delete oas; delete oas;
s->storage.num_pending_ops--; s->storage.num_pending_ops--;
grpc_cronet_trace.Log(GPR_DEBUG, "Freed %p. Now %d in the queue", oas, CRONET_LOG(GPR_DEBUG, "Freed %p. Now %d in the queue", oas,
s->storage.num_pending_ops); s->storage.num_pending_ops);
} else { } else {
for (curr = s->storage.head; curr != nullptr; curr = curr->next) { for (curr = s->storage.head; curr != nullptr; curr = curr->next) {
if (curr->next == oas) { if (curr->next == oas) {
curr->next = oas->next; curr->next = oas->next;
s->storage.num_pending_ops--; s->storage.num_pending_ops--;
grpc_cronet_trace.Log(GPR_DEBUG, "Freed %p. Now %d in the queue", oas, CRONET_LOG(GPR_DEBUG, "Freed %p. Now %d in the queue", oas,
s->storage.num_pending_ops); s->storage.num_pending_ops);
delete oas; delete oas;
break; break;
} else if (GPR_UNLIKELY(curr->next == nullptr)) { } else if (GPR_UNLIKELY(curr->next == nullptr)) {
grpc_cronet_trace.Log(GPR_ERROR, CRONET_LOG(GPR_ERROR, "Reached end of LL and did not find op to free");
"Reached end of LL and did not find op to free");
} }
} }
} }
@ -383,12 +386,11 @@ static void remove_from_storage(struct stream_obj* s,
static void execute_from_storage(stream_obj* s) { static void execute_from_storage(stream_obj* s) {
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
for (struct op_and_state* curr = s->storage.head; curr != nullptr;) { for (struct op_and_state* curr = s->storage.head; curr != nullptr;) {
grpc_cronet_trace.Log(GPR_DEBUG, "calling op at %p. done = %d", curr, CRONET_LOG(GPR_DEBUG, "calling op at %p. done = %d", curr, curr->done);
curr->done);
GPR_ASSERT(!curr->done); GPR_ASSERT(!curr->done);
enum e_op_result result = execute_stream_op(curr); enum e_op_result result = execute_stream_op(curr);
grpc_cronet_trace.Log(GPR_DEBUG, "execute_stream_op[%p] returns %s", curr, CRONET_LOG(GPR_DEBUG, "execute_stream_op[%p] returns %s", curr,
op_result_string(result)); op_result_string(result));
/* if this op is done, then remove it and free memory */ /* if this op is done, then remove it and free memory */
if (curr->done) { if (curr->done) {
struct op_and_state* next = curr->next; struct op_and_state* next = curr->next;
@ -408,9 +410,8 @@ static void convert_cronet_array_to_metadata(
const bidirectional_stream_header_array* header_array, const bidirectional_stream_header_array* header_array,
grpc_chttp2_incoming_metadata_buffer* mds) { grpc_chttp2_incoming_metadata_buffer* mds) {
for (size_t i = 0; i < header_array->count; i++) { for (size_t i = 0; i < header_array->count; i++) {
grpc_cronet_trace.Log(GPR_DEBUG, "header key=%s, value=%s", CRONET_LOG(GPR_DEBUG, "header key=%s, value=%s",
header_array->headers[i].key, header_array->headers[i].key, header_array->headers[i].value);
header_array->headers[i].value);
grpc_slice key = grpc_slice_intern( grpc_slice key = grpc_slice_intern(
grpc_slice_from_static_string(header_array->headers[i].key)); grpc_slice_from_static_string(header_array->headers[i].key));
grpc_slice value; grpc_slice value;
@ -460,7 +461,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) {
Cronet callback Cronet callback
*/ */
static void on_canceled(bidirectional_stream* stream) { static void on_canceled(bidirectional_stream* stream) {
grpc_cronet_trace.Log(GPR_DEBUG, "on_canceled(%p)", stream); CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream);
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
@ -487,7 +488,7 @@ static void on_canceled(bidirectional_stream* stream) {
Cronet callback Cronet callback
*/ */
static void on_succeeded(bidirectional_stream* stream) { static void on_succeeded(bidirectional_stream* stream) {
grpc_cronet_trace.Log(GPR_DEBUG, "on_succeeded(%p)", stream); CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream);
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
@ -506,7 +507,7 @@ static void on_succeeded(bidirectional_stream* stream) {
Cronet callback Cronet callback
*/ */
static void on_stream_ready(bidirectional_stream* stream) { static void on_stream_ready(bidirectional_stream* stream) {
grpc_cronet_trace.Log(GPR_DEBUG, "W: on_stream_ready(%p)", stream); CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream);
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
stream_obj* s = static_cast<stream_obj*>(stream->annotation); stream_obj* s = static_cast<stream_obj*>(stream->annotation);
@ -523,8 +524,7 @@ static void on_stream_ready(bidirectional_stream* stream) {
* SEND_TRAILING_METADATA ops pending */ * SEND_TRAILING_METADATA ops pending */
if (t->use_packet_coalescing) { if (t->use_packet_coalescing) {
if (s->state.flush_cronet_when_ready) { if (s->state.flush_cronet_when_ready) {
grpc_cronet_trace.Log(GPR_DEBUG, "cronet_bidirectional_stream_flush (%p)", CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_flush (%p)", s->cbs);
s->cbs);
bidirectional_stream_flush(stream); bidirectional_stream_flush(stream);
} }
} }
@ -541,9 +541,8 @@ static void on_response_headers_received(
const char* negotiated_protocol) { const char* negotiated_protocol) {
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_cronet_trace.Log(GPR_DEBUG, CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream,
"R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol);
headers, negotiated_protocol);
stream_obj* s = static_cast<stream_obj*>(stream->annotation); stream_obj* s = static_cast<stream_obj*>(stream->annotation);
/* Identify if this is a header or a trailer (in a trailer-only response case) /* Identify if this is a header or a trailer (in a trailer-only response case)
@ -580,8 +579,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) {
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
stream_obj* s = static_cast<stream_obj*>(stream->annotation); stream_obj* s = static_cast<stream_obj*>(stream->annotation);
grpc_cronet_trace.Log(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data);
data);
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
if (s->state.ws.write_buffer) { if (s->state.ws.write_buffer) {
gpr_free(s->state.ws.write_buffer); gpr_free(s->state.ws.write_buffer);
@ -600,12 +598,12 @@ static void on_read_completed(bidirectional_stream* stream, char* data,
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
stream_obj* s = static_cast<stream_obj*>(stream->annotation); stream_obj* s = static_cast<stream_obj*>(stream->annotation);
grpc_cronet_trace.Log(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data,
data, count); count);
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
s->state.state_callback_received[OP_RECV_MESSAGE] = true; s->state.state_callback_received[OP_RECV_MESSAGE] = true;
if (count > 0 && s->state.flush_read) { if (count > 0 && s->state.flush_read) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs);
bidirectional_stream_read(s->cbs, s->state.rs.read_buffer, bidirectional_stream_read(s->cbs, s->state.rs.read_buffer,
GRPC_FLUSH_READ_SIZE); GRPC_FLUSH_READ_SIZE);
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
@ -613,7 +611,7 @@ static void on_read_completed(bidirectional_stream* stream, char* data,
s->state.rs.received_bytes += count; s->state.rs.received_bytes += count;
s->state.rs.remaining_bytes -= count; s->state.rs.remaining_bytes -= count;
if (s->state.rs.remaining_bytes > 0) { if (s->state.rs.remaining_bytes > 0) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs);
s->state.state_op_done[OP_READ_REQ_MADE] = true; s->state.state_op_done[OP_READ_REQ_MADE] = true;
bidirectional_stream_read( bidirectional_stream_read(
s->cbs, s->state.rs.read_buffer + s->state.rs.received_bytes, s->cbs, s->state.rs.read_buffer + s->state.rs.received_bytes,
@ -639,8 +637,8 @@ static void on_response_trailers_received(
const bidirectional_stream_header_array* trailers) { const bidirectional_stream_header_array* trailers) {
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_cronet_trace.Log(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream,
stream, trailers); trailers);
stream_obj* s = static_cast<stream_obj*>(stream->annotation); stream_obj* s = static_cast<stream_obj*>(stream->annotation);
grpc_cronet_transport* t = s->curr_ct; grpc_cronet_transport* t = s->curr_ct;
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
@ -655,13 +653,11 @@ static void on_response_trailers_received(
if (!s->state.state_op_done[OP_SEND_TRAILING_METADATA] && if (!s->state.state_op_done[OP_SEND_TRAILING_METADATA] &&
!(s->state.state_op_done[OP_CANCEL_ERROR] || !(s->state.state_op_done[OP_CANCEL_ERROR] ||
s->state.state_callback_received[OP_FAILED])) { s->state.state_callback_received[OP_FAILED])) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", s->cbs);
s->cbs);
s->state.state_callback_received[OP_SEND_MESSAGE] = false; s->state.state_callback_received[OP_SEND_MESSAGE] = false;
bidirectional_stream_write(s->cbs, "", 0, true); bidirectional_stream_write(s->cbs, "", 0, true);
if (t->use_packet_coalescing) { if (t->use_packet_coalescing) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_flush (%p)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_flush (%p)", s->cbs);
s->cbs);
bidirectional_stream_flush(s->cbs); bidirectional_stream_flush(s->cbs);
} }
s->state.state_op_done[OP_SEND_TRAILING_METADATA] = true; s->state.state_op_done[OP_SEND_TRAILING_METADATA] = true;
@ -774,7 +770,7 @@ static void convert_metadata_to_cronet_headers(
gpr_free(value); gpr_free(value);
continue; continue;
} }
grpc_cronet_trace.Log(GPR_DEBUG, "header %s = %s", key, value); CRONET_LOG(GPR_DEBUG, "header %s = %s", key, value);
headers[num_headers].key = key; headers[num_headers].key = key;
headers[num_headers].value = value; headers[num_headers].value = value;
num_headers++; num_headers++;
@ -837,34 +833,34 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op,
stream_state->state_callback_received[OP_FAILED]; stream_state->state_callback_received[OP_FAILED];
if (is_canceled_or_failed) { if (is_canceled_or_failed) {
if (op_id == OP_SEND_INITIAL_METADATA) { if (op_id == OP_SEND_INITIAL_METADATA) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
if (op_id == OP_SEND_MESSAGE) { if (op_id == OP_SEND_MESSAGE) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
if (op_id == OP_SEND_TRAILING_METADATA) { if (op_id == OP_SEND_TRAILING_METADATA) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
if (op_id == OP_CANCEL_ERROR) { if (op_id == OP_CANCEL_ERROR) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
/* already executed */ /* already executed */
if (op_id == OP_RECV_INITIAL_METADATA && if (op_id == OP_RECV_INITIAL_METADATA &&
stream_state->state_op_done[OP_RECV_INITIAL_METADATA]) { stream_state->state_op_done[OP_RECV_INITIAL_METADATA]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
if (op_id == OP_RECV_MESSAGE && op_state->state_op_done[OP_RECV_MESSAGE]) { if (op_id == OP_RECV_MESSAGE && op_state->state_op_done[OP_RECV_MESSAGE]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
if (op_id == OP_RECV_TRAILING_METADATA && if (op_id == OP_RECV_TRAILING_METADATA &&
stream_state->state_op_done[OP_RECV_TRAILING_METADATA]) { stream_state->state_op_done[OP_RECV_TRAILING_METADATA]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
/* ON_COMPLETE can be processed if one of the following conditions is met: /* ON_COMPLETE can be processed if one of the following conditions is met:
@ -877,7 +873,7 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op,
stream_state->state_callback_received[OP_CANCELED] || stream_state->state_callback_received[OP_CANCELED] ||
stream_state->state_callback_received[OP_SUCCEEDED] || stream_state->state_callback_received[OP_SUCCEEDED] ||
!stream_state->state_op_done[OP_SEND_INITIAL_METADATA])) { !stream_state->state_op_done[OP_SEND_INITIAL_METADATA])) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
} else if (op_id == OP_SEND_INITIAL_METADATA) { } else if (op_id == OP_SEND_INITIAL_METADATA) {
@ -959,7 +955,7 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op,
if (op_state->state_op_done[OP_ON_COMPLETE]) { if (op_state->state_op_done[OP_ON_COMPLETE]) {
/* already executed (note we're checking op specific state, not stream /* already executed (note we're checking op specific state, not stream
state) */ state) */
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
/* Check if every op that was asked for is done. */ /* Check if every op that was asked for is done. */
@ -969,36 +965,36 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op,
* there are still recv ops pending. */ * there are still recv ops pending. */
else if (curr_op->send_initial_metadata && else if (curr_op->send_initial_metadata &&
!stream_state->state_callback_received[OP_SEND_INITIAL_METADATA]) { !stream_state->state_callback_received[OP_SEND_INITIAL_METADATA]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->send_message && } else if (curr_op->send_message &&
!op_state->state_op_done[OP_SEND_MESSAGE]) { !op_state->state_op_done[OP_SEND_MESSAGE]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->send_message && } else if (curr_op->send_message &&
!stream_state->state_callback_received[OP_SEND_MESSAGE]) { !stream_state->state_callback_received[OP_SEND_MESSAGE]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->send_trailing_metadata && } else if (curr_op->send_trailing_metadata &&
!stream_state->state_op_done[OP_SEND_TRAILING_METADATA]) { !stream_state->state_op_done[OP_SEND_TRAILING_METADATA]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->recv_initial_metadata && } else if (curr_op->recv_initial_metadata &&
!stream_state->state_op_done[OP_RECV_INITIAL_METADATA]) { !stream_state->state_op_done[OP_RECV_INITIAL_METADATA]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->recv_message && } else if (curr_op->recv_message &&
!op_state->state_op_done[OP_RECV_MESSAGE]) { !op_state->state_op_done[OP_RECV_MESSAGE]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->cancel_stream && } else if (curr_op->cancel_stream &&
!stream_state->state_callback_received[OP_CANCELED]) { !stream_state->state_callback_received[OP_CANCELED]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} else if (curr_op->recv_trailing_metadata) { } else if (curr_op->recv_trailing_metadata) {
/* We aren't done with trailing metadata yet */ /* We aren't done with trailing metadata yet */
if (!stream_state->state_op_done[OP_RECV_TRAILING_METADATA]) { if (!stream_state->state_op_done[OP_RECV_TRAILING_METADATA]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
/* We've asked for actual message in an earlier op, and it hasn't been /* We've asked for actual message in an earlier op, and it hasn't been
@ -1008,7 +1004,7 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op,
op has asked), and the read hasn't been delivered. */ op has asked), and the read hasn't been delivered. */
if (!curr_op->recv_message && if (!curr_op->recv_message &&
!stream_state->state_callback_received[OP_SUCCEEDED]) { !stream_state->state_callback_received[OP_SUCCEEDED]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Because"); CRONET_LOG(GPR_DEBUG, "Because");
result = false; result = false;
} }
} }
@ -1020,8 +1016,8 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op,
result = false; result = false;
} }
} }
grpc_cronet_trace.Log(GPR_DEBUG, "op_can_be_run %s : %s", op_id_string(op_id), CRONET_LOG(GPR_DEBUG, "op_can_be_run %s : %s", op_id_string(op_id),
result ? "YES" : "NO"); result ? "YES" : "NO");
return result; return result;
} }
@ -1036,16 +1032,14 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
enum e_op_result result = NO_ACTION_POSSIBLE; enum e_op_result result = NO_ACTION_POSSIBLE;
if (stream_op->send_initial_metadata && if (stream_op->send_initial_metadata &&
op_can_be_run(stream_op, s, &oas->state, OP_SEND_INITIAL_METADATA)) { op_can_be_run(stream_op, s, &oas->state, OP_SEND_INITIAL_METADATA)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_SEND_INITIAL_METADATA", CRONET_LOG(GPR_DEBUG, "running: %p OP_SEND_INITIAL_METADATA", oas);
oas);
/* Start new cronet stream. It is destroyed in on_succeeded, on_canceled, /* Start new cronet stream. It is destroyed in on_succeeded, on_canceled,
* on_failed */ * on_failed */
GPR_ASSERT(s->cbs == nullptr); GPR_ASSERT(s->cbs == nullptr);
GPR_ASSERT(!stream_state->state_op_done[OP_SEND_INITIAL_METADATA]); GPR_ASSERT(!stream_state->state_op_done[OP_SEND_INITIAL_METADATA]);
s->cbs = s->cbs =
bidirectional_stream_create(t->engine, s->curr_gs, &cronet_callbacks); bidirectional_stream_create(t->engine, s->curr_gs, &cronet_callbacks);
grpc_cronet_trace.Log(GPR_DEBUG, "%p = bidirectional_stream_create()", CRONET_LOG(GPR_DEBUG, "%p = bidirectional_stream_create()", s->cbs);
s->cbs);
if (t->use_packet_coalescing) { if (t->use_packet_coalescing) {
bidirectional_stream_disable_auto_flush(s->cbs, true); bidirectional_stream_disable_auto_flush(s->cbs, true);
bidirectional_stream_delay_request_headers_until_flush(s->cbs, true); bidirectional_stream_delay_request_headers_until_flush(s->cbs, true);
@ -1058,8 +1052,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
t->host, &url, &s->header_array.headers, &s->header_array.count, t->host, &url, &s->header_array.headers, &s->header_array.count,
&method); &method);
s->header_array.capacity = s->header_array.count; s->header_array.capacity = s->header_array.count;
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs,
s->cbs, url.c_str()); url.c_str());
bidirectional_stream_start(s->cbs, url.c_str(), 0, method, &s->header_array, bidirectional_stream_start(s->cbs, url.c_str(), 0, method, &s->header_array,
false); false);
unsigned int header_index; unsigned int header_index;
@ -1077,14 +1071,13 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
result = ACTION_TAKEN_WITH_CALLBACK; result = ACTION_TAKEN_WITH_CALLBACK;
} else if (stream_op->send_message && } else if (stream_op->send_message &&
op_can_be_run(stream_op, s, &oas->state, OP_SEND_MESSAGE)) { op_can_be_run(stream_op, s, &oas->state, OP_SEND_MESSAGE)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_SEND_MESSAGE", oas); CRONET_LOG(GPR_DEBUG, "running: %p OP_SEND_MESSAGE", oas);
stream_state->pending_send_message = false; stream_state->pending_send_message = false;
if (stream_state->state_op_done[OP_CANCEL_ERROR] || if (stream_state->state_op_done[OP_CANCEL_ERROR] ||
stream_state->state_callback_received[OP_FAILED] || stream_state->state_callback_received[OP_FAILED] ||
stream_state->state_callback_received[OP_SUCCEEDED]) { stream_state->state_callback_received[OP_SUCCEEDED]) {
result = NO_ACTION_POSSIBLE; result = NO_ACTION_POSSIBLE;
grpc_cronet_trace.Log(GPR_DEBUG, CRONET_LOG(GPR_DEBUG, "Stream is either cancelled, failed or finished");
"Stream is either cancelled, failed or finished");
} else { } else {
grpc_slice_buffer write_slice_buffer; grpc_slice_buffer write_slice_buffer;
grpc_slice slice; grpc_slice slice;
@ -1112,16 +1105,15 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
&write_buffer_size, &write_buffer_size,
stream_op->payload->send_message.send_message->flags()); stream_op->payload->send_message.send_message->flags());
if (write_buffer_size > 0) { if (write_buffer_size > 0) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", s->cbs,
s->cbs, stream_state->ws.write_buffer); stream_state->ws.write_buffer);
stream_state->state_callback_received[OP_SEND_MESSAGE] = false; stream_state->state_callback_received[OP_SEND_MESSAGE] = false;
bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer,
static_cast<int>(write_buffer_size), false); static_cast<int>(write_buffer_size), false);
grpc_slice_buffer_destroy_internal(&write_slice_buffer); grpc_slice_buffer_destroy_internal(&write_slice_buffer);
if (t->use_packet_coalescing) { if (t->use_packet_coalescing) {
if (!stream_op->send_trailing_metadata) { if (!stream_op->send_trailing_metadata) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_flush (%p)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_flush (%p)", s->cbs);
s->cbs);
bidirectional_stream_flush(s->cbs); bidirectional_stream_flush(s->cbs);
result = ACTION_TAKEN_WITH_CALLBACK; result = ACTION_TAKEN_WITH_CALLBACK;
} else { } else {
@ -1142,22 +1134,18 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
} else if (stream_op->send_trailing_metadata && } else if (stream_op->send_trailing_metadata &&
op_can_be_run(stream_op, s, &oas->state, op_can_be_run(stream_op, s, &oas->state,
OP_SEND_TRAILING_METADATA)) { OP_SEND_TRAILING_METADATA)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_SEND_TRAILING_METADATA", CRONET_LOG(GPR_DEBUG, "running: %p OP_SEND_TRAILING_METADATA", oas);
oas);
if (stream_state->state_op_done[OP_CANCEL_ERROR] || if (stream_state->state_op_done[OP_CANCEL_ERROR] ||
stream_state->state_callback_received[OP_FAILED] || stream_state->state_callback_received[OP_FAILED] ||
stream_state->state_callback_received[OP_SUCCEEDED]) { stream_state->state_callback_received[OP_SUCCEEDED]) {
result = NO_ACTION_POSSIBLE; result = NO_ACTION_POSSIBLE;
grpc_cronet_trace.Log(GPR_DEBUG, CRONET_LOG(GPR_DEBUG, "Stream is either cancelled, failed or finished");
"Stream is either cancelled, failed or finished");
} else { } else {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", s->cbs);
s->cbs);
stream_state->state_callback_received[OP_SEND_MESSAGE] = false; stream_state->state_callback_received[OP_SEND_MESSAGE] = false;
bidirectional_stream_write(s->cbs, "", 0, true); bidirectional_stream_write(s->cbs, "", 0, true);
if (t->use_packet_coalescing) { if (t->use_packet_coalescing) {
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_flush (%p)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_flush (%p)", s->cbs);
s->cbs);
bidirectional_stream_flush(s->cbs); bidirectional_stream_flush(s->cbs);
} }
result = ACTION_TAKEN_WITH_CALLBACK; result = ACTION_TAKEN_WITH_CALLBACK;
@ -1166,8 +1154,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
} else if (stream_op->recv_initial_metadata && } else if (stream_op->recv_initial_metadata &&
op_can_be_run(stream_op, s, &oas->state, op_can_be_run(stream_op, s, &oas->state,
OP_RECV_INITIAL_METADATA)) { OP_RECV_INITIAL_METADATA)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_RECV_INITIAL_METADATA", CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_INITIAL_METADATA", oas);
oas);
if (stream_state->state_op_done[OP_CANCEL_ERROR]) { if (stream_state->state_op_done[OP_CANCEL_ERROR]) {
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, DEBUG_LOCATION,
@ -1196,9 +1183,9 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
result = ACTION_TAKEN_NO_CALLBACK; result = ACTION_TAKEN_NO_CALLBACK;
} else if (stream_op->recv_message && } else if (stream_op->recv_message &&
op_can_be_run(stream_op, s, &oas->state, OP_RECV_MESSAGE)) { op_can_be_run(stream_op, s, &oas->state, OP_RECV_MESSAGE)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_RECV_MESSAGE", oas); CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_MESSAGE", oas);
if (stream_state->state_op_done[OP_CANCEL_ERROR]) { if (stream_state->state_op_done[OP_CANCEL_ERROR]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Stream is cancelled."); CRONET_LOG(GPR_DEBUG, "Stream is cancelled.");
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready, DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready,
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
@ -1206,7 +1193,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
oas->state.state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true;
result = ACTION_TAKEN_NO_CALLBACK; result = ACTION_TAKEN_NO_CALLBACK;
} else if (stream_state->state_callback_received[OP_FAILED]) { } else if (stream_state->state_callback_received[OP_FAILED]) {
grpc_cronet_trace.Log(GPR_DEBUG, "Stream failed."); CRONET_LOG(GPR_DEBUG, "Stream failed.");
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready, DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready,
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
@ -1215,7 +1202,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
result = ACTION_TAKEN_NO_CALLBACK; result = ACTION_TAKEN_NO_CALLBACK;
} else if (stream_state->rs.read_stream_closed) { } else if (stream_state->rs.read_stream_closed) {
/* No more data will be received */ /* No more data will be received */
grpc_cronet_trace.Log(GPR_DEBUG, "read stream closed"); CRONET_LOG(GPR_DEBUG, "read stream closed");
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready, DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready,
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
@ -1223,7 +1210,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
oas->state.state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true;
result = ACTION_TAKEN_NO_CALLBACK; result = ACTION_TAKEN_NO_CALLBACK;
} else if (stream_state->flush_read) { } else if (stream_state->flush_read) {
grpc_cronet_trace.Log(GPR_DEBUG, "flush read"); CRONET_LOG(GPR_DEBUG, "flush read");
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready, DEBUG_LOCATION, stream_op->payload->recv_message.recv_message_ready,
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
@ -1238,16 +1225,15 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
parse_grpc_header( parse_grpc_header(
reinterpret_cast<const uint8_t*>(stream_state->rs.read_buffer), reinterpret_cast<const uint8_t*>(stream_state->rs.read_buffer),
&stream_state->rs.length_field, &stream_state->rs.compressed); &stream_state->rs.length_field, &stream_state->rs.compressed);
grpc_cronet_trace.Log(GPR_DEBUG, "length field = %d", CRONET_LOG(GPR_DEBUG, "length field = %d",
stream_state->rs.length_field); stream_state->rs.length_field);
if (stream_state->rs.length_field > 0) { if (stream_state->rs.length_field > 0) {
stream_state->rs.read_buffer = static_cast<char*>( stream_state->rs.read_buffer = static_cast<char*>(
gpr_malloc(static_cast<size_t>(stream_state->rs.length_field))); gpr_malloc(static_cast<size_t>(stream_state->rs.length_field)));
GPR_ASSERT(stream_state->rs.read_buffer); GPR_ASSERT(stream_state->rs.read_buffer);
stream_state->rs.remaining_bytes = stream_state->rs.length_field; stream_state->rs.remaining_bytes = stream_state->rs.length_field;
stream_state->rs.received_bytes = 0; stream_state->rs.received_bytes = 0;
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_read(%p)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs);
s->cbs);
stream_state->state_op_done[OP_READ_REQ_MADE] = stream_state->state_op_done[OP_READ_REQ_MADE] =
true; /* Indicates that at least one read request has been made */ true; /* Indicates that at least one read request has been made */
bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer,
@ -1255,8 +1241,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
result = ACTION_TAKEN_WITH_CALLBACK; result = ACTION_TAKEN_WITH_CALLBACK;
} else { } else {
stream_state->rs.remaining_bytes = 0; stream_state->rs.remaining_bytes = 0;
grpc_cronet_trace.Log(GPR_DEBUG, CRONET_LOG(GPR_DEBUG, "read operation complete. Empty response.");
"read operation complete. Empty response.");
/* Clean up read_slice_buffer in case there is unread data. */ /* Clean up read_slice_buffer in case there is unread data. */
grpc_slice_buffer_destroy_internal( grpc_slice_buffer_destroy_internal(
&stream_state->rs.read_slice_buffer); &stream_state->rs.read_slice_buffer);
@ -1288,8 +1273,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
stream_state->rs.remaining_bytes = GRPC_HEADER_SIZE_IN_BYTES; stream_state->rs.remaining_bytes = GRPC_HEADER_SIZE_IN_BYTES;
stream_state->rs.received_bytes = 0; stream_state->rs.received_bytes = 0;
stream_state->rs.compressed = false; stream_state->rs.compressed = false;
grpc_cronet_trace.Log(GPR_DEBUG, "bidirectional_stream_read(%p)", CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs);
s->cbs);
stream_state->state_op_done[OP_READ_REQ_MADE] = stream_state->state_op_done[OP_READ_REQ_MADE] =
true; /* Indicates that at least one read request has been made */ true; /* Indicates that at least one read request has been made */
bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer,
@ -1299,7 +1283,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
result = NO_ACTION_POSSIBLE; result = NO_ACTION_POSSIBLE;
} }
} else if (stream_state->rs.remaining_bytes == 0) { } else if (stream_state->rs.remaining_bytes == 0) {
grpc_cronet_trace.Log(GPR_DEBUG, "read operation complete"); CRONET_LOG(GPR_DEBUG, "read operation complete");
grpc_slice read_data_slice = grpc_slice read_data_slice =
GRPC_SLICE_MALLOC((uint32_t)stream_state->rs.length_field); GRPC_SLICE_MALLOC((uint32_t)stream_state->rs.length_field);
uint8_t* dst_p = GRPC_SLICE_START_PTR(read_data_slice); uint8_t* dst_p = GRPC_SLICE_START_PTR(read_data_slice);
@ -1332,8 +1316,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
} else if (stream_op->recv_trailing_metadata && } else if (stream_op->recv_trailing_metadata &&
op_can_be_run(stream_op, s, &oas->state, op_can_be_run(stream_op, s, &oas->state,
OP_RECV_TRAILING_METADATA)) { OP_RECV_TRAILING_METADATA)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_RECV_TRAILING_METADATA", CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_TRAILING_METADATA", oas);
oas);
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
if (stream_state->state_op_done[OP_CANCEL_ERROR]) { if (stream_state->state_op_done[OP_CANCEL_ERROR]) {
error = GRPC_ERROR_REF(stream_state->cancel_error); error = GRPC_ERROR_REF(stream_state->cancel_error);
@ -1357,10 +1340,9 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
result = ACTION_TAKEN_NO_CALLBACK; result = ACTION_TAKEN_NO_CALLBACK;
} else if (stream_op->cancel_stream && } else if (stream_op->cancel_stream &&
op_can_be_run(stream_op, s, &oas->state, OP_CANCEL_ERROR)) { op_can_be_run(stream_op, s, &oas->state, OP_CANCEL_ERROR)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_CANCEL_ERROR", oas); CRONET_LOG(GPR_DEBUG, "running: %p OP_CANCEL_ERROR", oas);
if (s->cbs) { if (s->cbs) {
grpc_cronet_trace.Log(GPR_DEBUG, "W: bidirectional_stream_cancel(%p)", CRONET_LOG(GPR_DEBUG, "W: bidirectional_stream_cancel(%p)", s->cbs);
s->cbs);
bidirectional_stream_cancel(s->cbs); bidirectional_stream_cancel(s->cbs);
result = ACTION_TAKEN_WITH_CALLBACK; result = ACTION_TAKEN_WITH_CALLBACK;
} else { } else {
@ -1372,7 +1354,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
GRPC_ERROR_REF(stream_op->payload->cancel_stream.cancel_error); GRPC_ERROR_REF(stream_op->payload->cancel_stream.cancel_error);
} }
} else if (op_can_be_run(stream_op, s, &oas->state, OP_ON_COMPLETE)) { } else if (op_can_be_run(stream_op, s, &oas->state, OP_ON_COMPLETE)) {
grpc_cronet_trace.Log(GPR_DEBUG, "running: %p OP_ON_COMPLETE", oas); CRONET_LOG(GPR_DEBUG, "running: %p OP_ON_COMPLETE", oas);
if (stream_state->state_op_done[OP_CANCEL_ERROR]) { if (stream_state->state_op_done[OP_CANCEL_ERROR]) {
if (stream_op->on_complete) { if (stream_op->on_complete) {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, stream_op->on_complete, grpc_core::ExecCtx::Run(DEBUG_LOCATION, stream_op->on_complete,
@ -1457,7 +1439,7 @@ static void set_pollset_set_do_nothing(grpc_transport* /*gt*/,
static void perform_stream_op(grpc_transport* /*gt*/, grpc_stream* gs, static void perform_stream_op(grpc_transport* /*gt*/, grpc_stream* gs,
grpc_transport_stream_op_batch* op) { grpc_transport_stream_op_batch* op) {
grpc_cronet_trace.Log(GPR_DEBUG, "perform_stream_op"); CRONET_LOG(GPR_DEBUG, "perform_stream_op");
if (op->send_initial_metadata && if (op->send_initial_metadata &&
header_has_authority(op->payload->send_initial_metadata header_has_authority(op->payload->send_initial_metadata
.send_initial_metadata->list.head)) { .send_initial_metadata->list.head)) {

@ -1576,8 +1576,10 @@ grpc_error_handle RetryPolicyParse(
} else if (code == "unavailable") { } else if (code == "unavailable") {
retry_to_return.retry_on.Add(GRPC_STATUS_UNAVAILABLE); retry_to_return.retry_on.Add(GRPC_STATUS_UNAVAILABLE);
} else { } else {
context.tracer->Log(GPR_INFO, "Unsupported retry_on policy %s.", if (GRPC_TRACE_FLAG_ENABLED(*context.tracer)) {
std::string(code).c_str()); gpr_log(GPR_INFO, "Unsupported retry_on policy %s.",
std::string(code).c_str());
}
} }
} }
// TODO(donnadionne): when we add support for per_try_timeout, we will need to // TODO(donnadionne): when we add support for per_try_timeout, we will need to

@ -200,9 +200,10 @@ class XdsClient::ChannelState::AdsCallState
.c_str()); .c_str());
watcher_error = grpc_error_set_int( watcher_error = grpc_error_set_int(
watcher_error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); watcher_error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
ads_calld_->xds_client(), gpr_log(GPR_INFO, "[xds_client %p] %s", ads_calld_->xds_client(),
grpc_error_std_string(watcher_error).c_str()); grpc_error_std_string(watcher_error).c_str());
}
if (type_url_ == XdsApi::kLdsTypeUrl) { if (type_url_ == XdsApi::kLdsTypeUrl) {
ListenerState& state = ads_calld_->xds_client()->listener_map_[name_]; ListenerState& state = ads_calld_->xds_client()->listener_map_[name_];
state.meta.client_status = XdsApi::ResourceMetadata::DOES_NOT_EXIST; state.meta.client_status = XdsApi::ResourceMetadata::DOES_NOT_EXIST;
@ -486,17 +487,20 @@ XdsClient::ChannelState::ChannelState(WeakRefCountedPtr<XdsClient> xds_client,
: nullptr), : nullptr),
xds_client_(std::move(xds_client)), xds_client_(std::move(xds_client)),
server_(server) { server_(server) {
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] creating channel to %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
xds_client_.get(), server.server_uri.c_str()); gpr_log(GPR_INFO, "[xds_client %p] creating channel to %s",
xds_client_.get(), server.server_uri.c_str());
}
channel_ = CreateXdsChannel(xds_client_->args_, server); channel_ = CreateXdsChannel(xds_client_->args_, server);
GPR_ASSERT(channel_ != nullptr); GPR_ASSERT(channel_ != nullptr);
StartConnectivityWatchLocked(); StartConnectivityWatchLocked();
} }
XdsClient::ChannelState::~ChannelState() { XdsClient::ChannelState::~ChannelState() {
grpc_xds_client_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
"[xds_client %p] Destroying xds channel %p", gpr_log(GPR_INFO, "[xds_client %p] Destroying xds channel %p", xds_client(),
xds_client(), this); this);
}
grpc_channel_destroy(channel_); grpc_channel_destroy(channel_);
xds_client_.reset(DEBUG_LOCATION, "ChannelState"); xds_client_.reset(DEBUG_LOCATION, "ChannelState");
} }
@ -625,11 +629,12 @@ void XdsClient::ChannelState::RetryableCall<T>::StartNewCallLocked() {
if (shutting_down_) return; if (shutting_down_) return;
GPR_ASSERT(chand_->channel_ != nullptr); GPR_ASSERT(chand_->channel_ != nullptr);
GPR_ASSERT(calld_ == nullptr); GPR_ASSERT(calld_ == nullptr);
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] Start new call from retryable call (chand: %p, " "[xds_client %p] Start new call from retryable call (chand: %p, "
"retryable call: %p)", "retryable call: %p)",
chand()->xds_client(), chand(), this); chand()->xds_client(), chand(), this);
}
calld_ = MakeOrphanable<T>( calld_ = MakeOrphanable<T>(
this->Ref(DEBUG_LOCATION, "RetryableCall+start_new_call")); this->Ref(DEBUG_LOCATION, "RetryableCall+start_new_call"));
} }
@ -638,12 +643,13 @@ template <typename T>
void XdsClient::ChannelState::RetryableCall<T>::StartRetryTimerLocked() { void XdsClient::ChannelState::RetryableCall<T>::StartRetryTimerLocked() {
if (shutting_down_) return; if (shutting_down_) return;
const grpc_millis next_attempt_time = backoff_.NextAttemptTime(); const grpc_millis next_attempt_time = backoff_.NextAttemptTime();
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, grpc_millis timeout = GPR_MAX(next_attempt_time - ExecCtx::Get()->Now(), 0);
"[xds_client %p] Failed to connect to xds server (chand: %p) " gpr_log(GPR_INFO,
"retry timer will fire in %" PRId64 "ms.", "[xds_client %p] Failed to connect to xds server (chand: %p) "
chand()->xds_client(), chand(), "retry timer will fire in %" PRId64 "ms.",
GPR_MAX(next_attempt_time - ExecCtx::Get()->Now(), 0)); chand()->xds_client(), chand(), timeout);
}
this->Ref(DEBUG_LOCATION, "RetryableCall+retry_timer_start").release(); this->Ref(DEBUG_LOCATION, "RetryableCall+retry_timer_start").release();
grpc_timer_init(&retry_timer_, next_attempt_time, &on_retry_timer_); grpc_timer_init(&retry_timer_, next_attempt_time, &on_retry_timer_);
retry_timer_callback_pending_ = true; retry_timer_callback_pending_ = true;
@ -665,10 +671,12 @@ void XdsClient::ChannelState::RetryableCall<T>::OnRetryTimerLocked(
grpc_error_handle error) { grpc_error_handle error) {
retry_timer_callback_pending_ = false; retry_timer_callback_pending_ = false;
if (!shutting_down_ && error == GRPC_ERROR_NONE) { if (!shutting_down_ && error == GRPC_ERROR_NONE) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(
"[xds_client %p] Retry timer fires (chand: %p, retryable call: %p)", GPR_INFO,
chand()->xds_client(), chand(), this); "[xds_client %p] Retry timer fires (chand: %p, retryable call: %p)",
chand()->xds_client(), chand(), this);
}
StartNewCallLocked(); StartNewCallLocked();
} }
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
@ -703,11 +711,12 @@ XdsClient::ChannelState::AdsCallState::AdsCallState(
grpc_metadata_array_init(&initial_metadata_recv_); grpc_metadata_array_init(&initial_metadata_recv_);
grpc_metadata_array_init(&trailing_metadata_recv_); grpc_metadata_array_init(&trailing_metadata_recv_);
// Start the call. // Start the call.
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] Starting ADS call (chand: %p, calld: %p, " "[xds_client %p] Starting ADS call (chand: %p, calld: %p, "
"call: %p)", "call: %p)",
xds_client(), chand(), this, call_); xds_client(), chand(), this, call_);
}
// Create the ops. // Create the ops.
grpc_call_error call_error; grpc_call_error call_error;
grpc_op ops[3]; grpc_op ops[3];
@ -820,14 +829,15 @@ void XdsClient::ChannelState::AdsCallState::SendMessageLocked(
state_map_.erase(type_url); state_map_.erase(type_url);
} }
sent_initial_message_ = true; sent_initial_message_ = true;
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] sending ADS request: type=%s version=%s nonce=%s " "[xds_client %p] sending ADS request: type=%s version=%s nonce=%s "
"error=%s resources=%s", "error=%s resources=%s",
xds_client(), type_url.c_str(), xds_client(), type_url.c_str(),
xds_client()->resource_version_map_[type_url].c_str(), xds_client()->resource_version_map_[type_url].c_str(),
state.nonce.c_str(), grpc_error_std_string(state.error).c_str(), state.nonce.c_str(), grpc_error_std_string(state.error).c_str(),
absl::StrJoin(resource_names, " ").c_str()); absl::StrJoin(resource_names, " ").c_str());
}
GRPC_ERROR_UNREF(state.error); GRPC_ERROR_UNREF(state.error);
state.error = GRPC_ERROR_NONE; state.error = GRPC_ERROR_NONE;
// Create message payload. // Create message payload.
@ -895,10 +905,12 @@ XdsApi::ResourceMetadata CreateResourceMetadataAcked(
void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked( void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
std::string version, grpc_millis update_time, std::string version, grpc_millis update_time,
XdsApi::LdsUpdateMap lds_update_map) { XdsApi::LdsUpdateMap lds_update_map) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] LDS update received containing %" PRIuPTR " resources", "[xds_client %p] LDS update received containing %" PRIuPTR
xds_client(), lds_update_map.size()); " resources",
xds_client(), lds_update_map.size());
}
auto& lds_state = state_map_[XdsApi::kLdsTypeUrl]; auto& lds_state = state_map_[XdsApi::kLdsTypeUrl];
std::set<std::string> rds_resource_names_seen; std::set<std::string> rds_resource_names_seen;
for (auto& p : lds_update_map) { for (auto& p : lds_update_map) {
@ -906,9 +918,10 @@ void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
XdsApi::LdsUpdate& lds_update = p.second.resource; XdsApi::LdsUpdate& lds_update = p.second.resource;
auto& state = lds_state.subscribed_resources[listener_name]; auto& state = lds_state.subscribed_resources[listener_name];
if (state != nullptr) state->Finish(); if (state != nullptr) state->Finish();
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] LDS resource %s: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
xds_client(), listener_name.c_str(), gpr_log(GPR_INFO, "[xds_client %p] LDS resource %s: %s", xds_client(),
lds_update.ToString().c_str()); listener_name.c_str(), lds_update.ToString().c_str());
}
// Record the RDS resource names seen. // Record the RDS resource names seen.
if (!lds_update.http_connection_manager.route_config_name.empty()) { if (!lds_update.http_connection_manager.route_config_name.empty()) {
rds_resource_names_seen.insert( rds_resource_names_seen.insert(
@ -918,11 +931,12 @@ void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
ListenerState& listener_state = xds_client()->listener_map_[listener_name]; ListenerState& listener_state = xds_client()->listener_map_[listener_name];
if (listener_state.update.has_value() && if (listener_state.update.has_value() &&
*listener_state.update == lds_update) { *listener_state.update == lds_update) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] LDS update for %s identical to current, " "[xds_client %p] LDS update for %s identical to current, "
"ignoring.", "ignoring.",
xds_client(), listener_name.c_str()); xds_client(), listener_name.c_str());
}
continue; continue;
} }
// Update the listener state. // Update the listener state.
@ -975,27 +989,32 @@ void XdsClient::ChannelState::AdsCallState::AcceptLdsUpdateLocked(
void XdsClient::ChannelState::AdsCallState::AcceptRdsUpdateLocked( void XdsClient::ChannelState::AdsCallState::AcceptRdsUpdateLocked(
std::string version, grpc_millis update_time, std::string version, grpc_millis update_time,
XdsApi::RdsUpdateMap rds_update_map) { XdsApi::RdsUpdateMap rds_update_map) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] RDS update received containing %" PRIuPTR " resources", "[xds_client %p] RDS update received containing %" PRIuPTR
xds_client(), rds_update_map.size()); " resources",
xds_client(), rds_update_map.size());
}
auto& rds_state = state_map_[XdsApi::kRdsTypeUrl]; auto& rds_state = state_map_[XdsApi::kRdsTypeUrl];
for (auto& p : rds_update_map) { for (auto& p : rds_update_map) {
const std::string& route_config_name = p.first; const std::string& route_config_name = p.first;
XdsApi::RdsUpdate& rds_update = p.second.resource; XdsApi::RdsUpdate& rds_update = p.second.resource;
auto& state = rds_state.subscribed_resources[route_config_name]; auto& state = rds_state.subscribed_resources[route_config_name];
if (state != nullptr) state->Finish(); if (state != nullptr) state->Finish();
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] RDS resource:\n%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
xds_client(), rds_update.ToString().c_str()); gpr_log(GPR_INFO, "[xds_client %p] RDS resource:\n%s", xds_client(),
rds_update.ToString().c_str());
}
RouteConfigState& route_config_state = RouteConfigState& route_config_state =
xds_client()->route_config_map_[route_config_name]; xds_client()->route_config_map_[route_config_name];
// Ignore identical update. // Ignore identical update.
if (route_config_state.update.has_value() && if (route_config_state.update.has_value() &&
*route_config_state.update == rds_update) { *route_config_state.update == rds_update) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] RDS resource identical to current, ignoring", "[xds_client %p] RDS resource identical to current, ignoring",
xds_client()); xds_client());
}
continue; continue;
} }
// Update the cache. // Update the cache.
@ -1012,10 +1031,12 @@ void XdsClient::ChannelState::AdsCallState::AcceptRdsUpdateLocked(
void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked( void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
std::string version, grpc_millis update_time, std::string version, grpc_millis update_time,
XdsApi::CdsUpdateMap cds_update_map) { XdsApi::CdsUpdateMap cds_update_map) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] CDS update received containing %" PRIuPTR " resources", "[xds_client %p] CDS update received containing %" PRIuPTR
xds_client(), cds_update_map.size()); " resources",
xds_client(), cds_update_map.size());
}
auto& cds_state = state_map_[XdsApi::kCdsTypeUrl]; auto& cds_state = state_map_[XdsApi::kCdsTypeUrl];
std::set<std::string> eds_resource_names_seen; std::set<std::string> eds_resource_names_seen;
for (auto& p : cds_update_map) { for (auto& p : cds_update_map) {
@ -1023,9 +1044,10 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
XdsApi::CdsUpdate& cds_update = p.second.resource; XdsApi::CdsUpdate& cds_update = p.second.resource;
auto& state = cds_state.subscribed_resources[cluster_name]; auto& state = cds_state.subscribed_resources[cluster_name];
if (state != nullptr) state->Finish(); if (state != nullptr) state->Finish();
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] cluster=%s: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
xds_client(), cluster_name, gpr_log(GPR_INFO, "[xds_client %p] cluster=%s: %s", xds_client(),
cds_update.ToString().c_str()); cluster_name, cds_update.ToString().c_str());
}
// Record the EDS resource names seen. // Record the EDS resource names seen.
eds_resource_names_seen.insert(cds_update.eds_service_name.empty() eds_resource_names_seen.insert(cds_update.eds_service_name.empty()
? cluster_name ? cluster_name
@ -1034,10 +1056,11 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
ClusterState& cluster_state = xds_client()->cluster_map_[cluster_name]; ClusterState& cluster_state = xds_client()->cluster_map_[cluster_name];
if (cluster_state.update.has_value() && if (cluster_state.update.has_value() &&
*cluster_state.update == cds_update) { *cluster_state.update == cds_update) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] CDS update identical to current, ignoring.", "[xds_client %p] CDS update identical to current, ignoring.",
xds_client()); xds_client());
}
continue; continue;
} }
// Update the cluster state. // Update the cluster state.
@ -1089,28 +1112,32 @@ void XdsClient::ChannelState::AdsCallState::AcceptCdsUpdateLocked(
void XdsClient::ChannelState::AdsCallState::AcceptEdsUpdateLocked( void XdsClient::ChannelState::AdsCallState::AcceptEdsUpdateLocked(
std::string version, grpc_millis update_time, std::string version, grpc_millis update_time,
XdsApi::EdsUpdateMap eds_update_map) { XdsApi::EdsUpdateMap eds_update_map) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] EDS update received containing %" PRIuPTR " resources", "[xds_client %p] EDS update received containing %" PRIuPTR
xds_client(), eds_update_map.size()); " resources",
xds_client(), eds_update_map.size());
}
auto& eds_state = state_map_[XdsApi::kEdsTypeUrl]; auto& eds_state = state_map_[XdsApi::kEdsTypeUrl];
for (auto& p : eds_update_map) { for (auto& p : eds_update_map) {
const char* eds_service_name = p.first.c_str(); const char* eds_service_name = p.first.c_str();
XdsApi::EdsUpdate& eds_update = p.second.resource; XdsApi::EdsUpdate& eds_update = p.second.resource;
auto& state = eds_state.subscribed_resources[eds_service_name]; auto& state = eds_state.subscribed_resources[eds_service_name];
if (state != nullptr) state->Finish(); if (state != nullptr) state->Finish();
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] EDS resource %s: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
xds_client(), eds_service_name, gpr_log(GPR_INFO, "[xds_client %p] EDS resource %s: %s", xds_client(),
eds_update.ToString().c_str()); eds_service_name, eds_update.ToString().c_str());
}
EndpointState& endpoint_state = EndpointState& endpoint_state =
xds_client()->endpoint_map_[eds_service_name]; xds_client()->endpoint_map_[eds_service_name];
// Ignore identical update. // Ignore identical update.
if (endpoint_state.update.has_value() && if (endpoint_state.update.has_value() &&
*endpoint_state.update == eds_update) { *endpoint_state.update == eds_update) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] EDS update identical to current, ignoring.", "[xds_client %p] EDS update identical to current, ignoring.",
xds_client()); xds_client());
}
continue; continue;
} }
// Update the cluster state. // Update the cluster state.
@ -1143,11 +1170,13 @@ template <typename StateMap>
void XdsClient::ChannelState::AdsCallState::RejectAdsUpdateLocked( void XdsClient::ChannelState::AdsCallState::RejectAdsUpdateLocked(
grpc_millis update_time, const XdsApi::AdsParseResult& result, grpc_millis update_time, const XdsApi::AdsParseResult& result,
StateMap* state_map) { StateMap* state_map) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] %s update NACKed containing %" PRIuPTR " resources", "[xds_client %p] %s update NACKed containing %" PRIuPTR
xds_client(), result.type_url.c_str(), " resources",
result.resource_names_failed.size()); xds_client(), result.type_url.c_str(),
result.resource_names_failed.size());
}
std::string details = grpc_error_std_string(result.parse_error); std::string details = grpc_error_std_string(result.parse_error);
for (auto& name : result.resource_names_failed) { for (auto& name : result.resource_names_failed) {
auto it = state_map->find(name); auto it = state_map->find(name);
@ -1526,11 +1555,12 @@ XdsClient::ChannelState::LrsCallState::LrsCallState(
grpc_metadata_array_init(&initial_metadata_recv_); grpc_metadata_array_init(&initial_metadata_recv_);
grpc_metadata_array_init(&trailing_metadata_recv_); grpc_metadata_array_init(&trailing_metadata_recv_);
// Start the call. // Start the call.
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] Starting LRS call (chand: %p, calld: %p, " "[xds_client %p] Starting LRS call (chand: %p, calld: %p, "
"call: %p)", "call: %p)",
xds_client(), chand(), this, call_); xds_client(), chand(), this, call_);
}
// Create the ops. // Create the ops.
grpc_call_error call_error; grpc_call_error call_error;
grpc_op ops[3]; grpc_op ops[3];
@ -1713,21 +1743,23 @@ bool XdsClient::ChannelState::LrsCallState::OnResponseReceivedLocked() {
GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS) { GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS) {
new_load_reporting_interval = new_load_reporting_interval =
GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS; GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS;
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] Increased load_report_interval to minimum " "[xds_client %p] Increased load_report_interval to minimum "
"value %dms", "value %dms",
xds_client(), GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS); xds_client(), GRPC_XDS_MIN_CLIENT_LOAD_REPORTING_INTERVAL_MS);
}
} }
// Ignore identical update. // Ignore identical update.
if (send_all_clusters == send_all_clusters_ && if (send_all_clusters == send_all_clusters_ &&
cluster_names_ == new_cluster_names && cluster_names_ == new_cluster_names &&
load_reporting_interval_ == new_load_reporting_interval) { load_reporting_interval_ == new_load_reporting_interval) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] Incoming LRS response identical to current, " "[xds_client %p] Incoming LRS response identical to current, "
"ignoring.", "ignoring.",
xds_client()); xds_client());
}
return; return;
} }
// Stop current load reporting (if any) to adopt the new config. // Stop current load reporting (if any) to adopt the new config.
@ -1833,16 +1865,18 @@ XdsClient::XdsClient(std::unique_ptr<XdsBootstrap> bootstrap,
bootstrap_->certificate_providers())), bootstrap_->certificate_providers())),
api_(this, &grpc_xds_client_trace, bootstrap_->node(), api_(this, &grpc_xds_client_trace, bootstrap_->node(),
&bootstrap_->certificate_providers()) { &bootstrap_->certificate_providers()) {
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] creating xds client", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
this); gpr_log(GPR_INFO, "[xds_client %p] creating xds client", this);
}
// Create ChannelState object. // Create ChannelState object.
chand_ = MakeOrphanable<ChannelState>( chand_ = MakeOrphanable<ChannelState>(
WeakRef(DEBUG_LOCATION, "XdsClient+ChannelState"), bootstrap_->server()); WeakRef(DEBUG_LOCATION, "XdsClient+ChannelState"), bootstrap_->server());
} }
XdsClient::~XdsClient() { XdsClient::~XdsClient() {
grpc_xds_client_trace.Log(GPR_INFO, "[xds_client %p] destroying xds client", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
this); gpr_log(GPR_INFO, "[xds_client %p] destroying xds client", this);
}
grpc_channel_args_destroy(args_); grpc_channel_args_destroy(args_);
grpc_pollset_set_destroy(interested_parties_); grpc_pollset_set_destroy(interested_parties_);
} }
@ -1868,8 +1902,9 @@ void XdsClient::RemoveChannelzLinkage(
} }
void XdsClient::Orphan() { void XdsClient::Orphan() {
grpc_xds_client_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
"[xds_client %p] shutting down xds client", this); gpr_log(GPR_INFO, "[xds_client %p] shutting down xds client", this);
}
{ {
MutexLock lock(g_mu); MutexLock lock(g_mu);
if (g_xds_client == this) g_xds_client = nullptr; if (g_xds_client == this) g_xds_client = nullptr;
@ -1903,9 +1938,10 @@ void XdsClient::WatchListenerData(
// If we've already received an LDS update, notify the new watcher // If we've already received an LDS update, notify the new watcher
// immediately. // immediately.
if (listener_state.update.has_value()) { if (listener_state.update.has_value()) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, "[xds_client %p] returning cached listener data for %s", this, gpr_log(GPR_INFO, "[xds_client %p] returning cached listener data for %s",
listener_name_str.c_str()); this, listener_name_str.c_str());
}
w->OnListenerChanged(*listener_state.update); w->OnListenerChanged(*listener_state.update);
} }
chand_->SubscribeLocked(XdsApi::kLdsTypeUrl, listener_name_str); chand_->SubscribeLocked(XdsApi::kLdsTypeUrl, listener_name_str);
@ -1941,9 +1977,11 @@ void XdsClient::WatchRouteConfigData(
// If we've already received an RDS update, notify the new watcher // If we've already received an RDS update, notify the new watcher
// immediately. // immediately.
if (route_config_state.update.has_value()) { if (route_config_state.update.has_value()) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, "[xds_client %p] returning cached route config data for %s", gpr_log(GPR_INFO,
this, route_config_name_str.c_str()); "[xds_client %p] returning cached route config data for %s", this,
route_config_name_str.c_str());
}
w->OnRouteConfigChanged(*route_config_state.update); w->OnRouteConfigChanged(*route_config_state.update);
} }
chand_->SubscribeLocked(XdsApi::kRdsTypeUrl, route_config_name_str); chand_->SubscribeLocked(XdsApi::kRdsTypeUrl, route_config_name_str);
@ -1979,9 +2017,10 @@ void XdsClient::WatchClusterData(
// If we've already received a CDS update, notify the new watcher // If we've already received a CDS update, notify the new watcher
// immediately. // immediately.
if (cluster_state.update.has_value()) { if (cluster_state.update.has_value()) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, "[xds_client %p] returning cached cluster data for %s", this, gpr_log(GPR_INFO, "[xds_client %p] returning cached cluster data for %s",
cluster_name_str.c_str()); this, cluster_name_str.c_str());
}
w->OnClusterChanged(cluster_state.update.value()); w->OnClusterChanged(cluster_state.update.value());
} }
chand_->SubscribeLocked(XdsApi::kCdsTypeUrl, cluster_name_str); chand_->SubscribeLocked(XdsApi::kCdsTypeUrl, cluster_name_str);
@ -2016,9 +2055,10 @@ void XdsClient::WatchEndpointData(
// If we've already received an EDS update, notify the new watcher // If we've already received an EDS update, notify the new watcher
// immediately. // immediately.
if (endpoint_state.update.has_value()) { if (endpoint_state.update.has_value()) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, "[xds_client %p] returning cached endpoint data for %s", this, gpr_log(GPR_INFO, "[xds_client %p] returning cached endpoint data for %s",
eds_service_name_str.c_str()); this, eds_service_name_str.c_str());
}
w->OnEndpointChanged(endpoint_state.update.value()); w->OnEndpointChanged(endpoint_state.update.value());
} }
chand_->SubscribeLocked(XdsApi::kEdsTypeUrl, eds_service_name_str); chand_->SubscribeLocked(XdsApi::kEdsTypeUrl, eds_service_name_str);
@ -2194,8 +2234,9 @@ void XdsClient::NotifyOnErrorLocked(grpc_error_handle error) {
XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked( XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked(
bool send_all_clusters, const std::set<std::string>& clusters) { bool send_all_clusters, const std::set<std::string>& clusters) {
grpc_xds_client_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
"[xds_client %p] start building load report", this); gpr_log(GPR_INFO, "[xds_client %p] start building load report", this);
}
XdsApi::ClusterLoadReportMap snapshot_map; XdsApi::ClusterLoadReportMap snapshot_map;
for (auto load_report_it = load_report_map_.begin(); for (auto load_report_it = load_report_map_.begin();
load_report_it != load_report_map_.end();) { load_report_it != load_report_map_.end();) {
@ -2217,11 +2258,12 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked(
if (load_report.drop_stats != nullptr) { if (load_report.drop_stats != nullptr) {
snapshot.dropped_requests += snapshot.dropped_requests +=
load_report.drop_stats->GetSnapshotAndReset(); load_report.drop_stats->GetSnapshotAndReset();
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] cluster=%s eds_service_name=%s drop_stats=%p", this, "[xds_client %p] cluster=%s eds_service_name=%s drop_stats=%p",
cluster_key.first.c_str(), cluster_key.second.c_str(), this, cluster_key.first.c_str(), cluster_key.second.c_str(),
load_report.drop_stats); load_report.drop_stats);
}
} }
// Aggregate locality stats. // Aggregate locality stats.
for (auto it = load_report.locality_stats.begin(); for (auto it = load_report.locality_stats.begin();
@ -2234,13 +2276,14 @@ XdsApi::ClusterLoadReportMap XdsClient::BuildLoadReportSnapshotLocked(
if (locality_state.locality_stats != nullptr) { if (locality_state.locality_stats != nullptr) {
locality_snapshot += locality_snapshot +=
locality_state.locality_stats->GetSnapshotAndReset(); locality_state.locality_stats->GetSnapshotAndReset();
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] cluster=%s eds_service_name=%s " "[xds_client %p] cluster=%s eds_service_name=%s "
"locality=%s locality_stats=%p", "locality=%s locality_stats=%p",
this, cluster_key.first.c_str(), cluster_key.second.c_str(), this, cluster_key.first.c_str(), cluster_key.second.c_str(),
locality_name->AsHumanReadableString().c_str(), locality_name->AsHumanReadableString().c_str(),
locality_state.locality_stats); locality_state.locality_stats);
}
} }
// If the only thing left in this entry was final snapshots from // If the only thing left in this entry was final snapshots from
// deleted locality stats objects, remove the entry. // deleted locality stats objects, remove the entry.
@ -2332,11 +2375,12 @@ std::string GetBootstrapContents(const char* fallback_config,
// First, try GRPC_XDS_BOOTSTRAP env var. // First, try GRPC_XDS_BOOTSTRAP env var.
grpc_core::UniquePtr<char> path(gpr_getenv("GRPC_XDS_BOOTSTRAP")); grpc_core::UniquePtr<char> path(gpr_getenv("GRPC_XDS_BOOTSTRAP"));
if (path != nullptr) { if (path != nullptr) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"Got bootstrap file location from GRPC_XDS_BOOTSTRAP " "Got bootstrap file location from GRPC_XDS_BOOTSTRAP "
"environment variable: %s", "environment variable: %s",
path.get()); path.get());
}
grpc_slice contents; grpc_slice contents;
*error = *error =
grpc_load_file(path.get(), /*add_null_terminator=*/true, &contents); grpc_load_file(path.get(), /*add_null_terminator=*/true, &contents);
@ -2349,16 +2393,18 @@ std::string GetBootstrapContents(const char* fallback_config,
grpc_core::UniquePtr<char> env_config( grpc_core::UniquePtr<char> env_config(
gpr_getenv("GRPC_XDS_BOOTSTRAP_CONFIG")); gpr_getenv("GRPC_XDS_BOOTSTRAP_CONFIG"));
if (env_config != nullptr) { if (env_config != nullptr) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG " "Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG "
"environment variable"); "environment variable");
}
return env_config.get(); return env_config.get();
} }
// Finally, try fallback config. // Finally, try fallback config.
if (fallback_config != nullptr) { if (fallback_config != nullptr) {
grpc_xds_client_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
"Got bootstrap contents from fallback config"); gpr_log(GPR_INFO, "Got bootstrap contents from fallback config");
}
return fallback_config; return fallback_config;
} }
// No bootstrap config found. // No bootstrap config found.
@ -2400,8 +2446,10 @@ RefCountedPtr<XdsClient> XdsClient::GetOrCreate(const grpc_channel_args* args,
std::string bootstrap_contents = std::string bootstrap_contents =
GetBootstrapContents(g_fallback_bootstrap_config, error); GetBootstrapContents(g_fallback_bootstrap_config, error);
if (*error != GRPC_ERROR_NONE) return nullptr; if (*error != GRPC_ERROR_NONE) return nullptr;
grpc_xds_client_trace.Log(GPR_INFO, "xDS bootstrap contents: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
bootstrap_contents.c_str()); gpr_log(GPR_INFO, "xDS bootstrap contents: %s",
bootstrap_contents.c_str());
}
// Parse bootstrap. // Parse bootstrap.
std::unique_ptr<XdsBootstrap> bootstrap = std::unique_ptr<XdsBootstrap> bootstrap =
XdsBootstrap::Create(bootstrap_contents, error); XdsBootstrap::Create(bootstrap_contents, error);

@ -52,19 +52,22 @@ XdsClusterDropStats::XdsClusterDropStats(RefCountedPtr<XdsClient> xds_client,
lrs_server_name_(lrs_server_name), lrs_server_name_(lrs_server_name),
cluster_name_(cluster_name), cluster_name_(cluster_name),
eds_service_name_(eds_service_name) { eds_service_name_(eds_service_name) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, "[xds_client %p] created drop stats %p for {%s, %s, %s}", gpr_log(GPR_INFO, "[xds_client %p] created drop stats %p for {%s, %s, %s}",
xds_client_.get(), this, std::string(lrs_server_name_).c_str(), xds_client_.get(), this, std::string(lrs_server_name_).c_str(),
std::string(cluster_name_).c_str(), std::string(cluster_name_).c_str(),
std::string(eds_service_name_).c_str()); std::string(eds_service_name_).c_str());
}
} }
XdsClusterDropStats::~XdsClusterDropStats() { XdsClusterDropStats::~XdsClusterDropStats() {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, "[xds_client %p] destroying drop stats %p for {%s, %s, %s}", gpr_log(GPR_INFO,
xds_client_.get(), this, std::string(lrs_server_name_).c_str(), "[xds_client %p] destroying drop stats %p for {%s, %s, %s}",
std::string(cluster_name_).c_str(), xds_client_.get(), this, std::string(lrs_server_name_).c_str(),
std::string(eds_service_name_).c_str()); std::string(cluster_name_).c_str(),
std::string(eds_service_name_).c_str());
}
xds_client_->RemoveClusterDropStats(lrs_server_name_, cluster_name_, xds_client_->RemoveClusterDropStats(lrs_server_name_, cluster_name_,
eds_service_name_, this); eds_service_name_, this);
xds_client_.reset(DEBUG_LOCATION, "DropStats"); xds_client_.reset(DEBUG_LOCATION, "DropStats");
@ -103,23 +106,25 @@ XdsClusterLocalityStats::XdsClusterLocalityStats(
cluster_name_(cluster_name), cluster_name_(cluster_name),
eds_service_name_(eds_service_name), eds_service_name_(eds_service_name),
name_(std::move(name)) { name_(std::move(name)) {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] created locality stats %p for {%s, %s, %s, %s}", "[xds_client %p] created locality stats %p for {%s, %s, %s, %s}",
xds_client_.get(), this, std::string(lrs_server_name_).c_str(), xds_client_.get(), this, std::string(lrs_server_name_).c_str(),
std::string(cluster_name_).c_str(), std::string(cluster_name_).c_str(),
std::string(eds_service_name_).c_str(), std::string(eds_service_name_).c_str(),
name_->AsHumanReadableString().c_str()); name_->AsHumanReadableString().c_str());
}
} }
XdsClusterLocalityStats::~XdsClusterLocalityStats() { XdsClusterLocalityStats::~XdsClusterLocalityStats() {
grpc_xds_client_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"[xds_client %p] destroying locality stats %p for {%s, %s, %s, %s}", "[xds_client %p] destroying locality stats %p for {%s, %s, %s, %s}",
xds_client_.get(), this, std::string(lrs_server_name_).c_str(), xds_client_.get(), this, std::string(lrs_server_name_).c_str(),
std::string(cluster_name_).c_str(), std::string(cluster_name_).c_str(),
std::string(eds_service_name_).c_str(), std::string(eds_service_name_).c_str(),
name_->AsHumanReadableString().c_str()); name_->AsHumanReadableString().c_str());
}
xds_client_->RemoveClusterLocalityStats(lrs_server_name_, cluster_name_, xds_client_->RemoveClusterLocalityStats(lrs_server_name_, cluster_name_,
eds_service_name_, name_, this); eds_service_name_, name_, this);
xds_client_.reset(DEBUG_LOCATION, "LocalityStats"); xds_client_.reset(DEBUG_LOCATION, "LocalityStats");

@ -413,10 +413,12 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher {
ListenerWatcher& operator=(const ListenerWatcher&) = delete; ListenerWatcher& operator=(const ListenerWatcher&) = delete;
void OnListenerChanged(XdsApi::LdsUpdate listener) override { void OnListenerChanged(XdsApi::LdsUpdate listener) override {
grpc_xds_server_config_fetcher_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_server_config_fetcher_trace)) {
GPR_INFO, gpr_log(
"[ListenerWatcher %p] Received LDS update from xds client %p: %s", GPR_INFO,
this, xds_client_.get(), listener.ToString().c_str()); "[ListenerWatcher %p] Received LDS update from xds client %p: %s",
this, xds_client_.get(), listener.ToString().c_str());
}
if (listener.address != listening_address_) { if (listener.address != listening_address_) {
OnFatalError(absl::FailedPreconditionError( OnFatalError(absl::FailedPreconditionError(
"Address in LDS update does not match listening address")); "Address in LDS update does not match listening address"));

@ -56,10 +56,12 @@ std::string HandshakerArgsString(HandshakerArgs* args) {
HandshakeManager::HandshakeManager() {} HandshakeManager::HandshakeManager() {}
void HandshakeManager::Add(RefCountedPtr<Handshaker> handshaker) { void HandshakeManager::Add(RefCountedPtr<Handshaker> handshaker) {
grpc_handshaker_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_handshaker_trace)) {
GPR_INFO, gpr_log(
"handshake_manager %p: adding handshaker %s [%p] at index %" PRIuPTR, GPR_INFO,
this, handshaker->name(), handshaker.get(), handshakers_.size()); "handshake_manager %p: adding handshaker %s [%p] at index %" PRIuPTR,
this, handshaker->name(), handshaker.get(), handshakers_.size());
}
MutexLock lock(&mu_); MutexLock lock(&mu_);
handshakers_.push_back(std::move(handshaker)); handshakers_.push_back(std::move(handshaker));
} }
@ -82,11 +84,13 @@ void HandshakeManager::Shutdown(grpc_error_handle why) {
// on_handshake_done callback. // on_handshake_done callback.
// Returns true if we've scheduled the on_handshake_done callback. // Returns true if we've scheduled the on_handshake_done callback.
bool HandshakeManager::CallNextHandshakerLocked(grpc_error_handle error) { bool HandshakeManager::CallNextHandshakerLocked(grpc_error_handle error) {
grpc_handshaker_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_handshaker_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"handshake_manager %p: error=%s shutdown=%d index=%" PRIuPTR ", args=%s", "handshake_manager %p: error=%s shutdown=%d index=%" PRIuPTR
this, grpc_error_std_string(error).c_str(), is_shutdown_, index_, ", args=%s",
HandshakerArgsString(&args_).c_str()); this, grpc_error_std_string(error).c_str(), is_shutdown_, index_,
HandshakerArgsString(&args_).c_str());
}
GPR_ASSERT(index_ <= handshakers_.size()); GPR_ASSERT(index_ <= handshakers_.size());
// If we got an error or we've been shut down or we're exiting early or // If we got an error or we've been shut down or we're exiting early or
// we've finished the last handshaker, invoke the on_handshake_done // we've finished the last handshaker, invoke the on_handshake_done
@ -113,11 +117,12 @@ bool HandshakeManager::CallNextHandshakerLocked(grpc_error_handle error) {
args_.read_buffer = nullptr; args_.read_buffer = nullptr;
} }
} }
grpc_handshaker_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_handshaker_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"handshake_manager %p: handshaking complete -- scheduling " "handshake_manager %p: handshaking complete -- scheduling "
"on_handshake_done with error=%s", "on_handshake_done with error=%s",
this, grpc_error_std_string(error).c_str()); this, grpc_error_std_string(error).c_str());
}
// Cancel deadline timer, since we're invoking the on_handshake_done // Cancel deadline timer, since we're invoking the on_handshake_done
// callback now. // callback now.
grpc_timer_cancel(&deadline_timer_); grpc_timer_cancel(&deadline_timer_);
@ -125,10 +130,12 @@ bool HandshakeManager::CallNextHandshakerLocked(grpc_error_handle error) {
is_shutdown_ = true; is_shutdown_ = true;
} else { } else {
auto handshaker = handshakers_[index_]; auto handshaker = handshakers_[index_];
grpc_handshaker_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_handshaker_trace)) {
GPR_INFO, gpr_log(
"handshake_manager %p: calling handshaker %s [%p] at index %" PRIuPTR, GPR_INFO,
this, handshaker->name(), handshaker.get(), index_); "handshake_manager %p: calling handshaker %s [%p] at index %" PRIuPTR,
this, handshaker->name(), handshaker.get(), index_);
}
handshaker->DoHandshake(acceptor_, &call_next_handshaker_, &args_); handshaker->DoHandshake(acceptor_, &call_next_handshaker_, &args_);
} }
++index_; ++index_;

@ -24,7 +24,6 @@
#include <grpc/support/atm.h> #include <grpc/support/atm.h>
#include <stdbool.h> #include <stdbool.h>
#include "src/core/lib/gpr/log_internal.h"
#include "src/core/lib/gprpp/global_config.h" #include "src/core/lib/gprpp/global_config.h"
GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_trace); GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_trace);
@ -89,16 +88,6 @@ class TraceFlag {
bool enabled() { return false; } bool enabled() { return false; }
#endif /* defined(GRPC_USE_TRACERS) || !defined(NDEBUG) */ #endif /* defined(GRPC_USE_TRACERS) || !defined(NDEBUG) */
void Log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) GPR_PRINT_FORMAT_CHECK(5, 6) {
if (GPR_UNLIKELY(enabled())) {
va_list args;
va_start(args, format);
gpr_vlog(file, line, severity, format, args);
va_end(args);
}
}
private: private:
friend void grpc_core::testing::grpc_tracer_enable_flag(TraceFlag* flag); friend void grpc_core::testing::grpc_tracer_enable_flag(TraceFlag* flag);
friend class TraceFlagList; friend class TraceFlagList;
@ -131,7 +120,6 @@ class DebugOnlyTraceFlag {
} }
constexpr bool enabled() const { return false; } constexpr bool enabled() const { return false; }
constexpr const char* name() const { return "DebugOnlyTraceFlag"; } constexpr const char* name() const { return "DebugOnlyTraceFlag"; }
void Log(const char*, int, gpr_log_severity, const char*, ...) {}
private: private:
void set_enabled(bool /*enabled*/) {} void set_enabled(bool /*enabled*/) {}

@ -27,8 +27,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "src/core/lib/gpr/log_internal.h"
static android_LogPriority severity_to_log_priority(gpr_log_severity severity) { static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
switch (severity) { switch (severity) {
case GPR_LOG_SEVERITY_DEBUG: case GPR_LOG_SEVERITY_DEBUG:
@ -47,16 +45,11 @@ void gpr_log(const char* file, int line, gpr_log_severity severity,
if (gpr_should_log(severity) == 0) { if (gpr_should_log(severity) == 0) {
return; return;
} }
char* message = NULL;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
gpr_vlog(file, line, severity, format, args);
va_end(args);
}
void gpr_vlog(const char* file, int line, gpr_log_severity severity,
const char* format, va_list args) {
char* message = NULL;
vasprintf(&message, format, args); vasprintf(&message, format, args);
va_end(args);
gpr_log_message(file, line, severity, message); gpr_log_message(file, line, severity, message);
free(message); free(message);
} }

@ -1,25 +0,0 @@
// Copyright 2021 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <grpc/support/port_platform.h>
#ifndef GRPC_CORE_LIB_GPR_LOG_INTERNAL_H
#define GRPC_CORE_LIB_GPR_LOG_INTERNAL_H
#include "grpc/support/log.h"
/// Log a message, accepting a variadic argument list. See also \a gpr_log.
void gpr_vlog(const char* file, int line, gpr_log_severity severity,
const char* format, va_list args);
#endif // GRPC_CORE_LIB_GPR_LOG_INTERNAL_H

@ -42,7 +42,6 @@
#include <string> #include <string>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "src/core/lib/gpr/log_internal.h"
#include "src/core/lib/gpr/tls.h" #include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gprpp/examine_stack.h" #include "src/core/lib/gprpp/examine_stack.h"
@ -56,19 +55,14 @@ void gpr_log(const char* file, int line, gpr_log_severity severity,
if (gpr_should_log(severity) == 0) { if (gpr_should_log(severity) == 0) {
return; return;
} }
char* message = nullptr;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
gpr_vlog(file, line, severity, format, args);
va_end(args);
}
void gpr_vlog(const char* file, int line, gpr_log_severity severity,
const char* format, va_list args) {
char* message = nullptr;
if (vasprintf(&message, format, args) == -1) { if (vasprintf(&message, format, args) == -1) {
va_end(args); va_end(args);
return; return;
} }
va_end(args);
gpr_log_message(file, line, severity, message); gpr_log_message(file, line, severity, message);
/* message has been allocated by vasprintf above, and needs free */ /* message has been allocated by vasprintf above, and needs free */
free(message); free(message);

@ -32,7 +32,6 @@
#include <string> #include <string>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "src/core/lib/gpr/log_internal.h"
#include "src/core/lib/gprpp/examine_stack.h" #include "src/core/lib/gprpp/examine_stack.h"
int gpr_should_log_stacktrace(gpr_log_severity severity); int gpr_should_log_stacktrace(gpr_log_severity severity);
@ -45,28 +44,23 @@ void gpr_log(const char* file, int line, gpr_log_severity severity,
if (gpr_should_log(severity) == 0) { if (gpr_should_log(severity) == 0) {
return; return;
} }
va_list args;
va_start(args, format);
gpr_vlog(file, line, severity, format, args);
va_end(args);
}
void gpr_vlog(const char* file, int line, gpr_log_severity severity,
const char* format, va_list args) {
char buf[64]; char buf[64];
char* allocated = nullptr; char* allocated = nullptr;
char* message = nullptr; char* message = nullptr;
// a va_list cannot be used twice. int ret;
va_list args_copy; va_list args;
va_copy(args_copy, args); va_start(args, format);
int ret = vsnprintf(buf, sizeof(buf), format, args_copy); ret = vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
if (ret < 0) { if (ret < 0) {
message = nullptr; message = nullptr;
} else if ((size_t)ret <= sizeof(buf) - 1) { } else if ((size_t)ret <= sizeof(buf) - 1) {
message = buf; message = buf;
} else { } else {
message = allocated = (char*)gpr_malloc((size_t)ret + 1); message = allocated = (char*)gpr_malloc((size_t)ret + 1);
va_start(args, format);
vsnprintf(message, (size_t)(ret + 1), format, args); vsnprintf(message, (size_t)(ret + 1), format, args);
va_end(args);
} }
gpr_log_message(file, line, severity, message); gpr_log_message(file, line, severity, message);
gpr_free(allocated); gpr_free(allocated);

@ -29,7 +29,6 @@
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/gpr/log_internal.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/string_windows.h" #include "src/core/lib/gpr/string_windows.h"
#include "src/core/lib/gprpp/examine_stack.h" #include "src/core/lib/gprpp/examine_stack.h"
@ -42,16 +41,15 @@ void gpr_log(const char* file, int line, gpr_log_severity severity,
if (gpr_should_log(severity) == 0) { if (gpr_should_log(severity) == 0) {
return; return;
} }
char* message = NULL;
va_list args; va_list args;
int ret;
/* Determine the length. */
va_start(args, format); va_start(args, format);
gpr_vlog(file, line, severity, format, args); ret = _vscprintf(format, args);
va_end(args); va_end(args);
}
void gpr_vlog(const char* file, int line, gpr_log_severity severity,
const char* format, va_list args) {
char* message;
int ret = _vscprintf(format, args);
if (ret < 0) { if (ret < 0) {
message = NULL; message = NULL;
} else { } else {
@ -60,8 +58,10 @@ void gpr_vlog(const char* file, int line, gpr_log_severity severity,
message = (char*)gpr_malloc(strp_buflen); message = (char*)gpr_malloc(strp_buflen);
/* Print to the buffer. */ /* Print to the buffer. */
va_start(args, format);
ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args); ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args);
if (GPR_UNLIKELY((size_t)ret != strp_buflen - 1)) { va_end(args);
if ((size_t)ret != strp_buflen - 1) {
/* This should never happen. */ /* This should never happen. */
gpr_free(message); gpr_free(message);
message = NULL; message = NULL;

@ -319,9 +319,10 @@ static grpc_error_handle addbyte(grpc_http_parser* parser, uint8_t byte,
case GRPC_HTTP_FIRST_LINE: case GRPC_HTTP_FIRST_LINE:
case GRPC_HTTP_HEADERS: case GRPC_HTTP_HEADERS:
if (parser->cur_line_length >= GRPC_HTTP_PARSER_MAX_HEADER_LENGTH) { if (parser->cur_line_length >= GRPC_HTTP_PARSER_MAX_HEADER_LENGTH) {
grpc_http1_trace.Log(GPR_ERROR, if (GRPC_TRACE_FLAG_ENABLED(grpc_http1_trace)) {
"HTTP header max line length (%d) exceeded", gpr_log(GPR_ERROR, "HTTP header max line length (%d) exceeded",
GRPC_HTTP_PARSER_MAX_HEADER_LENGTH); GRPC_HTTP_PARSER_MAX_HEADER_LENGTH);
}
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"HTTP header max line length exceeded"); "HTTP header max line length exceeded");
} }

@ -114,25 +114,32 @@ void CallCombiner::ScheduleClosure(grpc_closure* closure,
void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error, void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error,
DEBUG_ARGS const char* reason) { DEBUG_ARGS const char* reason) {
GPR_TIMER_SCOPE("CallCombiner::Start", 0); GPR_TIMER_SCOPE("CallCombiner::Start", 0);
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"==> CallCombiner::Start() [%p] closure=%p [" DEBUG_FMT_STR "==> CallCombiner::Start() [%p] closure=%p [" DEBUG_FMT_STR
"%s] error=%s", "%s] error=%s",
this, closure DEBUG_FMT_ARGS, reason, this, closure DEBUG_FMT_ARGS, reason,
grpc_error_std_string(error).c_str()); grpc_error_std_string(error).c_str());
}
size_t prev_size = size_t prev_size =
static_cast<size_t>(gpr_atm_full_fetch_add(&size_, (gpr_atm)1)); static_cast<size_t>(gpr_atm_full_fetch_add(&size_, (gpr_atm)1));
grpc_call_combiner_trace.Log(GPR_INFO, " size: %" PRIdPTR " -> %" PRIdPTR, if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
prev_size, prev_size + 1); gpr_log(GPR_INFO, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
prev_size + 1);
}
GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(); GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS();
if (prev_size == 0) { if (prev_size == 0) {
GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(); GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED();
GPR_TIMER_MARK("call_combiner_initiate", 0); GPR_TIMER_MARK("call_combiner_initiate", 0);
grpc_call_combiner_trace.Log(GPR_INFO, " EXECUTING IMMEDIATELY"); if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY");
}
// Queue was empty, so execute this closure immediately. // Queue was empty, so execute this closure immediately.
ScheduleClosure(closure, error); ScheduleClosure(closure, error);
} else { } else {
grpc_call_combiner_trace.Log(GPR_INFO, " QUEUING"); if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " QUEUING");
}
// Queue was not empty, so add closure to queue. // Queue was not empty, so add closure to queue.
closure->error_data.error = error; closure->error_data.error = error;
queue_.Push( queue_.Push(
@ -142,35 +149,43 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error,
void CallCombiner::Stop(DEBUG_ARGS const char* reason) { void CallCombiner::Stop(DEBUG_ARGS const char* reason) {
GPR_TIMER_SCOPE("CallCombiner::Stop", 0); GPR_TIMER_SCOPE("CallCombiner::Stop", 0);
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, "==> CallCombiner::Stop() [%p] [" DEBUG_FMT_STR "%s]", gpr_log(GPR_INFO, "==> CallCombiner::Stop() [%p] [" DEBUG_FMT_STR "%s]",
this DEBUG_FMT_ARGS, reason); this DEBUG_FMT_ARGS, reason);
}
size_t prev_size = size_t prev_size =
static_cast<size_t>(gpr_atm_full_fetch_add(&size_, (gpr_atm)-1)); static_cast<size_t>(gpr_atm_full_fetch_add(&size_, (gpr_atm)-1));
grpc_call_combiner_trace.Log(GPR_INFO, " size: %" PRIdPTR " -> %" PRIdPTR, if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
prev_size, prev_size - 1); gpr_log(GPR_INFO, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
prev_size - 1);
}
GPR_ASSERT(prev_size >= 1); GPR_ASSERT(prev_size >= 1);
if (prev_size > 1) { if (prev_size > 1) {
while (true) { while (true) {
grpc_call_combiner_trace.Log(GPR_INFO, " checking queue"); if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " checking queue");
}
bool empty; bool empty;
grpc_closure* closure = grpc_closure* closure =
reinterpret_cast<grpc_closure*>(queue_.PopAndCheckEnd(&empty)); reinterpret_cast<grpc_closure*>(queue_.PopAndCheckEnd(&empty));
if (closure == nullptr) { if (closure == nullptr) {
// This can happen either due to a race condition within the mpscq // This can happen either due to a race condition within the mpscq
// code or because of a race with Start(). // code or because of a race with Start().
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, " queue returned no result; checking again"); gpr_log(GPR_INFO, " queue returned no result; checking again");
}
continue; continue;
} }
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, " EXECUTING FROM QUEUE: closure=%p error=%s", closure, gpr_log(GPR_INFO, " EXECUTING FROM QUEUE: closure=%p error=%s",
grpc_error_std_string(closure->error_data.error).c_str()); closure,
grpc_error_std_string(closure->error_data.error).c_str());
}
ScheduleClosure(closure, closure->error_data.error); ScheduleClosure(closure, closure->error_data.error);
break; break;
} }
} else { } else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
grpc_call_combiner_trace.Log(GPR_INFO, " queue empty"); gpr_log(GPR_INFO, " queue empty");
} }
} }
@ -183,27 +198,31 @@ void CallCombiner::SetNotifyOnCancel(grpc_closure* closure) {
// If error is set, invoke the cancellation closure immediately. // If error is set, invoke the cancellation closure immediately.
// Otherwise, store the new closure. // Otherwise, store the new closure.
if (original_error != GRPC_ERROR_NONE) { if (original_error != GRPC_ERROR_NONE) {
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"call_combiner=%p: scheduling notify_on_cancel callback=%p " "call_combiner=%p: scheduling notify_on_cancel callback=%p "
"for pre-existing cancellation", "for pre-existing cancellation",
this, closure); this, closure);
}
ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_REF(original_error)); ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_REF(original_error));
break; break;
} else { } else {
if (gpr_atm_full_cas(&cancel_state_, original_state, if (gpr_atm_full_cas(&cancel_state_, original_state,
reinterpret_cast<gpr_atm>(closure))) { reinterpret_cast<gpr_atm>(closure))) {
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, "call_combiner=%p: setting notify_on_cancel=%p", this, gpr_log(GPR_INFO, "call_combiner=%p: setting notify_on_cancel=%p",
closure); this, closure);
}
// If we replaced an earlier closure, invoke the original // If we replaced an earlier closure, invoke the original
// closure with GRPC_ERROR_NONE. This allows callers to clean // closure with GRPC_ERROR_NONE. This allows callers to clean
// up any resources they may be holding for the callback. // up any resources they may be holding for the callback.
if (original_state != 0) { if (original_state != 0) {
closure = reinterpret_cast<grpc_closure*>(original_state); closure = reinterpret_cast<grpc_closure*>(original_state);
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, "call_combiner=%p: scheduling old cancel callback=%p", gpr_log(GPR_INFO,
this, closure); "call_combiner=%p: scheduling old cancel callback=%p", this,
closure);
}
ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_NONE); ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_NONE);
} }
break; break;
@ -227,10 +246,11 @@ void CallCombiner::Cancel(grpc_error_handle error) {
if (original_state != 0) { if (original_state != 0) {
grpc_closure* notify_on_cancel = grpc_closure* notify_on_cancel =
reinterpret_cast<grpc_closure*>(original_state); reinterpret_cast<grpc_closure*>(original_state);
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"call_combiner=%p: scheduling notify_on_cancel callback=%p", this, "call_combiner=%p: scheduling notify_on_cancel callback=%p",
notify_on_cancel); this, notify_on_cancel);
}
ExecCtx::Run(DEBUG_LOCATION, notify_on_cancel, GRPC_ERROR_REF(error)); ExecCtx::Run(DEBUG_LOCATION, notify_on_cancel, GRPC_ERROR_REF(error));
} }
break; break;

@ -168,12 +168,14 @@ class CallCombinerClosureList {
GRPC_CALL_COMBINER_START(call_combiner, closure.closure, closure.error, GRPC_CALL_COMBINER_START(call_combiner, closure.closure, closure.error,
closure.reason); closure.reason);
} }
grpc_call_combiner_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"CallCombinerClosureList executing closure while already " "CallCombinerClosureList executing closure while already "
"holding call_combiner %p: closure=%p error=%s reason=%s", "holding call_combiner %p: closure=%p error=%s reason=%s",
call_combiner, closures_[0].closure, call_combiner, closures_[0].closure,
grpc_error_std_string(closures_[0].error).c_str(), closures_[0].reason); grpc_error_std_string(closures_[0].error).c_str(),
closures_[0].reason);
}
// This will release the call combiner. // This will release the call combiner.
ExecCtx::Run(DEBUG_LOCATION, closures_[0].closure, closures_[0].error); ExecCtx::Run(DEBUG_LOCATION, closures_[0].closure, closures_[0].error);
closures_.clear(); closures_.clear();

@ -65,8 +65,10 @@ void CFStreamHandle::ReadCallback(CFReadStreamRef stream,
grpc_error_handle error; grpc_error_handle error;
CFErrorRef stream_error; CFErrorRef stream_error;
CFStreamHandle* handle = static_cast<CFStreamHandle*>(client_callback_info); CFStreamHandle* handle = static_cast<CFStreamHandle*>(client_callback_info);
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream ReadCallback (%p, %p, %lu, %p)", if (grpc_tcp_trace.enabled()) {
handle, stream, type, client_callback_info); gpr_log(GPR_DEBUG, "CFStream ReadCallback (%p, %p, %lu, %p)", handle,
stream, type, client_callback_info);
}
switch (type) { switch (type) {
case kCFStreamEventOpenCompleted: case kCFStreamEventOpenCompleted:
handle->open_event_.SetReady(); handle->open_event_.SetReady();
@ -98,8 +100,10 @@ void CFStreamHandle::WriteCallback(CFWriteStreamRef stream,
grpc_error_handle error; grpc_error_handle error;
CFErrorRef stream_error; CFErrorRef stream_error;
CFStreamHandle* handle = static_cast<CFStreamHandle*>(clientCallBackInfo); CFStreamHandle* handle = static_cast<CFStreamHandle*>(clientCallBackInfo);
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream WriteCallback (%p, %p, %lu, %p)", if (grpc_tcp_trace.enabled()) {
handle, stream, type, clientCallBackInfo); gpr_log(GPR_DEBUG, "CFStream WriteCallback (%p, %p, %lu, %p)", handle,
stream, type, clientCallBackInfo);
}
switch (type) { switch (type) {
case kCFStreamEventOpenCompleted: case kCFStreamEventOpenCompleted:
handle->open_event_.SetReady(); handle->open_event_.SetReady();

@ -235,15 +235,18 @@ class Closure {
return; return;
} }
#ifndef NDEBUG #ifndef NDEBUG
grpc_trace_closure.Log( if (grpc_trace_closure.enabled()) {
GPR_DEBUG, "running closure %p: created [%s:%d]: run [%s:%d]", closure, gpr_log(GPR_DEBUG, "running closure %p: created [%s:%d]: run [%s:%d]",
closure->file_created, closure->line_created, location.file(), closure, closure->file_created, closure->line_created,
location.line()); location.file(), location.line());
}
GPR_ASSERT(closure->cb != nullptr); GPR_ASSERT(closure->cb != nullptr);
#endif #endif
closure->cb(closure->cb_arg, error); closure->cb(closure->cb_arg, error);
#ifndef NDEBUG #ifndef NDEBUG
grpc_trace_closure.Log(GPR_DEBUG, "closure %p finished", closure); if (grpc_trace_closure.enabled()) {
gpr_log(GPR_DEBUG, "closure %p finished", closure);
}
#endif #endif
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
} }

@ -35,6 +35,13 @@
grpc_core::DebugOnlyTraceFlag grpc_combiner_trace(false, "combiner"); grpc_core::DebugOnlyTraceFlag grpc_combiner_trace(false, "combiner");
#define GRPC_COMBINER_TRACE(fn) \
do { \
if (grpc_combiner_trace.enabled()) { \
fn; \
} \
} while (0)
#define STATE_UNORPHANED 1 #define STATE_UNORPHANED 1
#define STATE_ELEM_COUNT_LOW_BIT 2 #define STATE_ELEM_COUNT_LOW_BIT 2
@ -52,34 +59,33 @@ grpc_core::Combiner* grpc_combiner_create(void) {
gpr_atm_no_barrier_store(&lock->state, STATE_UNORPHANED); gpr_atm_no_barrier_store(&lock->state, STATE_UNORPHANED);
grpc_closure_list_init(&lock->final_list); grpc_closure_list_init(&lock->final_list);
GRPC_CLOSURE_INIT(&lock->offload, offload, lock, nullptr); GRPC_CLOSURE_INIT(&lock->offload, offload, lock, nullptr);
grpc_combiner_trace.Log(GPR_INFO, "C:%p create", lock); GRPC_COMBINER_TRACE(gpr_log(GPR_INFO, "C:%p create", lock));
return lock; return lock;
} }
static void really_destroy(grpc_core::Combiner* lock) { static void really_destroy(grpc_core::Combiner* lock) {
grpc_combiner_trace.Log(GPR_INFO, "C:%p really_destroy", lock); GRPC_COMBINER_TRACE(gpr_log(GPR_INFO, "C:%p really_destroy", lock));
GPR_ASSERT(gpr_atm_no_barrier_load(&lock->state) == 0); GPR_ASSERT(gpr_atm_no_barrier_load(&lock->state) == 0);
delete lock; delete lock;
} }
static void start_destroy(grpc_core::Combiner* lock) { static void start_destroy(grpc_core::Combiner* lock) {
gpr_atm old_state = gpr_atm_full_fetch_add(&lock->state, -STATE_UNORPHANED); gpr_atm old_state = gpr_atm_full_fetch_add(&lock->state, -STATE_UNORPHANED);
grpc_combiner_trace.Log(GPR_INFO, "C:%p really_destroy old_state=%" PRIdPTR, GRPC_COMBINER_TRACE(gpr_log(
lock, old_state); GPR_INFO, "C:%p really_destroy old_state=%" PRIdPTR, lock, old_state));
if (old_state == 1) { if (old_state == 1) {
really_destroy(lock); really_destroy(lock);
} }
} }
#ifndef NDEBUG #ifndef NDEBUG
#define GRPC_COMBINER_DEBUG_SPAM(op, delta) \ #define GRPC_COMBINER_DEBUG_SPAM(op, delta) \
do { \ if (grpc_combiner_trace.enabled()) { \
grpc_combiner_trace.Log( \ gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, \
file, line, GPR_LOG_SEVERITY_DEBUG, \ "C:%p %s %" PRIdPTR " --> %" PRIdPTR " %s", lock, (op), \
"C:%p %s %" PRIdPTR " --> %" PRIdPTR " %s", lock, (op), \ gpr_atm_no_barrier_load(&lock->refs.count), \
gpr_atm_no_barrier_load(&lock->refs.count), \ gpr_atm_no_barrier_load(&lock->refs.count) + (delta), reason); \
gpr_atm_no_barrier_load(&lock->refs.count) + (delta), reason); \ }
} while (0)
#else #else
#define GRPC_COMBINER_DEBUG_SPAM(op, delta) #define GRPC_COMBINER_DEBUG_SPAM(op, delta)
#endif #endif
@ -125,9 +131,9 @@ static void combiner_exec(grpc_core::Combiner* lock, grpc_closure* cl,
GPR_TIMER_SCOPE("combiner.execute", 0); GPR_TIMER_SCOPE("combiner.execute", 0);
GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(); GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS();
gpr_atm last = gpr_atm_full_fetch_add(&lock->state, STATE_ELEM_COUNT_LOW_BIT); gpr_atm last = gpr_atm_full_fetch_add(&lock->state, STATE_ELEM_COUNT_LOW_BIT);
grpc_combiner_trace.Log(GPR_INFO, GRPC_COMBINER_TRACE(gpr_log(GPR_INFO,
"C:%p grpc_combiner_execute c=%p last=%" PRIdPTR, "C:%p grpc_combiner_execute c=%p last=%" PRIdPTR,
lock, cl, last); lock, cl, last));
if (last == 1) { if (last == 1) {
GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(); GRPC_STATS_INC_COMBINER_LOCKS_INITIATED();
GPR_TIMER_MARK("combiner.initiated", 0); GPR_TIMER_MARK("combiner.initiated", 0);
@ -171,7 +177,7 @@ static void offload(void* arg, grpc_error_handle /*error*/) {
static void queue_offload(grpc_core::Combiner* lock) { static void queue_offload(grpc_core::Combiner* lock) {
GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(); GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED();
move_next(); move_next();
grpc_combiner_trace.Log(GPR_INFO, "C:%p queue_offload", lock); GRPC_COMBINER_TRACE(gpr_log(GPR_INFO, "C:%p queue_offload", lock));
grpc_core::Executor::Run(&lock->offload, GRPC_ERROR_NONE); grpc_core::Executor::Run(&lock->offload, GRPC_ERROR_NONE);
} }
@ -186,14 +192,14 @@ bool grpc_combiner_continue_exec_ctx() {
bool contended = bool contended =
gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null) == 0; gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null) == 0;
grpc_combiner_trace.Log(GPR_INFO, GRPC_COMBINER_TRACE(gpr_log(GPR_INFO,
"C:%p grpc_combiner_continue_exec_ctx " "C:%p grpc_combiner_continue_exec_ctx "
"contended=%d " "contended=%d "
"exec_ctx_ready_to_finish=%d " "exec_ctx_ready_to_finish=%d "
"time_to_execute_final_list=%d", "time_to_execute_final_list=%d",
lock, contended, lock, contended,
grpc_core::ExecCtx::Get()->IsReadyToFinish(), grpc_core::ExecCtx::Get()->IsReadyToFinish(),
lock->time_to_execute_final_list); lock->time_to_execute_final_list));
// offload only if all the following conditions are true: // offload only if all the following conditions are true:
// 1. the combiner is contended and has more than one closure to execute // 1. the combiner is contended and has more than one closure to execute
@ -215,7 +221,8 @@ bool grpc_combiner_continue_exec_ctx() {
// priority // priority
(gpr_atm_acq_load(&lock->state) >> 1) > 1) { (gpr_atm_acq_load(&lock->state) >> 1) > 1) {
grpc_core::MultiProducerSingleConsumerQueue::Node* n = lock->queue.Pop(); grpc_core::MultiProducerSingleConsumerQueue::Node* n = lock->queue.Pop();
grpc_combiner_trace.Log(GPR_INFO, "C:%p maybe_finish_one n=%p", lock, n); GRPC_COMBINER_TRACE(
gpr_log(GPR_INFO, "C:%p maybe_finish_one n=%p", lock, n));
if (n == nullptr) { if (n == nullptr) {
// queue is in an inconsistent state: use this as a cue that we should // queue is in an inconsistent state: use this as a cue that we should
// go off and do something else for a while (and come back later) // go off and do something else for a while (and come back later)
@ -238,8 +245,8 @@ bool grpc_combiner_continue_exec_ctx() {
int loops = 0; int loops = 0;
while (c != nullptr) { while (c != nullptr) {
GPR_TIMER_SCOPE("combiner.exec_1final", 0); GPR_TIMER_SCOPE("combiner.exec_1final", 0);
grpc_combiner_trace.Log(GPR_INFO, "C:%p execute_final[%d] c=%p", lock, GRPC_COMBINER_TRACE(
loops, c); gpr_log(GPR_INFO, "C:%p execute_final[%d] c=%p", lock, loops, c));
grpc_closure* next = c->next_data.next; grpc_closure* next = c->next_data.next;
grpc_error_handle error = c->error_data.error; grpc_error_handle error = c->error_data.error;
#ifndef NDEBUG #ifndef NDEBUG
@ -256,8 +263,8 @@ bool grpc_combiner_continue_exec_ctx() {
lock->time_to_execute_final_list = false; lock->time_to_execute_final_list = false;
gpr_atm old_state = gpr_atm old_state =
gpr_atm_full_fetch_add(&lock->state, -STATE_ELEM_COUNT_LOW_BIT); gpr_atm_full_fetch_add(&lock->state, -STATE_ELEM_COUNT_LOW_BIT);
grpc_combiner_trace.Log(GPR_INFO, "C:%p finish old_state=%" PRIdPTR, lock, GRPC_COMBINER_TRACE(
old_state); gpr_log(GPR_INFO, "C:%p finish old_state=%" PRIdPTR, lock, old_state));
// Define a macro to ease readability of the following switch statement. // Define a macro to ease readability of the following switch statement.
#define OLD_STATE_WAS(orphaned, elem_count) \ #define OLD_STATE_WAS(orphaned, elem_count) \
(((orphaned) ? 0 : STATE_UNORPHANED) | \ (((orphaned) ? 0 : STATE_UNORPHANED) | \
@ -300,9 +307,9 @@ static void combiner_finally_exec(grpc_core::Combiner* lock,
GPR_ASSERT(lock != nullptr); GPR_ASSERT(lock != nullptr);
GPR_TIMER_SCOPE("combiner.execute_finally", 0); GPR_TIMER_SCOPE("combiner.execute_finally", 0);
GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(); GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS();
grpc_combiner_trace.Log( GRPC_COMBINER_TRACE(gpr_log(
GPR_INFO, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, closure, GPR_INFO, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, closure,
grpc_core::ExecCtx::Get()->combiner_data()->active_combiner); grpc_core::ExecCtx::Get()->combiner_data()->active_combiner));
if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner != lock) { if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner != lock) {
GPR_TIMER_MARK("slowpath", 0); GPR_TIMER_MARK("slowpath", 0);
// Using error_data.scratch to store the combiner so that it can be accessed // Using error_data.scratch to store the combiner so that it can be accessed

@ -136,10 +136,11 @@ static void CallReadCb(CFStreamEndpoint* ep, grpc_error_handle error) {
} }
static void CallWriteCb(CFStreamEndpoint* ep, grpc_error_handle error) { static void CallWriteCb(CFStreamEndpoint* ep, grpc_error_handle error) {
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream endpoint:%p call_write_cb %p %p:%p", if (grpc_tcp_trace.enabled()) {
ep, ep->write_cb, ep->write_cb->cb, ep->write_cb->cb_arg); gpr_log(GPR_DEBUG, "CFStream endpoint:%p call_write_cb %p %p:%p", ep,
grpc_tcp_trace.Log(GPR_DEBUG, "write: error=%s", ep->write_cb, ep->write_cb->cb, ep->write_cb->cb_arg);
grpc_error_std_string(error).c_str()); gpr_log(GPR_DEBUG, "write: error=%s", grpc_error_std_string(error).c_str());
}
grpc_closure* cb = ep->write_cb; grpc_closure* cb = ep->write_cb;
ep->write_cb = nullptr; ep->write_cb = nullptr;
ep->write_slices = nullptr; ep->write_slices = nullptr;
@ -252,8 +253,10 @@ static void CFStreamReadAllocationDone(void* arg, grpc_error_handle error) {
static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices, static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices,
grpc_closure* cb, bool urgent) { grpc_closure* cb, bool urgent) {
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep); CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream endpoint:%p read (%p, %p) length:%zu", if (grpc_tcp_trace.enabled()) {
ep_impl, slices, cb, slices->length); gpr_log(GPR_DEBUG, "CFStream endpoint:%p read (%p, %p) length:%zu", ep_impl,
slices, cb, slices->length);
}
GPR_ASSERT(ep_impl->read_cb == nullptr); GPR_ASSERT(ep_impl->read_cb == nullptr);
ep_impl->read_cb = cb; ep_impl->read_cb = cb;
ep_impl->read_slices = slices; ep_impl->read_slices = slices;
@ -270,9 +273,10 @@ static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices,
static void CFStreamWrite(grpc_endpoint* ep, grpc_slice_buffer* slices, static void CFStreamWrite(grpc_endpoint* ep, grpc_slice_buffer* slices,
grpc_closure* cb, void* arg) { grpc_closure* cb, void* arg) {
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep); CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
grpc_tcp_trace.Log(GPR_DEBUG, if (grpc_tcp_trace.enabled()) {
"CFStream endpoint:%p write (%p, %p) length:%zu", ep_impl, gpr_log(GPR_DEBUG, "CFStream endpoint:%p write (%p, %p) length:%zu",
slices, cb, slices->length); ep_impl, slices, cb, slices->length);
}
GPR_ASSERT(ep_impl->write_cb == nullptr); GPR_ASSERT(ep_impl->write_cb == nullptr);
ep_impl->write_cb = cb; ep_impl->write_cb = cb;
ep_impl->write_slices = slices; ep_impl->write_slices = slices;
@ -282,18 +286,22 @@ static void CFStreamWrite(grpc_endpoint* ep, grpc_slice_buffer* slices,
void CFStreamShutdown(grpc_endpoint* ep, grpc_error_handle why) { void CFStreamShutdown(grpc_endpoint* ep, grpc_error_handle why) {
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep); CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream endpoint:%p shutdown (%p)", ep_impl, if (grpc_tcp_trace.enabled()) {
why); gpr_log(GPR_DEBUG, "CFStream endpoint:%p shutdown (%p)", ep_impl, why);
}
CFReadStreamClose(ep_impl->read_stream); CFReadStreamClose(ep_impl->read_stream);
CFWriteStreamClose(ep_impl->write_stream); CFWriteStreamClose(ep_impl->write_stream);
ep_impl->stream_sync->Shutdown(why); ep_impl->stream_sync->Shutdown(why);
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream endpoint:%p shutdown DONE (%p)", if (grpc_tcp_trace.enabled()) {
ep_impl, why); gpr_log(GPR_DEBUG, "CFStream endpoint:%p shutdown DONE (%p)", ep_impl, why);
}
} }
void CFStreamDestroy(grpc_endpoint* ep) { void CFStreamDestroy(grpc_endpoint* ep) {
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep); CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
grpc_tcp_trace.Log(GPR_DEBUG, "CFStream endpoint:%p destroy", ep_impl); if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "CFStream endpoint:%p destroy", ep_impl);
}
EP_UNREF(ep_impl, "destroy"); EP_UNREF(ep_impl, "destroy");
} }
@ -333,9 +341,11 @@ grpc_endpoint* grpc_cfstream_endpoint_create(
const char* peer_string, grpc_slice_allocator* slice_allocator, const char* peer_string, grpc_slice_allocator* slice_allocator,
CFStreamHandle* stream_sync) { CFStreamHandle* stream_sync) {
CFStreamEndpoint* ep_impl = new CFStreamEndpoint; CFStreamEndpoint* ep_impl = new CFStreamEndpoint;
grpc_tcp_trace.Log( if (grpc_tcp_trace.enabled()) {
GPR_DEBUG, "CFStream endpoint:%p create readStream:%p writeStream: %p", gpr_log(GPR_DEBUG,
ep_impl, read_stream, write_stream); "CFStream endpoint:%p create readStream:%p writeStream: %p",
ep_impl, read_stream, write_stream);
}
ep_impl->base.vtable = &vtable; ep_impl->base.vtable = &vtable;
gpr_ref_init(&ep_impl->refcount, 1); gpr_ref_init(&ep_impl->refcount, 1);
ep_impl->read_stream = read_stream; ep_impl->read_stream = read_stream;

@ -231,10 +231,11 @@ static const char* error_time_name(grpc_error_times key) {
#ifndef NDEBUG #ifndef NDEBUG
grpc_error_handle grpc_error_do_ref(grpc_error_handle err, const char* file, grpc_error_handle grpc_error_do_ref(grpc_error_handle err, const char* file,
int line) { int line) {
grpc_trace_error_refcount.Log( if (grpc_trace_error_refcount.enabled()) {
GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err, gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err,
gpr_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count),
gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line); gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line);
}
gpr_ref(&err->atomics.refs); gpr_ref(&err->atomics.refs);
return err; return err;
} }
@ -278,10 +279,11 @@ static void error_destroy(grpc_error_handle err) {
#ifndef NDEBUG #ifndef NDEBUG
void grpc_error_do_unref(grpc_error_handle err, const char* file, int line) { void grpc_error_do_unref(grpc_error_handle err, const char* file, int line) {
grpc_trace_error_refcount.Log( if (grpc_trace_error_refcount.enabled()) {
GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err, gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err,
gpr_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count),
gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line); gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line);
}
if (gpr_unref(&err->atomics.refs)) { if (gpr_unref(&err->atomics.refs)) {
error_destroy(err); error_destroy(err);
} }
@ -303,12 +305,18 @@ static uint8_t get_placement(grpc_error_handle* err, size_t size) {
if ((*err)->arena_size + slots > (*err)->arena_capacity) { if ((*err)->arena_size + slots > (*err)->arena_capacity) {
return UINT8_MAX; return UINT8_MAX;
} }
#ifndef NDEBUG
grpc_error_handle orig = *err; grpc_error_handle orig = *err;
#endif
*err = static_cast<grpc_error_handle>(gpr_realloc( *err = static_cast<grpc_error_handle>(gpr_realloc(
*err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t))); *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t)));
if (*err != orig) { #ifndef NDEBUG
grpc_trace_error_refcount.Log(GPR_DEBUG, "realloc %p -> %p", orig, *err); if (grpc_trace_error_refcount.enabled()) {
if (*err != orig) {
gpr_log(GPR_DEBUG, "realloc %p -> %p", orig, *err);
}
} }
#endif
} }
uint8_t placement = (*err)->arena_size; uint8_t placement = (*err)->arena_size;
(*err)->arena_size = static_cast<uint8_t>((*err)->arena_size + slots); (*err)->arena_size = static_cast<uint8_t>((*err)->arena_size + slots);
@ -426,8 +434,9 @@ grpc_error_handle grpc_error_create(const char* file, int line,
file, line); file, line);
abort(); abort();
} }
grpc_trace_error_refcount.Log(GPR_DEBUG, "%p create [%s:%d]", err, file, if (grpc_trace_error_refcount.enabled()) {
line); gpr_log(GPR_DEBUG, "%p create [%s:%d]", err, file, line);
}
#endif #endif
err->arena_size = 0; err->arena_size = 0;
@ -508,7 +517,11 @@ static grpc_error_handle copy_error_and_unref(grpc_error_handle in) {
} }
out = static_cast<grpc_error_handle>( out = static_cast<grpc_error_handle>(
gpr_malloc(sizeof(*in) + new_arena_capacity * sizeof(intptr_t))); gpr_malloc(sizeof(*in) + new_arena_capacity * sizeof(intptr_t)));
grpc_trace_error_refcount.Log(GPR_DEBUG, "%p create copying %p", out, in); #ifndef NDEBUG
if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p create copying %p", out, in);
}
#endif
// bulk memcpy of the rest of the struct. // bulk memcpy of the rest of the struct.
// NOLINTNEXTLINE(bugprone-sizeof-expression) // NOLINTNEXTLINE(bugprone-sizeof-expression)
size_t skip = sizeof(&out->atomics); size_t skip = sizeof(&out->atomics);

@ -42,8 +42,10 @@
grpc_core::DebugOnlyTraceFlag grpc_apple_polling_trace(false, "apple_polling"); grpc_core::DebugOnlyTraceFlag grpc_apple_polling_trace(false, "apple_polling");
#ifndef NDEBUG #ifndef NDEBUG
#define GRPC_POLLING_TRACE(format, ...) \ #define GRPC_POLLING_TRACE(format, ...) \
grpc_apple_polling_trace.Log(GPR_DEBUG, "(polling) " format, __VA_ARGS__); if (GRPC_TRACE_FLAG_ENABLED(grpc_apple_polling_trace)) { \
gpr_log(GPR_DEBUG, "(polling) " format, __VA_ARGS__); \
}
#else #else
#define GRPC_POLLING_TRACE(...) #define GRPC_POLLING_TRACE(...)
#endif // NDEBUG #endif // NDEBUG

@ -355,8 +355,11 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) {
std::string fd_name = absl::StrCat(name, " fd=", fd); std::string fd_name = absl::StrCat(name, " fd=", fd);
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name.c_str()); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name.c_str());
fork_fd_list_add_grpc_fd(new_fd); fork_fd_list_add_grpc_fd(new_fd);
grpc_trace_fd_refcount.Log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, #ifndef NDEBUG
fd_name.c_str()); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name.c_str());
}
#endif
struct epoll_event ev; struct epoll_event ev;
ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLOUT | EPOLLET); ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLOUT | EPOLLET);
@ -729,7 +732,9 @@ static grpc_error_handle do_epoll_wait(grpc_pollset* ps, grpc_millis deadline) {
GRPC_STATS_INC_POLL_EVENTS_RETURNED(r); GRPC_STATS_INC_POLL_EVENTS_RETURNED(r);
grpc_polling_trace.Log(GPR_INFO, "ps: %p poll got %d events", ps, r); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "ps: %p poll got %d events", ps, r);
}
gpr_atm_rel_store(&g_epoll_set.num_events, r); gpr_atm_rel_store(&g_epoll_set.num_events, r);
gpr_atm_rel_store(&g_epoll_set.cursor, 0); gpr_atm_rel_store(&g_epoll_set.cursor, 0);
@ -747,7 +752,9 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT; worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT;
pollset->begin_refs++; pollset->begin_refs++;
grpc_polling_trace.Log(GPR_INFO, "PS:%p BEGIN_STARTS:%p", pollset, worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p BEGIN_STARTS:%p", pollset, worker);
}
if (pollset->seen_inactive) { if (pollset->seen_inactive) {
// pollset has been observed to be inactive, we need to move back to the // pollset has been observed to be inactive, we need to move back to the
@ -764,9 +771,11 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
retry_lock_neighborhood: retry_lock_neighborhood:
gpr_mu_lock(&neighborhood->mu); gpr_mu_lock(&neighborhood->mu);
gpr_mu_lock(&pollset->mu); gpr_mu_lock(&pollset->mu);
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d", gpr_log(GPR_INFO, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d",
pollset, worker, kick_state_string(worker->state), is_reassigning); pollset, worker, kick_state_string(worker->state),
is_reassigning);
}
if (pollset->seen_inactive) { if (pollset->seen_inactive) {
if (neighborhood != pollset->neighborhood) { if (neighborhood != pollset->neighborhood) {
gpr_mu_unlock(&neighborhood->mu); gpr_mu_unlock(&neighborhood->mu);
@ -815,9 +824,11 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
worker->initialized_cv = true; worker->initialized_cv = true;
gpr_cv_init(&worker->cv); gpr_cv_init(&worker->cv);
while (worker->state == UNKICKED && !pollset->shutting_down) { while (worker->state == UNKICKED && !pollset->shutting_down) {
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d", pollset, gpr_log(GPR_INFO, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d",
worker, kick_state_string(worker->state), pollset->shutting_down); pollset, worker, kick_state_string(worker->state),
pollset->shutting_down);
}
if (gpr_cv_wait(&worker->cv, &pollset->mu, if (gpr_cv_wait(&worker->cv, &pollset->mu,
grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)) && grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)) &&
@ -830,12 +841,13 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
grpc_core::ExecCtx::Get()->InvalidateNow(); grpc_core::ExecCtx::Get()->InvalidateNow();
} }
grpc_polling_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
"PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d " gpr_log(GPR_INFO,
"kicked_without_poller: %d", "PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d "
pollset, worker, kick_state_string(worker->state), "kicked_without_poller: %d",
pollset->shutting_down, pollset, worker, kick_state_string(worker->state),
pollset->kicked_without_poller); pollset->shutting_down, pollset->kicked_without_poller);
}
/* We release pollset lock in this function at a couple of places: /* We release pollset lock in this function at a couple of places:
* 1. Briefly when assigning pollset to a neighborhood * 1. Briefly when assigning pollset to a neighborhood
@ -873,8 +885,10 @@ static bool check_neighborhood_for_available_poller(
if (gpr_atm_no_barrier_cas( if (gpr_atm_no_barrier_cas(
&g_active_poller, 0, &g_active_poller, 0,
reinterpret_cast<gpr_atm>(inspect_worker))) { reinterpret_cast<gpr_atm>(inspect_worker))) {
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, " .. choose next poller to be %p", inspect_worker); gpr_log(GPR_INFO, " .. choose next poller to be %p",
inspect_worker);
}
SET_KICK_STATE(inspect_worker, DESIGNATED_POLLER); SET_KICK_STATE(inspect_worker, DESIGNATED_POLLER);
if (inspect_worker->initialized_cv) { if (inspect_worker->initialized_cv) {
GPR_TIMER_MARK("signal worker", 0); GPR_TIMER_MARK("signal worker", 0);
@ -882,8 +896,9 @@ static bool check_neighborhood_for_available_poller(
gpr_cv_signal(&inspect_worker->cv); gpr_cv_signal(&inspect_worker->cv);
} }
} else { } else {
grpc_polling_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
" .. beaten to choose next poller"); gpr_log(GPR_INFO, " .. beaten to choose next poller");
}
} }
// even if we didn't win the cas, there's a worker, we can stop // even if we didn't win the cas, there's a worker, we can stop
found_worker = true; found_worker = true;
@ -899,7 +914,9 @@ static bool check_neighborhood_for_available_poller(
} while (!found_worker && inspect_worker != inspect->root_worker); } while (!found_worker && inspect_worker != inspect->root_worker);
} }
if (!found_worker) { if (!found_worker) {
grpc_polling_trace.Log(GPR_INFO, " .. mark pollset %p inactive", inspect); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. mark pollset %p inactive", inspect);
}
inspect->seen_inactive = true; inspect->seen_inactive = true;
if (inspect == neighborhood->active_root) { if (inspect == neighborhood->active_root) {
neighborhood->active_root = neighborhood->active_root =
@ -917,7 +934,9 @@ static bool check_neighborhood_for_available_poller(
static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
grpc_pollset_worker** worker_hdl) { grpc_pollset_worker** worker_hdl) {
GPR_TIMER_SCOPE("end_worker", 0); GPR_TIMER_SCOPE("end_worker", 0);
grpc_polling_trace.Log(GPR_INFO, "PS:%p END_WORKER:%p", pollset, worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p END_WORKER:%p", pollset, worker);
}
if (worker_hdl != nullptr) *worker_hdl = nullptr; if (worker_hdl != nullptr) *worker_hdl = nullptr;
/* Make sure we appear kicked */ /* Make sure we appear kicked */
SET_KICK_STATE(worker, KICKED); SET_KICK_STATE(worker, KICKED);
@ -926,8 +945,9 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
if (gpr_atm_no_barrier_load(&g_active_poller) == if (gpr_atm_no_barrier_load(&g_active_poller) ==
reinterpret_cast<gpr_atm>(worker)) { reinterpret_cast<gpr_atm>(worker)) {
if (worker->next != worker && worker->next->state == UNKICKED) { if (worker->next != worker && worker->next->state == UNKICKED) {
grpc_polling_trace.Log(GPR_INFO, " .. choose next poller to be peer %p", if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
worker); gpr_log(GPR_INFO, " .. choose next poller to be peer %p", worker);
}
GPR_ASSERT(worker->next->initialized_cv); GPR_ASSERT(worker->next->initialized_cv);
gpr_atm_no_barrier_store(&g_active_poller, (gpr_atm)worker->next); gpr_atm_no_barrier_store(&g_active_poller, (gpr_atm)worker->next);
SET_KICK_STATE(worker->next, DESIGNATED_POLLER); SET_KICK_STATE(worker->next, DESIGNATED_POLLER);
@ -977,7 +997,9 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
if (worker->initialized_cv) { if (worker->initialized_cv) {
gpr_cv_destroy(&worker->cv); gpr_cv_destroy(&worker->cv);
} }
grpc_polling_trace.Log(GPR_INFO, " .. remove worker"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. remove worker");
}
if (EMPTIED == worker_remove(pollset, worker)) { if (EMPTIED == worker_remove(pollset, worker)) {
pollset_maybe_finish_shutdown(pollset); pollset_maybe_finish_shutdown(pollset);
} }
@ -1070,18 +1092,24 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
if (root_worker == nullptr) { if (root_worker == nullptr) {
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER();
pollset->kicked_without_poller = true; pollset->kicked_without_poller = true;
grpc_polling_trace.Log(GPR_INFO, " .. kicked_without_poller"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kicked_without_poller");
}
goto done; goto done;
} }
grpc_pollset_worker* next_worker = root_worker->next; grpc_pollset_worker* next_worker = root_worker->next;
if (root_worker->state == KICKED) { if (root_worker->state == KICKED) {
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); GRPC_STATS_INC_POLLSET_KICKED_AGAIN();
grpc_polling_trace.Log(GPR_INFO, " .. already kicked %p", root_worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. already kicked %p", root_worker);
}
SET_KICK_STATE(root_worker, KICKED); SET_KICK_STATE(root_worker, KICKED);
goto done; goto done;
} else if (next_worker->state == KICKED) { } else if (next_worker->state == KICKED) {
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); GRPC_STATS_INC_POLLSET_KICKED_AGAIN();
grpc_polling_trace.Log(GPR_INFO, " .. already kicked %p", next_worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. already kicked %p", next_worker);
}
SET_KICK_STATE(next_worker, KICKED); SET_KICK_STATE(next_worker, KICKED);
goto done; goto done;
} else if (root_worker == next_worker && // only try and wake up a poller } else if (root_worker == next_worker && // only try and wake up a poller
@ -1090,23 +1118,29 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
reinterpret_cast<grpc_pollset_worker*>( reinterpret_cast<grpc_pollset_worker*>(
gpr_atm_no_barrier_load(&g_active_poller))) { gpr_atm_no_barrier_load(&g_active_poller))) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD();
grpc_polling_trace.Log(GPR_INFO, " .. kicked %p", root_worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kicked %p", root_worker);
}
SET_KICK_STATE(root_worker, KICKED); SET_KICK_STATE(root_worker, KICKED);
ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd);
goto done; goto done;
} else if (next_worker->state == UNKICKED) { } else if (next_worker->state == UNKICKED) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV();
grpc_polling_trace.Log(GPR_INFO, " .. kicked %p", next_worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kicked %p", next_worker);
}
GPR_ASSERT(next_worker->initialized_cv); GPR_ASSERT(next_worker->initialized_cv);
SET_KICK_STATE(next_worker, KICKED); SET_KICK_STATE(next_worker, KICKED);
gpr_cv_signal(&next_worker->cv); gpr_cv_signal(&next_worker->cv);
goto done; goto done;
} else if (next_worker->state == DESIGNATED_POLLER) { } else if (next_worker->state == DESIGNATED_POLLER) {
if (root_worker->state != DESIGNATED_POLLER) { if (root_worker->state != DESIGNATED_POLLER) {
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, gpr_log(
" .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)", GPR_INFO,
root_worker, root_worker->initialized_cv, next_worker); " .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)",
root_worker, root_worker->initialized_cv, next_worker);
}
SET_KICK_STATE(root_worker, KICKED); SET_KICK_STATE(root_worker, KICKED);
if (root_worker->initialized_cv) { if (root_worker->initialized_cv) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV();
@ -1115,8 +1149,10 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
goto done; goto done;
} else { } else {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD();
grpc_polling_trace.Log(GPR_INFO, " .. non-root poller %p (root=%p)", if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
next_worker, root_worker); gpr_log(GPR_INFO, " .. non-root poller %p (root=%p)", next_worker,
root_worker);
}
SET_KICK_STATE(next_worker, KICKED); SET_KICK_STATE(next_worker, KICKED);
ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd);
goto done; goto done;
@ -1129,7 +1165,9 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
} }
} else { } else {
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD();
grpc_polling_trace.Log(GPR_INFO, " .. kicked while waking up"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kicked while waking up");
}
goto done; goto done;
} }
@ -1137,30 +1175,40 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
} }
if (specific_worker->state == KICKED) { if (specific_worker->state == KICKED) {
grpc_polling_trace.Log(GPR_INFO, " .. specific worker already kicked"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. specific worker already kicked");
}
goto done; goto done;
} else if (g_current_thread_worker == specific_worker) { } else if (g_current_thread_worker == specific_worker) {
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD();
grpc_polling_trace.Log(GPR_INFO, " .. mark %p kicked", specific_worker); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. mark %p kicked", specific_worker);
}
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
goto done; goto done;
} else if (specific_worker == } else if (specific_worker ==
reinterpret_cast<grpc_pollset_worker*>( reinterpret_cast<grpc_pollset_worker*>(
gpr_atm_no_barrier_load(&g_active_poller))) { gpr_atm_no_barrier_load(&g_active_poller))) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD();
grpc_polling_trace.Log(GPR_INFO, " .. kick active poller"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kick active poller");
}
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd);
goto done; goto done;
} else if (specific_worker->initialized_cv) { } else if (specific_worker->initialized_cv) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV();
grpc_polling_trace.Log(GPR_INFO, " .. kick waiting worker"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kick waiting worker");
}
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
gpr_cv_signal(&specific_worker->cv); gpr_cv_signal(&specific_worker->cv);
goto done; goto done;
} else { } else {
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); GRPC_STATS_INC_POLLSET_KICKED_AGAIN();
grpc_polling_trace.Log(GPR_INFO, " .. kick non-waiting worker"); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, " .. kick non-waiting worker");
}
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
goto done; goto done;
} }

@ -171,8 +171,11 @@ struct grpc_fd {
std::string fd_name = absl::StrCat(name, " fd=", fd); std::string fd_name = absl::StrCat(name, " fd=", fd);
grpc_iomgr_register_object(&iomgr_object, fd_name.c_str()); grpc_iomgr_register_object(&iomgr_object, fd_name.c_str());
grpc_trace_fd_refcount.Log(GPR_DEBUG, "FD %d %p create %s", fd, this, #ifndef NDEBUG
fd_name.c_str()); if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, this, fd_name.c_str());
}
#endif
} }
// This is really the dtor, but the poller threads waking up from // This is really the dtor, but the poller threads waking up from
@ -346,10 +349,12 @@ static gpr_mu fd_freelist_mu;
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file,
int line) { int line) {
grpc_trace_fd_refcount.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
GPR_DEBUG, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", gpr_log(GPR_DEBUG,
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line); fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
}
#else #else
#define REF_BY(fd, n, reason) \ #define REF_BY(fd, n, reason) \
do { \ do { \
@ -381,10 +386,12 @@ static void fd_destroy(void* arg, grpc_error_handle /*error*/) {
#ifndef NDEBUG #ifndef NDEBUG
static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file, static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file,
int line) { int line) {
grpc_trace_fd_refcount.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
GPR_DEBUG, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", gpr_log(GPR_DEBUG,
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line); fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
}
#else #else
static void unref_by(grpc_fd* fd, int n) { static void unref_by(grpc_fd* fd, int n) {
#endif #endif
@ -606,8 +613,9 @@ static grpc_error_handle pollable_add_fd(pollable* p, grpc_fd* fd) {
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
static const char* err_desc = "pollable_add_fd"; static const char* err_desc = "pollable_add_fd";
const int epfd = p->epfd; const int epfd = p->epfd;
grpc_polling_trace.Log(GPR_INFO, "add fd %p (%d) to pollable %p", fd, fd->fd, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
p); gpr_log(GPR_INFO, "add fd %p (%d) to pollable %p", fd, fd->fd, p);
}
struct epoll_event ev_fd; struct epoll_event ev_fd;
ev_fd.events = ev_fd.events =
@ -649,12 +657,13 @@ static void pollset_global_shutdown(void) {
/* pollset->mu must be held while calling this function */ /* pollset->mu must be held while calling this function */
static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) {
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) " "PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) "
"rw=%p (target:NULL) cpsc=%d (target:0)", "rw=%p (target:NULL) cpsc=%d (target:0)",
pollset, pollset->active_pollable, pollset->shutdown_closure, pollset, pollset->active_pollable, pollset->shutdown_closure,
pollset->root_worker, pollset->containing_pollset_set_count); pollset->root_worker, pollset->containing_pollset_set_count);
}
if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr &&
pollset->containing_pollset_set_count == 0) { pollset->containing_pollset_set_count == 0) {
GPR_TIMER_MARK("pollset_finish_shutdown", 0); GPR_TIMER_MARK("pollset_finish_shutdown", 0);
@ -674,27 +683,34 @@ static grpc_error_handle kick_one_worker(grpc_pollset_worker* specific_worker) {
grpc_core::MutexLockForGprMu lock(&p->mu); grpc_core::MutexLockForGprMu lock(&p->mu);
GPR_ASSERT(specific_worker != nullptr); GPR_ASSERT(specific_worker != nullptr);
if (specific_worker->kicked) { if (specific_worker->kicked) {
grpc_polling_trace.Log(GPR_INFO, "PS:%p kicked_specific_but_already_kicked", if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
p); gpr_log(GPR_INFO, "PS:%p kicked_specific_but_already_kicked", p);
}
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); GRPC_STATS_INC_POLLSET_KICKED_AGAIN();
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
if (g_current_thread_worker == specific_worker) { if (g_current_thread_worker == specific_worker) {
grpc_polling_trace.Log(GPR_INFO, "PS:%p kicked_specific_but_awake", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p kicked_specific_but_awake", p);
}
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD();
specific_worker->kicked = true; specific_worker->kicked = true;
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
if (specific_worker == p->root_worker) { if (specific_worker == p->root_worker) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD();
grpc_polling_trace.Log(GPR_INFO, "PS:%p kicked_specific_via_wakeup_fd", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p kicked_specific_via_wakeup_fd", p);
}
specific_worker->kicked = true; specific_worker->kicked = true;
grpc_error_handle error = grpc_wakeup_fd_wakeup(&p->wakeup); grpc_error_handle error = grpc_wakeup_fd_wakeup(&p->wakeup);
return error; return error;
} }
if (specific_worker->initialized_cv) { if (specific_worker->initialized_cv) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV();
grpc_polling_trace.Log(GPR_INFO, "PS:%p kicked_specific_via_cv", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p kicked_specific_via_cv", p);
}
specific_worker->kicked = true; specific_worker->kicked = true;
gpr_cv_signal(&specific_worker->cv); gpr_cv_signal(&specific_worker->cv);
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
@ -708,17 +724,19 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
grpc_pollset_worker* specific_worker) { grpc_pollset_worker* specific_worker) {
GPR_TIMER_SCOPE("pollset_kick", 0); GPR_TIMER_SCOPE("pollset_kick", 0);
GRPC_STATS_INC_POLLSET_KICK(); GRPC_STATS_INC_POLLSET_KICK();
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p", "PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p",
pollset, specific_worker, static_cast<void*>(g_current_thread_pollset), pollset, specific_worker,
static_cast<void*>(g_current_thread_worker), pollset->root_worker); static_cast<void*>(g_current_thread_pollset),
static_cast<void*>(g_current_thread_worker), pollset->root_worker);
}
if (specific_worker == nullptr) { if (specific_worker == nullptr) {
if (g_current_thread_pollset != pollset) { if (g_current_thread_pollset != pollset) {
if (pollset->root_worker == nullptr) { if (pollset->root_worker == nullptr) {
grpc_polling_trace.Log(GPR_INFO, "PS:%p kicked_any_without_poller", if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p kicked_any_without_poller", pollset);
pollset); }
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER();
pollset->kicked_without_poller = true; pollset->kicked_without_poller = true;
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
@ -742,7 +760,9 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
pollset->root_worker->links[PWLINK_POLLSET].next); pollset->root_worker->links[PWLINK_POLLSET].next);
} }
} else { } else {
grpc_polling_trace.Log(GPR_INFO, "PS:%p kicked_any_but_awake", pollset); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PS:%p kicked_any_but_awake", pollset);
}
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD();
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
@ -860,8 +880,9 @@ static grpc_error_handle pollable_process_events(grpc_pollset* pollset,
struct epoll_event* ev = &pollable_obj->events[n]; struct epoll_event* ev = &pollable_obj->events[n];
void* data_ptr = ev->data.ptr; void* data_ptr = ev->data.ptr;
if (1 & reinterpret_cast<intptr_t>(data_ptr)) { if (1 & reinterpret_cast<intptr_t>(data_ptr)) {
grpc_polling_trace.Log(GPR_INFO, "PS:%p got pollset_wakeup %p", pollset, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
data_ptr); gpr_log(GPR_INFO, "PS:%p got pollset_wakeup %p", pollset, data_ptr);
}
append_error( append_error(
&error, &error,
grpc_wakeup_fd_consume_wakeup(reinterpret_cast<grpc_wakeup_fd*>( grpc_wakeup_fd_consume_wakeup(reinterpret_cast<grpc_wakeup_fd*>(
@ -878,10 +899,12 @@ static grpc_error_handle pollable_process_events(grpc_pollset* pollset,
bool write_ev = (ev->events & EPOLLOUT) != 0; bool write_ev = (ev->events & EPOLLOUT) != 0;
bool err_fallback = error && !track_err; bool err_fallback = error && !track_err;
grpc_polling_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
"PS:%p got fd %p: cancel=%d read=%d " gpr_log(GPR_INFO,
"write=%d", "PS:%p got fd %p: cancel=%d read=%d "
pollset, fd, cancel, read_ev, write_ev); "write=%d",
pollset, fd, cancel, read_ev, write_ev);
}
if (error && !err_fallback) { if (error && !err_fallback) {
fd_has_errors(fd); fd_has_errors(fd);
} }
@ -908,8 +931,10 @@ static grpc_error_handle pollable_epoll(pollable* p, grpc_millis deadline) {
GPR_TIMER_SCOPE("pollable_epoll", 0); GPR_TIMER_SCOPE("pollable_epoll", 0);
int timeout = poll_deadline_to_millis_timeout(deadline); int timeout = poll_deadline_to_millis_timeout(deadline);
grpc_polling_trace.Log(GPR_INFO, "POLLABLE:%p[%s] poll for %dms", p, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
pollable_desc(p).c_str(), timeout); gpr_log(GPR_INFO, "POLLABLE:%p[%s] poll for %dms", p,
pollable_desc(p).c_str(), timeout);
}
if (timeout != 0) { if (timeout != 0) {
GRPC_SCHEDULING_START_BLOCKING_REGION; GRPC_SCHEDULING_START_BLOCKING_REGION;
@ -925,7 +950,9 @@ static grpc_error_handle pollable_epoll(pollable* p, grpc_millis deadline) {
if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait");
grpc_polling_trace.Log(GPR_INFO, "POLLABLE:%p got %d events", p, r); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "POLLABLE:%p got %d events", p, r);
}
p->event_cursor = 0; p->event_cursor = 0;
p->event_count = r; p->event_count = r;
@ -1002,16 +1029,21 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
while (do_poll && worker->pollable_obj->root_worker != worker) { while (do_poll && worker->pollable_obj->root_worker != worker) {
if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu, if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu,
grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) { grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) {
grpc_polling_trace.Log(GPR_INFO, "PS:%p timeout_wait %p w=%p", pollset, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
worker->pollable_obj, worker); gpr_log(GPR_INFO, "PS:%p timeout_wait %p w=%p", pollset,
worker->pollable_obj, worker);
}
do_poll = false; do_poll = false;
} else if (worker->kicked) { } else if (worker->kicked) {
grpc_polling_trace.Log(GPR_INFO, "PS:%p wakeup %p w=%p", pollset, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
worker->pollable_obj, worker); gpr_log(GPR_INFO, "PS:%p wakeup %p w=%p", pollset,
worker->pollable_obj, worker);
}
do_poll = false; do_poll = false;
} else if (worker->pollable_obj->root_worker != worker) { } else if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace) &&
grpc_polling_trace.Log(GPR_INFO, "PS:%p spurious_wakeup %p w=%p", worker->pollable_obj->root_worker != worker) {
pollset, worker->pollable_obj, worker); gpr_log(GPR_INFO, "PS:%p spurious_wakeup %p w=%p", pollset,
worker->pollable_obj, worker);
} }
} }
grpc_core::ExecCtx::Get()->InvalidateNow(); grpc_core::ExecCtx::Get()->InvalidateNow();
@ -1081,12 +1113,13 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset,
#ifndef NDEBUG #ifndef NDEBUG
WORKER_PTR->originator = sys_gettid(); WORKER_PTR->originator = sys_gettid();
#endif #endif
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"PS:%p work hdl=%p worker=%p now=%" PRId64 " deadline=%" PRId64 "PS:%p work hdl=%p worker=%p now=%" PRId64 " deadline=%" PRId64
" kwp=%d pollable=%p", " kwp=%d pollable=%p",
pollset, worker_hdl, WORKER_PTR, grpc_core::ExecCtx::Get()->Now(), pollset, worker_hdl, WORKER_PTR, grpc_core::ExecCtx::Get()->Now(),
deadline, pollset->kicked_without_poller, pollset->active_pollable); deadline, pollset->kicked_without_poller, pollset->active_pollable);
}
static const char* err_desc = "pollset_work"; static const char* err_desc = "pollset_work";
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
if (pollset->kicked_without_poller) { if (pollset->kicked_without_poller) {
@ -1121,9 +1154,11 @@ static grpc_error_handle pollset_transition_pollable_from_empty_to_fd_locked(
grpc_pollset* pollset, grpc_fd* fd) { grpc_pollset* pollset, grpc_fd* fd) {
static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd"; static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd";
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, "PS:%p add fd %p (%d); transition pollable from empty to fd", gpr_log(GPR_INFO,
pollset, fd, fd->fd); "PS:%p add fd %p (%d); transition pollable from empty to fd",
pollset, fd, fd->fd);
}
append_error(&error, pollset_kick_all(pollset), err_desc); append_error(&error, pollset_kick_all(pollset), err_desc);
POLLABLE_UNREF(pollset->active_pollable, "pollset"); POLLABLE_UNREF(pollset->active_pollable, "pollset");
append_error(&error, get_fd_pollable(fd, &pollset->active_pollable), append_error(&error, get_fd_pollable(fd, &pollset->active_pollable),
@ -1135,11 +1170,13 @@ static grpc_error_handle pollset_transition_pollable_from_fd_to_multi_locked(
grpc_pollset* pollset, grpc_fd* and_add_fd) { grpc_pollset* pollset, grpc_fd* and_add_fd) {
static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi"; static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi";
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, gpr_log(
"PS:%p add fd %p (%d); transition pollable from fd %p to multipoller", GPR_INFO,
pollset, and_add_fd, and_add_fd ? and_add_fd->fd : -1, "PS:%p add fd %p (%d); transition pollable from fd %p to multipoller",
pollset->active_pollable->owner_fd); pollset, and_add_fd, and_add_fd ? and_add_fd->fd : -1,
pollset->active_pollable->owner_fd);
}
append_error(&error, pollset_kick_all(pollset), err_desc); append_error(&error, pollset_kick_all(pollset), err_desc);
grpc_fd* initial_fd = pollset->active_pollable->owner_fd; grpc_fd* initial_fd = pollset->active_pollable->owner_fd;
POLLABLE_UNREF(pollset->active_pollable, "pollset"); POLLABLE_UNREF(pollset->active_pollable, "pollset");
@ -1206,9 +1243,11 @@ static grpc_error_handle pollset_as_multipollable_locked(
error = pollable_create(PO_MULTI, &pollset->active_pollable); error = pollable_create(PO_MULTI, &pollset->active_pollable);
/* Any workers currently polling on this pollset must now be woked up so /* Any workers currently polling on this pollset must now be woked up so
* that they can pick up the new active_pollable */ * that they can pick up the new active_pollable */
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, "PS:%p active pollable transition from empty to multi", gpr_log(GPR_INFO,
pollset); "PS:%p active pollable transition from empty to multi",
pollset);
}
static const char* err_desc = static const char* err_desc =
"pollset_as_multipollable_locked: empty -> multi"; "pollset_as_multipollable_locked: empty -> multi";
append_error(&error, pollset_kick_all(pollset), err_desc); append_error(&error, pollset_kick_all(pollset), err_desc);
@ -1308,7 +1347,9 @@ static void pollset_set_unref(grpc_pollset_set* pss) {
static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {
GPR_TIMER_SCOPE("pollset_set_add_fd", 0); GPR_TIMER_SCOPE("pollset_set_add_fd", 0);
grpc_polling_trace.Log(GPR_INFO, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd);
}
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
static const char* err_desc = "pollset_set_add_fd"; static const char* err_desc = "pollset_set_add_fd";
pss = pss_lock_adam(pss); pss = pss_lock_adam(pss);
@ -1330,7 +1371,9 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {
static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) {
GPR_TIMER_SCOPE("pollset_set_del_fd", 0); GPR_TIMER_SCOPE("pollset_set_del_fd", 0);
grpc_polling_trace.Log(GPR_INFO, "PSS:%p: del fd %p", pss, fd); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS:%p: del fd %p", pss, fd);
}
pss = pss_lock_adam(pss); pss = pss_lock_adam(pss);
size_t i; size_t i;
for (i = 0; i < pss->fd_count; i++) { for (i = 0; i < pss->fd_count; i++) {
@ -1349,7 +1392,9 @@ static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) {
static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
GPR_TIMER_SCOPE("pollset_set_del_pollset", 0); GPR_TIMER_SCOPE("pollset_set_del_pollset", 0);
grpc_polling_trace.Log(GPR_INFO, "PSS:%p: del pollset %p", pss, ps); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS:%p: del pollset %p", pss, ps);
}
pss = pss_lock_adam(pss); pss = pss_lock_adam(pss);
size_t i; size_t i;
for (i = 0; i < pss->pollset_count; i++) { for (i = 0; i < pss->pollset_count; i++) {
@ -1400,7 +1445,9 @@ static grpc_error_handle add_fds_to_pollsets(grpc_fd** fds, size_t fd_count,
static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
GPR_TIMER_SCOPE("pollset_set_add_pollset", 0); GPR_TIMER_SCOPE("pollset_set_add_pollset", 0);
grpc_polling_trace.Log(GPR_INFO, "PSS:%p: add pollset %p", pss, ps); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS:%p: add pollset %p", pss, ps);
}
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
static const char* err_desc = "pollset_set_add_pollset"; static const char* err_desc = "pollset_set_add_pollset";
pollable* pollable_obj = nullptr; pollable* pollable_obj = nullptr;
@ -1435,7 +1482,9 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
static void pollset_set_add_pollset_set(grpc_pollset_set* a, static void pollset_set_add_pollset_set(grpc_pollset_set* a,
grpc_pollset_set* b) { grpc_pollset_set* b) {
GPR_TIMER_SCOPE("pollset_set_add_pollset_set", 0); GPR_TIMER_SCOPE("pollset_set_add_pollset_set", 0);
grpc_polling_trace.Log(GPR_INFO, "PSS: merge (%p, %p)", a, b); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS: merge (%p, %p)", a, b);
}
grpc_error_handle error = GRPC_ERROR_NONE; grpc_error_handle error = GRPC_ERROR_NONE;
static const char* err_desc = "pollset_set_add_fd"; static const char* err_desc = "pollset_set_add_fd";
for (;;) { for (;;) {
@ -1467,7 +1516,9 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
if (b_size > a_size) { if (b_size > a_size) {
GPR_SWAP(grpc_pollset_set*, a, b); GPR_SWAP(grpc_pollset_set*, a, b);
} }
grpc_polling_trace.Log(GPR_INFO, "PSS: parent %p to %p", b, a); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS: parent %p to %p", b, a);
}
a->refs.Ref(); a->refs.Ref();
b->parent = a; b->parent = a;
if (a->fd_capacity < a->fd_count + b->fd_count) { if (a->fd_capacity < a->fd_count + b->fd_count) {

@ -319,10 +319,12 @@ static void fork_fd_list_add_wakeup_fd(grpc_cached_wakeup_fd* fd) {
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file,
int line) { int line) {
grpc_trace_fd_refcount.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
GPR_DEBUG, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", gpr_log(GPR_DEBUG,
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line); fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
}
#else #else
#define REF_BY(fd, n, reason) \ #define REF_BY(fd, n, reason) \
do { \ do { \
@ -342,10 +344,12 @@ static void ref_by(grpc_fd* fd, int n) {
#ifndef NDEBUG #ifndef NDEBUG
static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file, static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file,
int line) { int line) {
grpc_trace_fd_refcount.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
GPR_DEBUG, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", gpr_log(GPR_DEBUG,
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line); fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
}
#else #else
static void unref_by(grpc_fd* fd, int n) { static void unref_by(grpc_fd* fd, int n) {
#endif #endif
@ -570,8 +574,9 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) {
} }
static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) { static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) {
grpc_polling_trace.Log(GPR_ERROR, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
"Polling engine does not support tracking errors."); gpr_log(GPR_ERROR, "Polling engine does not support tracking errors.");
}
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_CANCELLED); grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_CANCELLED);
} }
@ -588,8 +593,9 @@ static void fd_set_writable(grpc_fd* fd) {
} }
static void fd_set_error(grpc_fd* /*fd*/) { static void fd_set_error(grpc_fd* /*fd*/) {
grpc_polling_trace.Log(GPR_ERROR, if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
"Polling engine does not support tracking errors."); gpr_log(GPR_ERROR, "Polling engine does not support tracking errors.");
}
} }
static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset,
@ -1013,7 +1019,9 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset,
r = grpc_poll_function(pfds, pfd_count, timeout); r = grpc_poll_function(pfds, pfd_count, timeout);
GRPC_SCHEDULING_END_BLOCKING_REGION; GRPC_SCHEDULING_END_BLOCKING_REGION;
grpc_polling_trace.Log(GPR_INFO, "%p poll=%d", pollset, r); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "%p poll=%d", pollset, r);
}
if (r < 0) { if (r < 0) {
if (errno != EINTR) { if (errno != EINTR) {
@ -1035,7 +1043,9 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset,
} }
} else { } else {
if (pfds[0].revents & POLLIN_CHECK) { if (pfds[0].revents & POLLIN_CHECK) {
grpc_polling_trace.Log(GPR_INFO, "%p: got_wakeup", pollset); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "%p: got_wakeup", pollset);
}
work_combine_error( work_combine_error(
&error, grpc_wakeup_fd_consume_wakeup(&worker.wakeup_fd->fd)); &error, grpc_wakeup_fd_consume_wakeup(&worker.wakeup_fd->fd));
} }
@ -1043,10 +1053,11 @@ static grpc_error_handle pollset_work(grpc_pollset* pollset,
if (watchers[i].fd == nullptr) { if (watchers[i].fd == nullptr) {
fd_end_poll(&watchers[i], 0, 0); fd_end_poll(&watchers[i], 0, 0);
} else { } else {
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_INFO, "%p got_event: %d r:%d w:%d [%d]", pollset, gpr_log(GPR_INFO, "%p got_event: %d r:%d w:%d [%d]", pollset,
pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0,
(pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents);
}
/* This is a mitigation to prevent poll() from spinning on a /* This is a mitigation to prevent poll() from spinning on a
** POLLHUP https://github.com/grpc/grpc/pull/13665 ** POLLHUP https://github.com/grpc/grpc/pull/13665
*/ */

@ -54,8 +54,10 @@ grpc_core::DebugOnlyTraceFlag grpc_polling_api_trace(false, "polling_api");
// Polling API trace only enabled in debug builds // Polling API trace only enabled in debug builds
#ifndef NDEBUG #ifndef NDEBUG
#define GRPC_POLLING_API_TRACE(format, ...) \ #define GRPC_POLLING_API_TRACE(format, ...) \
grpc_polling_api_trace.Log(GPR_INFO, "(polling-api) " format, __VA_ARGS__); if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_api_trace)) { \
gpr_log(GPR_INFO, "(polling-api) " format, __VA_ARGS__); \
}
#else #else
#define GRPC_POLLING_API_TRACE(...) #define GRPC_POLLING_API_TRACE(...)
#endif // NDEBUG #endif // NDEBUG

@ -36,8 +36,10 @@ extern grpc_core::DebugOnlyTraceFlag grpc_fd_trace; /* Disabled by default */
extern grpc_core::DebugOnlyTraceFlag extern grpc_core::DebugOnlyTraceFlag
grpc_polling_trace; /* Disabled by default */ grpc_polling_trace; /* Disabled by default */
#define GRPC_FD_TRACE(format, ...) \ #define GRPC_FD_TRACE(format, ...) \
grpc_fd_trace.Log(GPR_INFO, "(fd-trace) " format, __VA_ARGS__); if (GRPC_TRACE_FLAG_ENABLED(grpc_fd_trace)) { \
gpr_log(GPR_INFO, "(fd-trace) " format, __VA_ARGS__); \
}
typedef struct grpc_fd grpc_fd; typedef struct grpc_fd grpc_fd;

@ -30,17 +30,19 @@ EventEngine::Callback GrpcClosureToCallback(grpc_closure* closure,
grpc_error_add_child(error, absl_status_to_grpc_error(status)); grpc_error_add_child(error, absl_status_to_grpc_error(status));
#ifndef NDEBUG #ifndef NDEBUG
closure->scheduled = false; closure->scheduled = false;
grpc_trace_closure.Log( if (grpc_trace_closure.enabled()) {
GPR_DEBUG, gpr_log(GPR_DEBUG,
"EventEngine: running closure %p: created [%s:%d]: %s [%s:%d]", closure, "EventEngine: running closure %p: created [%s:%d]: %s [%s:%d]",
closure->file_created, closure->line_created, closure, closure->file_created, closure->line_created,
closure->run ? "run" : "scheduled", closure->file_initiated, closure->run ? "run" : "scheduled", closure->file_initiated,
closure->line_initiated); closure->line_initiated);
}
#endif #endif
closure->cb(closure->cb_arg, new_error); closure->cb(closure->cb_arg, new_error);
#ifndef NDEBUG #ifndef NDEBUG
grpc_trace_closure.Log(GPR_DEBUG, "EventEngine: closure %p finished", if (grpc_trace_closure.enabled()) {
closure); gpr_log(GPR_DEBUG, "EventEngine: closure %p finished", closure);
}
#endif #endif
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
grpc_pollset_ee_broadcast_event(); grpc_pollset_ee_broadcast_event();

@ -33,15 +33,18 @@
static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) { static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) {
#ifndef NDEBUG #ifndef NDEBUG
closure->scheduled = false; closure->scheduled = false;
grpc_trace_closure.Log(GPR_DEBUG, if (grpc_trace_closure.enabled()) {
"running closure %p: created [%s:%d]: %s [%s:%d]", gpr_log(GPR_DEBUG, "running closure %p: created [%s:%d]: %s [%s:%d]",
closure, closure->file_created, closure->line_created, closure, closure->file_created, closure->line_created,
closure->run ? "run" : "scheduled", closure->run ? "run" : "scheduled", closure->file_initiated,
closure->file_initiated, closure->line_initiated); closure->line_initiated);
}
#endif #endif
closure->cb(closure->cb_arg, error); closure->cb(closure->cb_arg, error);
#ifndef NDEBUG #ifndef NDEBUG
grpc_trace_closure.Log(GPR_DEBUG, "closure %p finished", closure); if (grpc_trace_closure.enabled()) {
gpr_log(GPR_DEBUG, "closure %p finished", closure);
}
#endif #endif
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
} }

@ -95,9 +95,11 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) {
* sure that the shutdown error has been initialized properly before us * sure that the shutdown error has been initialized properly before us
* referencing it. */ * referencing it. */
gpr_atm curr = gpr_atm_acq_load(&state_); gpr_atm curr = gpr_atm_acq_load(&state_);
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_DEBUG, "LockfreeEvent::NotifyOn: %p curr=%" PRIxPTR " closure=%p", gpr_log(GPR_DEBUG,
this, curr, closure); "LockfreeEvent::NotifyOn: %p curr=%" PRIxPTR " closure=%p", this,
curr, closure);
}
switch (curr) { switch (curr) {
case kClosureNotReady: { case kClosureNotReady: {
/* kClosureNotReady -> <closure>. /* kClosureNotReady -> <closure>.
@ -162,9 +164,11 @@ bool LockfreeEvent::SetShutdown(grpc_error_handle shutdown_error) {
while (true) { while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(&state_); gpr_atm curr = gpr_atm_no_barrier_load(&state_);
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_DEBUG, "LockfreeEvent::SetShutdown: %p curr=%" PRIxPTR " err=%s", gpr_log(GPR_DEBUG,
&state_, curr, grpc_error_std_string(shutdown_error).c_str()); "LockfreeEvent::SetShutdown: %p curr=%" PRIxPTR " err=%s",
&state_, curr, grpc_error_std_string(shutdown_error).c_str());
}
switch (curr) { switch (curr) {
case kClosureReady: case kClosureReady:
case kClosureNotReady: case kClosureNotReady:
@ -210,8 +214,10 @@ void LockfreeEvent::SetReady() {
while (true) { while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(&state_); gpr_atm curr = gpr_atm_no_barrier_load(&state_);
grpc_polling_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
GPR_DEBUG, "LockfreeEvent::SetReady: %p curr=%" PRIxPTR, &state_, curr); gpr_log(GPR_DEBUG, "LockfreeEvent::SetReady: %p curr=%" PRIxPTR, &state_,
curr);
}
switch (curr) { switch (curr) {
case kClosureReady: { case kClosureReady: {

@ -321,12 +321,13 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) {
while ((resource_user = rulist_pop_head(resource_quota, while ((resource_user = rulist_pop_head(resource_quota,
GRPC_RULIST_AWAITING_ALLOCATION))) { GRPC_RULIST_AWAITING_ALLOCATION))) {
gpr_mu_lock(&resource_user->mu); gpr_mu_lock(&resource_user->mu);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"RQ: check allocation for user %p shutdown=%" PRIdPTR "RQ: check allocation for user %p shutdown=%" PRIdPTR
" free_pool=%" PRId64 " outstanding_allocations=%" PRId64, " free_pool=%" PRId64 " outstanding_allocations=%" PRId64,
resource_user, gpr_atm_no_barrier_load(&resource_user->shutdown), resource_user, gpr_atm_no_barrier_load(&resource_user->shutdown),
resource_user->free_pool, resource_user->outstanding_allocations); resource_user->free_pool, resource_user->outstanding_allocations);
}
if (gpr_atm_no_barrier_load(&resource_user->shutdown)) { if (gpr_atm_no_barrier_load(&resource_user->shutdown)) {
resource_user->allocating = false; resource_user->allocating = false;
grpc_closure_list_fail_all( grpc_closure_list_fail_all(
@ -348,11 +349,13 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) {
resource_user->free_pool = 0; resource_user->free_pool = 0;
resource_quota->free_pool -= amt; resource_quota->free_pool -= amt;
rq_update_estimate(resource_quota); rq_update_estimate(resource_quota);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"RQ %s %s: grant alloc %" PRId64 " bytes; rq_free_pool -> %" PRId64, "RQ %s %s: grant alloc %" PRId64
resource_quota->name.c_str(), resource_user->name.c_str(), amt, " bytes; rq_free_pool -> %" PRId64,
resource_quota->free_pool); resource_quota->name.c_str(), resource_user->name.c_str(), amt,
resource_quota->free_pool);
}
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace) && } else if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace) &&
resource_user->free_pool >= 0) { resource_user->free_pool >= 0) {
gpr_log(GPR_INFO, "RQ %s %s: discard already satisfied alloc request", gpr_log(GPR_INFO, "RQ %s %s: discard already satisfied alloc request",
@ -385,21 +388,23 @@ static bool rq_reclaim_from_per_user_free_pool(
resource_user->free_pool = 0; resource_user->free_pool = 0;
resource_quota->free_pool += amt; resource_quota->free_pool += amt;
rq_update_estimate(resource_quota); rq_update_estimate(resource_quota);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"RQ %s %s: reclaim_from_per_user_free_pool %" PRId64 "RQ %s %s: reclaim_from_per_user_free_pool %" PRId64
" bytes; rq_free_pool -> %" PRId64, " bytes; rq_free_pool -> %" PRId64,
resource_quota->name.c_str(), resource_user->name.c_str(), amt, resource_quota->name.c_str(), resource_user->name.c_str(), amt,
resource_quota->free_pool); resource_quota->free_pool);
}
gpr_mu_unlock(&resource_user->mu); gpr_mu_unlock(&resource_user->mu);
return true; return true;
} else { } else {
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"RQ %s %s: failed to reclaim_from_per_user_free_pool; " "RQ %s %s: failed to reclaim_from_per_user_free_pool; "
"free_pool = %" PRId64 "; rq_free_pool = %" PRId64, "free_pool = %" PRId64 "; rq_free_pool = %" PRId64,
resource_quota->name.c_str(), resource_user->name.c_str(), resource_quota->name.c_str(), resource_user->name.c_str(),
resource_user->free_pool, resource_quota->free_pool); resource_user->free_pool, resource_quota->free_pool);
}
gpr_mu_unlock(&resource_user->mu); gpr_mu_unlock(&resource_user->mu);
} }
} }
@ -413,10 +418,11 @@ static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive) {
: GRPC_RULIST_RECLAIMER_BENIGN; : GRPC_RULIST_RECLAIMER_BENIGN;
grpc_resource_user* resource_user = rulist_pop_head(resource_quota, list); grpc_resource_user* resource_user = rulist_pop_head(resource_quota, list);
if (resource_user == nullptr) return false; if (resource_user == nullptr) return false;
grpc_resource_quota_trace.Log(GPR_INFO, "RQ %s %s: initiate %s reclamation", if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
resource_quota->name.c_str(), gpr_log(GPR_INFO, "RQ %s %s: initiate %s reclamation",
resource_user->name.c_str(), resource_quota->name.c_str(), resource_user->name.c_str(),
destructive ? "destructive" : "benign"); destructive ? "destructive" : "benign");
}
resource_quota->reclaiming = true; resource_quota->reclaiming = true;
grpc_resource_quota_ref_internal(resource_quota); grpc_resource_quota_ref_internal(resource_quota);
grpc_closure* c = resource_user->reclaimers[destructive]; grpc_closure* c = resource_user->reclaimers[destructive];
@ -546,7 +552,9 @@ static void ru_post_destructive_reclaimer(void* ru,
} }
static void ru_shutdown(void* ru, grpc_error_handle /*error*/) { static void ru_shutdown(void* ru, grpc_error_handle /*error*/) {
grpc_resource_quota_trace.Log(GPR_INFO, "RU shutdown %p", ru); if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
gpr_log(GPR_INFO, "RU shutdown %p", ru);
}
grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru); grpc_resource_user* resource_user = static_cast<grpc_resource_user*>(ru);
gpr_mu_lock(&resource_user->mu); gpr_mu_lock(&resource_user->mu);
grpc_core::ExecCtx::Run(DEBUG_LOCATION, resource_user->reclaimers[0], grpc_core::ExecCtx::Run(DEBUG_LOCATION, resource_user->reclaimers[0],
@ -584,8 +592,10 @@ static void ru_destroy(void* ru, grpc_error_handle /*error*/) {
} }
grpc_resource_quota_unref_internal(resource_user->resource_quota); grpc_resource_quota_unref_internal(resource_user->resource_quota);
gpr_mu_destroy(&resource_user->mu); gpr_mu_destroy(&resource_user->mu);
grpc_resource_quota_trace.Log(GPR_INFO, "RU '%s' (%p) destroyed", if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
resource_user->name.c_str(), resource_user); gpr_log(GPR_INFO, "RU '%s' (%p) destroyed", resource_user->name.c_str(),
resource_user);
}
delete resource_user; delete resource_user;
} }
@ -800,8 +810,10 @@ grpc_resource_user* grpc_resource_user_create(
resource_user->name = absl::StrCat( resource_user->name = absl::StrCat(
"anonymous_resource_user_", reinterpret_cast<intptr_t>(resource_user)); "anonymous_resource_user_", reinterpret_cast<intptr_t>(resource_user));
} }
grpc_resource_quota_trace.Log(GPR_INFO, "RU '%s' (%p) created", if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
resource_user->name.c_str(), resource_user); gpr_log(GPR_INFO, "RU '%s' (%p) created", resource_user->name.c_str(),
resource_user);
}
return resource_user; return resource_user;
} }
@ -813,9 +825,10 @@ grpc_resource_quota* grpc_resource_user_quota(
static void ru_ref_by(grpc_resource_user* resource_user, gpr_atm amount) { static void ru_ref_by(grpc_resource_user* resource_user, gpr_atm amount) {
GPR_ASSERT(amount > 0); GPR_ASSERT(amount > 0);
gpr_atm prior = gpr_atm_no_barrier_fetch_add(&resource_user->refs, amount); gpr_atm prior = gpr_atm_no_barrier_fetch_add(&resource_user->refs, amount);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, "RU '%s' (%p) reffing: %" PRIdPTR " -> %" PRIdPTR, gpr_log(GPR_INFO, "RU '%s' (%p) reffing: %" PRIdPTR " -> %" PRIdPTR,
resource_user->name.c_str(), resource_user, prior, prior + amount); resource_user->name.c_str(), resource_user, prior, prior + amount);
}
GPR_ASSERT(prior != 0); GPR_ASSERT(prior != 0);
} }
@ -823,9 +836,10 @@ static void ru_unref_by(grpc_resource_user* resource_user, gpr_atm amount) {
GPR_ASSERT(amount > 0); GPR_ASSERT(amount > 0);
gpr_atm old = gpr_atm_full_fetch_add(&resource_user->refs, -amount); gpr_atm old = gpr_atm_full_fetch_add(&resource_user->refs, -amount);
GPR_ASSERT(old >= amount); GPR_ASSERT(old >= amount);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, "RU '%s' (%p) unreffing: %" PRIdPTR " -> %" PRIdPTR, gpr_log(GPR_INFO, "RU '%s' (%p) unreffing: %" PRIdPTR " -> %" PRIdPTR,
resource_user->name.c_str(), resource_user, old, old - amount); resource_user->name.c_str(), resource_user, old, old - amount);
}
if (old == amount) { if (old == amount) {
resource_user->resource_quota->combiner->Run( resource_user->resource_quota->combiner->Run(
&resource_user->destroy_closure, GRPC_ERROR_NONE); &resource_user->destroy_closure, GRPC_ERROR_NONE);
@ -889,10 +903,11 @@ static bool resource_user_alloc_locked(grpc_resource_user* resource_user,
grpc_closure* optional_on_done) { grpc_closure* optional_on_done) {
ru_ref_by(resource_user, static_cast<gpr_atm>(size)); ru_ref_by(resource_user, static_cast<gpr_atm>(size));
resource_user->free_pool -= static_cast<int64_t>(size); resource_user->free_pool -= static_cast<int64_t>(size);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, "RQ %s %s: alloc %" PRIdPTR "; free_pool -> %" PRId64, gpr_log(GPR_INFO, "RQ %s %s: alloc %" PRIdPTR "; free_pool -> %" PRId64,
resource_user->resource_quota->name.c_str(), resource_user->name.c_str(), resource_user->resource_quota->name.c_str(),
size, resource_user->free_pool); resource_user->name.c_str(), size, resource_user->free_pool);
}
if (GPR_LIKELY(resource_user->free_pool >= 0)) return true; if (GPR_LIKELY(resource_user->free_pool >= 0)) return true;
// Slow path: We need to wait for the free pool to refill. // Slow path: We need to wait for the free pool to refill.
if (optional_on_done != nullptr) { if (optional_on_done != nullptr) {
@ -949,10 +964,11 @@ void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) {
GPR_ASSERT(prior >= static_cast<long>(size)); GPR_ASSERT(prior >= static_cast<long>(size));
bool was_zero_or_negative = resource_user->free_pool <= 0; bool was_zero_or_negative = resource_user->free_pool <= 0;
resource_user->free_pool += static_cast<int64_t>(size); resource_user->free_pool += static_cast<int64_t>(size);
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, "RQ %s %s: free %" PRIdPTR "; free_pool -> %" PRId64, gpr_log(GPR_INFO, "RQ %s %s: free %" PRIdPTR "; free_pool -> %" PRId64,
resource_user->resource_quota->name.c_str(), resource_user->name.c_str(), resource_user->resource_quota->name.c_str(),
size, resource_user->free_pool); resource_user->name.c_str(), size, resource_user->free_pool);
}
bool is_bigger_than_zero = resource_user->free_pool > 0; bool is_bigger_than_zero = resource_user->free_pool > 0;
if (is_bigger_than_zero && was_zero_or_negative && if (is_bigger_than_zero && was_zero_or_negative &&
!resource_user->added_to_free_pool) { !resource_user->added_to_free_pool) {
@ -974,9 +990,11 @@ void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user,
} }
void grpc_resource_user_finish_reclamation(grpc_resource_user* resource_user) { void grpc_resource_user_finish_reclamation(grpc_resource_user* resource_user) {
grpc_resource_quota_trace.Log(GPR_INFO, "RQ %s %s: reclamation complete", if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
resource_user->resource_quota->name.c_str(), gpr_log(GPR_INFO, "RQ %s %s: reclamation complete",
resource_user->name.c_str()); resource_user->resource_quota->name.c_str(),
resource_user->name.c_str());
}
resource_user->resource_quota->combiner->Run( resource_user->resource_quota->combiner->Run(
&resource_user->resource_quota->rq_reclamation_done_closure, &resource_user->resource_quota->rq_reclamation_done_closure,
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
@ -1028,13 +1046,15 @@ static size_t grpc_slice_allocator_adjust_allocation_length(
if (target > rqmax / 16 && rqmax > 1024) { if (target > rqmax / 16 && rqmax > 1024) {
target = rqmax / 16; target = rqmax / 16;
} }
grpc_resource_quota_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
GPR_INFO, gpr_log(
"SliceAllocator(%p) requested %zu bytes for (%s) intent, adjusted " GPR_INFO,
"allocation size to %zu", "SliceAllocator(%p) requested %zu bytes for (%s) intent, adjusted "
slice_allocator, requested_length, "allocation size to %zu",
intent == grpc_slice_allocator_intent::kDefault ? "default" : "read", slice_allocator, requested_length,
target); intent == grpc_slice_allocator_intent::kDefault ? "default" : "read",
target);
}
return target; return target;
} }

@ -357,9 +357,10 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout(
} }
} }
if (g_socket_supports_tcp_user_timeout.load() > 0) { if (g_socket_supports_tcp_user_timeout.load() > 0) {
grpc_tcp_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"Enabling TCP_USER_TIMEOUT with a timeout of %d ms", gpr_log(GPR_INFO, "Enabling TCP_USER_TIMEOUT with a timeout of %d ms",
timeout); timeout);
}
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout,
sizeof(timeout))) { sizeof(timeout))) {
gpr_log(GPR_ERROR, "setsockopt(TCP_USER_TIMEOUT) %s", gpr_log(GPR_ERROR, "setsockopt(TCP_USER_TIMEOUT) %s",
@ -379,8 +380,9 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout(
} }
} }
} else { } else {
grpc_tcp_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"TCP_USER_TIMEOUT not supported for this platform"); gpr_log(GPR_INFO, "TCP_USER_TIMEOUT not supported for this platform");
}
} }
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }

@ -82,8 +82,9 @@ static void CFStreamConnectCleanup(CFStreamConnect* connect) {
static void OnAlarm(void* arg, grpc_error_handle error) { static void OnAlarm(void* arg, grpc_error_handle error) {
CFStreamConnect* connect = static_cast<CFStreamConnect*>(arg); CFStreamConnect* connect = static_cast<CFStreamConnect*>(arg);
grpc_tcp_trace.Log(GPR_DEBUG, "CLIENT_CONNECT :%p OnAlarm, error:%p", connect, if (grpc_tcp_trace.enabled()) {
error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT :%p OnAlarm, error:%p", connect, error);
}
gpr_mu_lock(&connect->mu); gpr_mu_lock(&connect->mu);
grpc_closure* closure = connect->closure; grpc_closure* closure = connect->closure;
connect->closure = nil; connect->closure = nil;
@ -102,8 +103,9 @@ static void OnAlarm(void* arg, grpc_error_handle error) {
static void OnOpen(void* arg, grpc_error_handle error) { static void OnOpen(void* arg, grpc_error_handle error) {
CFStreamConnect* connect = static_cast<CFStreamConnect*>(arg); CFStreamConnect* connect = static_cast<CFStreamConnect*>(arg);
grpc_tcp_trace.Log(GPR_DEBUG, "CLIENT_CONNECT :%p OnOpen, error:%p", connect, if (grpc_tcp_trace.enabled()) {
error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT :%p OnOpen, error:%p", connect, error);
}
gpr_mu_lock(&connect->mu); gpr_mu_lock(&connect->mu);
grpc_timer_cancel(&connect->alarm); grpc_timer_cancel(&connect->alarm);
grpc_closure* closure = connect->closure; grpc_closure* closure = connect->closure;
@ -167,9 +169,10 @@ static void CFStreamClientConnect(grpc_closure* closure, grpc_endpoint** ep,
gpr_ref_init(&connect->refcount, 1); gpr_ref_init(&connect->refcount, 1);
gpr_mu_init(&connect->mu); gpr_mu_init(&connect->mu);
grpc_tcp_trace.Log(GPR_DEBUG, if (grpc_tcp_trace.enabled()) {
"CLIENT_CONNECT: %p, %s: asynchronously connecting", gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %p, %s: asynchronously connecting",
connect, connect->addr_name.c_str()); connect, connect->addr_name.c_str());
}
connect->slice_allocator = slice_allocator; connect->slice_allocator = slice_allocator;
CFReadStreamRef read_stream; CFReadStreamRef read_stream;

@ -65,9 +65,10 @@ static void on_alarm(void* acp, grpc_error_handle error) {
int done; int done;
grpc_custom_socket* socket = static_cast<grpc_custom_socket*>(acp); grpc_custom_socket* socket = static_cast<grpc_custom_socket*>(acp);
grpc_custom_tcp_connect* connect = socket->connector; grpc_custom_tcp_connect* connect = socket->connector;
grpc_tcp_trace.Log(GPR_INFO, "CLIENT_CONNECT: %s: on_alarm: error=%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
connect->addr_name.c_str(), gpr_log(GPR_INFO, "CLIENT_CONNECT: %s: on_alarm: error=%s",
grpc_error_std_string(error).c_str()); connect->addr_name.c_str(), grpc_error_std_string(error).c_str());
}
if (error == GRPC_ERROR_NONE) { if (error == GRPC_ERROR_NONE) {
/* error == NONE implies that the timer ran out, and wasn't cancelled. If /* error == NONE implies that the timer ran out, and wasn't cancelled. If
it was cancelled, then the handler that cancelled it also should close it was cancelled, then the handler that cancelled it also should close
@ -136,9 +137,10 @@ static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep,
socket->listener = nullptr; socket->listener = nullptr;
connect->refs = 2; connect->refs = 2;
grpc_tcp_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"CLIENT_CONNECT: %p %s: asynchronously connecting", socket, gpr_log(GPR_INFO, "CLIENT_CONNECT: %p %s: asynchronously connecting",
connect->addr_name.c_str()); socket, connect->addr_name.c_str());
}
GRPC_CLOSURE_INIT(&connect->on_alarm, on_alarm, socket, GRPC_CLOSURE_INIT(&connect->on_alarm, on_alarm, socket,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);

@ -106,9 +106,10 @@ done:
static void tc_on_alarm(void* acp, grpc_error_handle error) { static void tc_on_alarm(void* acp, grpc_error_handle error) {
int done; int done;
async_connect* ac = static_cast<async_connect*>(acp); async_connect* ac = static_cast<async_connect*>(acp);
grpc_tcp_trace.Log(GPR_INFO, "CLIENT_CONNECT: %s: on_alarm: error=%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
ac->addr_str.c_str(), gpr_log(GPR_INFO, "CLIENT_CONNECT: %s: on_alarm: error=%s",
grpc_error_std_string(error).c_str()); ac->addr_str.c_str(), grpc_error_std_string(error).c_str());
}
gpr_mu_lock(&ac->mu); gpr_mu_lock(&ac->mu);
if (ac->fd != nullptr) { if (ac->fd != nullptr) {
grpc_fd_shutdown( grpc_fd_shutdown(
@ -144,9 +145,10 @@ static void on_writable(void* acp, grpc_error_handle error) {
GRPC_ERROR_REF(error); GRPC_ERROR_REF(error);
grpc_tcp_trace.Log(GPR_INFO, "CLIENT_CONNECT: %s: on_writable: error=%s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
ac->addr_str.c_str(), gpr_log(GPR_INFO, "CLIENT_CONNECT: %s: on_writable: error=%s",
grpc_error_std_string(error).c_str()); ac->addr_str.c_str(), grpc_error_std_string(error).c_str());
}
gpr_mu_lock(&ac->mu); gpr_mu_lock(&ac->mu);
GPR_ASSERT(ac->fd); GPR_ASSERT(ac->fd);
@ -331,9 +333,10 @@ void grpc_tcp_client_create_from_prepared_fd(
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
ac->channel_args = grpc_channel_args_copy(channel_args); ac->channel_args = grpc_channel_args_copy(channel_args);
grpc_tcp_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"CLIENT_CONNECT: %s: asynchronously connecting fd %p", gpr_log(GPR_INFO, "CLIENT_CONNECT: %s: asynchronously connecting fd %p",
ac->addr_str.c_str(), fdobj); ac->addr_str.c_str(), fdobj);
}
gpr_mu_lock(&ac->mu); gpr_mu_lock(&ac->mu);
GRPC_CLOSURE_INIT(&ac->on_alarm, tc_on_alarm, ac, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&ac->on_alarm, tc_on_alarm, ac, grpc_schedule_on_exec_ctx);

@ -170,8 +170,10 @@ static void custom_read_callback(grpc_custom_socket* socket, size_t nread,
static void tcp_read_allocation_done(void* tcpp, grpc_error_handle error) { static void tcp_read_allocation_done(void* tcpp, grpc_error_handle error) {
custom_tcp_endpoint* tcp = static_cast<custom_tcp_endpoint*>(tcpp); custom_tcp_endpoint* tcp = static_cast<custom_tcp_endpoint*>(tcpp);
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p read_allocation_done: %s", tcp->socket, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "TCP:%p read_allocation_done: %s", tcp->socket,
grpc_error_std_string(error).c_str());
}
if (error == GRPC_ERROR_NONE) { if (error == GRPC_ERROR_NONE) {
/* Before calling read, we allocate a buffer with exactly one slice /* Before calling read, we allocate a buffer with exactly one slice
* to tcp->read_slices and wait for the callback indicating that the * to tcp->read_slices and wait for the callback indicating that the
@ -185,8 +187,10 @@ static void tcp_read_allocation_done(void* tcpp, grpc_error_handle error) {
grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices);
call_read_cb(tcp, GRPC_ERROR_REF(error)); call_read_cb(tcp, GRPC_ERROR_REF(error));
} }
grpc_tcp_trace.Log(GPR_INFO, "Initiating read on %p: error=%s", tcp->socket, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "Initiating read on %p: error=%s", tcp->socket,
grpc_error_std_string(error).c_str());
}
} }
static void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, static void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices,
@ -214,8 +218,10 @@ static void custom_write_callback(grpc_custom_socket* socket,
reinterpret_cast<custom_tcp_endpoint*>(socket->endpoint); reinterpret_cast<custom_tcp_endpoint*>(socket->endpoint);
grpc_closure* cb = tcp->write_cb; grpc_closure* cb = tcp->write_cb;
tcp->write_cb = nullptr; tcp->write_cb = nullptr;
grpc_tcp_trace.Log(GPR_INFO, "write complete on %p: error=%s", tcp->socket, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "write complete on %p: error=%s", tcp->socket,
grpc_error_std_string(error).c_str());
}
TCP_UNREF(tcp, "write"); TCP_UNREF(tcp, "write");
grpc_core::ExecCtx::Run(DEBUG_LOCATION, cb, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, cb, error);
} }
@ -282,8 +288,10 @@ static void endpoint_delete_from_pollset_set(grpc_endpoint* ep,
static void endpoint_shutdown(grpc_endpoint* ep, grpc_error_handle why) { static void endpoint_shutdown(grpc_endpoint* ep, grpc_error_handle why) {
custom_tcp_endpoint* tcp = reinterpret_cast<custom_tcp_endpoint*>(ep); custom_tcp_endpoint* tcp = reinterpret_cast<custom_tcp_endpoint*>(ep);
if (!tcp->shutting_down) { if (!tcp->shutting_down) {
grpc_tcp_trace.Log(GPR_INFO, "TCP %p shutdown why=%s", tcp->socket, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(why).c_str()); gpr_log(GPR_INFO, "TCP %p shutdown why=%s", tcp->socket,
grpc_error_std_string(why).c_str());
}
tcp->shutting_down = true; tcp->shutting_down = true;
// grpc_core::ExecCtx::Run(DEBUG_LOCATION,tcp->read_cb, // grpc_core::ExecCtx::Run(DEBUG_LOCATION,tcp->read_cb,
// GRPC_ERROR_REF(why)); // GRPC_ERROR_REF(why));
@ -346,7 +354,9 @@ grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket,
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_tcp_trace.Log(GPR_INFO, "Creating TCP endpoint %p", socket); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "Creating TCP endpoint %p", socket);
}
socket->refs++; socket->refs++;
socket->endpoint = reinterpret_cast<grpc_endpoint*>(tcp); socket->endpoint = reinterpret_cast<grpc_endpoint*>(tcp);
tcp->socket = socket; tcp->socket = socket;

@ -444,14 +444,18 @@ static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */,
static void done_poller(void* bp, grpc_error_handle /*error_ignored*/) { static void done_poller(void* bp, grpc_error_handle /*error_ignored*/) {
backup_poller* p = static_cast<backup_poller*>(bp); backup_poller* p = static_cast<backup_poller*>(bp);
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p destroy", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "BACKUP_POLLER:%p destroy", p);
}
grpc_pollset_destroy(BACKUP_POLLER_POLLSET(p)); grpc_pollset_destroy(BACKUP_POLLER_POLLSET(p));
gpr_free(p); gpr_free(p);
} }
static void run_poller(void* bp, grpc_error_handle /*error_ignored*/) { static void run_poller(void* bp, grpc_error_handle /*error_ignored*/) {
backup_poller* p = static_cast<backup_poller*>(bp); backup_poller* p = static_cast<backup_poller*>(bp);
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p run", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "BACKUP_POLLER:%p run", p);
}
gpr_mu_lock(p->pollset_mu); gpr_mu_lock(p->pollset_mu);
grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC;
GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(); GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS();
@ -466,13 +470,17 @@ static void run_poller(void* bp, grpc_error_handle /*error_ignored*/) {
g_backup_poller = nullptr; g_backup_poller = nullptr;
g_uncovered_notifications_pending = 0; g_uncovered_notifications_pending = 0;
g_backup_poller_mu->Unlock(); g_backup_poller_mu->Unlock();
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p shutdown", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "BACKUP_POLLER:%p shutdown", p);
}
grpc_pollset_shutdown(BACKUP_POLLER_POLLSET(p), grpc_pollset_shutdown(BACKUP_POLLER_POLLSET(p),
GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p,
grpc_schedule_on_exec_ctx)); grpc_schedule_on_exec_ctx));
} else { } else {
g_backup_poller_mu->Unlock(); g_backup_poller_mu->Unlock();
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p reschedule", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "BACKUP_POLLER:%p reschedule", p);
}
grpc_core::Executor::Run(&p->run_poller, GRPC_ERROR_NONE, grpc_core::Executor::Run(&p->run_poller, GRPC_ERROR_NONE,
grpc_core::ExecutorType::DEFAULT, grpc_core::ExecutorType::DEFAULT,
grpc_core::ExecutorJobType::LONG); grpc_core::ExecutorJobType::LONG);
@ -487,8 +495,10 @@ static void drop_uncovered(grpc_tcp* /*tcp*/) {
old_count = g_uncovered_notifications_pending--; old_count = g_uncovered_notifications_pending--;
g_backup_poller_mu->Unlock(); g_backup_poller_mu->Unlock();
GPR_ASSERT(old_count > 1); GPR_ASSERT(old_count > 1);
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p uncover cnt %d->%d", p, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
old_count, old_count - 1); gpr_log(GPR_INFO, "BACKUP_POLLER:%p uncover cnt %d->%d", p, old_count,
old_count - 1);
}
} }
// gRPC API considers a Write operation to be done the moment it clears ‘flow // gRPC API considers a Write operation to be done the moment it clears ‘flow
@ -510,7 +520,9 @@ static void cover_self(grpc_tcp* tcp) {
grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu); grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu);
g_backup_poller_mu->Unlock(); g_backup_poller_mu->Unlock();
GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(); GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED();
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p create", p); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "BACKUP_POLLER:%p create", p);
}
grpc_core::Executor::Run( grpc_core::Executor::Run(
GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p, nullptr), GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p, nullptr),
GRPC_ERROR_NONE, grpc_core::ExecutorType::DEFAULT, GRPC_ERROR_NONE, grpc_core::ExecutorType::DEFAULT,
@ -520,18 +532,24 @@ static void cover_self(grpc_tcp* tcp) {
p = g_backup_poller; p = g_backup_poller;
g_backup_poller_mu->Unlock(); g_backup_poller_mu->Unlock();
} }
grpc_tcp_trace.Log(GPR_INFO, "BACKUP_POLLER:%p add %p cnt %d->%d", p, tcp, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
old_count - 1, old_count); gpr_log(GPR_INFO, "BACKUP_POLLER:%p add %p cnt %d->%d", p, tcp,
old_count - 1, old_count);
}
grpc_pollset_add_fd(BACKUP_POLLER_POLLSET(p), tcp->em_fd); grpc_pollset_add_fd(BACKUP_POLLER_POLLSET(p), tcp->em_fd);
} }
static void notify_on_read(grpc_tcp* tcp) { static void notify_on_read(grpc_tcp* tcp) {
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p notify_on_read", tcp); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "TCP:%p notify_on_read", tcp);
}
grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_done_closure); grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_done_closure);
} }
static void notify_on_write(grpc_tcp* tcp) { static void notify_on_write(grpc_tcp* tcp) {
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p notify_on_write", tcp); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "TCP:%p notify_on_write", tcp);
}
if (!grpc_event_engine_run_in_background()) { if (!grpc_event_engine_run_in_background()) {
cover_self(tcp); cover_self(tcp);
} }
@ -540,8 +558,10 @@ static void notify_on_write(grpc_tcp* tcp) {
static void tcp_drop_uncovered_then_handle_write(void* arg, static void tcp_drop_uncovered_then_handle_write(void* arg,
grpc_error_handle error) { grpc_error_handle error) {
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p got_write: %s", arg, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "TCP:%p got_write: %s", arg,
grpc_error_std_string(error).c_str());
}
drop_uncovered(static_cast<grpc_tcp*>(arg)); drop_uncovered(static_cast<grpc_tcp*>(arg));
tcp_handle_write(arg, error); tcp_handle_write(arg, error);
} }
@ -810,8 +830,10 @@ static void tcp_do_read(grpc_tcp* tcp) {
static void tcp_read_allocation_done(void* tcpp, grpc_error_handle error) { static void tcp_read_allocation_done(void* tcpp, grpc_error_handle error) {
grpc_tcp* tcp = static_cast<grpc_tcp*>(tcpp); grpc_tcp* tcp = static_cast<grpc_tcp*>(tcpp);
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p read_allocation_done: %s", tcp, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "TCP:%p read_allocation_done: %s", tcp,
grpc_error_std_string(error).c_str());
}
if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) { if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer);
grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer);
@ -826,7 +848,9 @@ static void tcp_continue_read(grpc_tcp* tcp) {
/* Wait for allocation only when there is no buffer left. */ /* Wait for allocation only when there is no buffer left. */
if (tcp->incoming_buffer->length == 0 && if (tcp->incoming_buffer->length == 0 &&
tcp->incoming_buffer->count < MAX_READ_IOVEC) { tcp->incoming_buffer->count < MAX_READ_IOVEC) {
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p alloc_slices", tcp); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "TCP:%p alloc_slices", tcp);
}
if (GPR_UNLIKELY(!grpc_slice_allocator_allocate( if (GPR_UNLIKELY(!grpc_slice_allocator_allocate(
tcp->slice_allocator, tcp->target_length, 1, tcp->slice_allocator, tcp->target_length, 1,
grpc_slice_allocator_intent::kReadBuffer, tcp->incoming_buffer, grpc_slice_allocator_intent::kReadBuffer, tcp->incoming_buffer,
@ -835,14 +859,18 @@ static void tcp_continue_read(grpc_tcp* tcp) {
return; return;
} }
} }
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p do_read", tcp); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "TCP:%p do_read", tcp);
}
tcp_do_read(tcp); tcp_do_read(tcp);
} }
static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error_handle error) { static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error_handle error) {
grpc_tcp* tcp = static_cast<grpc_tcp*>(arg); grpc_tcp* tcp = static_cast<grpc_tcp*>(arg);
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p got_read: %s", tcp, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "TCP:%p got_read: %s", tcp,
grpc_error_std_string(error).c_str());
}
if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) { if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer);
@ -955,8 +983,9 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
uint32_t opt = grpc_core::kTimestampingSocketOptions; uint32_t opt = grpc_core::kTimestampingSocketOptions;
if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING, if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING,
static_cast<void*>(&opt), sizeof(opt)) != 0) { static_cast<void*>(&opt), sizeof(opt)) != 0) {
grpc_tcp_trace.Log(GPR_ERROR, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"Failed to set timestamping options on the socket."); gpr_log(GPR_ERROR, "Failed to set timestamping options on the socket.");
}
return false; return false;
} }
tcp->bytes_counter = -1; tcp->bytes_counter = -1;
@ -1040,7 +1069,9 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
auto next_cmsg = CMSG_NXTHDR(msg, cmsg); auto next_cmsg = CMSG_NXTHDR(msg, cmsg);
cmsghdr* opt_stats = nullptr; cmsghdr* opt_stats = nullptr;
if (next_cmsg == nullptr) { if (next_cmsg == nullptr) {
grpc_tcp_trace.Log(GPR_ERROR, "Received timestamp without extended error"); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_ERROR, "Received timestamp without extended error");
}
return cmsg; return cmsg;
} }
@ -1050,8 +1081,9 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
opt_stats = next_cmsg; opt_stats = next_cmsg;
next_cmsg = CMSG_NXTHDR(msg, opt_stats); next_cmsg = CMSG_NXTHDR(msg, opt_stats);
if (next_cmsg == nullptr) { if (next_cmsg == nullptr) {
grpc_tcp_trace.Log(GPR_ERROR, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"Received timestamp without extended error"); gpr_log(GPR_ERROR, "Received timestamp without extended error");
}
return opt_stats; return opt_stats;
} }
} }
@ -1059,7 +1091,9 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
if (!(next_cmsg->cmsg_level == SOL_IP || next_cmsg->cmsg_level == SOL_IPV6) || if (!(next_cmsg->cmsg_level == SOL_IP || next_cmsg->cmsg_level == SOL_IPV6) ||
!(next_cmsg->cmsg_type == IP_RECVERR || !(next_cmsg->cmsg_type == IP_RECVERR ||
next_cmsg->cmsg_type == IPV6_RECVERR)) { next_cmsg->cmsg_type == IPV6_RECVERR)) {
grpc_tcp_trace.Log(GPR_ERROR, "Unexpected control message"); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_ERROR, "Unexpected control message");
}
return cmsg; return cmsg;
} }
@ -1144,9 +1178,11 @@ static bool process_errors(grpc_tcp* tcp) {
} else { } else {
/* Got a control message that is not a timestamp or zerocopy. Don't know /* Got a control message that is not a timestamp or zerocopy. Don't know
* how to handle this. */ * how to handle this. */
grpc_tcp_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
"unknown control message cmsg_level:%d cmsg_type:%d", gpr_log(GPR_INFO,
cmsg->cmsg_level, cmsg->cmsg_type); "unknown control message cmsg_level:%d cmsg_type:%d",
cmsg->cmsg_level, cmsg->cmsg_type);
}
return processed_err; return processed_err;
} }
} }
@ -1159,8 +1195,10 @@ static bool process_errors(grpc_tcp* tcp) {
static void tcp_handle_error(void* arg /* grpc_tcp */, static void tcp_handle_error(void* arg /* grpc_tcp */,
grpc_error_handle error) { grpc_error_handle error) {
grpc_tcp* tcp = static_cast<grpc_tcp*>(arg); grpc_tcp* tcp = static_cast<grpc_tcp*>(arg);
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p got_error: %s", tcp, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "TCP:%p got_error: %s", tcp,
grpc_error_std_string(error).c_str());
}
if (error != GRPC_ERROR_NONE || if (error != GRPC_ERROR_NONE ||
static_cast<bool>(gpr_atm_acq_load(&tcp->stop_error_notification))) { static_cast<bool>(gpr_atm_acq_load(&tcp->stop_error_notification))) {
@ -1482,7 +1520,9 @@ static void tcp_handle_write(void* arg /* grpc_tcp */,
? tcp_flush_zerocopy(tcp, tcp->current_zerocopy_send, &error) ? tcp_flush_zerocopy(tcp, tcp->current_zerocopy_send, &error)
: tcp_flush(tcp, &error); : tcp_flush(tcp, &error);
if (!flush_result) { if (!flush_result) {
grpc_tcp_trace.Log(GPR_INFO, "write: delayed"); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "write: delayed");
}
notify_on_write(tcp); notify_on_write(tcp);
// tcp_flush does not populate error if it has returned false. // tcp_flush does not populate error if it has returned false.
GPR_DEBUG_ASSERT(error == GRPC_ERROR_NONE); GPR_DEBUG_ASSERT(error == GRPC_ERROR_NONE);
@ -1490,8 +1530,9 @@ static void tcp_handle_write(void* arg /* grpc_tcp */,
cb = tcp->write_cb; cb = tcp->write_cb;
tcp->write_cb = nullptr; tcp->write_cb = nullptr;
tcp->current_zerocopy_send = nullptr; tcp->current_zerocopy_send = nullptr;
grpc_tcp_trace.Log(GPR_INFO, "write: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "write: %s", grpc_error_std_string(error).c_str());
}
// No need to take a ref on error since tcp_flush provides a ref. // No need to take a ref on error since tcp_flush provides a ref.
grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); grpc_core::Closure::Run(DEBUG_LOCATION, cb, error);
TCP_UNREF(tcp, "write"); TCP_UNREF(tcp, "write");
@ -1552,11 +1593,14 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
TCP_REF(tcp, "write"); TCP_REF(tcp, "write");
tcp->write_cb = cb; tcp->write_cb = cb;
tcp->current_zerocopy_send = zerocopy_send_record; tcp->current_zerocopy_send = zerocopy_send_record;
grpc_tcp_trace.Log(GPR_INFO, "write: delayed"); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "write: delayed");
}
notify_on_write(tcp); notify_on_write(tcp);
} else { } else {
grpc_tcp_trace.Log(GPR_INFO, "write: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_error_std_string(error).c_str()); gpr_log(GPR_INFO, "write: %s", grpc_error_std_string(error).c_str());
}
grpc_core::Closure::Run(DEBUG_LOCATION, cb, error); grpc_core::Closure::Run(DEBUG_LOCATION, cb, error);
} }
} }

@ -215,8 +215,10 @@ static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) {
GRPC_LOG_IF_ERROR("getpeername error", err); GRPC_LOG_IF_ERROR("getpeername error", err);
GRPC_ERROR_UNREF(err); GRPC_ERROR_UNREF(err);
} }
grpc_tcp_trace.Log(GPR_INFO, "SERVER_CONNECT: %p accepted connection: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
sp->server, peer_name_string.c_str()); gpr_log(GPR_INFO, "SERVER_CONNECT: %p accepted connection: %s", sp->server,
peer_name_string.c_str());
}
ep = custom_tcp_endpoint_create( ep = custom_tcp_endpoint_create(
socket, socket,
grpc_slice_allocator_factory_create_slice_allocator( grpc_slice_allocator_factory_create_slice_allocator(
@ -374,9 +376,11 @@ static grpc_error_handle tcp_server_add_port(grpc_tcp_server* s,
addr = &wildcard; addr = &wildcard;
} }
grpc_tcp_trace.Log(GPR_INFO, "SERVER %p add_port %s error=%s", s, if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
grpc_sockaddr_to_string(addr, false).c_str(), gpr_log(GPR_INFO, "SERVER %p add_port %s error=%s", s,
grpc_error_std_string(error).c_str()); grpc_sockaddr_to_string(addr, false).c_str(),
grpc_error_std_string(error).c_str());
}
family = grpc_sockaddr_get_family(addr); family = grpc_sockaddr_get_family(addr);
socket = socket =
@ -412,7 +416,9 @@ static void tcp_server_start(grpc_tcp_server* server,
grpc_tcp_server_cb on_accept_cb, void* cb_arg) { grpc_tcp_server_cb on_accept_cb, void* cb_arg) {
grpc_tcp_listener* sp; grpc_tcp_listener* sp;
GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD();
grpc_tcp_trace.Log(GPR_INFO, "SERVER_START %p", server); if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "SERVER_START %p", server);
}
GPR_ASSERT(on_accept_cb); GPR_ASSERT(on_accept_cb);
GPR_ASSERT(!server->on_accept_cb); GPR_ASSERT(!server->on_accept_cb);
server->on_accept_cb = on_accept_cb; server->on_accept_cb = on_accept_cb;

@ -245,8 +245,10 @@ static void on_read(void* arg, grpc_error_handle err) {
} }
std::string addr_str = grpc_sockaddr_to_uri(&addr); std::string addr_str = grpc_sockaddr_to_uri(&addr);
grpc_tcp_trace.Log(GPR_INFO, "SERVER_CONNECT: incoming connection: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
addr_str.c_str()); gpr_log(GPR_INFO, "SERVER_CONNECT: incoming connection: %s",
addr_str.c_str());
}
std::string name = absl::StrCat("tcp-server-connection:", addr_str); std::string name = absl::StrCat("tcp-server-connection:", addr_str);
grpc_fd* fdobj = grpc_fd_create(fd, name.c_str(), true); grpc_fd* fdobj = grpc_fd_create(fd, name.c_str(), true);
@ -595,9 +597,10 @@ class ExternalConnectionHandler : public grpc_core::TcpServerFdHandler {
} }
grpc_set_socket_no_sigpipe_if_possible(fd); grpc_set_socket_no_sigpipe_if_possible(fd);
std::string addr_str = grpc_sockaddr_to_uri(&addr); std::string addr_str = grpc_sockaddr_to_uri(&addr);
grpc_tcp_trace.Log(GPR_INFO, if (grpc_tcp_trace.enabled()) {
"SERVER_CONNECT: incoming external connection: %s", gpr_log(GPR_INFO, "SERVER_CONNECT: incoming external connection: %s",
addr_str.c_str()); addr_str.c_str());
}
std::string name = absl::StrCat("tcp-server-connection:", addr_str); std::string name = absl::StrCat("tcp-server-connection:", addr_str);
grpc_fd* fdobj = grpc_fd_create(fd, name.c_str(), true); grpc_fd* fdobj = grpc_fd_create(fd, name.c_str(), true);
read_notifier_pollset = read_notifier_pollset =

@ -183,7 +183,9 @@ static void on_read(void* tcpp, grpc_error_handle error) {
grpc_winsocket* socket = tcp->socket; grpc_winsocket* socket = tcp->socket;
grpc_winsocket_callback_info* info = &socket->read_info; grpc_winsocket_callback_info* info = &socket->read_info;
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p on_read", tcp); if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_INFO, "TCP:%p on_read", tcp);
}
GRPC_ERROR_REF(error); GRPC_ERROR_REF(error);
@ -217,7 +219,9 @@ static void on_read(void* tcpp, grpc_error_handle error) {
} }
} }
} else { } else {
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p unref read_slice", tcp); if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_INFO, "TCP:%p unref read_slice", tcp);
}
grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices);
error = tcp->shutting_down error = tcp->shutting_down
? GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( ? GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
@ -245,7 +249,9 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices,
WSABUF buffers[MAX_WSABUF_COUNT]; WSABUF buffers[MAX_WSABUF_COUNT];
size_t i; size_t i;
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p win_read", tcp); if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_INFO, "TCP:%p win_read", tcp);
}
if (tcp->shutting_down) { if (tcp->shutting_down) {
grpc_core::ExecCtx::Run( grpc_core::ExecCtx::Run(
@ -313,7 +319,9 @@ static void on_write(void* tcpp, grpc_error_handle error) {
grpc_winsocket_callback_info* info = &handle->write_info; grpc_winsocket_callback_info* info = &handle->write_info;
grpc_closure* cb; grpc_closure* cb;
grpc_tcp_trace.Log(GPR_INFO, "TCP:%p on_write", tcp); if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_INFO, "TCP:%p on_write", tcp);
}
GRPC_ERROR_REF(error); GRPC_ERROR_REF(error);

@ -363,9 +363,11 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
timer->hash_table_next = nullptr; timer->hash_table_next = nullptr;
#endif #endif
grpc_timer_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
GPR_INFO, "TIMER %p: SET %" PRId64 " now %" PRId64 " call %p[%p]", timer, gpr_log(GPR_INFO, "TIMER %p: SET %" PRId64 " now %" PRId64 " call %p[%p]",
deadline, grpc_core::ExecCtx::Get()->Now(), closure, closure->cb); timer, deadline, grpc_core::ExecCtx::Get()->Now(), closure,
closure->cb);
}
if (!g_shared_mutables.initialized) { if (!g_shared_mutables.initialized) {
timer->pending = false; timer->pending = false;
@ -398,12 +400,13 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
timer->heap_index = INVALID_HEAP_INDEX; timer->heap_index = INVALID_HEAP_INDEX;
list_join(&shard->list, timer); list_join(&shard->list, timer);
} }
grpc_timer_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
" .. add to shard %d with queue_deadline_cap=%" PRId64 gpr_log(GPR_INFO,
" => is_first_timer=%s", " .. add to shard %d with queue_deadline_cap=%" PRId64
static_cast<int>(shard - g_shards), " => is_first_timer=%s",
shard->queue_deadline_cap, static_cast<int>(shard - g_shards), shard->queue_deadline_cap,
is_first_timer ? "true" : "false"); is_first_timer ? "true" : "false");
}
gpr_mu_unlock(&shard->mu); gpr_mu_unlock(&shard->mu);
/* Deadline may have decreased, we need to adjust the main queue. Note /* Deadline may have decreased, we need to adjust the main queue. Note
@ -419,8 +422,10 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
grpc_timer_check. */ grpc_timer_check. */
if (is_first_timer) { if (is_first_timer) {
gpr_mu_lock(&g_shared_mutables.mu); gpr_mu_lock(&g_shared_mutables.mu);
grpc_timer_trace.Log(GPR_INFO, " .. old shard min_deadline=%" PRId64, if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
shard->min_deadline); gpr_log(GPR_INFO, " .. old shard min_deadline=%" PRId64,
shard->min_deadline);
}
if (deadline < shard->min_deadline) { if (deadline < shard->min_deadline) {
grpc_millis old_min_deadline = g_shard_queue[0]->min_deadline; grpc_millis old_min_deadline = g_shard_queue[0]->min_deadline;
shard->min_deadline = deadline; shard->min_deadline = deadline;
@ -461,8 +466,10 @@ static void timer_cancel(grpc_timer* timer) {
timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)];
gpr_mu_lock(&shard->mu); gpr_mu_lock(&shard->mu);
grpc_timer_trace.Log(GPR_INFO, "TIMER %p: CANCEL pending=%s", timer, if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
timer->pending ? "true" : "false"); gpr_log(GPR_INFO, "TIMER %p: CANCEL pending=%s", timer,
timer->pending ? "true" : "false");
}
if (timer->pending) { if (timer->pending) {
REMOVE_FROM_HASH_TABLE(timer); REMOVE_FROM_HASH_TABLE(timer);
@ -501,16 +508,18 @@ static bool refill_heap(timer_shard* shard, grpc_millis now) {
saturating_add(GPR_MAX(now, shard->queue_deadline_cap), saturating_add(GPR_MAX(now, shard->queue_deadline_cap),
static_cast<grpc_millis>(deadline_delta * 1000.0)); static_cast<grpc_millis>(deadline_delta * 1000.0));
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, " .. shard[%d]->queue_deadline_cap --> %" PRId64, gpr_log(GPR_INFO, " .. shard[%d]->queue_deadline_cap --> %" PRId64,
static_cast<int>(shard - g_shards), shard->queue_deadline_cap); static_cast<int>(shard - g_shards), shard->queue_deadline_cap);
}
for (timer = shard->list.next; timer != &shard->list; timer = next) { for (timer = shard->list.next; timer != &shard->list; timer = next) {
next = timer->next; next = timer->next;
if (timer->deadline < shard->queue_deadline_cap) { if (timer->deadline < shard->queue_deadline_cap) {
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, " .. add timer with deadline %" PRId64 " to heap", gpr_log(GPR_INFO, " .. add timer with deadline %" PRId64 " to heap",
timer->deadline); timer->deadline);
}
list_remove(timer); list_remove(timer);
grpc_timer_heap_add(&shard->heap, timer); grpc_timer_heap_add(&shard->heap, timer);
} }
@ -524,21 +533,26 @@ static bool refill_heap(timer_shard* shard, grpc_millis now) {
static grpc_timer* pop_one(timer_shard* shard, grpc_millis now) { static grpc_timer* pop_one(timer_shard* shard, grpc_millis now) {
grpc_timer* timer; grpc_timer* timer;
for (;;) { for (;;) {
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, " .. shard[%d]: heap_empty=%s", gpr_log(GPR_INFO, " .. shard[%d]: heap_empty=%s",
static_cast<int>(shard - g_shards), static_cast<int>(shard - g_shards),
grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false");
}
if (grpc_timer_heap_is_empty(&shard->heap)) { if (grpc_timer_heap_is_empty(&shard->heap)) {
if (now < shard->queue_deadline_cap) return nullptr; if (now < shard->queue_deadline_cap) return nullptr;
if (!refill_heap(shard, now)) return nullptr; if (!refill_heap(shard, now)) return nullptr;
} }
timer = grpc_timer_heap_top(&shard->heap); timer = grpc_timer_heap_top(&shard->heap);
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, " .. check top timer deadline=%" PRId64 " now=%" PRId64, gpr_log(GPR_INFO,
timer->deadline, now); " .. check top timer deadline=%" PRId64 " now=%" PRId64,
timer->deadline, now);
}
if (timer->deadline > now) return nullptr; if (timer->deadline > now) return nullptr;
grpc_timer_trace.Log(GPR_INFO, "TIMER %p: FIRE %" PRId64 "ms late", timer, if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
now - timer->deadline); gpr_log(GPR_INFO, "TIMER %p: FIRE %" PRId64 "ms late", timer,
now - timer->deadline);
}
timer->pending = false; timer->pending = false;
grpc_timer_heap_pop(&shard->heap); grpc_timer_heap_pop(&shard->heap);
return timer; return timer;
@ -560,8 +574,10 @@ static size_t pop_timers(timer_shard* shard, grpc_millis now,
} }
*new_min_deadline = compute_min_deadline(shard); *new_min_deadline = compute_min_deadline(shard);
gpr_mu_unlock(&shard->mu); gpr_mu_unlock(&shard->mu);
grpc_timer_check_trace.Log(GPR_INFO, " .. shard[%d] popped %" PRIdPTR, if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
static_cast<int>(shard - g_shards), n); gpr_log(GPR_INFO, " .. shard[%d] popped %" PRIdPTR,
static_cast<int>(shard - g_shards), n);
}
return n; return n;
} }
@ -594,10 +610,11 @@ static grpc_timer_check_result run_some_expired_timers(
gpr_mu_lock(&g_shared_mutables.mu); gpr_mu_lock(&g_shared_mutables.mu);
result = GRPC_TIMERS_CHECKED_AND_EMPTY; result = GRPC_TIMERS_CHECKED_AND_EMPTY;
grpc_timer_check_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
" .. shard[%d]->min_deadline = %" PRId64, gpr_log(GPR_INFO, " .. shard[%d]->min_deadline = %" PRId64,
static_cast<int>(g_shard_queue[0] - g_shards), static_cast<int>(g_shard_queue[0] - g_shards),
g_shard_queue[0]->min_deadline); g_shard_queue[0]->min_deadline);
}
while (g_shard_queue[0]->min_deadline < now || while (g_shard_queue[0]->min_deadline < now ||
(now != GRPC_MILLIS_INF_FUTURE && (now != GRPC_MILLIS_INF_FUTURE &&
@ -611,12 +628,14 @@ static grpc_timer_check_result run_some_expired_timers(
result = GRPC_TIMERS_FIRED; result = GRPC_TIMERS_FIRED;
} }
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
" .. result --> %d" " .. result --> %d"
", shard[%d]->min_deadline %" PRId64 " --> %" PRId64 ", now=%" PRId64, ", shard[%d]->min_deadline %" PRId64 " --> %" PRId64
result, static_cast<int>(g_shard_queue[0] - g_shards), ", now=%" PRId64,
g_shard_queue[0]->min_deadline, new_min_deadline, now); result, static_cast<int>(g_shard_queue[0] - g_shards),
g_shard_queue[0]->min_deadline, new_min_deadline, now);
}
/* An grpc_timer_init() on the shard could intervene here, adding a new /* An grpc_timer_init() on the shard could intervene here, adding a new
timer that is earlier than new_min_deadline. However, timer that is earlier than new_min_deadline. However,
@ -676,9 +695,10 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
if (next != nullptr) { if (next != nullptr) {
*next = GPR_MIN(*next, min_timer); *next = GPR_MIN(*next, min_timer);
} }
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, "TIMER CHECK SKIP: now=%" PRId64 " min_timer=%" PRId64, now, gpr_log(GPR_INFO, "TIMER CHECK SKIP: now=%" PRId64 " min_timer=%" PRId64,
min_timer); now, min_timer);
}
return GRPC_TIMERS_CHECKED_AND_EMPTY; return GRPC_TIMERS_CHECKED_AND_EMPTY;
} }

@ -84,7 +84,9 @@ static void start_timer_thread_and_unlock(void) {
++g_waiter_count; ++g_waiter_count;
++g_thread_count; ++g_thread_count;
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
grpc_timer_check_trace.Log(GPR_INFO, "Spawn timer thread"); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
gpr_log(GPR_INFO, "Spawn timer thread");
}
completed_thread* ct = completed_thread* ct =
static_cast<completed_thread*>(gpr_malloc(sizeof(*ct))); static_cast<completed_thread*>(gpr_malloc(sizeof(*ct)));
ct->thd = grpc_core::Thread("grpc_global_timer", timer_thread, ct); ct->thd = grpc_core::Thread("grpc_global_timer", timer_thread, ct);
@ -118,13 +120,17 @@ static void run_some_timers() {
// if there's no thread waiting with a timeout, kick an existing untimed // if there's no thread waiting with a timeout, kick an existing untimed
// waiter so that the next deadline is not missed // waiter so that the next deadline is not missed
if (!g_has_timed_waiter) { if (!g_has_timed_waiter) {
grpc_timer_check_trace.Log(GPR_INFO, "kick untimed waiter"); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
gpr_log(GPR_INFO, "kick untimed waiter");
}
gpr_cv_signal(&g_cv_wait); gpr_cv_signal(&g_cv_wait);
} }
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
} }
// without our lock, flush the exec_ctx // without our lock, flush the exec_ctx
grpc_timer_check_trace.Log(GPR_INFO, "flush exec_ctx"); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
gpr_log(GPR_INFO, "flush exec_ctx");
}
grpc_core::ExecCtx::Get()->Flush(); grpc_core::ExecCtx::Get()->Flush();
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);
// garbage collect any threads that are dead // garbage collect any threads that are dead
@ -194,9 +200,11 @@ static bool wait_until(grpc_millis next) {
gpr_cv_wait(&g_cv_wait, &g_mu, gpr_cv_wait(&g_cv_wait, &g_mu,
grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC)); grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC));
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, "wait ended: was_timed:%d kicked:%d", gpr_log(GPR_INFO, "wait ended: was_timed:%d kicked:%d",
my_timed_waiter_generation == g_timed_waiter_generation, g_kicked); my_timed_waiter_generation == g_timed_waiter_generation,
g_kicked);
}
// if this was the timed waiter, then we need to check timers, and flag // if this was the timed waiter, then we need to check timers, and flag
// that there's now no timed waiter... we'll look for a replacement if // that there's now no timed waiter... we'll look for a replacement if
// there's work to do after checking timers (code above) // there's work to do after checking timers (code above)
@ -238,8 +246,9 @@ static void timer_main_loop() {
Consequently, we can just sleep forever here and be happy at some Consequently, we can just sleep forever here and be happy at some
saved wakeup cycles. */ saved wakeup cycles. */
grpc_timer_check_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
GPR_INFO, "timers not checked: expect another thread to"); gpr_log(GPR_INFO, "timers not checked: expect another thread to");
}
next = GRPC_MILLIS_INF_FUTURE; next = GRPC_MILLIS_INF_FUTURE;
ABSL_FALLTHROUGH_INTENDED; ABSL_FALLTHROUGH_INTENDED;
case GRPC_TIMERS_CHECKED_AND_EMPTY: case GRPC_TIMERS_CHECKED_AND_EMPTY:
@ -263,7 +272,9 @@ static void timer_thread_cleanup(completed_thread* ct) {
ct->next = g_completed_threads; ct->next = g_completed_threads;
g_completed_threads = ct; g_completed_threads = ct;
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
grpc_timer_check_trace.Log(GPR_INFO, "End timer thread"); if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
gpr_log(GPR_INFO, "End timer thread");
}
} }
static void timer_thread(void* completed_thread_ptr) { static void timer_thread(void* completed_thread_ptr) {
@ -302,17 +313,20 @@ void grpc_timer_manager_init(void) {
static void stop_threads(void) { static void stop_threads(void) {
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);
grpc_timer_check_trace.Log(GPR_INFO, "stop timer threads: threaded=%d", if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
g_threaded); gpr_log(GPR_INFO, "stop timer threads: threaded=%d", g_threaded);
}
if (g_threaded) { if (g_threaded) {
g_threaded = false; g_threaded = false;
gpr_cv_broadcast(&g_cv_wait); gpr_cv_broadcast(&g_cv_wait);
grpc_timer_check_trace.Log(GPR_INFO, "num timer threads: %d", if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
g_thread_count); gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count);
}
while (g_thread_count > 0) { while (g_thread_count > 0) {
gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
grpc_timer_check_trace.Log(GPR_INFO, "num timer threads: %d", if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
g_thread_count); gpr_log(GPR_INFO, "num timer threads: %d", g_thread_count);
}
gc_completed_threads(); gc_completed_threads();
} }
} }

@ -51,16 +51,19 @@ class WorkSerializer::WorkSerializerImpl : public Orphanable {
void WorkSerializer::WorkSerializerImpl::Run( void WorkSerializer::WorkSerializerImpl::Run(
std::function<void()> callback, const grpc_core::DebugLocation& location) { std::function<void()> callback, const grpc_core::DebugLocation& location) {
grpc_work_serializer_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
GPR_INFO, "WorkSerializer::Run() %p Scheduling callback [%s:%d]", this, gpr_log(GPR_INFO, "WorkSerializer::Run() %p Scheduling callback [%s:%d]",
location.file(), location.line()); this, location.file(), location.line());
}
const size_t prev_size = size_.fetch_add(1); const size_t prev_size = size_.fetch_add(1);
// The work serializer should not have been orphaned. // The work serializer should not have been orphaned.
GPR_DEBUG_ASSERT(prev_size > 0); GPR_DEBUG_ASSERT(prev_size > 0);
if (prev_size == 1) { if (prev_size == 1) {
// There is no other closure executing right now on this work serializer. // There is no other closure executing right now on this work serializer.
// Execute this closure immediately. // Execute this closure immediately.
grpc_work_serializer_trace.Log(GPR_INFO, " Executing immediately"); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Executing immediately");
}
callback(); callback();
// Loan this thread to the work serializer thread and drain the queue. // Loan this thread to the work serializer thread and drain the queue.
DrainQueue(); DrainQueue();
@ -69,17 +72,22 @@ void WorkSerializer::WorkSerializerImpl::Run(
new CallbackWrapper(std::move(callback), location); new CallbackWrapper(std::move(callback), location);
// There already are closures executing on this work serializer. Simply add // There already are closures executing on this work serializer. Simply add
// this closure to the queue. // this closure to the queue.
grpc_work_serializer_trace.Log(GPR_INFO, " Scheduling on queue : item %p", if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
cb_wrapper); gpr_log(GPR_INFO, " Scheduling on queue : item %p", cb_wrapper);
}
queue_.Push(&cb_wrapper->mpscq_node); queue_.Push(&cb_wrapper->mpscq_node);
} }
} }
void WorkSerializer::WorkSerializerImpl::Orphan() { void WorkSerializer::WorkSerializerImpl::Orphan() {
grpc_work_serializer_trace.Log(GPR_INFO, "WorkSerializer::Orphan() %p", this); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, "WorkSerializer::Orphan() %p", this);
}
size_t prev_size = size_.fetch_sub(1); size_t prev_size = size_.fetch_sub(1);
if (prev_size == 1) { if (prev_size == 1) {
grpc_work_serializer_trace.Log(GPR_INFO, " Destroying"); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Destroying");
}
delete this; delete this;
} }
} }
@ -90,19 +98,24 @@ void WorkSerializer::WorkSerializerImpl::Orphan() {
// is at least 1. // is at least 1.
void WorkSerializer::WorkSerializerImpl::DrainQueue() { void WorkSerializer::WorkSerializerImpl::DrainQueue() {
while (true) { while (true) {
grpc_work_serializer_trace.Log(GPR_INFO, "WorkSerializer::DrainQueue() %p", if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
this); gpr_log(GPR_INFO, "WorkSerializer::DrainQueue() %p", this);
}
size_t prev_size = size_.fetch_sub(1); size_t prev_size = size_.fetch_sub(1);
GPR_DEBUG_ASSERT(prev_size >= 1); GPR_DEBUG_ASSERT(prev_size >= 1);
// It is possible that while draining the queue, one of the callbacks ended // It is possible that while draining the queue, one of the callbacks ended
// up orphaning the work serializer. In that case, delete the object. // up orphaning the work serializer. In that case, delete the object.
if (prev_size == 1) { if (prev_size == 1) {
grpc_work_serializer_trace.Log(GPR_INFO, " Queue Drained. Destroying"); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Queue Drained. Destroying");
}
delete this; delete this;
return; return;
} }
if (prev_size == 2) { if (prev_size == 2) {
grpc_work_serializer_trace.Log(GPR_INFO, " Queue Drained"); if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Queue Drained");
}
return; return;
} }
// There is at least one callback on the queue. Pop the callback from the // There is at least one callback on the queue. Pop the callback from the
@ -113,12 +126,15 @@ void WorkSerializer::WorkSerializerImpl::DrainQueue() {
queue_.PopAndCheckEnd(&empty_unused))) == nullptr) { queue_.PopAndCheckEnd(&empty_unused))) == nullptr) {
// This can happen either due to a race condition within the mpscq // This can happen either due to a race condition within the mpscq
// implementation or because of a race with Run() // implementation or because of a race with Run()
grpc_work_serializer_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
" Queue returned nullptr, trying again"); gpr_log(GPR_INFO, " Queue returned nullptr, trying again");
}
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Running item %p : callback scheduled at [%s:%d]",
cb_wrapper, cb_wrapper->location.file(),
cb_wrapper->location.line());
} }
grpc_work_serializer_trace.Log(
GPR_INFO, " Running item %p : callback scheduled at [%s:%d]",
cb_wrapper, cb_wrapper->location.file(), cb_wrapper->location.line());
cb_wrapper->callback(); cb_wrapper->callback();
delete cb_wrapper; delete cb_wrapper;
} }

@ -499,11 +499,12 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
const char* json_refresh_token, void* reserved) { const char* json_refresh_token, void* reserved) {
grpc_auth_refresh_token token = grpc_auth_refresh_token token =
grpc_auth_refresh_token_create_from_string(json_refresh_token); grpc_auth_refresh_token_create_from_string(json_refresh_token);
grpc_api_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_api_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"grpc_refresh_token_credentials_create(json_refresh_token=%s, " "grpc_refresh_token_credentials_create(json_refresh_token=%s, "
"reserved=%p)", "reserved=%p)",
create_loggable_refresh_token(&token).c_str(), reserved); create_loggable_refresh_token(&token).c_str(), reserved);
}
GPR_ASSERT(reserved == nullptr); GPR_ASSERT(reserved == nullptr);
return grpc_refresh_token_credentials_create_from_auth_refresh_token(token) return grpc_refresh_token_credentials_create_from_auth_refresh_token(token)
.release(); .release();

@ -132,11 +132,12 @@ static void plugin_md_request_metadata_ready(void* request,
GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
grpc_plugin_credentials::pending_request* r = grpc_plugin_credentials::pending_request* r =
static_cast<grpc_plugin_credentials::pending_request*>(request); static_cast<grpc_plugin_credentials::pending_request*>(request);
grpc_plugin_credentials_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned " "plugin_credentials[%p]: request %p: plugin returned "
"asynchronously", "asynchronously",
r->creds, r); r->creds, r);
}
// Remove request from pending list if not previously cancelled. // Remove request from pending list if not previously cancelled.
r->creds->pending_request_complete(r); r->creds->pending_request_complete(r);
// If it has not been cancelled, process it. // If it has not been cancelled, process it.
@ -144,12 +145,12 @@ static void plugin_md_request_metadata_ready(void* request,
grpc_error_handle error = grpc_error_handle error =
process_plugin_result(r, md, num_md, status, error_details); process_plugin_result(r, md, num_md, status, error_details);
grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_request_metadata, error); grpc_core::ExecCtx::Run(DEBUG_LOCATION, r->on_request_metadata, error);
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin was previously "
"cancelled",
r->creds, r);
} }
grpc_plugin_credentials_trace.Log(
GPR_INFO,
"plugin_credentials[%p]: request %p: plugin was previously "
"cancelled",
r->creds, r);
gpr_free(r); gpr_free(r);
} }
@ -174,9 +175,10 @@ bool grpc_plugin_credentials::get_request_metadata(
pending_requests_ = request; pending_requests_ = request;
gpr_mu_unlock(&mu_); gpr_mu_unlock(&mu_);
// Invoke the plugin. The callback holds a ref to us. // Invoke the plugin. The callback holds a ref to us.
grpc_plugin_credentials_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin", this, gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin",
request); this, request);
}
Ref().release(); Ref().release();
grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX]; grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX];
size_t num_creds_md = 0; size_t num_creds_md = 0;
@ -185,11 +187,12 @@ bool grpc_plugin_credentials::get_request_metadata(
if (!plugin_.get_metadata( if (!plugin_.get_metadata(
plugin_.state, context, plugin_md_request_metadata_ready, request, plugin_.state, context, plugin_md_request_metadata_ready, request,
creds_md, &num_creds_md, &status, &error_details)) { creds_md, &num_creds_md, &status, &error_details)) {
grpc_plugin_credentials_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin will return " "plugin_credentials[%p]: request %p: plugin will return "
"asynchronously", "asynchronously",
this, request); this, request);
}
return false; // Asynchronous return. return false; // Asynchronous return.
} }
// Returned synchronously. // Returned synchronously.
@ -199,18 +202,20 @@ bool grpc_plugin_credentials::get_request_metadata(
// asynchronously by plugin_cancel_get_request_metadata(), so return // asynchronously by plugin_cancel_get_request_metadata(), so return
// false. Otherwise, process the result. // false. Otherwise, process the result.
if (request->cancelled) { if (request->cancelled) {
grpc_plugin_credentials_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p was cancelled, error " "plugin_credentials[%p]: request %p was cancelled, error "
"will be returned asynchronously", "will be returned asynchronously",
this, request); this, request);
}
retval = false; retval = false;
} else { } else {
grpc_plugin_credentials_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned " "plugin_credentials[%p]: request %p: plugin returned "
"synchronously", "synchronously",
this, request); this, request);
}
*error = process_plugin_result(request, creds_md, num_creds_md, status, *error = process_plugin_result(request, creds_md, num_creds_md, status,
error_details); error_details);
} }
@ -231,9 +236,10 @@ void grpc_plugin_credentials::cancel_get_request_metadata(
for (pending_request* pending_request = pending_requests_; for (pending_request* pending_request = pending_requests_;
pending_request != nullptr; pending_request = pending_request->next) { pending_request != nullptr; pending_request = pending_request->next) {
if (pending_request->md_array == md_array) { if (pending_request->md_array == md_array) {
grpc_plugin_credentials_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
GPR_INFO, "plugin_credentials[%p]: cancelling request %p", this, gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", this,
pending_request); pending_request);
}
pending_request->cancelled = true; pending_request->cancelled = true;
grpc_core::ExecCtx::Run(DEBUG_LOCATION, grpc_core::ExecCtx::Run(DEBUG_LOCATION,
pending_request->on_request_metadata, pending_request->on_request_metadata,

@ -744,9 +744,10 @@ static void cancel_with_status(grpc_call* c, grpc_status_code status,
} }
static void set_final_status(grpc_call* call, grpc_error_handle error) { static void set_final_status(grpc_call* call, grpc_error_handle error) {
grpc_call_error_trace.Log(GPR_DEBUG, "set_final_status %s: %s", if (GRPC_TRACE_FLAG_ENABLED(grpc_call_error_trace)) {
call->is_client ? "CLI" : "SVR", gpr_log(GPR_DEBUG, "set_final_status %s", call->is_client ? "CLI" : "SVR");
grpc_error_std_string(error).c_str()); gpr_log(GPR_DEBUG, "%s", grpc_error_std_string(error).c_str());
}
if (call->is_client) { if (call->is_client) {
grpc_error_get_status(error, call->send_deadline, grpc_error_get_status(error, call->send_deadline,
call->final_op.client.status, call->final_op.client.status,

@ -1152,7 +1152,9 @@ void Server::ChannelData::Destroy() {
server_->MaybeFinishShutdown(); server_->MaybeFinishShutdown();
GRPC_CLOSURE_INIT(&finish_destroy_channel_closure_, FinishDestroy, this, GRPC_CLOSURE_INIT(&finish_destroy_channel_closure_, FinishDestroy, this,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
grpc_server_channel_trace.Log(GPR_INFO, "Disconnected client"); if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) {
gpr_log(GPR_INFO, "Disconnected client");
}
grpc_transport_op* op = grpc_transport_op* op =
grpc_make_transport_op(&finish_destroy_channel_closure_); grpc_make_transport_op(&finish_destroy_channel_closure_);
op->set_accept_stream = true; op->set_accept_stream = true;

@ -46,17 +46,21 @@ grpc_millis BdpEstimator::CompletePing() {
1e-9 * static_cast<double>(dt_ts.tv_nsec); 1e-9 * static_cast<double>(dt_ts.tv_nsec);
double bw = dt > 0 ? (static_cast<double>(accumulator_) / dt) : 0; double bw = dt > 0 ? (static_cast<double>(accumulator_) / dt) : 0;
int start_inter_ping_delay = inter_ping_delay_; int start_inter_ping_delay = inter_ping_delay_;
grpc_bdp_estimator_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace)) {
"bdp[%s]:complete acc=%" PRId64 " est=%" PRId64 gpr_log(GPR_INFO,
" dt=%lf bw=%lfMbs bw_est=%lfMbs", "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64
name_, accumulator_, estimate_, dt, " dt=%lf bw=%lfMbs bw_est=%lfMbs",
bw / 125000.0, bw_est_ / 125000.0); name_, accumulator_, estimate_, dt, bw / 125000.0,
bw_est_ / 125000.0);
}
GPR_ASSERT(ping_state_ == PingState::STARTED); GPR_ASSERT(ping_state_ == PingState::STARTED);
if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) { if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) {
estimate_ = GPR_MAX(accumulator_, estimate_ * 2); estimate_ = GPR_MAX(accumulator_, estimate_ * 2);
bw_est_ = bw; bw_est_ = bw;
grpc_bdp_estimator_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace)) {
GPR_INFO, "bdp[%s]: estimate increased to %" PRId64, name_, estimate_); gpr_log(GPR_INFO, "bdp[%s]: estimate increased to %" PRId64, name_,
estimate_);
}
inter_ping_delay_ /= 2; // if the ping estimate changes, inter_ping_delay_ /= 2; // if the ping estimate changes,
// exponentially get faster at probing // exponentially get faster at probing
} else if (inter_ping_delay_ < 10000) { } else if (inter_ping_delay_ < 10000) {
@ -70,8 +74,10 @@ grpc_millis BdpEstimator::CompletePing() {
} }
if (start_inter_ping_delay != inter_ping_delay_) { if (start_inter_ping_delay != inter_ping_delay_) {
stable_estimate_count_ = 0; stable_estimate_count_ = 0;
grpc_bdp_estimator_trace.Log(GPR_INFO, "bdp[%s]:update_inter_time to %dms", if (GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace)) {
name_, inter_ping_delay_); gpr_log(GPR_INFO, "bdp[%s]:update_inter_time to %dms", name_,
inter_ping_delay_);
}
} }
ping_state_ = PingState::UNSCHEDULED; ping_state_ = PingState::UNSCHEDULED;
accumulator_ = 0; accumulator_ = 0;

@ -49,9 +49,10 @@ class BdpEstimator {
// grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a // grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a
// transport (but not necessarily started) // transport (but not necessarily started)
void SchedulePing() { void SchedulePing() {
grpc_bdp_estimator_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace)) {
"bdp[%s]:sched acc=%" PRId64 " est=%" PRId64, gpr_log(GPR_INFO, "bdp[%s]:sched acc=%" PRId64 " est=%" PRId64, name_,
name_, accumulator_, estimate_); accumulator_, estimate_);
}
GPR_ASSERT(ping_state_ == PingState::UNSCHEDULED); GPR_ASSERT(ping_state_ == PingState::UNSCHEDULED);
ping_state_ = PingState::SCHEDULED; ping_state_ = PingState::SCHEDULED;
accumulator_ = 0; accumulator_ = 0;
@ -61,9 +62,10 @@ class BdpEstimator {
// once // once
// the ping is on the wire // the ping is on the wire
void StartPing() { void StartPing() {
grpc_bdp_estimator_trace.Log(GPR_INFO, if (GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace)) {
"bdp[%s]:start acc=%" PRId64 " est=%" PRId64, gpr_log(GPR_INFO, "bdp[%s]:start acc=%" PRId64 " est=%" PRId64, name_,
name_, accumulator_, estimate_); accumulator_, estimate_);
}
GPR_ASSERT(ping_state_ == PingState::SCHEDULED); GPR_ASSERT(ping_state_ == PingState::SCHEDULED);
ping_state_ = PingState::STARTED; ping_state_ = PingState::STARTED;
ping_start_time_ = gpr_now(GPR_CLOCK_MONOTONIC); ping_start_time_ = gpr_now(GPR_CLOCK_MONOTONIC);

@ -75,10 +75,11 @@ class AsyncConnectivityStateWatcherInterface::Notifier {
private: private:
static void SendNotification(void* arg, grpc_error_handle /*ignored*/) { static void SendNotification(void* arg, grpc_error_handle /*ignored*/) {
Notifier* self = static_cast<Notifier*>(arg); Notifier* self = static_cast<Notifier*>(arg);
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, "watcher %p: delivering async notification for %s (%s)", gpr_log(GPR_INFO, "watcher %p: delivering async notification for %s (%s)",
self->watcher_.get(), ConnectivityStateName(self->state_), self->watcher_.get(), ConnectivityStateName(self->state_),
self->status_.ToString().c_str()); self->status_.ToString().c_str());
}
self->watcher_->OnConnectivityStateChange(self->state_, self->status_); self->watcher_->OnConnectivityStateChange(self->state_, self->status_);
delete self; delete self;
} }
@ -104,11 +105,12 @@ ConnectivityStateTracker::~ConnectivityStateTracker() {
state_.load(std::memory_order_relaxed); state_.load(std::memory_order_relaxed);
if (current_state == GRPC_CHANNEL_SHUTDOWN) return; if (current_state == GRPC_CHANNEL_SHUTDOWN) return;
for (const auto& p : watchers_) { for (const auto& p : watchers_) {
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s",
name_, this, p.first, ConnectivityStateName(current_state), name_, this, p.first, ConnectivityStateName(current_state),
ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN)); ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN));
}
p.second->Notify(GRPC_CHANNEL_SHUTDOWN, absl::Status()); p.second->Notify(GRPC_CHANNEL_SHUTDOWN, absl::Status());
} }
} }
@ -116,17 +118,19 @@ ConnectivityStateTracker::~ConnectivityStateTracker() {
void ConnectivityStateTracker::AddWatcher( void ConnectivityStateTracker::AddWatcher(
grpc_connectivity_state initial_state, grpc_connectivity_state initial_state,
OrphanablePtr<ConnectivityStateWatcherInterface> watcher) { OrphanablePtr<ConnectivityStateWatcherInterface> watcher) {
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, "ConnectivityStateTracker %s[%p]: add watcher %p", name_, this, gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: add watcher %p", name_,
watcher.get()); this, watcher.get());
}
grpc_connectivity_state current_state = grpc_connectivity_state current_state =
state_.load(std::memory_order_relaxed); state_.load(std::memory_order_relaxed);
if (initial_state != current_state) { if (initial_state != current_state) {
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s",
name_, this, watcher.get(), ConnectivityStateName(initial_state), name_, this, watcher.get(), ConnectivityStateName(initial_state),
ConnectivityStateName(current_state)); ConnectivityStateName(current_state));
}
watcher->Notify(current_state, status_); watcher->Notify(current_state, status_);
} }
// If we're in state SHUTDOWN, don't add the watcher, so that it will // If we're in state SHUTDOWN, don't add the watcher, so that it will
@ -138,9 +142,10 @@ void ConnectivityStateTracker::AddWatcher(
void ConnectivityStateTracker::RemoveWatcher( void ConnectivityStateTracker::RemoveWatcher(
ConnectivityStateWatcherInterface* watcher) { ConnectivityStateWatcherInterface* watcher) {
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, "ConnectivityStateTracker %s[%p]: remove watcher %p", name_, gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: remove watcher %p",
this, watcher); name_, this, watcher);
}
watchers_.erase(watcher); watchers_.erase(watcher);
} }
@ -150,18 +155,20 @@ void ConnectivityStateTracker::SetState(grpc_connectivity_state state,
grpc_connectivity_state current_state = grpc_connectivity_state current_state =
state_.load(std::memory_order_relaxed); state_.load(std::memory_order_relaxed);
if (state == current_state) return; if (state == current_state) return;
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, "ConnectivityStateTracker %s[%p]: %s -> %s (%s, %s)", name_, gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: %s -> %s (%s, %s)",
this, ConnectivityStateName(current_state), ConnectivityStateName(state), name_, this, ConnectivityStateName(current_state),
reason, status.ToString().c_str()); ConnectivityStateName(state), reason, status.ToString().c_str());
}
state_.store(state, std::memory_order_relaxed); state_.store(state, std::memory_order_relaxed);
status_ = status; status_ = status;
for (const auto& p : watchers_) { for (const auto& p : watchers_) {
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, gpr_log(GPR_INFO,
"ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s",
name_, this, p.first, ConnectivityStateName(current_state), name_, this, p.first, ConnectivityStateName(current_state),
ConnectivityStateName(state)); ConnectivityStateName(state));
}
p.second->Notify(state, status); p.second->Notify(state, status);
} }
// If the new state is SHUTDOWN, orphan all of the watchers. This // If the new state is SHUTDOWN, orphan all of the watchers. This
@ -171,9 +178,10 @@ void ConnectivityStateTracker::SetState(grpc_connectivity_state state,
grpc_connectivity_state ConnectivityStateTracker::state() const { grpc_connectivity_state ConnectivityStateTracker::state() const {
grpc_connectivity_state state = state_.load(std::memory_order_relaxed); grpc_connectivity_state state = state_.load(std::memory_order_relaxed);
grpc_connectivity_state_trace.Log( if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) {
GPR_INFO, "ConnectivityStateTracker %s[%p]: get current state: %s", name_, gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: get current state: %s",
this, ConnectivityStateName(state)); name_, this, ConnectivityStateName(state));
}
return state; return state;
} }

@ -81,10 +81,10 @@ void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs,
#ifndef NDEBUG #ifndef NDEBUG
inline void grpc_stream_ref(grpc_stream_refcount* refcount, inline void grpc_stream_ref(grpc_stream_refcount* refcount,
const char* reason) { const char* reason) {
grpc_trace_stream_refcount.Log(GPR_DEBUG, "%s %p:%p REF %s", if (grpc_trace_stream_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%s %p:%p REF %s", refcount->object_type, refcount,
refcount->object_type, refcount, refcount->destroy.cb_arg, reason);
refcount->destroy.cb_arg, reason); }
refcount->refs.RefNonZero(DEBUG_LOCATION, reason); refcount->refs.RefNonZero(DEBUG_LOCATION, reason);
} }
#else #else
@ -98,10 +98,10 @@ void grpc_stream_destroy(grpc_stream_refcount* refcount);
#ifndef NDEBUG #ifndef NDEBUG
inline void grpc_stream_unref(grpc_stream_refcount* refcount, inline void grpc_stream_unref(grpc_stream_refcount* refcount,
const char* reason) { const char* reason) {
grpc_trace_stream_refcount.Log(GPR_DEBUG, "%s %p:%p UNREF %s", if (grpc_trace_stream_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%s %p:%p UNREF %s", refcount->object_type, refcount,
refcount->object_type, refcount, refcount->destroy.cb_arg, reason);
refcount->destroy.cb_arg, reason); }
if (GPR_UNLIKELY(refcount->refs.Unref(DEBUG_LOCATION, reason))) { if (GPR_UNLIKELY(refcount->refs.Unref(DEBUG_LOCATION, reason))) {
grpc_stream_destroy(refcount); grpc_stream_destroy(refcount);
} }

@ -598,9 +598,11 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer(
if (next_message_to_send > TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { if (next_message_to_send > TSI_FAKE_HANDSHAKE_MESSAGE_MAX) {
next_message_to_send = TSI_FAKE_HANDSHAKE_MESSAGE_MAX; next_message_to_send = TSI_FAKE_HANDSHAKE_MESSAGE_MAX;
} }
tsi_tracing_enabled.Log( if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
GPR_INFO, "%s prepared %s.", impl->is_client ? "Client" : "Server", gpr_log(GPR_INFO, "%s prepared %s.",
tsi_fake_handshake_message_to_string(impl->next_message_to_send)); impl->is_client ? "Client" : "Server",
tsi_fake_handshake_message_to_string(impl->next_message_to_send));
}
impl->next_message_to_send = next_message_to_send; impl->next_message_to_send = next_message_to_send;
} }
result = tsi_fake_frame_encode(bytes, bytes_size, &impl->outgoing_frame); result = tsi_fake_frame_encode(bytes, bytes_size, &impl->outgoing_frame);
@ -608,7 +610,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer(
if (!impl->is_client && if (!impl->is_client &&
impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) {
/* We're done. */ /* We're done. */
tsi_tracing_enabled.Log(GPR_INFO, "Server is done."); if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
gpr_log(GPR_INFO, "Server is done.");
}
impl->result = TSI_OK; impl->result = TSI_OK;
} else { } else {
impl->needs_incoming_message = 1; impl->needs_incoming_message = 1;
@ -645,15 +649,17 @@ static tsi_result fake_handshaker_process_bytes_from_peer(
tsi_fake_handshake_message_to_string(received_msg), tsi_fake_handshake_message_to_string(received_msg),
tsi_fake_handshake_message_to_string(expected_msg)); tsi_fake_handshake_message_to_string(expected_msg));
} }
tsi_tracing_enabled.Log(GPR_INFO, "%s received %s.", if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
impl->is_client ? "Client" : "Server", gpr_log(GPR_INFO, "%s received %s.", impl->is_client ? "Client" : "Server",
tsi_fake_handshake_message_to_string(received_msg)); tsi_fake_handshake_message_to_string(received_msg));
}
tsi_fake_frame_reset(&impl->incoming_frame, 0 /* needs_draining */); tsi_fake_frame_reset(&impl->incoming_frame, 0 /* needs_draining */);
impl->needs_incoming_message = 0; impl->needs_incoming_message = 0;
if (impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { if (impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) {
/* We're done. */ /* We're done. */
tsi_tracing_enabled.Log(GPR_INFO, "%s is done.", if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
impl->is_client ? "Client" : "Server"); gpr_log(GPR_INFO, "%s is done.", impl->is_client ? "Client" : "Server");
}
impl->result = TSI_OK; impl->result = TSI_OK;
} }
return TSI_OK; return TSI_OK;

@ -165,10 +165,10 @@ static int alpn_select_cb(SSL* /*ssl*/, const uint8_t** out, uint8_t* out_len,
static void ssl_log_where_info(const SSL* ssl, int where, int flag, static void ssl_log_where_info(const SSL* ssl, int where, int flag,
const char* msg) { const char* msg) {
if (where & flag) { if ((where & flag) &&
client_ssl_tsi_tracing_enabled.Log(GPR_INFO, "%20.20s - %30.30s - %5.10s", GRPC_TRACE_FLAG_ENABLED(client_ssl_tsi_tracing_enabled)) {
msg, SSL_state_string_long(ssl), gpr_log(GPR_INFO, "%20.20s - %30.30s - %5.10s", msg,
SSL_state_string(ssl)); SSL_state_string_long(ssl), SSL_state_string(ssl));
} }
} }

@ -1732,7 +1732,6 @@ src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/log.cc \ src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_internal.h \
src/core/lib/gpr/log_linux.cc \ src/core/lib/gpr/log_linux.cc \
src/core/lib/gpr/log_posix.cc \ src/core/lib/gpr/log_posix.cc \
src/core/lib/gpr/log_windows.cc \ src/core/lib/gpr/log_windows.cc \

@ -1570,7 +1570,6 @@ src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/log.cc \ src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_internal.h \
src/core/lib/gpr/log_linux.cc \ src/core/lib/gpr/log_linux.cc \
src/core/lib/gpr/log_posix.cc \ src/core/lib/gpr/log_posix.cc \
src/core/lib/gpr/log_windows.cc \ src/core/lib/gpr/log_windows.cc \

Loading…
Cancel
Save