#include <grpc/support/port_platform.h>
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h"
#include <grpc/event_engine/event_engine.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/container/inlined_vector.h"
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#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"
#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
#include <grpc/grpc.h>
#include <grpc/impl/codegen/connectivity_state.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/impl/codegen/propagation_bits.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/filters/client_channel/client_channel.h"
#include "src/core/ext/filters/client_channel/lb_policy.h"
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h"
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h"
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h"
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h"
#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
#include "src/core/ext/filters/client_channel/lb_policy_registry.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/ext/filters/client_channel/subchannel_interface.h"
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/event_engine/event_engine_factory.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/iomgr/resolved_address.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/socket_utils.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/iomgr/work_serializer.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/resolver/resolver.h"
#include "src/core/lib/resolver/server_address.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_refcount.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#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"
Go to the source code of this file.
Namespaces | |
grpc_core | |
Macros | |
#define | GRPC_GRPCLB_DEFAULT_FALLBACK_TIMEOUT_MS 10000 |
#define | GRPC_GRPCLB_DEFAULT_SUBCHANNEL_DELETION_DELAY_MS 10000 |
#define | GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1 |
#define | GRPC_GRPCLB_RECONNECT_BACKOFF_MULTIPLIER 1.6 |
#define | GRPC_GRPCLB_RECONNECT_JITTER 0.2 |
#define | GRPC_GRPCLB_RECONNECT_MAX_BACKOFF_SECONDS 120 |
Functions | |
void | grpc_lb_policy_grpclb_init () |
void | grpc_lb_policy_grpclb_shutdown () |
void | grpc_core::RegisterGrpcLbLoadReportingFilter (CoreConfiguration::Builder *builder) |
Variables | |
TraceFlag | grpc_core::grpc_lb_glb_trace (false, "glb") |
const char | grpc_core::kGrpcLbAddressAttributeKey [] = "grpclb" |
#define GRPC_GRPCLB_DEFAULT_SUBCHANNEL_DELETION_DELAY_MS 10000 |
#define GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1 |
Implementation of the gRPC LB policy.
This policy takes as input a list of resolved addresses, which must include at least one balancer address.
An internal channel (lb_channel_) is created for the addresses from that are balancers. This channel behaves just like a regular channel that uses pick_first to select from the list of balancer addresses.
When we get our initial update, we instantiate the internal streaming call to the LB server (whichever address pick_first chose). The call will be complete when either the balancer sends status or when we cancel the call (e.g., because we are shutting down). In needed, we retry the call. If we received at least one valid message from the server, a new call attempt will be made immediately; otherwise, we apply back-off delays between attempts.
We maintain an internal round_robin policy instance for distributing requests across backends. Whenever we receive a new serverlist from the balancer, we update the round_robin policy with the new list of addresses. If we cannot communicate with the balancer on startup, however, we may enter fallback mode, in which case we will populate the child policy's addresses from the backend addresses returned by the resolver.
Once a child policy instance is in place (and getting updated as described), calls for a pick, a ping, or a cancellation will be serviced right away by forwarding them to the child policy instance. Any time there's no child policy available (i.e., right after the creation of the gRPCLB policy), pick requests are queued.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |