|
|
|
@ -78,7 +78,6 @@ |
|
|
|
|
#include "absl/strings/str_format.h" |
|
|
|
|
#include "absl/strings/str_join.h" |
|
|
|
|
#include "absl/strings/string_view.h" |
|
|
|
|
#include "absl/strings/strip.h" |
|
|
|
|
#include "absl/types/optional.h" |
|
|
|
|
#include "absl/types/variant.h" |
|
|
|
|
#include "upb/upb.hpp" |
|
|
|
@ -144,7 +143,6 @@ |
|
|
|
|
#include "src/core/lib/surface/channel_stack_type.h" |
|
|
|
|
#include "src/core/lib/transport/connectivity_state.h" |
|
|
|
|
#include "src/core/lib/transport/metadata_batch.h" |
|
|
|
|
#include "src/core/lib/uri/uri_parser.h" |
|
|
|
|
|
|
|
|
|
#define GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1 |
|
|
|
|
#define GRPC_GRPCLB_RECONNECT_BACKOFF_MULTIPLIER 1.6 |
|
|
|
@ -523,8 +521,6 @@ class GrpcLb : public LoadBalancingPolicy { |
|
|
|
|
void StartSubchannelCacheTimerLocked(); |
|
|
|
|
void OnSubchannelCacheTimerLocked(); |
|
|
|
|
|
|
|
|
|
// Who the client is trying to communicate with.
|
|
|
|
|
std::string server_name_; |
|
|
|
|
// Configurations for the policy.
|
|
|
|
|
RefCountedPtr<GrpcLbConfig> config_; |
|
|
|
|
|
|
|
|
@ -854,8 +850,6 @@ GrpcLb::BalancerCallState::BalancerCallState( |
|
|
|
|
// Init the LB call. Note that the LB call will progress every time there's
|
|
|
|
|
// activity in grpclb_policy_->interested_parties(), which is comprised of
|
|
|
|
|
// the polling entities from client_channel.
|
|
|
|
|
GPR_ASSERT(!grpclb_policy()->server_name_.empty()); |
|
|
|
|
// Closure Initialization
|
|
|
|
|
GRPC_CLOSURE_INIT(&lb_on_initial_request_sent_, OnInitialRequestSent, this, |
|
|
|
|
grpc_schedule_on_exec_ctx); |
|
|
|
|
GRPC_CLOSURE_INIT(&lb_on_balancer_message_received_, |
|
|
|
@ -877,8 +871,8 @@ GrpcLb::BalancerCallState::BalancerCallState( |
|
|
|
|
upb::Arena arena; |
|
|
|
|
grpc_slice request_payload_slice = GrpcLbRequestCreate( |
|
|
|
|
grpclb_policy()->config_->service_name().empty() |
|
|
|
|
? grpclb_policy()->server_name_.c_str() |
|
|
|
|
: grpclb_policy()->config_->service_name().c_str(), |
|
|
|
|
? grpclb_policy()->channel_control_helper()->GetAuthority() |
|
|
|
|
: grpclb_policy()->config_->service_name(), |
|
|
|
|
arena.ptr()); |
|
|
|
|
send_message_payload_ = |
|
|
|
|
grpc_raw_byte_buffer_create(&request_payload_slice, 1); |
|
|
|
@ -1372,10 +1366,6 @@ ChannelArgs BuildBalancerChannelArgs( |
|
|
|
|
// Strip out the service config, since we don't want the LB policy
|
|
|
|
|
// config specified for the parent channel to affect the LB channel.
|
|
|
|
|
.Remove(GRPC_ARG_SERVICE_CONFIG) |
|
|
|
|
// The channel arg for the server URI, since that will be different
|
|
|
|
|
// for the LB channel than for the parent channel. The client
|
|
|
|
|
// channel factory will re-add this arg with the right value.
|
|
|
|
|
.Remove(GRPC_ARG_SERVER_URI) |
|
|
|
|
// The fake resolver response generator, because we are replacing it
|
|
|
|
|
// with the one from the grpclb policy, used to propagate updates to
|
|
|
|
|
// the LB channel.
|
|
|
|
@ -1411,16 +1401,8 @@ ChannelArgs BuildBalancerChannelArgs( |
|
|
|
|
// ctor and dtor
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
std::string GetServerNameFromChannelArgs(const ChannelArgs& args) { |
|
|
|
|
absl::StatusOr<URI> uri = |
|
|
|
|
URI::Parse(args.GetString(GRPC_ARG_SERVER_URI).value()); |
|
|
|
|
GPR_ASSERT(uri.ok() && !uri->path().empty()); |
|
|
|
|
return std::string(absl::StripPrefix(uri->path(), "/")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GrpcLb::GrpcLb(Args args) |
|
|
|
|
: LoadBalancingPolicy(std::move(args)), |
|
|
|
|
server_name_(GetServerNameFromChannelArgs(channel_args())), |
|
|
|
|
response_generator_(MakeRefCounted<FakeResolverResponseGenerator>()), |
|
|
|
|
lb_call_timeout_(std::max( |
|
|
|
|
Duration::Zero(), |
|
|
|
@ -1451,7 +1433,8 @@ GrpcLb::GrpcLb(Args args) |
|
|
|
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) { |
|
|
|
|
gpr_log(GPR_INFO, |
|
|
|
|
"[grpclb %p] Will use '%s' as the server name for LB request.", |
|
|
|
|
this, server_name_.c_str()); |
|
|
|
|
this, |
|
|
|
|
std::string(channel_control_helper()->GetAuthority()).c_str()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1581,7 +1564,8 @@ absl::Status GrpcLb::UpdateBalancerChannelLocked() { |
|
|
|
|
BuildBalancerChannelArgs(response_generator_.get(), args_); |
|
|
|
|
// Create balancer channel if needed.
|
|
|
|
|
if (lb_channel_ == nullptr) { |
|
|
|
|
std::string uri_str = absl::StrCat("fake:///", server_name_); |
|
|
|
|
std::string uri_str = |
|
|
|
|
absl::StrCat("fake:///", channel_control_helper()->GetAuthority()); |
|
|
|
|
lb_channel_ = |
|
|
|
|
grpc_channel_create(uri_str.c_str(), channel_credentials.get(), |
|
|
|
|
lb_channel_args.ToC().get()); |
|
|
|
|