ha

package
v0.40.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ha registers leader/follower HA for a Base app.

Import it for side-effect-free registration:

import _ "github.com/hanzoai/base/plugins/ha"

Then call Register from your main:

app := base.New()
ha.Register(app)
app.Start()

Config lives under the BASE_* env namespace. See the base-ha README for the full variable reference.

HA is a no-op unless at least one of BASE_LOCAL_TARGET, BASE_STATIC_LEADER, or BASE_PEERS is set. That way you can import this plugin unconditionally and enable clustering per-deployment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(app core.App)

Register wires HA into the given app.

Behavior depends on env:

  • BASE_STATIC_LEADER=http://... → all writes forward to that URL.
  • BASE_LOCAL_TARGET=http://... + BASE_PEERS=a,b → lightweight lux heartbeat-lease election; local node redirects to elected leader.
  • Neither set → plugin is inactive (standalone Base).

The full go-ha CDC pipeline (change-set capture over NATS-compatible JetStream) is provisioned by the base-ha binary at the SQL driver level. This plugin only handles the HTTP surface: leader-forwarding middleware and the /_ha/heartbeat endpoint.

Types

type LeaderProvider

type LeaderProvider interface {
	IsLeader() bool
	RedirectTarget() string
}

LeaderProvider abstracts election strategies.

type LuxConfig

type LuxConfig struct {
	NodeID            string
	LocalTarget       string
	Peers             []string
	HeartbeatInterval time.Duration
	LeaseTimeout      time.Duration
}

type LuxLeader

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

LuxLeader is a lightweight heartbeat-lease leader election.

Peers exchange signed heartbeats on an interval; the alive peer with the lowest-sorted NodeID is the leader for the current epoch. Much lighter than RAFT — no log, no snapshots, no state machine. O(peers) memory, O(1) per heartbeat.

func NewLuxLeader

func NewLuxLeader(cfg LuxConfig) (*LuxLeader, error)

NewLuxLeader returns a started LuxLeader. Returns an error if LocalTarget is missing.

func (*LuxLeader) Close

func (l *LuxLeader) Close()

Close stops the background loop.

func (*LuxLeader) HandleHeartbeat

func (l *LuxLeader) HandleHeartbeat(w http.ResponseWriter, r *http.Request)

HandleHeartbeat is the HTTP handler for peer heartbeats.

func (*LuxLeader) IsLeader

func (l *LuxLeader) IsLeader() bool

IsLeader reports whether this node is currently the minimum-ranked alive peer.

func (*LuxLeader) Ready

func (l *LuxLeader) Ready() <-chan struct{}

Ready returns a channel closed after the first election round.

func (*LuxLeader) RedirectTarget

func (l *LuxLeader) RedirectTarget() string

RedirectTarget returns the current leader's URL.

type StaticLeader

type StaticLeader struct{ Target string }

StaticLeader always routes writes to a fixed URL.

func (*StaticLeader) IsLeader

func (s *StaticLeader) IsLeader() bool

func (*StaticLeader) RedirectTarget

func (s *StaticLeader) RedirectTarget() string

Jump to

Keyboard shortcuts

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