Replaced grpc_core::Map with std::map

pull/20958/head
Esun Kim 5 years ago
parent ae6b1c9d38
commit 3de8f0b849
  1. 4
      src/core/ext/filters/client_channel/backend_metric.cc
  2. 10
      src/core/ext/filters/client_channel/client_channel.cc
  3. 5
      src/core/ext/filters/client_channel/lb_policy.h
  4. 3
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  5. 4
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  6. 6
      src/core/ext/filters/client_channel/subchannel.h
  7. 6
      src/core/ext/filters/client_channel/xds/xds_api.cc
  8. 2
      src/core/ext/filters/client_channel/xds/xds_api.h
  9. 2
      src/core/ext/filters/client_channel/xds/xds_bootstrap.cc
  10. 7
      src/core/ext/filters/client_channel/xds/xds_bootstrap.h
  11. 4
      src/core/ext/filters/client_channel/xds/xds_client.h
  12. 14
      src/core/ext/filters/client_channel/xds/xds_client_stats.h
  13. 8
      src/core/lib/channel/channelz.h
  14. 2
      src/core/lib/channel/channelz_registry.h
  15. 8
      src/core/lib/gprpp/map.h
  16. 12
      src/core/lib/security/credentials/credentials.cc
  17. 6
      src/core/lib/security/credentials/credentials.h
  18. 4
      src/core/lib/transport/connectivity_state.h

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

@ -291,7 +291,7 @@ class ChannelData {
RefCountedPtr<ServiceConfig> saved_service_config_; RefCountedPtr<ServiceConfig> saved_service_config_;
bool received_first_resolver_result_ = false; bool received_first_resolver_result_ = false;
// The number of SubchannelWrapper instances referencing a given Subchannel. // The number of SubchannelWrapper instances referencing a given Subchannel.
Map<Subchannel*, int> subchannel_refcount_map_; std::map<Subchannel*, int> subchannel_refcount_map_;
// The set of SubchannelWrappers that currently exist. // The set of SubchannelWrappers that currently exist.
// No need to hold a ref, since the map is updated in the control-plane // No need to hold a ref, since the map is updated in the control-plane
// combiner when the SubchannelWrappers are created and destroyed. // combiner when the SubchannelWrappers are created and destroyed.
@ -299,8 +299,8 @@ class ChannelData {
// Pending ConnectedSubchannel updates for each SubchannelWrapper. // Pending ConnectedSubchannel updates for each SubchannelWrapper.
// Updates are queued here in the control plane combiner and then applied // Updates are queued here in the control plane combiner and then applied
// in the data plane mutex when the picker is updated. // in the data plane mutex when the picker is updated.
Map<RefCountedPtr<SubchannelWrapper>, RefCountedPtr<ConnectedSubchannel>, std::map<RefCountedPtr<SubchannelWrapper>, RefCountedPtr<ConnectedSubchannel>,
RefCountedPtrLess<SubchannelWrapper>> RefCountedPtrLess<SubchannelWrapper>>
pending_subchannel_updates_; pending_subchannel_updates_;
// //
@ -321,7 +321,7 @@ class ChannelData {
// synchronously via grpc_channel_num_external_connectivity_watchers(). // synchronously via grpc_channel_num_external_connectivity_watchers().
// //
mutable Mutex external_watchers_mu_; mutable Mutex external_watchers_mu_;
Map<grpc_closure*, ExternalConnectivityWatcher*> external_watchers_; std::map<grpc_closure*, ExternalConnectivityWatcher*> external_watchers_;
}; };
// //
@ -1116,7 +1116,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
// subchannel. This is needed so that when the LB policy calls // subchannel. This is needed so that when the LB policy calls
// CancelConnectivityStateWatch() with its watcher, we know the // CancelConnectivityStateWatch() with its watcher, we know the
// corresponding WrapperWatcher to cancel on the underlying subchannel. // corresponding WrapperWatcher to cancel on the underlying subchannel.
Map<ConnectivityStateWatcherInterface*, WatcherWrapper*> watcher_map_; std::map<ConnectivityStateWatcherInterface*, WatcherWrapper*> watcher_map_;
// To be accessed only in the control plane combiner. // To be accessed only in the control plane combiner.
RefCountedPtr<ConnectedSubchannel> connected_subchannel_; RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
// To be accessed only in the data plane mutex. // To be accessed only in the data plane mutex.

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

@ -479,8 +479,7 @@ int equal_cmp(void* /*p1*/, void* /*p2*/) {
// token or client stats. A better approach might be to find somewhere // token or client stats. A better approach might be to find somewhere
// other than the subchannel args to store the LB token and client // other than the subchannel args to store the LB token and client
// stats. They could be stored in a map and then looked up for each // stats. They could be stored in a map and then looked up for each
// call (although we'd need to make sure our Map<> implementation is // call. Or we could do something more complicated whereby
// performant enough). Or we could do something more complicated whereby
// we create our own subchannel wrapper to store them, although that would // we create our own subchannel wrapper to store them, although that would
// involve a lot of refcounting overhead. // involve a lot of refcounting overhead.
// Given that we're trying to move from grpclb to xds at this point, // Given that we're trying to move from grpclb to xds at this point,

@ -327,8 +327,8 @@ class XdsLb : public LoadBalancingPolicy {
RefCountedPtr<XdsLb> xds_policy_; RefCountedPtr<XdsLb> xds_policy_;
Map<RefCountedPtr<XdsLocalityName>, OrphanablePtr<Locality>, std::map<RefCountedPtr<XdsLocalityName>, OrphanablePtr<Locality>,
XdsLocalityName::Less> XdsLocalityName::Less>
localities_; localities_;
const uint32_t priority_; const uint32_t priority_;
grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE; grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE;

@ -293,8 +293,8 @@ class Subchannel {
private: private:
// TODO(roth): Once we can use C++-14 heterogeneous lookups, this can // TODO(roth): Once we can use C++-14 heterogeneous lookups, this can
// be a set instead of a map. // be a set instead of a map.
Map<ConnectivityStateWatcherInterface*, std::map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>> OrphanablePtr<ConnectivityStateWatcherInterface>>
watchers_; watchers_;
}; };
@ -327,7 +327,7 @@ class Subchannel {
private: private:
class HealthWatcher; class HealthWatcher;
Map<const char*, OrphanablePtr<HealthWatcher>, StringLess> map_; std::map<const char*, OrphanablePtr<HealthWatcher>, StringLess> map_;
}; };
class ConnectedSubchannelStateWatcher; class ConnectedSubchannelStateWatcher;

@ -114,9 +114,9 @@ void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value,
} }
} }
void PopulateMetadata( void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb,
upb_arena* arena, google_protobuf_Struct* metadata_pb, const std::map<const char*, XdsBootstrap::MetadataValue,
const Map<const char*, XdsBootstrap::MetadataValue, StringLess>& metadata) { StringLess>& metadata) {
for (const auto& p : metadata) { for (const auto& p : metadata) {
google_protobuf_Struct_FieldsEntry* field = google_protobuf_Struct_FieldsEntry* field =
google_protobuf_Struct_add_fields(metadata_pb, arena); google_protobuf_Struct_add_fields(metadata_pb, arena);

@ -59,7 +59,7 @@ class XdsPriorityListUpdate {
size_t size() const { return localities.size(); } size_t size() const { return localities.size(); }
Map<RefCountedPtr<XdsLocalityName>, Locality, XdsLocalityName::Less> std::map<RefCountedPtr<XdsLocalityName>, Locality, XdsLocalityName::Less>
localities; localities;
}; };

@ -320,7 +320,7 @@ grpc_error* XdsBootstrap::ParseLocality(grpc_json* json) {
InlinedVector<grpc_error*, 1> XdsBootstrap::ParseMetadataStruct( InlinedVector<grpc_error*, 1> XdsBootstrap::ParseMetadataStruct(
grpc_json* json, grpc_json* json,
Map<const char*, XdsBootstrap::MetadataValue, StringLess>* result) { std::map<const char*, XdsBootstrap::MetadataValue, StringLess>* result) {
InlinedVector<grpc_error*, 1> error_list; InlinedVector<grpc_error*, 1> error_list;
for (grpc_json* child = json->child; child != nullptr; child = child->next) { for (grpc_json* child = json->child; child != nullptr; child = child->next) {
if (child->key == nullptr) { if (child->key == nullptr) {

@ -40,7 +40,7 @@ class XdsBootstrap {
double double_value; double double_value;
const char* string_value; const char* string_value;
bool bool_value; bool bool_value;
Map<const char*, MetadataValue, StringLess> struct_value; std::map<const char*, MetadataValue, StringLess> struct_value;
std::vector<MetadataValue> list_value; std::vector<MetadataValue> list_value;
}; };
@ -50,7 +50,7 @@ class XdsBootstrap {
const char* locality_region = nullptr; const char* locality_region = nullptr;
const char* locality_zone = nullptr; const char* locality_zone = nullptr;
const char* locality_subzone = nullptr; const char* locality_subzone = nullptr;
Map<const char*, MetadataValue, StringLess> metadata; std::map<const char*, MetadataValue, StringLess> metadata;
}; };
struct ChannelCreds { struct ChannelCreds {
@ -80,7 +80,8 @@ class XdsBootstrap {
grpc_error* ParseLocality(grpc_json* json); grpc_error* ParseLocality(grpc_json* json);
InlinedVector<grpc_error*, 1> ParseMetadataStruct( InlinedVector<grpc_error*, 1> ParseMetadataStruct(
grpc_json* json, Map<const char*, MetadataValue, StringLess>* result); grpc_json* json,
std::map<const char*, MetadataValue, StringLess>* result);
InlinedVector<grpc_error*, 1> ParseMetadataList( InlinedVector<grpc_error*, 1> ParseMetadataList(
grpc_json* json, std::vector<MetadataValue>* result); grpc_json* json, std::vector<MetadataValue>* result);
grpc_error* ParseMetadataValue(grpc_json* json, size_t idx, grpc_error* ParseMetadataValue(grpc_json* json, size_t idx,

@ -171,9 +171,9 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
}; };
struct ClusterState { struct ClusterState {
Map<ClusterWatcherInterface*, UniquePtr<ClusterWatcherInterface>> std::map<ClusterWatcherInterface*, UniquePtr<ClusterWatcherInterface>>
cluster_watchers; cluster_watchers;
Map<EndpointWatcherInterface*, UniquePtr<EndpointWatcherInterface>> std::map<EndpointWatcherInterface*, UniquePtr<EndpointWatcherInterface>>
endpoint_watchers; endpoint_watchers;
Set<XdsClientStats*> client_stats; Set<XdsClientStats*> client_stats;
// The latest data seen from EDS. // The latest data seen from EDS.

@ -111,9 +111,9 @@ class XdsClientStats {
double total_metric_value_{0}; double total_metric_value_{0};
}; };
using LoadMetricMap = Map<UniquePtr<char>, LoadMetric, StringLess>; using LoadMetricMap = std::map<UniquePtr<char>, LoadMetric, StringLess>;
using LoadMetricSnapshotMap = using LoadMetricSnapshotMap =
Map<UniquePtr<char>, LoadMetric::Snapshot, StringLess>; std::map<UniquePtr<char>, LoadMetric::Snapshot, StringLess>;
struct Snapshot { struct Snapshot {
// TODO(juanlishen): Change this to const method when const_iterator is // TODO(juanlishen): Change this to const method when const_iterator is
@ -180,12 +180,12 @@ class XdsClientStats {
// UniquePtr<>. We should remove this wrapper if the value type of Map<> // UniquePtr<>. We should remove this wrapper if the value type of Map<>
// doesn't have to be movable. // doesn't have to be movable.
using LocalityStatsMap = using LocalityStatsMap =
Map<RefCountedPtr<XdsLocalityName>, RefCountedPtr<LocalityStats>, std::map<RefCountedPtr<XdsLocalityName>, RefCountedPtr<LocalityStats>,
XdsLocalityName::Less>; XdsLocalityName::Less>;
using LocalityStatsSnapshotMap = using LocalityStatsSnapshotMap =
Map<RefCountedPtr<XdsLocalityName>, LocalityStats::Snapshot, std::map<RefCountedPtr<XdsLocalityName>, LocalityStats::Snapshot,
XdsLocalityName::Less>; XdsLocalityName::Less>;
using DroppedRequestsMap = Map<UniquePtr<char>, uint64_t, StringLess>; using DroppedRequestsMap = std::map<UniquePtr<char>, uint64_t, StringLess>;
using DroppedRequestsSnapshotMap = DroppedRequestsMap; using DroppedRequestsSnapshotMap = DroppedRequestsMap;
struct Snapshot { struct Snapshot {

@ -221,8 +221,8 @@ class ChannelNode : public BaseNode {
// TODO(roth): We don't actually use the values here, only the keys, so // TODO(roth): We don't actually use the values here, only the keys, so
// these should be sets instead of maps, but we don't currently have a set // these should be sets instead of maps, but we don't currently have a set
// implementation. Change this if/when we have one. // implementation. Change this if/when we have one.
Map<intptr_t, bool> child_channels_; std::map<intptr_t, bool> child_channels_;
Map<intptr_t, bool> child_subchannels_; std::map<intptr_t, bool> child_subchannels_;
}; };
// Handles channelz bookkeeping for servers // Handles channelz bookkeeping for servers
@ -262,8 +262,8 @@ class ServerNode : public BaseNode {
CallCountingHelper call_counter_; CallCountingHelper call_counter_;
ChannelTrace trace_; ChannelTrace trace_;
Mutex child_mu_; // Guards child maps below. Mutex child_mu_; // Guards child maps below.
Map<intptr_t, RefCountedPtr<SocketNode>> child_sockets_; std::map<intptr_t, RefCountedPtr<SocketNode>> child_sockets_;
Map<intptr_t, RefCountedPtr<ListenSocketNode>> child_listen_sockets_; std::map<intptr_t, RefCountedPtr<ListenSocketNode>> child_listen_sockets_;
}; };
// Handles channelz bookkeeping for sockets // Handles channelz bookkeeping for sockets

@ -87,7 +87,7 @@ class ChannelzRegistry {
// protects members // protects members
Mutex mu_; Mutex mu_;
Map<intptr_t, BaseNode*> node_map_; std::map<intptr_t, BaseNode*> node_map_;
intptr_t uuid_generator_ = 0; intptr_t uuid_generator_ = 0;
}; };

@ -23,21 +23,13 @@
#include <string.h> #include <string.h>
#include <algorithm>
#include <functional>
#include <iterator>
#include <map> #include <map>
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/string_view.h" #include "src/core/lib/gprpp/string_view.h"
namespace grpc_core { namespace grpc_core {
template <class Key, class T, class Compare = std::less<Key>>
using Map = std::map<Key, T, Compare, Allocator<std::pair<const Key, T>>>;
struct StringLess { struct StringLess {
bool operator()(const char* a, const char* b) const { bool operator()(const char* a, const char* b) const {
return strcmp(a, b) < 0; return strcmp(a, b) < 0;

@ -45,18 +45,18 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) {
if (creds) creds->Unref(); if (creds) creds->Unref();
} }
static grpc_core::Map<grpc_core::UniquePtr<char>, static std::map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>, grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>* g_grpc_control_plane_creds; grpc_core::StringLess>* g_grpc_control_plane_creds;
static gpr_mu g_control_plane_creds_mu; static gpr_mu g_control_plane_creds_mu;
static void do_control_plane_creds_init() { static void do_control_plane_creds_init() {
gpr_mu_init(&g_control_plane_creds_mu); gpr_mu_init(&g_control_plane_creds_mu);
GPR_ASSERT(g_grpc_control_plane_creds == nullptr); GPR_ASSERT(g_grpc_control_plane_creds == nullptr);
g_grpc_control_plane_creds = grpc_core::New< g_grpc_control_plane_creds = grpc_core::New<
grpc_core::Map<grpc_core::UniquePtr<char>, std::map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>, grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>>(); grpc_core::StringLess>>();
} }
void grpc_control_plane_credentials_init() { void grpc_control_plane_credentials_init() {

@ -148,9 +148,9 @@ struct grpc_channel_credentials
private: private:
const char* type_; const char* type_;
grpc_core::Map<grpc_core::UniquePtr<char>, std::map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>, grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess> grpc_core::StringLess>
local_control_plane_creds_; local_control_plane_creds_;
}; };

@ -119,8 +119,8 @@ class ConnectivityStateTracker {
Atomic<grpc_connectivity_state> state_; Atomic<grpc_connectivity_state> state_;
// TODO(roth): Once we can use C++-14 heterogeneous lookups, this can // TODO(roth): Once we can use C++-14 heterogeneous lookups, this can
// be a set instead of a map. // be a set instead of a map.
Map<ConnectivityStateWatcherInterface*, std::map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>> OrphanablePtr<ConnectivityStateWatcherInterface>>
watchers_; watchers_;
}; };

Loading…
Cancel
Save