grpc: google.golang.org/grpc/xds/internal/balancer/balancergroup Index | Files

package balancergroup

import "google.golang.org/grpc/xds/internal/balancer/balancergroup"

Package balancergroup implements a utility struct to bind multiple balancers into one balancer.

Index

Package Files

balancergroup.go

Variables

var DefaultSubBalancerCloseTimeout = 15 * time.Minute

DefaultSubBalancerCloseTimeout is defined as a variable instead of const for testing.

TODO: make it a parameter for New().

var NewRandomWRR = wrr.NewRandom

NewRandomWRR is the WRR constructor used to pick sub-pickers from sub-balancers. It's to be modified in tests.

type BalancerGroup Uses

type BalancerGroup struct {
    // contains filtered or unexported fields
}

BalancerGroup takes a list of balancers, and make them into one balancer.

Note that this struct doesn't implement balancer.Balancer, because it's not intended to be used directly as a balancer. It's expected to be used as a sub-balancer manager by a high level balancer.

Updates from ClientConn are forwarded to sub-balancers

- service config update
   - Not implemented
- address update
- subConn state change
   - find the corresponding balancer and forward

Actions from sub-balances are forwarded to parent ClientConn

- new/remove SubConn
- picker update and health states change
   - sub-pickers are grouped into a group-picker
   - aggregated connectivity state is the overall state of all pickers.
- resolveNow

Sub-balancers are only built when the balancer group is started. If the balancer group is closed, the sub-balancers are also closed. And it's guaranteed that no updates will be sent to parent ClientConn from a closed balancer group.

func New Uses

func New(cc balancer.ClientConn, loadStore lrs.Store, logger *grpclog.PrefixLogger) *BalancerGroup

New creates a new BalancerGroup. Note that the BalancerGroup needs to be started to work.

func (*BalancerGroup) Add Uses

func (bg *BalancerGroup) Add(id internal.LocalityID, weight uint32, builder balancer.Builder)

Add adds a balancer built by builder to the group, with given id and weight.

weight should never be zero.

func (*BalancerGroup) ChangeWeight Uses

func (bg *BalancerGroup) ChangeWeight(id internal.LocalityID, newWeight uint32)

ChangeWeight changes the weight of the balancer.

newWeight should never be zero.

NOTE: It always results in a picker update now. This probably isn't necessary. But it seems better to do the update because it's a change in the picker (which is balancer's snapshot).

func (*BalancerGroup) Close Uses

func (bg *BalancerGroup) Close()

Close closes the balancer. It stops sub-balancers, and removes the subconns. The BalancerGroup can be restarted later.

func (*BalancerGroup) Remove Uses

func (bg *BalancerGroup) Remove(id internal.LocalityID)

Remove removes the balancer with id from the group.

But doesn't close the balancer. The balancer is kept in a cache, and will be closed after timeout. Cleanup work (closing sub-balancer and removing subconns) will be done after timeout.

It also removes the picker generated from this balancer from the picker group. It always results in a picker update.

func (*BalancerGroup) ResolverError Uses

func (bg *BalancerGroup) ResolverError(err error)

ResolverError forwards resolver errors to all sub-balancers.

func (*BalancerGroup) Start Uses

func (bg *BalancerGroup) Start()

Start starts the balancer group, including building all the sub-balancers, and send the existing addresses to them.

A BalancerGroup can be closed and started later. When a BalancerGroup is closed, it can still receive address updates, which will be applied when restarted.

func (*BalancerGroup) UpdateClientConnState Uses

func (bg *BalancerGroup) UpdateClientConnState(id internal.LocalityID, s balancer.ClientConnState) error

UpdateClientConnState handles ClientState (including balancer config and addresses) from resolver. It finds the balancer and forwards the update.

func (*BalancerGroup) UpdateSubConnState Uses

func (bg *BalancerGroup) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState)

UpdateSubConnState handles the state for the subconn. It finds the corresponding balancer and forwards the update.

Package balancergroup imports 13 packages (graph) and is imported by 2 packages. Updated 2020-05-27. Refresh now. Tools for package owners.