Documentation
¶
Overview ¶
Package balancer implements a gRPC Balancer backed by a consistent hashring for connection selection.
As new connections are established new virtual nodes (members) are added to the hashring. When a connection is not in a Ready state we remove the member from the hashring.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrTooFewMembers = errors.New("too few members in the hashring")
)
Functions ¶
func NewConsistentHashring ¶
func NewConsistentHashring( hasher Hasher, cfg ConsistentHashringConfig, members ...Member, ) *consistentHashring
NewConsistentHashring constructs a Hashring providing consistent hashing configured with the configurations provided.
If one or more members are provided these members are immediately added to the hashring.
Types ¶
type ConsistentHashringConfig ¶
type ConsistentHashringConfig struct {
// ReplicationFactor controls the distribution of virtual members on the hashring.
//
// A ReplicationFactor greater than 1 means that each member added to the hashring
// will be added in multiple positions on the hashring.
ReplicationFactor int
}
func DefaultConsistentHashringConfig ¶
func DefaultConsistentHashringConfig() ConsistentHashringConfig
type Hashring ¶
type Hashring interface {
// AddMember adds the provided member to the hashring.
AddMember(Member)
// RemoveMember removes the provided member from the hashring.
RemoveMember(Member)
// FindNearestN finds the nearest n members on the hashring for the
// provided key. If there are an insufficient number of members in the
// hashring an ErrTooFewMembers error is returned.
FindNearestN(key []byte, n int) ([]Member, error)
}
Hashring defines an interface for managing virtual members of a consistent hashring circle.
type Member ¶
type Member interface {
String() string
}
Member represents a virtual node or member of a hashring. The String implementation provides the key value for the virtual member.
type StringMember ¶
type StringMember string
func (StringMember) String ¶
func (s StringMember) String() string
type UInt64Item ¶
type UInt64Item uint64