Documentation
¶
Overview ¶
Package election provides a unified manager for cluster and shard leader elections, abstracting the s3lect library and serving both election health endpoints from a single HTTPS server.
Index ¶
- type ElectionConfig
- type ElectorFactory
- type HealthServerConfig
- type Manager
- func (m *Manager) EnableClusterPeerMode(caCert []byte) error
- func (m *Manager) IsClusterLeader() bool
- func (m *Manager) IsShardLeader() bool
- func (m *Manager) StartClusterElection(ctx context.Context, cfg ElectionConfig) error
- func (m *Manager) StartHealthServer(ctx context.Context, cfg HealthServerConfig) error
- func (m *Manager) StartShardElection(ctx context.Context, cfg ElectionConfig) error
- func (m *Manager) Stop(ctx context.Context) error
- func (m *Manager) WaitForClusterElection(ctx context.Context) error
- type ManagerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ElectionConfig ¶
type ElectionConfig struct {
// Storage is the s3lect-compatible storage for leader election state
Storage storage.Storage
// PeerMode enables peer verification of leadership
PeerMode bool
// CACert is the CA certificate for peer verification (nil if peer mode disabled)
CACert []byte
// FrequentInterval is how often to check leadership when actively participating
FrequentInterval time.Duration
// InfrequentInterval is how often to check leadership when idle
InfrequentInterval time.Duration
// LeaderTimeout is how long before a leader is considered dead
LeaderTimeout time.Duration
// OnAcquire is called after successfully acquiring leadership
OnAcquire func(ctx context.Context) error
// OnLose is called after losing leadership
OnLose func(ctx context.Context) error
}
ElectionConfig contains configuration for starting an individual election.
type ElectorFactory ¶
type ElectorFactory func(opts s3lect.S3ElectorOptions) (s3lect.Elector, error)
ElectorFactory creates s3lect electors. Used for testing.
type HealthServerConfig ¶
type HealthServerConfig struct {
// BindAddr is the address to listen on (e.g. ":8443")
BindAddr string
// TLSCert is the TLS certificate for the HTTPS server
TLSCert tls.Certificate
}
HealthServerConfig contains configuration for the election health server.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages both cluster and shard leader elections.
func NewManager ¶
func NewManager(cfg ManagerConfig) *Manager
NewManager creates a new election manager.
func (*Manager) EnableClusterPeerMode ¶
EnableClusterPeerMode enables peer mode on the cluster elector with the given CA certificate.
func (*Manager) IsClusterLeader ¶
IsClusterLeader returns true if this server is the current cluster leader.
func (*Manager) IsShardLeader ¶
IsShardLeader returns true if this server is the current shard leader.
func (*Manager) StartClusterElection ¶
func (m *Manager) StartClusterElection(ctx context.Context, cfg ElectionConfig) error
StartClusterElection creates and starts the cluster leader election.
func (*Manager) StartHealthServer ¶
func (m *Manager) StartHealthServer(ctx context.Context, cfg HealthServerConfig) error
StartHealthServer creates and starts the election health HTTPS server. It registers handlers for /health/leadership/cluster and /health/leadership/shard. Unstarted electors will return 404 until their election is started.
func (*Manager) StartShardElection ¶
func (m *Manager) StartShardElection(ctx context.Context, cfg ElectionConfig) error
StartShardElection creates and starts the shard leader election.
type ManagerConfig ¶
type ManagerConfig struct {
// ClusterID is the cluster identifier
ClusterID string
// ShardID is the shard identifier (e.g. zone shard ID)
ShardID string
// ServerID is this server's unique identifier
ServerID string
// ServerAddr is the address other servers use for peer verification
ServerAddr string
// Logger for election events
Logger *slog.Logger
}
ManagerConfig contains configuration for the election manager.