Merge pull request #18081 from markdroth/service_config_ref_counted

Make service config ref-counted and hold refs to it in LB config.
reviewable/pr18094/r2^2
Mark D. Roth 6 years ago committed by GitHub
commit c9aebe3880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/ext/filters/client_channel/client_channel.cc
  2. 23
      src/core/ext/filters/client_channel/lb_policy.h
  3. 7
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  4. 4
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  5. 4
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  6. 90
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  7. 4
      src/core/ext/filters/client_channel/lb_policy_factory.h
  8. 3
      src/core/ext/filters/client_channel/resolver_result_parsing.cc
  9. 9
      src/core/ext/filters/client_channel/resolver_result_parsing.h
  10. 11
      src/core/ext/filters/client_channel/resolving_lb_policy.cc
  11. 15
      src/core/ext/filters/client_channel/resolving_lb_policy.h
  12. 2
      src/core/ext/filters/client_channel/subchannel.cc
  13. 2
      src/core/ext/filters/message_size/message_size_filter.cc
  14. 4
      src/core/lib/transport/service_config.cc
  15. 8
      src/core/lib/transport/service_config.h
  16. 25
      test/core/util/test_lb_policies.cc

@ -249,10 +249,9 @@ class ClientChannelControlHelper
// Synchronous callback from chand->resolving_lb_policy to process a resolver
// result update.
static bool process_resolver_result_locked(void* arg,
const grpc_channel_args& args,
const char** lb_policy_name,
grpc_json** lb_policy_config) {
static bool process_resolver_result_locked(
void* arg, const grpc_channel_args& args, const char** lb_policy_name,
grpc_core::RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config) {
channel_data* chand = static_cast<channel_data*>(arg);
chand->have_service_config = true;
ProcessedResolverResult resolver_result(args, chand->enable_retries);

@ -30,6 +30,7 @@
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/service_config.h"
extern grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
@ -214,6 +215,23 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
GRPC_ABSTRACT_BASE_CLASS
};
// Configuration for an LB policy instance.
class Config : public RefCounted<Config> {
public:
Config(const grpc_json* lb_config,
RefCountedPtr<ServiceConfig> service_config)
: json_(lb_config), service_config_(std::move(service_config)) {}
const grpc_json* json() const { return json_; }
RefCountedPtr<ServiceConfig> service_config() const {
return service_config_;
}
private:
const grpc_json* json_;
RefCountedPtr<ServiceConfig> service_config_;
};
/// Args used to instantiate an LB policy.
struct Args {
/// The combiner under which all LB policy calls will be run.
@ -243,7 +261,10 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
/// Note that the LB policy gets the set of addresses from the
/// GRPC_ARG_SERVER_ADDRESS_LIST channel arg.
virtual void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) GRPC_ABSTRACT;
RefCountedPtr<Config> lb_config) {
std::move(lb_config); // Suppress clang-tidy complaint.
GRPC_ABSTRACT;
}
/// Tries to enter a READY connectivity state.
/// This is a no-op by default, since most LB policies never go into

@ -127,7 +127,7 @@ class GrpcLb : public LoadBalancingPolicy {
const char* name() const override { return kGrpclb; }
void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) override;
RefCountedPtr<Config> lb_config) override;
void ResetBackoffLocked() override;
void FillChildRefsForChannelz(
channelz::ChildRefsList* child_subchannels,
@ -1171,7 +1171,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
// ctor and dtor
//
GrpcLb::GrpcLb(LoadBalancingPolicy::Args args)
GrpcLb::GrpcLb(Args args)
: LoadBalancingPolicy(std::move(args)),
response_generator_(MakeRefCounted<FakeResolverResponseGenerator>()),
lb_call_backoff_(
@ -1321,7 +1321,8 @@ void GrpcLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
grpc_channel_args_destroy(lb_channel_args);
}
void GrpcLb::UpdateLocked(const grpc_channel_args& args, grpc_json* lb_config) {
void GrpcLb::UpdateLocked(const grpc_channel_args& args,
RefCountedPtr<Config> lb_config) {
const bool is_initial_update = lb_channel_ == nullptr;
ProcessChannelArgsLocked(args);
// Update the existing RR policy.

@ -51,7 +51,7 @@ class PickFirst : public LoadBalancingPolicy {
const char* name() const override { return kPickFirst; }
void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) override;
RefCountedPtr<Config> lb_config) override;
void ExitIdleLocked() override;
void ResetBackoffLocked() override;
void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
@ -231,7 +231,7 @@ void PickFirst::UpdateChildRefsLocked() {
}
void PickFirst::UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) {
RefCountedPtr<Config> lb_config) {
AutoChildRefsUpdater guard(this);
const ServerAddressList* addresses = FindServerAddressListChannelArg(&args);
if (addresses == nullptr) {

@ -62,7 +62,7 @@ class RoundRobin : public LoadBalancingPolicy {
const char* name() const override { return kRoundRobin; }
void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) override;
RefCountedPtr<Config> lb_config) override;
void ResetBackoffLocked() override;
void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
channelz::ChildRefsList* ignored) override;
@ -477,7 +477,7 @@ void RoundRobin::RoundRobinSubchannelData::ProcessConnectivityChangeLocked(
}
void RoundRobin::UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) {
RefCountedPtr<Config> lb_config) {
AutoChildRefsUpdater guard(this);
const ServerAddressList* addresses = FindServerAddressListChannelArg(&args);
if (addresses == nullptr) {

@ -122,7 +122,7 @@ class XdsLb : public LoadBalancingPolicy {
const char* name() const override { return kXds; }
void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) override;
RefCountedPtr<Config> lb_config) override;
void ResetBackoffLocked() override;
void FillChildRefsForChannelz(
channelz::ChildRefsList* child_subchannels,
@ -242,9 +242,9 @@ class XdsLb : public LoadBalancingPolicy {
// Parses the xds config given the JSON node of the first child of XdsConfig.
// If parsing succeeds, updates \a balancer_name, and updates \a
// child_policy_json_dump_ and \a fallback_policy_json_dump_ if they are also
// child_policy_config_ and \a fallback_policy_config_ if they are also
// found. Does nothing upon failure.
void ParseLbConfig(grpc_json* xds_config_json);
void ParseLbConfig(Config* xds_config);
// Methods for dealing with the balancer channel and call.
void StartBalancerCallLocked();
@ -303,7 +303,8 @@ class XdsLb : public LoadBalancingPolicy {
// Timeout in milliseconds for before using fallback backend addresses.
// 0 means not using fallback.
UniquePtr<char> fallback_policy_json_string_;
UniquePtr<char> fallback_policy_name_;
RefCountedPtr<Config> fallback_policy_config_;
int lb_fallback_timeout_ms_ = 0;
// The backend addresses from the resolver.
UniquePtr<ServerAddressList> fallback_backend_addresses_;
@ -313,8 +314,9 @@ class XdsLb : public LoadBalancingPolicy {
grpc_closure lb_on_fallback_;
// The policy to use for the backends.
UniquePtr<char> child_policy_name_;
RefCountedPtr<Config> child_policy_config_;
OrphanablePtr<LoadBalancingPolicy> child_policy_;
UniquePtr<char> child_policy_json_string_;
};
//
@ -952,8 +954,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
// ctor and dtor
//
// TODO(vishalpowar): Use lb_config in args to configure LB policy.
XdsLb::XdsLb(LoadBalancingPolicy::Args args)
XdsLb::XdsLb(Args args)
: LoadBalancingPolicy(std::move(args)),
response_generator_(MakeRefCounted<FakeResolverResponseGenerator>()),
lb_call_backoff_(
@ -1087,11 +1088,12 @@ void XdsLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
grpc_channel_args_destroy(lb_channel_args);
}
void XdsLb::ParseLbConfig(grpc_json* xds_config_json) {
void XdsLb::ParseLbConfig(Config* xds_config) {
const grpc_json* xds_config_json = xds_config->json();
const char* balancer_name = nullptr;
grpc_json* child_policy = nullptr;
grpc_json* fallback_policy = nullptr;
for (grpc_json* field = xds_config_json; field != nullptr;
for (const grpc_json* field = xds_config_json; field != nullptr;
field = field->next) {
if (field->key == nullptr) return;
if (strcmp(field->key, "balancerName") == 0) {
@ -1108,19 +1110,22 @@ void XdsLb::ParseLbConfig(grpc_json* xds_config_json) {
}
if (balancer_name == nullptr) return; // Required field.
if (child_policy != nullptr) {
child_policy_json_string_ =
UniquePtr<char>(grpc_json_dump_to_string(child_policy, 0 /* indent */));
child_policy_name_ = UniquePtr<char>(gpr_strdup(child_policy->key));
child_policy_config_ = MakeRefCounted<Config>(child_policy->child,
xds_config->service_config());
}
if (fallback_policy != nullptr) {
fallback_policy_json_string_ = UniquePtr<char>(
grpc_json_dump_to_string(fallback_policy, 0 /* indent */));
fallback_policy_name_ = UniquePtr<char>(gpr_strdup(fallback_policy->key));
fallback_policy_config_ = MakeRefCounted<Config>(
fallback_policy->child, xds_config->service_config());
}
balancer_name_ = UniquePtr<char>(gpr_strdup(balancer_name));
}
void XdsLb::UpdateLocked(const grpc_channel_args& args, grpc_json* lb_config) {
void XdsLb::UpdateLocked(const grpc_channel_args& args,
RefCountedPtr<Config> lb_config) {
const bool is_initial_update = lb_channel_ == nullptr;
ParseLbConfig(lb_config);
ParseLbConfig(lb_config.get());
// TODO(juanlishen): Pass fallback policy config update after fallback policy
// is added.
if (balancer_name_ == nullptr) {
@ -1285,30 +1290,13 @@ void XdsLb::OnBalancerChannelConnectivityChangedLocked(void* arg,
// code for interacting with the child policy
//
void XdsLb::CreateChildPolicyLocked(const char* name, Args args) {
GPR_ASSERT(child_policy_ == nullptr);
child_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
name, std::move(args));
if (GPR_UNLIKELY(child_policy_ == nullptr)) {
gpr_log(GPR_ERROR, "[xdslb %p] Failure creating a child policy", this);
return;
}
// 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
// xDS LB, which in turn is tied to the application's call.
grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(),
interested_parties());
}
grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
bool is_backend_from_grpclb_load_balancer = false;
// This should never be invoked if we do not have serverlist_, as fallback
// mode is disabled for xDS plugin.
GPR_ASSERT(serverlist_ != nullptr);
GPR_ASSERT(serverlist_->num_servers > 0);
UniquePtr<ServerAddressList> addresses = ProcessServerlist(serverlist_);
GPR_ASSERT(addresses != nullptr);
is_backend_from_grpclb_load_balancer = true;
// Replace the server address list in the channel args that we pass down to
// the subchannel.
static const char* keys_to_remove[] = {GRPC_ARG_SERVER_ADDRESS_LIST};
@ -1318,7 +1306,7 @@ grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
// grpclb load balancer.
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_ADDRESS_IS_BACKEND_FROM_XDS_LOAD_BALANCER),
is_backend_from_grpclb_load_balancer),
1),
};
grpc_channel_args* args = grpc_channel_args_copy_and_add_and_remove(
args_, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add,
@ -1326,25 +1314,27 @@ grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
return args;
}
void XdsLb::CreateChildPolicyLocked(const char* name, Args args) {
GPR_ASSERT(child_policy_ == nullptr);
child_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
name, std::move(args));
if (GPR_UNLIKELY(child_policy_ == nullptr)) {
gpr_log(GPR_ERROR, "[xdslb %p] Failure creating a child policy", this);
return;
}
// 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
// xDS LB, which in turn is tied to the application's call.
grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(),
interested_parties());
}
void XdsLb::CreateOrUpdateChildPolicyLocked() {
if (shutting_down_) return;
grpc_channel_args* args = CreateChildPolicyArgsLocked();
GPR_ASSERT(args != nullptr);
const char* child_policy_name = nullptr;
grpc_json* child_policy_config = nullptr;
grpc_json* child_policy_json =
grpc_json_parse_string(child_policy_json_string_.get());
// TODO(juanlishen): If the child policy is not configured via service config,
// use whatever algorithm is specified by the balancer.
if (child_policy_json != nullptr) {
child_policy_name = child_policy_json->key;
child_policy_config = child_policy_json->child;
} else {
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO, "[xdslb %p] No valid child policy LB config", this);
}
child_policy_name = "round_robin";
}
// TODO(juanlishen): Switch policy according to child_policy_config->key.
if (child_policy_ == nullptr) {
LoadBalancingPolicy::Args lb_policy_args;
@ -1352,7 +1342,10 @@ void XdsLb::CreateOrUpdateChildPolicyLocked() {
lb_policy_args.args = args;
lb_policy_args.channel_control_helper =
UniquePtr<ChannelControlHelper>(New<Helper>(Ref()));
CreateChildPolicyLocked(child_policy_name, std::move(lb_policy_args));
CreateChildPolicyLocked(child_policy_name_ == nullptr
? "round_robin"
: child_policy_name_.get(),
std::move(lb_policy_args));
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO, "[xdslb %p] Created a new child policy %p", this,
child_policy_.get());
@ -1362,9 +1355,8 @@ void XdsLb::CreateOrUpdateChildPolicyLocked() {
gpr_log(GPR_INFO, "[xdslb %p] Updating child policy %p", this,
child_policy_.get());
}
child_policy_->UpdateLocked(*args, child_policy_config);
child_policy_->UpdateLocked(*args, child_policy_config_);
grpc_channel_args_destroy(args);
grpc_json_destroy(child_policy_json);
}
//

@ -33,9 +33,7 @@ class LoadBalancingPolicyFactory {
virtual OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
LoadBalancingPolicy::Args args) const {
std::move(args); // Suppress clang-tidy complaint.
// The rest of this is copied from the GRPC_ABSTRACT macro.
gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented");
GPR_ASSERT(false);
GRPC_ABSTRACT;
}
/// Returns the LB policy name that this factory provides.

@ -148,7 +148,8 @@ void ProcessedResolverResult::ParseLbConfigFromServiceConfig(
LoadBalancingPolicy::ParseLoadBalancingConfig(field);
if (policy != nullptr) {
lb_policy_name_.reset(gpr_strdup(policy->key));
lb_policy_config_ = policy->child;
lb_policy_config_ = MakeRefCounted<LoadBalancingPolicy::Config>(
policy->child, service_config_);
}
}

@ -21,6 +21,7 @@
#include <grpc/support/port_platform.h>
#include "src/core/ext/filters/client_channel/lb_policy.h"
#include "src/core/ext/filters/client_channel/retry_throttle.h"
#include "src/core/lib/channel/status_util.h"
#include "src/core/lib/gprpp/ref_counted.h"
@ -60,7 +61,9 @@ class ProcessedResolverResult {
return std::move(method_params_table_);
}
UniquePtr<char> lb_policy_name() { return std::move(lb_policy_name_); }
grpc_json* lb_policy_config() { return lb_policy_config_; }
RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config() {
return std::move(lb_policy_config_);
}
private:
// Finds the service config; extracts LB config and (maybe) retry throttle
@ -82,10 +85,10 @@ class ProcessedResolverResult {
// Service config.
UniquePtr<char> service_config_json_;
UniquePtr<grpc_core::ServiceConfig> service_config_;
RefCountedPtr<ServiceConfig> service_config_;
// LB policy.
grpc_json* lb_policy_config_ = nullptr;
UniquePtr<char> lb_policy_name_;
RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config_;
// Retry throttle data.
char* server_name_ = nullptr;
RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;

@ -117,14 +117,13 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
ResolvingLoadBalancingPolicy::ResolvingLoadBalancingPolicy(
Args args, TraceFlag* tracer, UniquePtr<char> target_uri,
UniquePtr<char> child_policy_name, grpc_json* child_lb_config,
UniquePtr<char> child_policy_name, RefCountedPtr<Config> child_lb_config,
grpc_error** error)
: LoadBalancingPolicy(std::move(args)),
tracer_(tracer),
target_uri_(std::move(target_uri)),
child_policy_name_(std::move(child_policy_name)),
child_lb_config_str_(grpc_json_dump_to_string(child_lb_config, 0)),
child_lb_config_(grpc_json_parse_string(child_lb_config_str_.get())) {
child_lb_config_(std::move(child_lb_config)) {
GPR_ASSERT(child_policy_name_ != nullptr);
// Don't fetch service config, since this ctor is for use in nested LB
// policies, not at the top level, and we only fetch the service
@ -170,7 +169,6 @@ grpc_error* ResolvingLoadBalancingPolicy::Init(const grpc_channel_args& args) {
ResolvingLoadBalancingPolicy::~ResolvingLoadBalancingPolicy() {
GPR_ASSERT(resolver_ == nullptr);
GPR_ASSERT(lb_policy_ == nullptr);
grpc_json_destroy(child_lb_config_);
}
void ResolvingLoadBalancingPolicy::ShutdownLocked() {
@ -406,7 +404,7 @@ void ResolvingLoadBalancingPolicy::OnResolverResultChangedLocked(
} else {
// Parse the resolver result.
const char* lb_policy_name = nullptr;
grpc_json* lb_policy_config = nullptr;
RefCountedPtr<Config> lb_policy_config;
bool service_config_changed = false;
if (self->process_resolver_result_ != nullptr) {
service_config_changed = self->process_resolver_result_(
@ -432,7 +430,8 @@ void ResolvingLoadBalancingPolicy::OnResolverResultChangedLocked(
gpr_log(GPR_INFO, "resolving_lb=%p: updating LB policy \"%s\" (%p)", self,
lb_policy_name, self->lb_policy_.get());
}
self->lb_policy_->UpdateLocked(*self->resolver_result_, lb_policy_config);
self->lb_policy_->UpdateLocked(*self->resolver_result_,
std::move(lb_policy_config));
// Add channel trace event.
if (self->channelz_node() != nullptr) {
if (service_config_changed) {

@ -56,17 +56,17 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
ResolvingLoadBalancingPolicy(Args args, TraceFlag* tracer,
UniquePtr<char> target_uri,
UniquePtr<char> child_policy_name,
grpc_json* child_lb_config, grpc_error** error);
RefCountedPtr<Config> child_lb_config,
grpc_error** error);
// Private ctor, to be used by client_channel only!
//
// Synchronous callback that takes the resolver result and sets
// lb_policy_name and lb_policy_config to point to the right data.
// Returns true if the service config has changed since the last result.
typedef bool (*ProcessResolverResultCallback)(void* user_data,
const grpc_channel_args& args,
const char** lb_policy_name,
grpc_json** lb_policy_config);
typedef bool (*ProcessResolverResultCallback)(
void* user_data, const grpc_channel_args& args,
const char** lb_policy_name, RefCountedPtr<Config>* lb_policy_config);
// If error is set when this returns, then construction failed, and
// the caller may not use the new object.
ResolvingLoadBalancingPolicy(
@ -80,7 +80,7 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
// TODO(roth): Need to support updating child LB policy's config for xds
// use case.
void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) override {}
RefCountedPtr<Config> lb_config) override {}
void ExitIdleLocked() override;
@ -116,8 +116,7 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
ProcessResolverResultCallback process_resolver_result_ = nullptr;
void* process_resolver_result_user_data_ = nullptr;
UniquePtr<char> child_policy_name_;
UniquePtr<char> child_lb_config_str_;
grpc_json* child_lb_config_ = nullptr;
RefCountedPtr<Config> child_lb_config_;
// Resolver and associated state.
OrphanablePtr<Resolver> resolver_;

@ -590,7 +590,7 @@ Subchannel::Subchannel(SubchannelKey* key, grpc_connector* connector,
const char* service_config_json = grpc_channel_arg_get_string(
grpc_channel_args_find(args_, GRPC_ARG_SERVICE_CONFIG));
if (service_config_json != nullptr) {
UniquePtr<ServiceConfig> service_config =
RefCountedPtr<ServiceConfig> service_config =
ServiceConfig::Create(service_config_json);
if (service_config != nullptr) {
HealthCheckParams params;

@ -319,7 +319,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVICE_CONFIG);
const char* service_config_str = grpc_channel_arg_get_string(channel_arg);
if (service_config_str != nullptr) {
grpc_core::UniquePtr<grpc_core::ServiceConfig> service_config =
grpc_core::RefCountedPtr<grpc_core::ServiceConfig> service_config =
grpc_core::ServiceConfig::Create(service_config_str);
if (service_config != nullptr) {
chand->method_limit_table = service_config->CreateMethodConfigTable(

@ -33,14 +33,14 @@
namespace grpc_core {
UniquePtr<ServiceConfig> ServiceConfig::Create(const char* json) {
RefCountedPtr<ServiceConfig> ServiceConfig::Create(const char* json) {
UniquePtr<char> json_string(gpr_strdup(json));
grpc_json* json_tree = grpc_json_parse_string(json_string.get());
if (json_tree == nullptr) {
gpr_log(GPR_INFO, "failed to parse JSON for service config");
return nullptr;
}
return MakeUnique<ServiceConfig>(std::move(json_string), json_tree);
return MakeRefCounted<ServiceConfig>(std::move(json_string), json_tree);
}
ServiceConfig::ServiceConfig(UniquePtr<char> json_string, grpc_json* json_tree)

@ -23,6 +23,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/gprpp/inlined_vector.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/slice/slice_hash_table.h"
@ -41,8 +42,7 @@
// }
// ],
// // remaining fields are optional.
// // see
// https://developers.google.com/protocol-buffers/docs/proto3#json
// // see https://developers.google.com/protocol-buffers/docs/proto3#json
// // for format details.
// "waitForReady": bool,
// "timeout": "duration_string",
@ -54,11 +54,11 @@
namespace grpc_core {
class ServiceConfig {
class ServiceConfig : public RefCounted<ServiceConfig> {
public:
/// Creates a new service config from parsing \a json_string.
/// Returns null on parse error.
static UniquePtr<ServiceConfig> Create(const char* json);
static RefCountedPtr<ServiceConfig> Create(const char* json);
~ServiceConfig();

@ -65,8 +65,8 @@ class ForwardingLoadBalancingPolicy : public LoadBalancingPolicy {
~ForwardingLoadBalancingPolicy() override = default;
void UpdateLocked(const grpc_channel_args& args,
grpc_json* lb_config) override {
delegate_->UpdateLocked(args, lb_config);
RefCountedPtr<Config> lb_config) override {
delegate_->UpdateLocked(args, std::move(lb_config));
}
void ExitIdleLocked() override { delegate_->ExitIdleLocked(); }
@ -102,7 +102,8 @@ class InterceptRecvTrailingMetadataLoadBalancingPolicy
RefCountedPtr<InterceptRecvTrailingMetadataLoadBalancingPolicy>(
this),
cb, user_data)),
std::move(args), /*delegate_lb_policy_name=*/"pick_first",
std::move(args),
/*delegate_lb_policy_name=*/"pick_first",
/*initial_refcount=*/2) {}
~InterceptRecvTrailingMetadataLoadBalancingPolicy() override = default;
@ -210,12 +211,11 @@ class InterceptTrailingFactory : public LoadBalancingPolicyFactory {
void* user_data)
: cb_(cb), user_data_(user_data) {}
grpc_core::OrphanablePtr<grpc_core::LoadBalancingPolicy>
CreateLoadBalancingPolicy(
grpc_core::LoadBalancingPolicy::Args args) const override {
return grpc_core::OrphanablePtr<grpc_core::LoadBalancingPolicy>(
grpc_core::New<InterceptRecvTrailingMetadataLoadBalancingPolicy>(
std::move(args), cb_, user_data_));
OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
LoadBalancingPolicy::Args args) const override {
return OrphanablePtr<LoadBalancingPolicy>(
New<InterceptRecvTrailingMetadataLoadBalancingPolicy>(std::move(args),
cb_, user_data_));
}
const char* name() const override {
@ -231,10 +231,9 @@ class InterceptTrailingFactory : public LoadBalancingPolicyFactory {
void RegisterInterceptRecvTrailingMetadataLoadBalancingPolicy(
InterceptRecvTrailingMetadataCallback cb, void* user_data) {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
grpc_core::UniquePtr<grpc_core::LoadBalancingPolicyFactory>(
grpc_core::New<InterceptTrailingFactory>(cb, user_data)));
LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
UniquePtr<LoadBalancingPolicyFactory>(
New<InterceptTrailingFactory>(cb, user_data)));
}
} // namespace grpc_core

Loading…
Cancel
Save