Implement locality/priority based load balancing #5610
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
This pull request attempts to implement the default EdfLoadBalancerBase which is the default load balancer used in envoy. Most load balancer implementations in envoy derive from this base class.
The basic load balancer supports locality weighted load balancing and priority levels.
Note that not all functionality (namely zone aware load balancing, etc..) have been implemented for simplicity.
Additionally, SubsetLoadBalancer has not been implemented in this PR for easier reviewing. The previous
SubsetLoadBalancer
will be replaced in the next (and final) pull request.This pull request mostly focuses on updating the
LoadBalancer
state when aClusterSnapshot
is updated.The flow is as follows:
ClusterEntry#accept
is called, which indicates aClusterSnapshot
has been updatedPrioritySet
contains a map ofInteger -> HostSet
where a HostSet contains host information for each health/locality.DefaultLbStateFactory
is created which creates aLbState
for theDefaultLoadBalancer
. ALbState
is a convenience object used to avoid potential race conditions. TheLbState
is replaced atomically from the perspective ofDefaultLoadBalancer
.envoy
source, each load balancer registers a callback which listens forHostSet
updates. Once aHostSet
is updated, the load balancer state is updated.HostSource
, and subsequently a host from the selectedHostSet
ref: #5450
Modifications:
ClusterEntry
now creates aPrioritySet
for eachClusterSnapshot
updatePrioritySet
, utility classesPriorityStateManager
,PriorityState
,HostSet
,UpdateHostsParam
have been created.EndpointUtil
,EndpointGroupUtil
have been createdDefaultLoadBalancer
has been introduced. The functionality of thisLoadBalancer
is equivalent toEdfLoadBalancer
.DefaultLbStateFactory
has been introduced to facilitate creating a state forDefaultLoadBalancer
. TheLbState
created byDefaultLbStateFactory
is intended to be updated atomically from the perspective ofDefaultLoadBalancer
.Result:
XdsEndpointGroup