leader

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBalanceElectors

func NewBalanceElectors(
	partitionID PartitionID,
	elector Elector,
	nodeAgent *cluster.NodeAgent,
	delayDuration time.Duration) (Elector, ElectionFactory)

Types

type ConstElectionFactory

type ConstElectionFactory struct {
	ConstID string
}

func (*ConstElectionFactory) NewElection

func (factory *ConstElectionFactory) NewElection(ctx context.Context, sequence int64) (Election, error)

type Election

type Election struct {
	Sequence int64
	ElectID  string
}

type ElectionFactory

type ElectionFactory interface {
	NewElection(ctx context.Context, sequence int64) (Election, error)
}

type ElectionFactoryFunc added in v0.3.0

type ElectionFactoryFunc func(ctx context.Context, sequence int64) (Election, error)

func (ElectionFactoryFunc) NewElection added in v0.3.0

func (fun ElectionFactoryFunc) NewElection(ctx context.Context, sequence int64) (Election, error)

type Elector

type Elector interface {
	PostElection(ctx context.Context, election Election) error
	KeepLive(ctx context.Context, keepLive KeepLive) error
	WaitElectionNotify(ctx context.Context) (Election, error)
}

type KeepLive

type KeepLive struct {
	Sequence int64
	ElectID  string
}

type Leaders

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

func NewLeaders

func NewLeaders(partitions ...*Partition) *Leaders

func (*Leaders) AllPartitions

func (pl *Leaders) AllPartitions() []PartitionID

func (*Leaders) GetPartitionMember

func (pl *Leaders) GetPartitionMember(ctx context.Context, id PartitionID) *Member

func (*Leaders) SyncLeader

func (pl *Leaders) SyncLeader(ctx context.Context, executor PartitionExecutor)

type Member

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

func NewMember

func NewMember(elector Elector, electFactory ElectionFactory, option Option) *Member

func (*Member) CloseWithContext

func (mb *Member) CloseWithContext(ctx context.Context) error

func (*Member) DoAsLeader

func (mb *Member) DoAsLeader(ctx context.Context, do func(ctx context.Context)) bool

func (*Member) GetInfo added in v0.3.0

func (mb *Member) GetInfo() MemberInfo

func (*Member) Start added in v0.3.0

func (mb *Member) Start() bool

func (*Member) StartElect

func (mb *Member) StartElect(ctx context.Context) error

func (*Member) SyncLeader added in v0.3.0

func (mb *Member) SyncLeader(ctx context.Context, do func(ctx context.Context))

block and run do until leader, return if not leader

func (*Member) ToFollower

func (mb *Member) ToFollower(ctx context.Context) error

type MemberInfo

type MemberInfo struct {
	LeaderID   string
	ElectionID string
	Sequence   int64
}

func (MemberInfo) IsLeader

func (info MemberInfo) IsLeader() bool

type MemoDecider

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

func NewMemoDecider

func NewMemoDecider() *MemoDecider

func (*MemoDecider) CreateElector

func (decider *MemoDecider) CreateElector() *MemoElector

type MemoElector added in v0.3.0

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

func (*MemoElector) KeepLive added in v0.3.0

func (elector *MemoElector) KeepLive(ctx context.Context, keepLive KeepLive) error

func (*MemoElector) PostElection added in v0.3.0

func (elector *MemoElector) PostElection(ctx context.Context, election Election) error

func (*MemoElector) WaitElectionNotify added in v0.3.0

func (elector *MemoElector) WaitElectionNotify(ctx context.Context) (Election, error)

type Middle

type Middle interface {
	WrapElector(elector Elector) Elector
}

func NewRecorderMiddle

func NewRecorderMiddle(factory record.Factory) Middle

type Option

type Option struct {
	MaxElectDuration    time.Duration
	MinElectDuration    time.Duration
	MaxKeepLiveDuration time.Duration
	MinKeepLiveDuration time.Duration
	MaxExecDuration     time.Duration
	MinExecDuration     time.Duration
}

type Partition

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

func NewPartition

func NewPartition(id PartitionID, member *Member, vars map[string]string) *Partition

func (*Partition) GetValue

func (part *Partition) GetValue(key string) string

func (*Partition) ID

func (part *Partition) ID() PartitionID

type PartitionExecutor

type PartitionExecutor func(ctx context.Context, partition *Partition)

type PartitionID added in v0.3.0

type PartitionID int64

type PartitionScheduleTrigger

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

func (*PartitionScheduleTrigger) WaitSchedulerTrigger

func (scheduler *PartitionScheduleTrigger) WaitSchedulerTrigger(ctx context.Context) ([]cluster.NodeSchedule, error)

type PartitionScheduler

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

func NewPartitionScheduler

func NewPartitionScheduler(partitions []PartitionID, maxKeepLiveDuration time.Duration) *PartitionScheduler

func (*PartitionScheduler) StartSchedule

func (factory *PartitionScheduler) StartSchedule(ctx context.Context, observer *cluster.NodeObserver) (cluster.ScheduleTrigger, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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