ha

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlLoop

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

Helps adapt systems that provide asynchronous notifications of leadership changes (*cough* *cough* Kubernetes *cough*) into mutually exclusive leader/follower states.

func StartControlLoop

func StartControlLoop(ctx context.Context, m Member) (*ControlLoop, context.Context)

func (*ControlLoop) BecomeFollower

func (l *ControlLoop) BecomeFollower(leader string)

func (*ControlLoop) BecomeLeader

func (l *ControlLoop) BecomeLeader(isLeaseAcceptable func(expiredToleration time.Duration) error)

func (*ControlLoop) StopAndWait

func (l *ControlLoop) StopAndWait() error

type Coordinator

type Coordinator interface {
	Run(ctx context.Context, m Member) error
}

type Follower

type Follower interface {
	// Runs when the member is a follower of another member. The context is
	// cancelled if this node is notified a member on another node (possibly
	// this node) has become the leader. Returning nil or context.Canceled is
	// a signal to a Coordinator that the followship was successful. Returning
	// another value of error won't necessarily do anything, but may cause a
	// calling Coordinator to try and become the leader.
	Follow(ctx context.Context, leader string) error
}

type FollowerFunc

type FollowerFunc func(ctx context.Context, leader string) error

func (FollowerFunc) Follow

func (m FollowerFunc) Follow(ctx context.Context, leader string) error

type Leader

type Leader interface {
	// Runs when the member becomes the leader. The context is cancelled if
	// this node is notified a member on another node has become the leader.
	// Returning nil or context.Canceled should signal to a Coordinator that the
	// leadership was successful and the leader is stepping down cleanly.
	// Returning another value of error indicates some sort of failure and the
	// leader must step down.
	Lead(ctx context.Context, isLeaseAcceptable func(expiredToleration time.Duration) error) error
}

type LeaderFollower

type LeaderFollower struct {
	Leader
	Follower
}

type LeaderFunc

type LeaderFunc func(ctx context.Context, isLeaseAcceptable func(expiredToleration time.Duration) error) error

func (LeaderFunc) Lead

func (m LeaderFunc) Lead(ctx context.Context, isLeaseAcceptable func(expiredToleration time.Duration) error) error

type Member

type Member interface {
	Leader
	Follower
}

type MemberGroup

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

func (*MemberGroup) Add

func (g *MemberGroup) Add(m Member)

func (*MemberGroup) Follow

func (g *MemberGroup) Follow(ctx context.Context, leader string) error

func (*MemberGroup) Lead

func (g *MemberGroup) Lead(
	ctx context.Context,
	isLeaseAcceptable func(expiredToleration time.Duration) error,
) error

type TrivialFollower

type TrivialFollower struct{}

func (TrivialFollower) Follow

func (TrivialFollower) Follow(ctx context.Context, _ string) error

type TrivialLeader

type TrivialLeader struct{}

func (TrivialLeader) Lead

func (TrivialLeader) Lead(ctx context.Context, _ func(_ time.Duration) error) error

Jump to

Keyboard shortcuts

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