Involved Source Files Package endpointsharding implements a load balancing policy that manages
homogeneous child policies each owning a single endpoint.
# Experimental
Notice: This package is EXPERIMENTAL and may be changed or removed in a
later release.
Package-Level Type Names (total 7, in which 4 are exported)
ChildState is the balancer state of a child along with the endpoint which
identifies the child balancer. Balancer exposes only the ExitIdler interface of the child LB policy.
Other methods of the child policy are called only by endpointsharding.Endpointresolver.EndpointStatebalancer.State
func ChildStatesFromPicker(picker balancer.Picker) []ChildState
ExitIdler provides access to only the ExitIdle method of the child balancer. ExitIdle instructs the LB policy to reconnect to backends / exit the
IDLE state, if appropriate and possible. Note that SubConns that enter
the IDLE state will not reconnect until SubConn.Connect is called.
google.golang.org/grpc/balancer.Balancer(interface)
google.golang.org/grpc/balancer.ExitIdler(interface)
*google.golang.org/grpc/internal/balancer/gracefulswitch.Balancer
*balancerWrapper
*endpointSharding
*google.golang.org/grpc/balancer/base.baseBalancer
*google.golang.org/grpc/balancer/pickfirst.pickfirstBalancer
*google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.pickfirstBalancer
google.golang.org/grpc/balancer/roundrobin.rrBalancer
google.golang.org/grpc/internal/balancer/gracefulswitch.balancerWrapper
ExitIdler : google.golang.org/grpc/balancer.ExitIdler
Options are the options to configure the behaviour of the
endpointsharding balancer. DisableAutoReconnect allows the balancer to keep child balancer in the
IDLE state until they are explicitly triggered to exit using the
ChildState obtained from the endpointsharding picker. When set to false,
the endpointsharding balancer will automatically call ExitIdle on child
connections that report IDLE.
func NewBalancer(cc balancer.ClientConn, opts balancer.BuildOptions, childBuilder ChildBuilderFunc, esOpts Options) balancer.Balancer
balancerWrapper is a wrapper of a balancer. It ID's a child balancer by
endpoint, and persists recent child balancer state. // embed to intercept UpdateState, doesn't deal with SubConns child contains the wrapped balancer. Access its methods only through
methods on balancerWrapper to ensure proper synchronizationchildStateChildStatees*endpointShardingisClosedbool ExitIdle pings an IDLE child balancer to exit idle in a new goroutine to
avoid deadlocks due to synchronous balancer state updates. MetricsRecorder provides the metrics recorder that balancers can use to
record metrics. Balancer implementations which do not register metrics on
metrics registry and record on them can ignore this method. The returned
MetricsRecorder is guaranteed to never be nil. NewSubConn is called by balancer to create a new SubConn.
It doesn't block and wait for the connections to be established.
Behaviors of the SubConn can be controlled by options.
Deprecated: please be aware that in a future version, SubConns will only
support one address per SubConn. RemoveSubConn removes the SubConn from ClientConn.
The SubConn will be shutdown.
Deprecated: use SubConn.Shutdown instead. ResolveNow is called by balancer to notify gRPC to do a name resolving. Target returns the dial target for this ClientConn.
Deprecated: Use the Target field in the BuildOptions instead. UpdateAddresses updates the addresses used in the passed in SubConn.
gRPC checks if the currently connected address is still in the new list.
If so, the connection will be kept. Else, the connection will be
gracefully closed, and a new connection will be created.
This may trigger a state transition for the SubConn.
Deprecated: this method will be removed. Create new SubConns for new
addresses instead.(*balancerWrapper) UpdateState(state balancer.State) closeLocked closes the child balancer. Callers must hold the child mutext of
the parent endpointsharding balancer.( balancerWrapper) enforceClientConnEmbedding()(*balancerWrapper) resolverErrorLocked(err error) updateClientConnStateLocked delivers the ClientConnState to the child
balancer. Callers must hold the child mutex of the parent endpointsharding
balancer.
*balancerWrapper : ExitIdler
*balancerWrapper : google.golang.org/grpc/balancer.ClientConn
*balancerWrapper : google.golang.org/grpc/balancer.ExitIdler
balancerWrapper : google.golang.org/grpc/internal.EnforceClientConnEmbedding
endpointSharding is a balancer that wraps child balancers. It creates a child
balancer with child config for every unique Endpoint received. It updates the
child states on any update from parent or child.bOptsbalancer.BuildOptionsccbalancer.ClientConnchildBuilderChildBuilderFunc childMu synchronizes calls to any single child. It must be held for all
calls into a child. To avoid deadlocks, do not acquire childMu while
holding mu.childrenatomic.Pointer[resolver.EndpointMap[*balancerWrapper]]esOptsOptions inhibitChildUpdates is set during UpdateClientConnState/ResolverError
calls (calls to children will each produce an update, only want one
update). mu synchronizes access to the state stored in balancerWrappers in the
children field. mu must not be held during calls into a child since
synchronous calls back from the child may require taking mu, causing a
deadlock. To avoid deadlocks, do not acquire childMu while holding mu.(*endpointSharding) Close()(*endpointSharding) ExitIdle() ResolverError forwards the resolver error to all of the endpointSharding's
children and sends a single synchronous update of the childStates at the end
of the ResolverError operation. UpdateClientConnState creates a child for new endpoints and deletes children
for endpoints that are no longer present. It also updates all the children,
and sends a single synchronous update of the childrens' aggregated state at
the end of the UpdateClientConnState operation. If any endpoint has no
addresses it will ignore that endpoint. Otherwise, returns first error found
from a child, but fully processes the new update.(*endpointSharding) UpdateSubConnState(balancer.SubConn, balancer.SubConnState) updateState updates this component's state. It sends the aggregated state,
and a picker with round robin behavior with all the child states present if
needed.
*endpointSharding : ExitIdler
*endpointSharding : google.golang.org/grpc/balancer.Balancer
*endpointSharding : google.golang.org/grpc/balancer.ExitIdler
Package-Level Functions (total 3, in which 2 are exported)
ChildStatesFromPicker returns the state of all the children managed by the
endpoint sharding balancer that created this picker.
NewBalancer returns a load balancing policy that manages homogeneous child
policies each owning a single endpoint. The endpointsharding balancer
forwards the LoadBalancingConfig in ClientConn state updates to its children.
rotateEndpoints returns a slice of all the input endpoints rotated a random
amount.
Package-Level Variables (only one, which is unexported)