Remove StringLess and src/core/lib/gprpp/map.h

pull/22735/head
Mark D. Roth 5 years ago
parent e652e17016
commit c0f82fc595
  1. 1
      BUILD
  2. 1
      BUILD.gn
  3. 1
      build_autogenerated.yaml
  4. 2
      gRPC-C++.podspec
  5. 2
      gRPC-Core.podspec
  6. 1
      grpc.gemspec
  7. 1
      package.xml
  8. 4
      src/core/ext/filters/client_channel/backend_metric.cc
  9. 47
      src/core/ext/filters/client_channel/client_channel.cc
  10. 7
      src/core/ext/filters/client_channel/health/health_check_client.cc
  11. 6
      src/core/ext/filters/client_channel/health/health_check_client.h
  12. 5
      src/core/ext/filters/client_channel/lb_policy.h
  13. 15
      src/core/ext/filters/client_channel/resolver_result_parsing.cc
  14. 6
      src/core/ext/filters/client_channel/resolver_result_parsing.h
  15. 43
      src/core/ext/filters/client_channel/subchannel.cc
  16. 18
      src/core/ext/filters/client_channel/subchannel.h
  17. 1
      src/core/ext/filters/client_channel/xds/xds_bootstrap.h
  18. 3
      src/core/ext/filters/client_channel/xds/xds_client.cc
  19. 2
      src/core/ext/filters/client_channel/xds/xds_client.h
  20. 4
      src/core/ext/filters/client_channel/xds/xds_client_stats.h
  21. 2
      src/core/lib/channel/channelz.h
  22. 3
      src/core/lib/channel/channelz_registry.h
  23. 51
      src/core/lib/gprpp/map.h
  24. 3
      src/core/lib/transport/connectivity_state.h
  25. 4
      test/core/client_channel/service_config_test.cc
  26. 2
      test/cpp/end2end/xds_end2end_test.cc
  27. 1
      tools/doxygen/Doxyfile.c++.internal
  28. 1
      tools/doxygen/Doxyfile.core.internal

@ -551,7 +551,6 @@ grpc_cc_library(
"src/core/lib/gprpp/global_config_generic.h",
"src/core/lib/gprpp/host_port.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mpscq.h",
"src/core/lib/gprpp/string_view.h",

@ -156,7 +156,6 @@ config("grpc_config") {
"src/core/lib/gprpp/host_port.cc",
"src/core/lib/gprpp/host_port.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mpscq.cc",
"src/core/lib/gprpp/mpscq.h",

@ -299,7 +299,6 @@ libs:
- src/core/lib/gprpp/global_config_generic.h
- src/core/lib/gprpp/host_port.h
- src/core/lib/gprpp/manual_constructor.h
- src/core/lib/gprpp/map.h
- src/core/lib/gprpp/memory.h
- src/core/lib/gprpp/mpscq.h
- src/core/lib/gprpp/string_view.h

@ -419,7 +419,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.h',
'src/core/lib/gprpp/orphanable.h',
@ -869,7 +868,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.h',
'src/core/lib/gprpp/orphanable.h',

@ -611,7 +611,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/host_port.cc',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.cc',
'src/core/lib/gprpp/mpscq.h',
@ -1225,7 +1224,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.h',
'src/core/lib/gprpp/orphanable.h',

@ -533,7 +533,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/host_port.cc )
s.files += %w( src/core/lib/gprpp/host_port.h )
s.files += %w( src/core/lib/gprpp/manual_constructor.h )
s.files += %w( src/core/lib/gprpp/map.h )
s.files += %w( src/core/lib/gprpp/memory.h )
s.files += %w( src/core/lib/gprpp/mpscq.cc )
s.files += %w( src/core/lib/gprpp/mpscq.h )

@ -513,7 +513,6 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/host_port.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/host_port.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/manual_constructor.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/map.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/mpscq.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/mpscq.h" role="src" />

@ -26,12 +26,12 @@ namespace grpc_core {
namespace {
template <typename EntryType>
std::map<StringView, double, StringLess> ParseMap(
std::map<StringView, double> ParseMap(
udpa_data_orca_v1_OrcaLoadReport* msg,
EntryType** (*entry_func)(udpa_data_orca_v1_OrcaLoadReport*, size_t*),
upb_strview (*key_func)(const EntryType*),
double (*value_func)(const EntryType*), Arena* arena) {
std::map<StringView, double, StringLess> result;
std::map<StringView, double> result;
size_t size;
const auto* const* entries = entry_func(msg, &size);
for (size_t i = 0; i < size; ++i) {

@ -26,6 +26,7 @@
#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <grpc/support/alloc.h>
@ -56,7 +57,6 @@
#include "src/core/lib/channel/status_util.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/polling_entity.h"
@ -295,7 +295,7 @@ class ChannelData {
RefCountedPtr<SubchannelPoolInterface> subchannel_pool_;
OrphanablePtr<ResolvingLoadBalancingPolicy> resolving_lb_policy_;
ConnectivityStateTracker state_tracker_;
grpc_core::UniquePtr<char> health_check_service_name_;
std::string health_check_service_name_;
RefCountedPtr<ServiceConfig> saved_service_config_;
bool received_first_resolver_result_ = false;
// The number of SubchannelWrapper instances referencing a given Subchannel.
@ -850,7 +850,7 @@ class CallData {
class ChannelData::SubchannelWrapper : public SubchannelInterface {
public:
SubchannelWrapper(ChannelData* chand, Subchannel* subchannel,
grpc_core::UniquePtr<char> health_check_service_name)
std::string health_check_service_name)
: SubchannelInterface(&grpc_client_channel_routing_trace),
chand_(chand),
subchannel_(subchannel),
@ -897,7 +897,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
grpc_connectivity_state CheckConnectivityState() override {
RefCountedPtr<ConnectedSubchannel> connected_subchannel;
grpc_connectivity_state connectivity_state =
subchannel_->CheckConnectivityState(health_check_service_name_.get(),
subchannel_->CheckConnectivityState(health_check_service_name_,
&connected_subchannel);
MaybeUpdateConnectedSubchannel(std::move(connected_subchannel));
return connectivity_state;
@ -912,9 +912,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
Ref(DEBUG_LOCATION, "WatcherWrapper"),
initial_state);
subchannel_->WatchConnectivityState(
initial_state,
grpc_core::UniquePtr<char>(
gpr_strdup(health_check_service_name_.get())),
initial_state, health_check_service_name_,
RefCountedPtr<Subchannel::ConnectivityStateWatcherInterface>(
watcher_wrapper));
}
@ -923,7 +921,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
ConnectivityStateWatcherInterface* watcher) override {
auto it = watcher_map_.find(watcher);
GPR_ASSERT(it != watcher_map_.end());
subchannel_->CancelConnectivityStateWatch(health_check_service_name_.get(),
subchannel_->CancelConnectivityStateWatch(health_check_service_name_,
it->second);
watcher_map_.erase(it);
}
@ -936,14 +934,13 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
return subchannel_->channel_args();
}
void UpdateHealthCheckServiceName(
grpc_core::UniquePtr<char> health_check_service_name) {
void UpdateHealthCheckServiceName(std::string health_check_service_name) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) {
gpr_log(GPR_INFO,
"chand=%p: subchannel wrapper %p: updating health check service "
"name from \"%s\" to \"%s\"",
chand_, this, health_check_service_name_.get(),
health_check_service_name.get());
chand_, this, health_check_service_name_.c_str(),
health_check_service_name.c_str());
}
for (auto& p : watcher_map_) {
WatcherWrapper*& watcher_wrapper = p.second;
@ -958,13 +955,11 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
// problem, we may be able to handle it by waiting for the new
// watcher to report READY before we use it to replace the old one.
WatcherWrapper* replacement = watcher_wrapper->MakeReplacement();
subchannel_->CancelConnectivityStateWatch(
health_check_service_name_.get(), watcher_wrapper);
subchannel_->CancelConnectivityStateWatch(health_check_service_name_,
watcher_wrapper);
watcher_wrapper = replacement;
subchannel_->WatchConnectivityState(
replacement->last_seen_state(),
grpc_core::UniquePtr<char>(
gpr_strdup(health_check_service_name.get())),
replacement->last_seen_state(), health_check_service_name,
RefCountedPtr<Subchannel::ConnectivityStateWatcherInterface>(
replacement));
}
@ -1102,7 +1097,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
ChannelData* chand_;
Subchannel* subchannel_;
grpc_core::UniquePtr<char> health_check_service_name_;
std::string health_check_service_name_;
// Maps from the address of the watcher passed to us by the LB policy
// to the address of the WrapperWatcher that we passed to the underlying
// subchannel. This is needed so that when the LB policy calls
@ -1265,10 +1260,9 @@ class ChannelData::ClientChannelControlHelper
const grpc_channel_args& args) override {
bool inhibit_health_checking = grpc_channel_arg_get_bool(
grpc_channel_args_find(&args, GRPC_ARG_INHIBIT_HEALTH_CHECKING), false);
grpc_core::UniquePtr<char> health_check_service_name;
std::string health_check_service_name;
if (!inhibit_health_checking) {
health_check_service_name.reset(
gpr_strdup(chand_->health_check_service_name_.get()));
health_check_service_name = chand_->health_check_service_name_;
}
static const char* args_to_remove[] = {
GRPC_ARG_INHIBIT_HEALTH_CHECKING,
@ -1463,7 +1457,7 @@ void ChannelData::UpdateStateAndPickerLocked(
std::unique_ptr<LoadBalancingPolicy::SubchannelPicker> picker) {
// Clean the control plane when entering IDLE.
if (picker_ == nullptr) {
health_check_service_name_.reset();
health_check_service_name_.clear();
saved_service_config_.reset();
received_first_resolver_result_ = false;
}
@ -1706,16 +1700,15 @@ bool ChannelData::ProcessResolverResultLocked(
}
// Save health check service name.
if (service_config != nullptr) {
chand->health_check_service_name_.reset(
gpr_strdup(parsed_service_config->health_check_service_name()));
chand->health_check_service_name_ =
parsed_service_config->health_check_service_name();
} else {
chand->health_check_service_name_.reset();
chand->health_check_service_name_.clear();
}
// Update health check service name used by existing subchannel wrappers.
for (auto* subchannel_wrapper : chand->subchannel_wrappers_) {
subchannel_wrapper->UpdateHealthCheckServiceName(
grpc_core::UniquePtr<char>(
gpr_strdup(chand->health_check_service_name_.get())));
chand->health_check_service_name_);
}
// Save service config.
chand->saved_service_config_ = std::move(service_config);

@ -44,7 +44,7 @@ TraceFlag grpc_health_check_client_trace(false, "health_check_client");
//
HealthCheckClient::HealthCheckClient(
const char* service_name,
absl::string_view service_name,
RefCountedPtr<ConnectedSubchannel> connected_subchannel,
grpc_pollset_set* interested_parties,
RefCountedPtr<channelz::SubchannelNode> channelz_node,
@ -171,13 +171,14 @@ void HealthCheckClient::OnRetryTimer(void* arg, grpc_error* error) {
namespace {
void EncodeRequest(const char* service_name,
void EncodeRequest(absl::string_view service_name,
ManualConstructor<SliceBufferByteStream>* send_message) {
upb::Arena arena;
grpc_health_v1_HealthCheckRequest* request_struct =
grpc_health_v1_HealthCheckRequest_new(arena.ptr());
grpc_health_v1_HealthCheckRequest_set_service(
request_struct, upb_strview_makez(service_name));
request_struct,
upb_strview_make(service_name.data(), service_name.size()));
size_t buf_length;
char* buf = grpc_health_v1_HealthCheckRequest_serialize(
request_struct, arena.ptr(), &buf_length);

@ -21,6 +21,8 @@
#include <grpc/support/port_platform.h>
#include "absl/strings/string_view.h"
#include <grpc/grpc.h>
#include <grpc/support/sync.h>
@ -44,7 +46,7 @@ namespace grpc_core {
class HealthCheckClient : public InternallyRefCounted<HealthCheckClient> {
public:
HealthCheckClient(const char* service_name,
HealthCheckClient(absl::string_view service_name,
RefCountedPtr<ConnectedSubchannel> connected_subchannel,
grpc_pollset_set* interested_parties,
RefCountedPtr<channelz::SubchannelNode> channelz_node,
@ -150,7 +152,7 @@ class HealthCheckClient : public InternallyRefCounted<HealthCheckClient> {
void SetHealthStatusLocked(grpc_connectivity_state state,
const char* reason); // Requires holding mu_.
const char* service_name_; // Do not own.
absl::string_view service_name_;
RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
grpc_pollset_set* interested_parties_; // Do not own.
RefCountedPtr<channelz::SubchannelNode> channelz_node_;

@ -27,7 +27,6 @@
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/ext/filters/client_channel/service_config.h"
#include "src/core/ext/filters/client_channel/subchannel_interface.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/string_view.h"
@ -93,11 +92,11 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
/// Application-specific requests cost metrics. Metric names are
/// determined by the application. Each value is an absolute cost
/// (e.g. 3487 bytes of storage) associated with the request.
std::map<StringView, double, StringLess> request_cost;
std::map<StringView, double> request_cost;
/// Application-specific resource utilization metrics. Metric names
/// are determined by the application. Each value is expressed as a
/// fraction of total resources available.
std::map<StringView, double, StringLess> utilization;
std::map<StringView, double> utilization;
};
/// Interface for accessing per-call state.

@ -284,13 +284,13 @@ grpc_error* ParseRetryThrottling(
return GRPC_ERROR_CREATE_FROM_VECTOR("retryPolicy", &error_list);
}
const char* ParseHealthCheckConfig(const Json& field, grpc_error** error) {
std::string ParseHealthCheckConfig(const Json& field, grpc_error** error) {
GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
const char* service_name = nullptr;
std::string service_name;
if (field.type() != Json::Type::OBJECT) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"field:healthCheckConfig error:should be of type object");
return nullptr;
return service_name;
}
std::vector<grpc_error*> error_list;
auto it = field.object_value().find("serviceName");
@ -299,12 +299,9 @@ const char* ParseHealthCheckConfig(const Json& field, grpc_error** error) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"field:serviceName error:should be of type string"));
} else {
service_name = it->second.string_value().c_str();
service_name = it->second.string_value();
}
}
if (!error_list.empty()) {
return nullptr;
}
*error =
GRPC_ERROR_CREATE_FROM_VECTOR("field:healthCheckConfig", &error_list);
return service_name;
@ -321,7 +318,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const Json& json,
std::string lb_policy_name;
absl::optional<ClientChannelGlobalParsedConfig::RetryThrottling>
retry_throttling;
const char* health_check_service_name = nullptr;
std::string health_check_service_name;
// Parse LB config.
auto it = json.object_value().find("loadBalancingConfig");
if (it != json.object_value().end()) {
@ -388,7 +385,7 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const Json& json,
if (*error == GRPC_ERROR_NONE) {
return absl::make_unique<ClientChannelGlobalParsedConfig>(
std::move(parsed_lb_config), std::move(lb_policy_name),
retry_throttling, health_check_service_name);
retry_throttling, std::move(health_check_service_name));
}
return nullptr;
}

@ -49,7 +49,7 @@ class ClientChannelGlobalParsedConfig : public ServiceConfig::ParsedConfig {
RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config,
std::string parsed_deprecated_lb_policy,
const absl::optional<RetryThrottling>& retry_throttling,
const char* health_check_service_name)
std::string health_check_service_name)
: parsed_lb_config_(std::move(parsed_lb_config)),
parsed_deprecated_lb_policy_(std::move(parsed_deprecated_lb_policy)),
retry_throttling_(retry_throttling),
@ -67,7 +67,7 @@ class ClientChannelGlobalParsedConfig : public ServiceConfig::ParsedConfig {
return parsed_deprecated_lb_policy_;
}
const char* health_check_service_name() const {
const std::string& health_check_service_name() const {
return health_check_service_name_;
}
@ -75,7 +75,7 @@ class ClientChannelGlobalParsedConfig : public ServiceConfig::ParsedConfig {
RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config_;
std::string parsed_deprecated_lb_policy_;
absl::optional<RetryThrottling> retry_throttling_;
const char* health_check_service_name_;
std::string health_check_service_name_;
};
class ClientChannelMethodParsedConfig : public ServiceConfig::ParsedConfig {

@ -424,11 +424,10 @@ void Subchannel::ConnectivityStateWatcherList::NotifyLocked(
class Subchannel::HealthWatcherMap::HealthWatcher
: public AsyncConnectivityStateWatcherInterface {
public:
HealthWatcher(Subchannel* c,
grpc_core::UniquePtr<char> health_check_service_name,
HealthWatcher(Subchannel* c, absl::string_view health_check_service_name,
grpc_connectivity_state subchannel_state)
: subchannel_(c),
health_check_service_name_(std::move(health_check_service_name)),
health_check_service_name_(std::string(health_check_service_name)),
state_(subchannel_state == GRPC_CHANNEL_READY ? GRPC_CHANNEL_CONNECTING
: subchannel_state) {
GRPC_SUBCHANNEL_WEAK_REF(subchannel_, "health_watcher");
@ -440,8 +439,8 @@ class Subchannel::HealthWatcherMap::HealthWatcher
GRPC_SUBCHANNEL_WEAK_UNREF(subchannel_, "health_watcher");
}
const char* health_check_service_name() const {
return health_check_service_name_.get();
absl::string_view health_check_service_name() const {
return health_check_service_name_;
}
grpc_connectivity_state state() const { return state_; }
@ -500,12 +499,12 @@ class Subchannel::HealthWatcherMap::HealthWatcher
void StartHealthCheckingLocked() {
GPR_ASSERT(health_check_client_ == nullptr);
health_check_client_ = MakeOrphanable<HealthCheckClient>(
health_check_service_name_.get(), subchannel_->connected_subchannel_,
health_check_service_name_, subchannel_->connected_subchannel_,
subchannel_->pollset_set_, subchannel_->channelz_node_, Ref());
}
Subchannel* subchannel_;
grpc_core::UniquePtr<char> health_check_service_name_;
std::string health_check_service_name_;
OrphanablePtr<HealthCheckClient> health_check_client_;
grpc_connectivity_state state_;
ConnectivityStateWatcherList watcher_list_;
@ -517,18 +516,17 @@ class Subchannel::HealthWatcherMap::HealthWatcher
void Subchannel::HealthWatcherMap::AddWatcherLocked(
Subchannel* subchannel, grpc_connectivity_state initial_state,
grpc_core::UniquePtr<char> health_check_service_name,
absl::string_view health_check_service_name,
RefCountedPtr<ConnectivityStateWatcherInterface> watcher) {
// If the health check service name is not already present in the map,
// add it.
auto it = map_.find(health_check_service_name.get());
auto it = map_.find(health_check_service_name);
HealthWatcher* health_watcher;
if (it == map_.end()) {
const char* key = health_check_service_name.get();
auto w = MakeOrphanable<HealthWatcher>(
subchannel, std::move(health_check_service_name), subchannel->state_);
subchannel, health_check_service_name, subchannel->state_);
health_watcher = w.get();
map_[key] = std::move(w);
map_[w->health_check_service_name()] = std::move(w);
} else {
health_watcher = it->second.get();
}
@ -537,7 +535,7 @@ void Subchannel::HealthWatcherMap::AddWatcherLocked(
}
void Subchannel::HealthWatcherMap::RemoveWatcherLocked(
const char* health_check_service_name,
absl::string_view health_check_service_name,
ConnectivityStateWatcherInterface* watcher) {
auto it = map_.find(health_check_service_name);
GPR_ASSERT(it != map_.end());
@ -555,7 +553,7 @@ void Subchannel::HealthWatcherMap::NotifyLocked(grpc_connectivity_state state) {
grpc_connectivity_state
Subchannel::HealthWatcherMap::CheckConnectivityStateLocked(
Subchannel* subchannel, const char* health_check_service_name) {
Subchannel* subchannel, absl::string_view health_check_service_name) {
auto it = map_.find(health_check_service_name);
if (it == map_.end()) {
// If the health check service name is not found in the map, we're
@ -799,11 +797,11 @@ channelz::SubchannelNode* Subchannel::channelz_node() {
}
grpc_connectivity_state Subchannel::CheckConnectivityState(
const char* health_check_service_name,
absl::string_view health_check_service_name,
RefCountedPtr<ConnectedSubchannel>* connected_subchannel) {
MutexLock lock(&mu_);
grpc_connectivity_state state;
if (health_check_service_name == nullptr) {
if (health_check_service_name.empty()) {
state = state_;
} else {
state = health_watcher_map_.CheckConnectivityStateLocked(
@ -817,34 +815,33 @@ grpc_connectivity_state Subchannel::CheckConnectivityState(
void Subchannel::WatchConnectivityState(
grpc_connectivity_state initial_state,
grpc_core::UniquePtr<char> health_check_service_name,
absl::string_view health_check_service_name,
RefCountedPtr<ConnectivityStateWatcherInterface> watcher) {
MutexLock lock(&mu_);
grpc_pollset_set* interested_parties = watcher->interested_parties();
if (interested_parties != nullptr) {
grpc_pollset_set_add_pollset_set(pollset_set_, interested_parties);
}
if (health_check_service_name == nullptr) {
if (health_check_service_name.empty()) {
if (state_ != initial_state) {
new AsyncWatcherNotifierLocked(watcher, this, state_);
}
watcher_list_.AddWatcherLocked(std::move(watcher));
} else {
health_watcher_map_.AddWatcherLocked(this, initial_state,
std::move(health_check_service_name),
std::move(watcher));
health_watcher_map_.AddWatcherLocked(
this, initial_state, health_check_service_name, std::move(watcher));
}
}
void Subchannel::CancelConnectivityStateWatch(
const char* health_check_service_name,
absl::string_view health_check_service_name,
ConnectivityStateWatcherInterface* watcher) {
MutexLock lock(&mu_);
grpc_pollset_set* interested_parties = watcher->interested_parties();
if (interested_parties != nullptr) {
grpc_pollset_set_del_pollset_set(pollset_set_, interested_parties);
}
if (health_check_service_name == nullptr) {
if (health_check_service_name.empty()) {
watcher_list_.RemoveWatcherLocked(watcher);
} else {
health_watcher_map_.RemoveWatcherLocked(health_check_service_name, watcher);

@ -23,6 +23,8 @@
#include <deque>
#include "absl/strings/string_view.h"
#include "src/core/ext/filters/client_channel/client_channel_channelz.h"
#include "src/core/ext/filters/client_channel/connector.h"
#include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
@ -30,7 +32,6 @@
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/gpr/time_precise.h"
#include "src/core/lib/gprpp/arena.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"
@ -251,7 +252,7 @@ class Subchannel {
// service name.
// If the return value is GRPC_CHANNEL_READY, also sets *connected_subchannel.
grpc_connectivity_state CheckConnectivityState(
const char* health_check_service_name,
absl::string_view health_check_service_name,
RefCountedPtr<ConnectedSubchannel>* connected_subchannel);
// Starts watching the subchannel's connectivity state.
@ -264,12 +265,12 @@ class Subchannel {
// destroyed or when CancelConnectivityStateWatch() is called.
void WatchConnectivityState(
grpc_connectivity_state initial_state,
grpc_core::UniquePtr<char> health_check_service_name,
absl::string_view health_check_service_name,
RefCountedPtr<ConnectivityStateWatcherInterface> watcher);
// Cancels a connectivity state watch.
// If the watcher has already been destroyed, this is a no-op.
void CancelConnectivityStateWatch(const char* health_check_service_name,
void CancelConnectivityStateWatch(absl::string_view health_check_service_name,
ConnectivityStateWatcherInterface* watcher);
// Attempt to connect to the backend. Has no effect if already connected.
@ -333,23 +334,24 @@ class Subchannel {
public:
void AddWatcherLocked(
Subchannel* subchannel, grpc_connectivity_state initial_state,
grpc_core::UniquePtr<char> health_check_service_name,
absl::string_view health_check_service_name,
RefCountedPtr<ConnectivityStateWatcherInterface> watcher);
void RemoveWatcherLocked(const char* health_check_service_name,
void RemoveWatcherLocked(absl::string_view health_check_service_name,
ConnectivityStateWatcherInterface* watcher);
// Notifies the watcher when the subchannel's state changes.
void NotifyLocked(grpc_connectivity_state state);
grpc_connectivity_state CheckConnectivityStateLocked(
Subchannel* subchannel, const char* health_check_service_name);
Subchannel* subchannel, absl::string_view health_check_service_name);
void ShutdownLocked();
private:
class HealthWatcher;
std::map<const char*, OrphanablePtr<HealthWatcher>, StringLess> map_;
// Key points to the health_check_service_name_ field in the value object.
std::map<absl::string_view, OrphanablePtr<HealthWatcher>> map_;
};
class ConnectedSubchannelStateWatcher;

@ -27,7 +27,6 @@
#include <grpc/impl/codegen/slice.h>
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/json/json.h"

@ -22,6 +22,8 @@
#include <limits.h>
#include <string.h>
#include <map>
#include "absl/container/inlined_vector.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
@ -45,7 +47,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"

@ -19,6 +19,7 @@
#include <grpc/support/port_platform.h>
#include <map>
#include <set>
#include "absl/types/optional.h"
@ -27,7 +28,6 @@
#include "src/core/ext/filters/client_channel/xds/xds_api.h"
#include "src/core/ext/filters/client_channel/xds/xds_bootstrap.h"
#include "src/core/ext/filters/client_channel/xds/xds_client_stats.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted.h"

@ -21,12 +21,14 @@
#include <grpc/support/port_platform.h>
#include <map>
#include <grpc/support/string_util.h>
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/string_view.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/iomgr/exec_ctx.h"

@ -23,6 +23,7 @@
#include <grpc/grpc.h>
#include <map>
#include <string>
#include "absl/container/inlined_vector.h"
@ -31,7 +32,6 @@
#include "src/core/lib/gpr/time_precise.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"

@ -23,9 +23,10 @@
#include <stdint.h>
#include <map>
#include "src/core/lib/channel/channel_trace.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/sync.h"
namespace grpc_core {

@ -1,51 +0,0 @@
/*
*
* Copyright 2017 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.
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_MAP_H
#define GRPC_CORE_LIB_GPRPP_MAP_H
#include <grpc/support/port_platform.h>
#include <string.h>
#include <map>
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/string_view.h"
namespace grpc_core {
struct StringLess {
bool operator()(const char* a, const char* b) const {
return strcmp(a, b) < 0;
}
bool operator()(const grpc_core::UniquePtr<char>& a,
const grpc_core::UniquePtr<char>& b) const {
return strcmp(a.get(), b.get()) < 0;
}
bool operator()(const StringView& a, const StringView& b) const {
const size_t min_size = std::min(a.size(), b.size());
int c = strncmp(a.data(), b.data(), min_size);
if (c != 0) return c < 0;
return a.size() < b.size();
}
};
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_MAP_H */

@ -21,11 +21,12 @@
#include <grpc/support/port_platform.h>
#include <map>
#include <grpc/grpc.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/exec_ctx.h"

@ -913,8 +913,8 @@ TEST_F(ClientChannelParserTest, ValidHealthCheck) {
static_cast<grpc_core::internal::ClientChannelGlobalParsedConfig*>(
svc_cfg->GetGlobalParsedConfig(0));
ASSERT_NE(parsed_config, nullptr);
EXPECT_STREQ(parsed_config->health_check_service_name(),
"health_check_service_name");
EXPECT_EQ(parsed_config->health_check_service_name(),
"health_check_service_name");
}
TEST_F(ClientChannelParserTest, InvalidHealthCheckMultipleEntries) {

@ -17,6 +17,7 @@
*/
#include <deque>
#include <map>
#include <memory>
#include <mutex>
#include <numeric>
@ -47,7 +48,6 @@
#include "src/core/ext/filters/client_channel/xds/xds_api.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/iomgr/sockaddr.h"

@ -1496,7 +1496,6 @@ src/core/lib/gprpp/global_config_generic.h \
src/core/lib/gprpp/host_port.cc \
src/core/lib/gprpp/host_port.h \
src/core/lib/gprpp/manual_constructor.h \
src/core/lib/gprpp/map.h \
src/core/lib/gprpp/memory.h \
src/core/lib/gprpp/mpscq.cc \
src/core/lib/gprpp/mpscq.h \

@ -1307,7 +1307,6 @@ src/core/lib/gprpp/global_config_generic.h \
src/core/lib/gprpp/host_port.cc \
src/core/lib/gprpp/host_port.h \
src/core/lib/gprpp/manual_constructor.h \
src/core/lib/gprpp/map.h \
src/core/lib/gprpp/memory.h \
src/core/lib/gprpp/mpscq.cc \
src/core/lib/gprpp/mpscq.h \

Loading…
Cancel
Save