Package io.grpc.xds
Class RingHashLoadBalancer
java.lang.Object
io.grpc.LoadBalancer
io.grpc.util.MultiChildLoadBalancer
io.grpc.xds.RingHashLoadBalancer
final class RingHashLoadBalancer
extends io.grpc.util.MultiChildLoadBalancer
A
LoadBalancer that provides consistent hashing based load balancing to upstream hosts.
It implements the "Ketama" hashing that maps hosts onto a circle (the "ring") by hashing its
addresses. Each request is routed to a host by hashing some property of the request and finding
the nearest corresponding host clockwise around the ring. Each host is placed on the ring some
number of times proportional to its weight. With the ring partitioned appropriately, the
addition or removal of one host from a set of N hosts will affect only 1/N requests.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class(package private) static final classConfigures the ring property.private static final classprivate static final classAn unmodifiable view of a subchannel with state not subject to its real connectivity state changes.Nested classes/interfaces inherited from class io.grpc.util.MultiChildLoadBalancer
io.grpc.util.MultiChildLoadBalancer.AcceptResolvedAddrRetVal, io.grpc.util.MultiChildLoadBalancer.ChildLbState, io.grpc.util.MultiChildLoadBalancer.EndpointNested classes/interfaces inherited from class io.grpc.LoadBalancer
io.grpc.LoadBalancer.CreateSubchannelArgs, io.grpc.LoadBalancer.ErrorPicker, io.grpc.LoadBalancer.Factory, io.grpc.LoadBalancer.FixedResultPicker, io.grpc.LoadBalancer.Helper, io.grpc.LoadBalancer.PickDetailsConsumer, io.grpc.LoadBalancer.PickResult, io.grpc.LoadBalancer.PickSubchannelArgs, io.grpc.LoadBalancer.ResolvedAddresses, io.grpc.LoadBalancer.Subchannel, io.grpc.LoadBalancer.SubchannelPicker, io.grpc.LoadBalancer.SubchannelStateListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final XxHash64private final io.grpc.LoadBalancer.Factoryprivate final XdsLoggerprivate List<RingHashLoadBalancer.RingEntry> private static final io.grpc.Statusprivate final io.grpc.SynchronizationContextFields inherited from class io.grpc.util.MultiChildLoadBalancer
currentConnectivityState, pickFirstLbProvider, resolvingAddressesFields inherited from class io.grpc.LoadBalancer
ATTR_HEALTH_CHECKING_CONFIG, DISABLE_SUBCHANNEL_RECONNECT_KEY, EMPTY_PICKER, HAS_HEALTH_PRODUCER_LISTENER_KEY, HEALTH_CONSUMER_LISTENER_ARG_KEY, IS_PETIOLE_POLICY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.grpc.StatusacceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses) private static List<RingHashLoadBalancer.RingEntry> protected io.grpc.util.MultiChildLoadBalancer.ChildLbStatecreateChildLbState(Object key) static io.grpc.EquivalentAddressGroupstripAttrs(io.grpc.EquivalentAddressGroup eag) protected voidUpdates the overall balancing state by aggregating the connectivity states of all subchannels.private io.grpc.StatusvalidateAddrList(List<io.grpc.EquivalentAddressGroup> addrList) private StringvalidateNoDuplicateAddresses(List<io.grpc.EquivalentAddressGroup> addrList) Methods inherited from class io.grpc.util.MultiChildLoadBalancer
acceptResolvedAddressesInternal, aggregateState, createChildAddressesMap, getChildLbState, getChildLbStateEag, getChildLbStates, getHelper, getReadyChildren, handleNameResolutionError, shutdown, shutdownRemovedMethods inherited from class io.grpc.LoadBalancer
canHandleEmptyAddressListFromNameResolution, handleResolvedAddresses, handleSubchannelState, requestConnection
-
Field Details
-
RPC_HASH_NOT_FOUND
private static final io.grpc.Status RPC_HASH_NOT_FOUND -
hashFunc
-
lazyLbFactory
private final io.grpc.LoadBalancer.Factory lazyLbFactory -
logger
-
syncContext
private final io.grpc.SynchronizationContext syncContext -
ring
-
-
Constructor Details
-
RingHashLoadBalancer
RingHashLoadBalancer(io.grpc.LoadBalancer.Helper helper)
-
-
Method Details
-
acceptResolvedAddresses
public io.grpc.Status acceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses) - Overrides:
acceptResolvedAddressesin classio.grpc.util.MultiChildLoadBalancer
-
updateOverallBalancingState
protected void updateOverallBalancingState()Updates the overall balancing state by aggregating the connectivity states of all subchannels.Aggregation rules (in order of dominance):
- If there is at least one subchannel in READY state, overall state is READY
- If there are 2 or more subchannels in TRANSIENT_FAILURE, overall state is TRANSIENT_FAILURE (to allow timely failover to another policy)
- If there is at least one subchannel in CONNECTING state, overall state is CONNECTING
- If there is one subchannel in TRANSIENT_FAILURE state and there is more than one subchannel, report CONNECTING
- If there is at least one subchannel in IDLE state, overall state is IDLE
- Otherwise, overall state is TRANSIENT_FAILURE
- Specified by:
updateOverallBalancingStatein classio.grpc.util.MultiChildLoadBalancer
-
createChildLbState
- Overrides:
createChildLbStatein classio.grpc.util.MultiChildLoadBalancer
-
validateAddrList
-
validateNoDuplicateAddresses
-
buildRing
private static List<RingHashLoadBalancer.RingEntry> buildRing(Map<io.grpc.EquivalentAddressGroup, Long> serverWeights, long totalWeight, double scale) -
stripAttrs
public static io.grpc.EquivalentAddressGroup stripAttrs(io.grpc.EquivalentAddressGroup eag)
-