Documentation
¶
Overview ¶
Package hash provides a consistent hashing function with bounded loads. For more information about the underlying algorithm, please take a look at https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html
We optimized and simplify this hash algorithm [implementation](https://github.com/buraksezer/consistent/issues/13)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInsufficientMemberCount represents an error which means there are not enough members to complete the task. ErrInsufficientMemberCount = errors.New("insufficient member count") // ErrMemberNotFound represents an error which means requested member could not be found in consistent hash ring. ErrMemberNotFound = errors.New("member could not be found in ring") // ErrHasherNotProvided will be thrown if the hasher is not provided. ErrHasherNotProvided = errors.New("hasher is required") // ErrInvalidReplication will be thrown if the replication factor is zero or negative. ErrInvalidReplicationFactor = errors.New("positive replication factor is required") // ErrInvalidNumPartitions will be thrown if the number of partitions is negative. ErrInvalidNumPartitions = errors.New("invalid number of the partitions") // ErrEmptyMembers will be thrown if no member is provided. ErrEmptyMembers = errors.New("at least one member is required") )
TODO: Modify these error definitions to coderr.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Hasher is responsible for generating unsigned, 64 bit hash of provided byte slice. Hasher Hasher // Keys are distributed among partitions. Prime numbers are good to // distribute keys uniformly. Select a big PartitionCount if you have // too many keys. ReplicationFactor int // The rule describes the partition affinity. PartitionAffinities []PartitionAffinity }
Config represents a structure to control consistent package.
type ConsistentUniformHash ¶
type ConsistentUniformHash struct {
// contains filtered or unexported fields
}
ConsistentUniformHash generates a uniform distribution of partitions over the members, and this distribution will keep as consistent as possible while the members has some tiny changes.
func BuildConsistentUniformHash ¶
func BuildConsistentUniformHash(numPartitions int, members []Member, config Config) (*ConsistentUniformHash, error)
BuildConsistentUniformHash creates and returns a new hash which is ensured to be uniform and as consistent as possible.
func (*ConsistentUniformHash) GetPartitionOwner ¶
func (c *ConsistentUniformHash) GetPartitionOwner(partID int) Member
GetPartitionOwner returns the owner of the given partition.
func (*ConsistentUniformHash) LoadDistribution ¶
func (c *ConsistentUniformHash) LoadDistribution() map[string]uint
LoadDistribution exposes load distribution of members.
func (*ConsistentUniformHash) MaxLoad ¶
func (c *ConsistentUniformHash) MaxLoad() uint
func (*ConsistentUniformHash) MinLoad ¶
func (c *ConsistentUniformHash) MinLoad() uint
type Member ¶
type Member interface {
String() string
}
Member interface represents a member in consistent hash ring.