-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
balancer/resolver: add loadBalancingConfig and pre-parsing support (#…
- Loading branch information
Showing
23 changed files
with
512 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ package balancer | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"net" | ||
"strings" | ||
|
@@ -31,6 +32,7 @@ import ( | |
"google.golang.org/grpc/internal" | ||
"google.golang.org/grpc/metadata" | ||
"google.golang.org/grpc/resolver" | ||
"google.golang.org/grpc/serviceconfig" | ||
) | ||
|
||
var ( | ||
|
@@ -39,7 +41,10 @@ var ( | |
) | ||
|
||
// Register registers the balancer builder to the balancer map. b.Name | ||
// (lowercased) will be used as the name registered with this builder. | ||
// (lowercased) will be used as the name registered with this builder. If the | ||
// Builder implements ConfigParser, ParseConfig will be called when new service | ||
// configs are received by the resolver, and the result will be provided to the | ||
// Balancer in UpdateClientConnState. | ||
// | ||
// NOTE: this function must only be called during initialization time (i.e. in | ||
// an init() function), and is not thread-safe. If multiple Balancers are | ||
|
@@ -172,6 +177,14 @@ type Builder interface { | |
Name() string | ||
} | ||
|
||
// ConfigParser parses load balancer configs. | ||
type ConfigParser interface { | ||
// ParseConfig parses the JSON load balancer config provided into an | ||
// internal form or returns an error if the config is invalid. For future | ||
// compatibility reasons, unknown fields in the config should be ignored. | ||
ParseConfig(LoadBalancingConfigJSON json.RawMessage) (serviceconfig.LoadBalancingConfig, error) | ||
} | ||
|
||
// PickOptions contains addition information for the Pick operation. | ||
type PickOptions struct { | ||
// FullMethodName is the method name that NewClientStream() is called | ||
|
@@ -270,7 +283,7 @@ type Balancer interface { | |
// non-nil error to gRPC. | ||
// | ||
// Deprecated: if V2Balancer is implemented by the Balancer, | ||
// UpdateResolverState will be called instead. | ||
// UpdateClientConnState will be called instead. | ||
HandleResolvedAddrs([]resolver.Address, error) | ||
// Close closes the balancer. The balancer is not required to call | ||
// ClientConn.RemoveSubConn for its existing SubConns. | ||
|
@@ -283,14 +296,23 @@ type SubConnState struct { | |
// TODO: add last connection error | ||
} | ||
|
||
// ClientConnState describes the state of a ClientConn relevant to the | ||
// balancer. | ||
type ClientConnState struct { | ||
ResolverState resolver.State | ||
// The parsed load balancing configuration returned by the builder's | ||
// ParseConfig method, if implemented. | ||
BalancerConfig serviceconfig.LoadBalancingConfig | ||
} | ||
|
||
// V2Balancer is defined for documentation purposes. If a Balancer also | ||
// implements V2Balancer, its UpdateResolverState method will be called instead | ||
// of HandleResolvedAddrs and its UpdateSubConnState will be called instead of | ||
// HandleSubConnStateChange. | ||
// implements V2Balancer, its UpdateClientConnState method will be called | ||
// instead of HandleResolvedAddrs and its UpdateSubConnState will be called | ||
// instead of HandleSubConnStateChange. | ||
type V2Balancer interface { | ||
// UpdateResolverState is called by gRPC when the state of the resolver | ||
// UpdateClientConnState is called by gRPC when the state of the ClientConn | ||
// changes. | ||
UpdateResolverState(resolver.State) | ||
UpdateClientConnState(ClientConnState) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dfawley
Author
Member
|
||
// UpdateSubConnState is called by gRPC when the state of a SubConn | ||
// changes. | ||
UpdateSubConnState(SubConn, SubConnState) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Can I ask why you changed the name of this public API function but didn't create a major release when doing so? This breaks dependent code when updating.