ip

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACTIVATED = "ACTIVATED"
	STANDBY   = "STANDBY"
	FAILING   = "FAILING"
	BOOTING   = "BOOTING"
)
View Source
const (
	FaultEvent              = "fault"
	ElectedEvent            = "elected"
	DemotedEvent            = "demoted"
	HealthCheckFailEvent    = "health_check_fail"
	HealthCheckSuccessEvent = "health_check_success"
)

Variables

View Source
var (
	// ErrIsNotMaster is an error sent by Failover when the node is not currently master
	ErrIsNotMaster = errors.New("this node is not master of this endpoint")

	// ErrNoOtherHosts is an error sent by Failover when there is no other node to fail over.
	ErrNoOtherHosts = errors.New("no other nodes are listening for this endpoint")

	// ErrReallocationTimedOut is an error returned by waitForReallocation if the reallocation did not happen in less than KeepAliveInterval
	ErrReallocationTimedOut = errors.New("reallocation timed out")
)

Functions

func NewStateMachine

func NewStateMachine(_ context.Context, opts NewStateMachineOpts) *fsm.FSM

Types

type EndpointManager

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

func NewManager

func NewManager(ctx context.Context, cfg config.Config, endpoint models.Endpoint, client *etcdv3.Client, storage models.Storage, leaseManager locker.EtcdLeaseManager, plugin plugin.Plugin) (*EndpointManager, error)

func (*EndpointManager) ElectionKey

func (m *EndpointManager) ElectionKey(ctx context.Context) string

func (*EndpointManager) Endpoint

func (m *EndpointManager) Endpoint() models.Endpoint

Endpoint returns the endpoint model linked to this manager

func (*EndpointManager) Failover

func (m *EndpointManager) Failover(ctx context.Context) error

Failover forces a change of the master. It can only be run on the current master instance for an endpoint. If there is another node available for this endpoint, it steps down as a master and ensure that another node becomes master. This function refuses to trigger a failover if the node is not master or if there are no other nodes. To trigger the failover, we unlock the endpoint (remove the lock key) and update the link between the host and the endpoint. Updating the link notifies watchers on this endpoint and other hosts will try to get the endpoint.

func (*EndpointManager) SetHealthChecks

func (m *EndpointManager) SetHealthChecks(ctx context.Context, cfg config.Config, healthChecks []models.HealthCheck)

func (*EndpointManager) Start

func (m *EndpointManager) Start(ctx context.Context)

func (*EndpointManager) Status

func (m *EndpointManager) Status() string

Status returns the current state of the state machine

func (*EndpointManager) Stop

func (m *EndpointManager) Stop(ctx context.Context) error

type Manager

type Manager interface {
	Start(ctx context.Context)
	Stop(ctx context.Context) error
	Failover(ctx context.Context) error
	Status() string
	Endpoint() models.Endpoint
	ElectionKey(ctx context.Context) string
	SetHealthChecks(ctx context.Context, config config.Config, checks []models.HealthCheck)
}

type NewStateMachineOpts

type NewStateMachineOpts struct {
	ActivatedCallback func(ctx context.Context, e *fsm.Event)
	StandbyCallback   func(ctx context.Context, e *fsm.Event)
	FailingCallback   func(ctx context.Context, e *fsm.Event)
}

Jump to

Keyboard shortcuts

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