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 ¶
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 ¶
LeaderProvider abstracts election strategies.
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 ¶
NewLuxLeader returns a started LuxLeader. Returns an error if LocalTarget is missing.
func (*LuxLeader) HandleHeartbeat ¶
func (l *LuxLeader) HandleHeartbeat(w http.ResponseWriter, r *http.Request)
HandleHeartbeat is the HTTP handler for peer heartbeats.
func (*LuxLeader) IsLeader ¶
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 ¶
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