Documentation ¶
Index ¶
- Constants
- Variables
- type ConsistentHashringBalancer
- func (b *ConsistentHashringBalancer) Close()
- func (b *ConsistentHashringBalancer) ResolverError(err error)
- func (b *ConsistentHashringBalancer) UpdateClientConnState(s balancer.ClientConnState) error
- func (b *ConsistentHashringBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState)
- type ConsistentHashringBalancerConfig
- type ConsistentHashringBuilder
Constants ¶
const ( // BalancerName is the name of consistent-hashring balancer. BalancerName = "consistent-hashring" // CtxKey is the key for the grpc request's context.Context which points to // the key to hash for the request. The value it points to must be []byte CtxKey ctxKey = "requestKey" )
Variables ¶
var DefaultBalancerServiceConfigJSON = defaultBalancerServiceConfig.MustToServiceConfigJSON()
DefaultBalancerServiceConfigJSON is a grpc Service Config JSON with the defaults for the ConsstentHashringBalancer configured.
Functions ¶
This section is empty.
Types ¶
type ConsistentHashringBalancer ¶ added in v1.22.0
type ConsistentHashringBalancer struct {
// contains filtered or unexported fields
}
ConsistentHashringBalancer implements balancer.Balancer and uses a consistent hashring to pick a backend for a request.
func (*ConsistentHashringBalancer) Close ¶ added in v1.22.0
func (b *ConsistentHashringBalancer) Close()
Close is a no-op because base balancer doesn't have internal state to clean up, and it doesn't need to call RemoveSubConn for the SubConns.
func (*ConsistentHashringBalancer) ResolverError ¶ added in v1.22.0
func (b *ConsistentHashringBalancer) ResolverError(err error)
ResolverError satisfies balancer.Balancer and is called when there is a an error in the resolver.
func (*ConsistentHashringBalancer) UpdateClientConnState ¶ added in v1.22.0
func (b *ConsistentHashringBalancer) UpdateClientConnState(s balancer.ClientConnState) error
UpdateClientConnState satisfies balancer.Balancer and is called when there are changes in the Address set or Service Config that the balancer may want to react to. In this case, the hashring is updated and a new picker using that hashring is generated.
func (*ConsistentHashringBalancer) UpdateSubConnState ¶ added in v1.22.0
func (b *ConsistentHashringBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState)
UpdateSubConnState satisfies balancer.Balancer and is called when there is a change in a subconnection state. Subconnection state can affect the overall state of the balancer. This also attempts to reconnect any idle connections.
type ConsistentHashringBalancerConfig ¶ added in v1.22.0
type ConsistentHashringBalancerConfig struct { serviceconfig.LoadBalancingConfig `json:"-"` ReplicationFactor uint16 `json:"replicationFactor,omitempty"` Spread uint8 `json:"spread,omitempty"` }
ConsistentHashringBalancerConfig supports common settings for the balancer. It should be converted to json with ToServiceConfigJSON or MustToServiceConfigJSON and passed to the grpc.WithDefaultServiceConfig option on grpc.Dial.
func (*ConsistentHashringBalancerConfig) MustToServiceConfigJSON ¶ added in v1.22.0
func (c *ConsistentHashringBalancerConfig) MustToServiceConfigJSON() string
MustToServiceConfigJSON calls ToServiceConfigJSON but panics if there is an error.
func (*ConsistentHashringBalancerConfig) ToServiceConfigJSON ¶ added in v1.22.0
func (c *ConsistentHashringBalancerConfig) ToServiceConfigJSON() (string, error)
ToServiceConfigJSON converts the config into the standard grpc Service Config json format.
type ConsistentHashringBuilder ¶ added in v1.22.0
ConsistentHashringBuilder stamps out new ConsistentHashringBalancer when requested by grpc.
func NewConsistentHashringBuilder ¶
func NewConsistentHashringBuilder(hasher consistent.HasherFunc) *ConsistentHashringBuilder
NewConsistentHashringBuilder creates a new balancer.Builder that will create a consistent hashring balancer. Before making a connection, register it with grpc with: `balancer.Register(consistent.NewConsistentHashringBuilder(hasher))`
func (*ConsistentHashringBuilder) Build ¶ added in v1.22.0
func (b *ConsistentHashringBuilder) Build(cc balancer.ClientConn, _ balancer.BuildOptions) balancer.Balancer
Build satisfies balancer.Builder and returns a new ConsistentHashringBalancer.
func (*ConsistentHashringBuilder) Name ¶ added in v1.22.0
func (b *ConsistentHashringBuilder) Name() string
Name satisfies balancer.Builder and returns the name of the balancer for use in Service Config files.
func (*ConsistentHashringBuilder) ParseConfig ¶ added in v1.22.0
func (b *ConsistentHashringBuilder) ParseConfig(js json.RawMessage) (serviceconfig.LoadBalancingConfig, error)
ParseConfig satisfies balancer.ConfigParser and is used to parse new Service Config json. The results are stored on the builder so that subsequently built Balancers use the config.