ha

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ha implements the L3 reconcile loop (Patroni-style run_cycle). See docs/architecture.md.

Index

Constants

View Source
const DefaultReconcileInterval = 3 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type DesiredState

type DesiredState struct {
	IsCoordLeader bool
	DBRole        dbdriver.Role
	Primary       dbdriver.PrimaryRef
	Reason        string
}

DesiredState is the outcome of one reconcile iteration.

type Option

type Option func(*Reconciler)

Option configures a Reconciler.

func WithApplyPromote

func WithApplyPromote(enable bool) Option

WithApplyPromote enables ApplyPrimary from reconcile (off by default in v0.3).

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets the reconcile loop tick interval.

func WithMySQLPort

func WithMySQLPort(port int) Option

WithMySQLPort sets the local MySQL port used when deriving ApplyReplica targets from NeoHA endpoints.

func WithPrimaryHooks

func WithPrimaryHooks(hooks *PrimaryHooks) Option

WithPrimaryHooks attaches primary accessibility hooks (VIP, LB, …).

type PrimaryHooks

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

PrimaryHooks runs configured actions when this node starts/stops serving as the writable primary. Examples: bind VIP, notify load balancer, custom orchestration scripts.

func NewPrimaryHooks

func NewPrimaryHooks(log *nlog.Log, hooks config.PrimaryHooksConfig) *PrimaryHooks

NewPrimaryHooks builds a hook runner from config (commands may be "nop").

func (*PrimaryHooks) Active

func (h *PrimaryHooks) Active() bool

Active reports whether the start hook has been applied on this process.

func (*PrimaryHooks) EnsurePrimary

func (h *PrimaryHooks) EnsurePrimary(ctx context.Context) error

EnsurePrimary runs on_primary_start when the DB is writable and serving as primary.

func (*PrimaryHooks) EnsureReplica

func (h *PrimaryHooks) EnsureReplica(ctx context.Context) error

EnsureReplica runs on_primary_stop when the node should not expose primary accessibility.

func (*PrimaryHooks) RunStopIfConfigured

func (h *PrimaryHooks) RunStopIfConfigured(ctx context.Context) error

RunStopIfConfigured executes on_primary_stop once (startup cleanup on followers).

func (*PrimaryHooks) SetSkipPrimaryStartOnce

func (h *PrimaryHooks) SetSkipPrimaryStartOnce()

SetSkipPrimaryStartOnce skips the next OnPrimaryStart (e.g. neoha -r LEADER).

type Reconciler

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

Reconciler aligns coordination leadership with database role via the Driver.

func NewReconciler

func NewReconciler(log *nlog.Log, coord coordination.Coordinator, driver dbdriver.Driver, tags *config.TagsConfig, opts ...Option) *Reconciler

NewReconciler builds a reconciler.

func (*Reconciler) Loop

func (r *Reconciler) Loop(ctx context.Context)

Loop runs reconcile cycles until ctx is cancelled.

func (*Reconciler) RunOnce

func (r *Reconciler) RunOnce(ctx context.Context) error

RunOnce executes a single reconcile cycle.

Jump to

Keyboard shortcuts

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