failover

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package failover provides primary/standby resource groups with manual and health-based failover policy skeletons. Failback is always a separate workflow.

Index

Constants

View Source
const DefaultMaxHistory = 256

DefaultMaxHistory bounds decision history.

Variables

View Source
var (
	ErrNotFound     = errors.New("failover: group not found")
	ErrDuplicate    = errors.New("failover: duplicate group")
	ErrNoStandby    = errors.New("failover: no healthy standby")
	ErrInvalidState = errors.New("failover: invalid state")
	ErrManualOnly   = errors.New("failover: policy is manual")
)

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Group    string
	From     resource.ResourceID
	To       resource.ResourceID
	Reason   string
	At       time.Time
	EpochAdv resource.EpochAdvance
	Failback bool
}

Decision records a failover or failback.

type Group

type Group struct {
	Name     string
	Policy   Policy
	Primary  resource.ResourceID
	Standbys []resource.ResourceID
	Active   resource.ResourceID
	Epoch    resource.ResourceEpoch
}

Group is a primary/standby set.

type GroupConfig

type GroupConfig struct {
	Name     string
	Primary  resource.ResourceID
	Standbys []resource.ResourceID
	Policy   Policy
}

GroupConfig configures a failover group.

type Manager

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

Manager owns failover groups and advances resource epochs via a registry.

func NewManager

func NewManager(reg *resource.Registry) *Manager

NewManager creates a failover manager.

func (*Manager) EvaluateHealth

func (m *Manager) EvaluateHealth(ctx context.Context, name string) (resource.ResourceID, bool, error)

EvaluateHealth is a health-based policy skeleton: returns a recommended standby when the active resource is unhealthy. Does not execute failover.

func (*Manager) ExecuteFailback

func (m *Manager) ExecuteFailback(ctx context.Context, name, reason string) (Decision, error)

ExecuteFailback is a separate controlled workflow back toward the configured primary. It never runs automatically from health policy.

func (*Manager) ExecuteFailover

func (m *Manager) ExecuteFailover(ctx context.Context, name, reason string, target *resource.ResourceID) (Decision, error)

ExecuteFailover promotes a standby (manual or health-based). Advances the newly active resource epoch in the registry.

func (*Manager) Get

func (m *Manager) Get(name string) (Group, error)

Get returns a copy of the group.

func (*Manager) History

func (m *Manager) History() []Decision

History returns recent decisions (copy).

func (*Manager) List

func (m *Manager) List() []Group

List returns copies of all groups.

func (*Manager) Register

func (m *Manager) Register(cfg GroupConfig) error

Register adds a failover group.

type Policy

type Policy string

Policy selects how failover decisions are made.

const (
	PolicyManual      Policy = "manual"
	PolicyHealthBased Policy = "health-based"
)

Jump to

Keyboard shortcuts

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