Use a single copy of CreateErrorFromVector from ServiceConfig

reviewable/pr18746/r2
Yash Tibrewal 6 years ago
parent a4036b2d8c
commit baa52808f1
  1. 3
      src/core/ext/filters/client_channel/client_channel.cc
  2. 21
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  3. 20
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  4. 28
      src/core/ext/filters/client_channel/resolver_result_parsing.cc
  5. 18
      src/core/ext/filters/client_channel/service_config.cc
  6. 18
      src/core/ext/filters/client_channel/service_config.h
  7. 21
      src/core/ext/filters/message_size/message_size_parser.cc

@ -3080,6 +3080,9 @@ void CallData::ApplyServiceConfigToCallLocked(grpc_call_element* elem) {
chand, this);
}
if (chand->service_config() != nullptr) {
// Store a ref to the service_config in CallData. Also, save pointers to the
// ServiceConfig and ServiceConfigObjectsVector (for this call) in the
// call_context so that all future filters can access it.
service_config_ = chand->service_config();
call_context_[GRPC_SERVICE_CONFIG].value = &service_config_;
const auto* method_params_vector_ptr =

@ -1798,24 +1798,6 @@ void GrpcLb::CreateOrUpdateChildPolicyLocked() {
policy_to_update->UpdateLocked(std::move(update_args));
}
// Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return GRPC_ERROR_NONE.
template <size_t N>
grpc_error* CreateErrorFromVector(const char* desc,
InlinedVector<grpc_error*, N>* error_list) {
grpc_error* error = GRPC_ERROR_NONE;
if (error_list->size() != 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
desc, error_list->data(), error_list->size());
// Remove refs to all errors in error_list.
for (size_t i = 0; i < error_list->size(); i++) {
GRPC_ERROR_UNREF((*error_list)[i]);
}
error_list->clear();
}
return error;
}
//
// factory
//
@ -1858,7 +1840,8 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
return UniquePtr<ParsedLoadBalancingConfig>(
New<ParsedGrpcLbConfig>(std::move(child_policy)));
} else {
*error = CreateErrorFromVector("GrpcLb Parser", &error_list);
*error =
ServiceConfig::CreateErrorFromVector("GrpcLb Parser", &error_list);
return nullptr;
}
}

@ -1652,24 +1652,6 @@ void XdsLb::LocalityMap::LocalityEntry::Helper::RequestReresolution() {
}
}
// Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return GRPC_ERROR_NONE.
template <size_t N>
grpc_error* CreateErrorFromVector(const char* desc,
InlinedVector<grpc_error*, N>* error_list) {
grpc_error* error = GRPC_ERROR_NONE;
if (error_list->size() != 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
desc, error_list->data(), error_list->size());
// Remove refs to all errors in error_list.
for (size_t i = 0; i < error_list->size(); i++) {
GRPC_ERROR_UNREF((*error_list)[i]);
}
error_list->clear();
}
return error;
}
//
// factory
//
@ -1743,7 +1725,7 @@ class XdsFactory : public LoadBalancingPolicyFactory {
return UniquePtr<ParsedLoadBalancingConfig>(New<ParsedXdsConfig>(
balancer_name, std::move(child_policy), std::move(fallback_policy)));
} else {
*error = CreateErrorFromVector("Xds Parser", &error_list);
*error = ServiceConfig::CreateErrorFromVector("Xds Parser", &error_list);
return nullptr;
}
}

@ -79,26 +79,6 @@ ProcessedResolverResult::ProcessedResolverResult(
if (lb_policy_name_ == nullptr) ProcessLbPolicyName(*resolver_result);
}
namespace {
// Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return GRPC_ERROR_NONE.
template <size_t N>
grpc_error* CreateErrorFromVector(const char* desc,
InlinedVector<grpc_error*, N>* error_list) {
grpc_error* error = GRPC_ERROR_NONE;
if (error_list->size() != 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
desc, error_list->data(), error_list->size());
// Remove refs to all errors in error_list.
for (size_t i = 0; i < error_list->size(); i++) {
GRPC_ERROR_UNREF((*error_list)[i]);
}
error_list->clear();
}
return error;
}
} // namespace
void ProcessedResolverResult::ProcessServiceConfig(
const Resolver::Result& resolver_result, bool parse_retry) {
if (service_config_ == nullptr) return;
@ -349,7 +329,7 @@ UniquePtr<ClientChannelMethodParsedObject::RetryPolicy> ParseRetryPolicy(
return nullptr;
}
}
*error = CreateErrorFromVector("retryPolicy", &error_list);
*error = ServiceConfig::CreateErrorFromVector("retryPolicy", &error_list);
return *error == GRPC_ERROR_NONE ? std::move(retry_policy) : nullptr;
}
@ -504,7 +484,8 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const grpc_json* json,
}
}
}
*error = CreateErrorFromVector("Client channel global parser", &error_list);
*error = ServiceConfig::CreateErrorFromVector("Client channel global parser",
&error_list);
if (*error == GRPC_ERROR_NONE) {
return UniquePtr<ServiceConfigParsedObject>(
New<ClientChannelGlobalParsedObject>(std::move(parsed_lb_config),
@ -560,7 +541,8 @@ ClientChannelServiceConfigParser::ParsePerMethodParams(const grpc_json* json,
}
}
}
*error = CreateErrorFromVector("Client channel parser", &error_list);
*error = ServiceConfig::CreateErrorFromVector("Client channel parser",
&error_list);
if (*error == GRPC_ERROR_NONE) {
return UniquePtr<ServiceConfigParsedObject>(
New<ClientChannelMethodParsedObject>(timeout, wait_for_ready,

@ -38,24 +38,6 @@ typedef InlinedVector<UniquePtr<ServiceConfigParser>,
ServiceConfig::kNumPreallocatedParsers>
ServiceConfigParserList;
ServiceConfigParserList* g_registered_parsers;
// Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return GRPC_ERROR_NONE.
template <size_t N>
grpc_error* CreateErrorFromVector(const char* desc,
InlinedVector<grpc_error*, N>* error_list) {
grpc_error* error = GRPC_ERROR_NONE;
if (error_list->size() != 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
desc, error_list->data(), error_list->size());
// Remove refs to all errors in error_list.
for (size_t i = 0; i < error_list->size(); i++) {
GRPC_ERROR_UNREF((*error_list)[i]);
}
error_list->clear();
}
return error;
}
} // namespace
RefCountedPtr<ServiceConfig> ServiceConfig::Create(const char* json,

@ -150,6 +150,24 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
static void Shutdown();
// Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return GRPC_ERROR_NONE.
template <size_t N>
static grpc_error* CreateErrorFromVector(
const char* desc, InlinedVector<grpc_error*, N>* error_list) {
grpc_error* error = GRPC_ERROR_NONE;
if (error_list->size() != 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
desc, error_list->data(), error_list->size());
// Remove refs to all errors in error_list.
for (size_t i = 0; i < error_list->size(); i++) {
GRPC_ERROR_UNREF((*error_list)[i]);
}
error_list->clear();
}
return error;
}
private:
// So New() can call our private ctor.
template <typename T, typename... Args>

@ -22,24 +22,6 @@
namespace {
size_t g_message_size_parser_index;
// Consumes all the errors in the vector and forms a referencing error from
// them. If the vector is empty, return GRPC_ERROR_NONE.
template <size_t N>
grpc_error* CreateErrorFromVector(
const char* desc, grpc_core::InlinedVector<grpc_error*, N>* error_list) {
grpc_error* error = GRPC_ERROR_NONE;
if (error_list->size() != 0) {
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
desc, error_list->data(), error_list->size());
// Remove refs to all errors in error_list.
for (size_t i = 0; i < error_list->size(); i++) {
GRPC_ERROR_UNREF((*error_list)[i]);
}
error_list->clear();
}
return error;
}
} // namespace
namespace grpc_core {
@ -85,7 +67,8 @@ UniquePtr<ServiceConfigParsedObject> MessageSizeParser::ParsePerMethodParams(
}
}
if (!error_list.empty()) {
*error = CreateErrorFromVector("Message size parser", &error_list);
*error = ServiceConfig::CreateErrorFromVector("Message size parser",
&error_list);
return nullptr;
}
return UniquePtr<ServiceConfigParsedObject>(New<MessageSizeParsedObject>(

Loading…
Cancel
Save