Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyPool is thrown when no availabel peer in pool.
	ErrEmptyPool = errors.New("empty pool")
	// ErrNegativeN is thrown when Shard.N is negative.
	ErrNegativeN = errors.New("negative n")
	// ErrUnexpected is thrown when a invalid code branch is reached and should never happen.
	ErrUnexpected = errors.New("unexpected error")
)

Functions

This section is empty.

Types

type HashFunc32

type HashFunc32 func(string) uint32

    HashFunc32 is the 32 bits hash function type

    type Hashring32

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

      Hashring32 will implement Choose, Add, Remove, Include, Exclude, Set, and Len.

      func New

      func New(hash HashFunc32, options ...Option) *Hashring32

        New creates a new Hashring32.

        func (*Hashring32) Add

        func (r *Hashring32) Add(member string) (new bool)

          Add adds a member into the hash ring and returns whether it is a new member.

          func (*Hashring32) Choose

          func (r *Hashring32) Choose(shard Shard) ([]string, error)

            Choose returns first (shard.N + 1) peers within the matched range of hashed shard.Key in the hash ring.

            func (*Hashring32) ChooseNth

            func (r *Hashring32) ChooseNth(shard Shard) (string, error)

              ChooseNth returns (shard.N + 1)th peer within the matched range of hashed shard.Key in the hash ring.

              func (*Hashring32) Exclude

              func (r *Hashring32) Exclude(group map[string]struct{})

                Exclude excludes a group of new members from the hash ring

                func (*Hashring32) Include

                func (r *Hashring32) Include(group map[string]struct{})

                  Include includes a group of new members into the hash ring

                  func (*Hashring32) Len

                  func (r *Hashring32) Len() int

                    Len returns number of members of the hash ring.

                    func (*Hashring32) Remove

                    func (r *Hashring32) Remove(member string) (found bool)

                      Remove removes a member from the hash ring and returns whether it was an existing member.

                      func (*Hashring32) Set

                      func (r *Hashring32) Set(group map[string]struct{})

                        Set clear the whole ring and replace with a group of new members.

                        type Option

                        type Option interface {
                        	// contains filtered or unexported methods
                        }

                          Option is an option for the hash ring constructor.

                          func NumPeersEstimate

                          func NumPeersEstimate(numPeersEstimate int) Option

                            NumPeersEstimate specifies an estimate for the number of identified peers the hashring will contain.

                            This figure and the number of replicas determines the initial capacity of the ring slice.

                            func NumReplicas

                            func NumReplicas(n int) Option

                              NumReplicas specifies the number of replicas to use for each peer.

                              More replicas produces a more even distribution of entities and slower membership updates.

                              Changing the replica number changes the topology of the ring. Do not change the replica number on a populated ring. Drain any stateful service before changing the number of replicas.

                              func ReplicaFormatter

                              func ReplicaFormatter(formatReplica ReplicaFormatterFunc) Option

                                ReplicaFormatter specifies the function the hash ring will use to construct replica names from a peer identifier and a replica number.

                                Replica names are hashed to find their positions within the hash ring.

                                The default replica formatter simply concatenates the peer identifier and the replica number as a decimal string.

                                type ReplicaFormatterFunc

                                type ReplicaFormatterFunc func(identifier string, replicaPoint int) string

                                  ReplicaFormatterFunc defines the format to stringify member identifier and replica point.

                                  func DelimitedReplicaFormatter

                                  func DelimitedReplicaFormatter(delimiter string) ReplicaFormatterFunc

                                    DelimitedReplicaFormatter joins a peer identifier and replica number with a given delimiter.

                                    type Shard

                                    type Shard struct {
                                    	Key string
                                    	N   int
                                    }

                                      Shard includes a shard key and a number indicating a rightward linear lookup in the ring.