Skip to content

Commit

Permalink
client channel: create a header file for internal interfaces (grpc#32423
Browse files Browse the repository at this point in the history
)

This is just a bit of a code reorganization, no functional changes.
  • Loading branch information
markdroth authored Feb 21, 2023
1 parent 50e6af1 commit 3faeb3a
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 144 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2769,14 +2769,14 @@ grpc_cc_library(
"//src/core:ext/filters/client_channel/client_channel.h",
"//src/core:ext/filters/client_channel/client_channel_channelz.h",
"//src/core:ext/filters/client_channel/client_channel_factory.h",
"//src/core:ext/filters/client_channel/client_channel_internal.h",
"//src/core:ext/filters/client_channel/client_channel_service_config.h",
"//src/core:ext/filters/client_channel/config_selector.h",
"//src/core:ext/filters/client_channel/connector.h",
"//src/core:ext/filters/client_channel/dynamic_filters.h",
"//src/core:ext/filters/client_channel/global_subchannel_pool.h",
"//src/core:ext/filters/client_channel/health/health_check_client.h",
"//src/core:ext/filters/client_channel/http_proxy.h",
"//src/core:ext/filters/client_channel/lb_call_state_internal.h",
"//src/core:ext/filters/client_channel/lb_policy/child_policy_handler.h",
"//src/core:ext/filters/client_channel/lb_policy/oob_backend_metric.h",
"//src/core:ext/filters/client_channel/lb_policy/oob_backend_metric_internal.h",
Expand Down
4 changes: 2 additions & 2 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gRPC-C++.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gRPC-Core.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion grpc.gemspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/core/ext/filters/client_channel/client_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <functional>
#include <new>
#include <type_traits>
#include <utility>
#include <vector>

#include "absl/cleanup/cleanup.h"
Expand All @@ -48,6 +49,7 @@
#include "src/core/ext/filters/client_channel/backend_metric.h"
#include "src/core/ext/filters/client_channel/backup_poller.h"
#include "src/core/ext/filters/client_channel/client_channel_channelz.h"
#include "src/core/ext/filters/client_channel/client_channel_internal.h"
#include "src/core/ext/filters/client_channel/client_channel_service_config.h"
#include "src/core/ext/filters/client_channel/config_selector.h"
#include "src/core/ext/filters/client_channel/dynamic_filters.h"
Expand All @@ -68,6 +70,7 @@
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/status_helper.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/unique_type_name.h"
#include "src/core/lib/gprpp/work_serializer.h"
#include "src/core/lib/handshaker/proxy_mapper_registry.h"
#include "src/core/lib/iomgr/exec_ctx.h"
Expand Down Expand Up @@ -2341,6 +2344,25 @@ void ClientChannel::FilterBasedCallData::
error);
}

//
// ClientChannel::LoadBalancedCall::LbCallState
//

class ClientChannel::LoadBalancedCall::LbCallState
: public ClientChannelLbCallState {
public:
explicit LbCallState(LoadBalancedCall* lb_call) : lb_call_(lb_call) {}

void* Alloc(size_t size) override { return lb_call_->arena()->Alloc(size); }

// Internal API to allow first-party LB policies to access per-call
// attributes set by the ConfigSelector.
absl::string_view GetCallAttribute(UniqueTypeName type) override;

private:
LoadBalancedCall* lb_call_;
};

//
// ClientChannel::LoadBalancedCall::Metadata
//
Expand Down
85 changes: 1 addition & 84 deletions src/core/ext/filters/client_channel/client_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <map>
#include <memory>
#include <string>
#include <utility>

#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_set.h"
Expand All @@ -40,7 +39,6 @@
#include "src/core/ext/filters/client_channel/client_channel_factory.h"
#include "src/core/ext/filters/client_channel/config_selector.h"
#include "src/core/ext/filters/client_channel/dynamic_filters.h"
#include "src/core/ext/filters/client_channel/lb_call_state_internal.h"
#include "src/core/ext/filters/client_channel/lb_policy/backend_metric_data.h"
#include "src/core/ext/filters/client_channel/subchannel.h"
#include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
Expand All @@ -56,7 +54,6 @@
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/gprpp/unique_type_name.h"
#include "src/core/lib/gprpp/work_serializer.h"
#include "src/core/lib/iomgr/call_combiner.h"
#include "src/core/lib/iomgr/closure.h"
Expand All @@ -67,8 +64,6 @@
#include "src/core/lib/resolver/resolver.h"
#include "src/core/lib/resource_quota/arena.h"
#include "src/core/lib/service_config/service_config.h"
#include "src/core/lib/service_config/service_config_call_data.h"
#include "src/core/lib/service_config/service_config_parser.h"
#include "src/core/lib/slice/slice_buffer.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/transport/connectivity_state.h"
Expand Down Expand Up @@ -372,21 +367,6 @@ class ClientChannel {
class ClientChannel::LoadBalancedCall
: public InternallyRefCounted<LoadBalancedCall, kUnrefCallDtor> {
public:
// TODO(roth): Make this private.
class LbCallState : public LbCallStateInternal {
public:
explicit LbCallState(LoadBalancedCall* lb_call) : lb_call_(lb_call) {}

void* Alloc(size_t size) override { return lb_call_->arena()->Alloc(size); }

// Internal API to allow first-party LB policies to access per-call
// attributes set by the ConfigSelector.
absl::string_view GetCallAttribute(UniqueTypeName type) override;

private:
LoadBalancedCall* lb_call_;
};

LoadBalancedCall(
ClientChannel* chand, grpc_call_context_element* call_context,
ConfigSelector::CallDispatchController* call_dispatch_controller,
Expand Down Expand Up @@ -439,6 +419,7 @@ class ClientChannel::LoadBalancedCall
absl::string_view peer_address);

private:
class LbCallState;
class Metadata;
class BackendMetricAccessor;

Expand Down Expand Up @@ -612,70 +593,6 @@ class ClientChannel::FilterBasedLoadBalancedCall
grpc_transport_stream_op_batch* pending_batches_[MAX_PENDING_BATCHES] = {};
};

// A sub-class of ServiceConfigCallData used to access the
// CallDispatchController. Allocated on the arena, stored in the call
// context, and destroyed when the call is destroyed.
// TODO(roth): Combine this with lb_call_state_internal.h.
class ClientChannelServiceConfigCallData : public ServiceConfigCallData {
public:
ClientChannelServiceConfigCallData(
RefCountedPtr<ServiceConfig> service_config,
const ServiceConfigParser::ParsedConfigVector* method_configs,
ServiceConfigCallData::CallAttributes call_attributes,
ConfigSelector::CallDispatchController* call_dispatch_controller,
grpc_call_context_element* call_context)
: ServiceConfigCallData(std::move(service_config), method_configs,
std::move(call_attributes)),
call_dispatch_controller_(call_dispatch_controller) {
call_context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value = this;
call_context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].destroy = Destroy;
}

ConfigSelector::CallDispatchController* call_dispatch_controller() {
return &call_dispatch_controller_;
}

private:
// A wrapper for the CallDispatchController returned by the ConfigSelector.
// Handles the case where the ConfigSelector doees not return any
// CallDispatchController.
// Also ensures that we call Commit() at most once, which allows the
// client channel code to call Commit() when the call is complete in case
// it wasn't called earlier, without needing to know whether or not it was.
class CallDispatchControllerWrapper
: public ConfigSelector::CallDispatchController {
public:
explicit CallDispatchControllerWrapper(
ConfigSelector::CallDispatchController* call_dispatch_controller)
: call_dispatch_controller_(call_dispatch_controller) {}

bool ShouldRetry() override {
if (call_dispatch_controller_ != nullptr) {
return call_dispatch_controller_->ShouldRetry();
}
return true;
}

void Commit() override {
if (call_dispatch_controller_ != nullptr && !commit_called_) {
call_dispatch_controller_->Commit();
commit_called_ = true;
}
}

private:
ConfigSelector::CallDispatchController* call_dispatch_controller_;
bool commit_called_ = false;
};

static void Destroy(void* ptr) {
auto* self = static_cast<ClientChannelServiceConfigCallData*>(ptr);
self->~ClientChannelServiceConfigCallData();
}

CallDispatchControllerWrapper call_dispatch_controller_;
};

} // namespace grpc_core

#endif // GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_H
Loading

0 comments on commit 3faeb3a

Please sign in to comment.