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.MultiChildLoadBalancerALoadBalancerthat 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 Classes Modifier and Type Class Description private static classRingHashLoadBalancer.RingEntry(package private) static classRingHashLoadBalancer.RingHashConfigConfigures the ring property.private static classRingHashLoadBalancer.RingHashPickerprivate static classRingHashLoadBalancer.SubchannelViewAn 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.Endpoint
-
Nested 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
Fields Modifier and Type Field Description private static XxHash64hashFuncprivate io.grpc.LoadBalancer.FactorylazyLbFactoryprivate XdsLoggerloggerprivate java.util.List<RingHashLoadBalancer.RingEntry>ringprivate static io.grpc.StatusRPC_HASH_NOT_FOUNDprivate io.grpc.SynchronizationContextsyncContext
-
Constructor Summary
Constructors Constructor Description RingHashLoadBalancer(io.grpc.LoadBalancer.Helper helper)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description io.grpc.StatusacceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)private static java.util.List<RingHashLoadBalancer.RingEntry>buildRing(java.util.Map<io.grpc.EquivalentAddressGroup,java.lang.Long> serverWeights, long totalWeight, double scale)protected io.grpc.util.MultiChildLoadBalancer.ChildLbStatecreateChildLbState(java.lang.Object key)static io.grpc.EquivalentAddressGroupstripAttrs(io.grpc.EquivalentAddressGroup eag)protected voidupdateOverallBalancingState()Updates the overall balancing state by aggregating the connectivity states of all subchannels.private io.grpc.StatusvalidateAddrList(java.util.List<io.grpc.EquivalentAddressGroup> addrList)private java.lang.StringvalidateNoDuplicateAddresses(java.util.List<io.grpc.EquivalentAddressGroup> addrList)-
Methods inherited from class io.grpc.util.MultiChildLoadBalancer
acceptResolvedAddressesInternal, aggregateState, createChildAddressesMap, getChildLbState, getChildLbStateEag, getChildLbStates, getHelper, getReadyChildren, handleNameResolutionError, shutdown, shutdownRemoved
-
-
-
-
Field Detail
-
RPC_HASH_NOT_FOUND
private static final io.grpc.Status RPC_HASH_NOT_FOUND
-
hashFunc
private static final XxHash64 hashFunc
-
lazyLbFactory
private final io.grpc.LoadBalancer.Factory lazyLbFactory
-
logger
private final XdsLogger logger
-
syncContext
private final io.grpc.SynchronizationContext syncContext
-
ring
private java.util.List<RingHashLoadBalancer.RingEntry> ring
-
-
Method Detail
-
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
protected io.grpc.util.MultiChildLoadBalancer.ChildLbState createChildLbState(java.lang.Object key)
- Overrides:
createChildLbStatein classio.grpc.util.MultiChildLoadBalancer
-
validateAddrList
private io.grpc.Status validateAddrList(java.util.List<io.grpc.EquivalentAddressGroup> addrList)
-
validateNoDuplicateAddresses
@Nullable private java.lang.String validateNoDuplicateAddresses(java.util.List<io.grpc.EquivalentAddressGroup> addrList)
-
buildRing
private static java.util.List<RingHashLoadBalancer.RingEntry> buildRing(java.util.Map<io.grpc.EquivalentAddressGroup,java.lang.Long> serverWeights, long totalWeight, double scale)
-
stripAttrs
public static io.grpc.EquivalentAddressGroup stripAttrs(io.grpc.EquivalentAddressGroup eag)
-
-