libra

package module
v0.0.0-...-94336eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinMultiplier = 1
	MaxMultiplier = 1 << 4 // max weight = 32
)

Variables

View Source
var (
	ErrNodeNotExist   = errors.New("node does not exist")
	ErrQuorumNotMet   = errors.New("quorum is not met")
	ErrUpdateLoadInCD = errors.New("updateLoad is in cooldown. try again later")
)
View Source
var (
	Port           = flag.Int("libra.port", 7946, "the port used for both UDP and TCP gossip")
	LoadMultiplier = flag.Int("libra.load_multiplier", 1, "load multiplier for current node")
	UpdateTimeout  = flag.Duration("libra.update_timeout", 10*time.Second, "timeout for update node")
)

Functions

func CalWeight

func CalWeight(mul int) int

func NewSugar

func NewSugar() *zap.SugaredLogger

Types

type Atlas

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

func (*Atlas) Free

func (a *Atlas) Free()

func (*Atlas) Get

func (a *Atlas) Get(id string) []string

func (*Atlas) GetStar

func (a *Atlas) GetStar(s *Star) []string

type Config

type Config struct {
	*memberlist.Config

	Seeds          []string
	LoadMultiplier int
}

type ConflictDelegate

type ConflictDelegate struct{}

type Consistent

type Consistent struct {
	Stars *Map

	sync.RWMutex
	// contains filtered or unexported fields
}

Consistent simple consistent hashing https://en.wikipedia.org/wiki/Consistent_hashing

func NewConsistent

func NewConsistent(nodes []*ml.Node) *Consistent

NewConsistent ...

func (*Consistent) Add

func (c *Consistent) Add(stars ...*Star)

func (*Consistent) Del

func (c *Consistent) Del(stars ...*Star)

func (*Consistent) Get

func (c *Consistent) Get(keys ...string) *Atlas

func (*Consistent) Len

func (c *Consistent) Len() int

func (*Consistent) Update

func (c *Consistent) Update(star *Star) error

type Delegate

type Delegate struct {
	*ml.Memberlist
}

func (*Delegate) GetBroadcasts

func (d *Delegate) GetBroadcasts(overhead, limit int) [][]byte

func (*Delegate) LocalState

func (d *Delegate) LocalState(join bool) []byte

func (*Delegate) MergeRemoteState

func (d *Delegate) MergeRemoteState(buf []byte, join bool)

func (*Delegate) NodeMeta

func (d *Delegate) NodeMeta(limit int) []byte

func (*Delegate) NotifyMsg

func (d *Delegate) NotifyMsg([]byte)

type EventDelegate

type EventDelegate struct {
	UpdateCh chan *ml.Node
}

func (*EventDelegate) NotifyJoin

func (ed *EventDelegate) NotifyJoin(n *ml.Node)

func (*EventDelegate) NotifyLeave

func (ed *EventDelegate) NotifyLeave(n *ml.Node)

func (*EventDelegate) NotifyUpdate

func (ed *EventDelegate) NotifyUpdate(n *ml.Node)

type Libra

type Libra struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Libra ...

func New

func New() (*Libra, error)

func (*Libra) Address

func (l *Libra) Address() string

func (*Libra) Get

func (l *Libra) Get(keys ...string) *Atlas

func (*Libra) Join

func (l *Libra) Join()

func (*Libra) Leave

func (l *Libra) Leave() error

func (*Libra) LocalID

func (l *Libra) LocalID() string

func (*Libra) Serve

func (l *Libra) Serve()

func (*Libra) Shutdown

func (l *Libra) Shutdown()

func (*Libra) UpdateWeight

func (l *Libra) UpdateWeight(mul int) error

type Map

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

Map simple string set based on map, not thread-safe

func NewMap

func NewMap(nodes []*ml.Node) *Map

func (*Map) Add

func (m *Map) Add(s *Star)

func (*Map) Collect

func (m *Map) Collect()

Collect cleans all items and put the set back to sync.Pool

func (*Map) Del

func (m *Map) Del(s *Star)

func (*Map) Diff

func (m *Map) Diff(o *Map) (add, del []*Star)

func (*Map) Get

func (m *Map) Get(name string) *Star

func (*Map) Has

func (m *Map) Has(name string) bool

func (*Map) HasStar

func (m *Map) HasStar(s *Star) bool

func (*Map) Len

func (m *Map) Len() int

func (*Map) ListName

func (m *Map) ListName() []string

func (*Map) ListStar

func (m *Map) ListStar() []*Star

type Poll

type Poll interface {
}

type Star

type Star struct {
	ID     string
	Weight int
}

Star node unit

func NodeToStar

func NodeToStar(nodes []*ml.Node) []*Star

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL