lifecycle

package
v0.107.0-nightly Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMaintenanceTTL = 15 * time.Minute

MaxMaintenanceTTL is the maximum duration a node can remain in maintenance mode. The leader's health monitor enforces this limit — nodes that exceed it are treated as unreachable so they can't hide in maintenance forever.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages a node's lifecycle state machine. It has no external dependencies (no LibP2P, no discovery imports) and is fully testable in isolation.

func NewManager

func NewManager() *Manager

NewManager creates a new lifecycle manager in the joining state.

func (*Manager) EnterMaintenance

func (m *Manager) EnterMaintenance(ttl time.Duration) error

EnterMaintenance transitions to maintenance with a TTL. The TTL is capped at MaxMaintenanceTTL.

func (*Manager) IsAvailable

func (m *Manager) IsAvailable() bool

IsAvailable returns true if the node is in a state that can serve requests.

func (*Manager) IsInMaintenance

func (m *Manager) IsInMaintenance() bool

IsInMaintenance returns true if the node is in maintenance mode.

func (*Manager) IsMaintenanceExpired

func (m *Manager) IsMaintenanceExpired() bool

IsMaintenanceExpired returns true if the node is in maintenance and the TTL has expired. Used by the leader's health monitor to enforce the max TTL.

func (*Manager) MaintenanceTTL

func (m *Manager) MaintenanceTTL() time.Time

MaintenanceTTL returns the maintenance mode expiration time. Returns zero value if not in maintenance.

func (*Manager) OnStateChange

func (m *Manager) OnStateChange(cb StateChangeCallback)

OnStateChange registers a callback invoked on state transitions. Callbacks are called with the lock released to avoid deadlocks.

func (*Manager) Snapshot

func (m *Manager) Snapshot() (state State, ttl time.Time)

Snapshot returns a point-in-time copy of the lifecycle state for embedding in metadata without holding the lock.

func (*Manager) State

func (m *Manager) State() State

State returns the current lifecycle state.

func (*Manager) StateEnteredAt

func (m *Manager) StateEnteredAt() time.Time

StateEnteredAt returns when the current state was entered.

func (*Manager) TransitionTo

func (m *Manager) TransitionTo(newState State) error

TransitionTo moves the node to a new lifecycle state. Returns an error if the transition is not valid.

type State

type State string

State represents a node's lifecycle state.

const (
	StateJoining     State = "joining"
	StateActive      State = "active"
	StateDraining    State = "draining"
	StateMaintenance State = "maintenance"
)

type StateChangeCallback

type StateChangeCallback func(old, new State)

StateChangeCallback is called when the lifecycle state changes.

Jump to

Keyboard shortcuts

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