Versions in this module Expand all Collapse all v0 v0.5.0 Oct 20, 2026 Changes in this version + const DefaultLeaseDuration + const DefaultOperationTimeout + const DefaultRenewInterval + const DefaultRetryPeriod + const DefaultSafetyMarginFraction + const MinSafetyMargin + var ErrAlreadyRunning = errors.New("leaderelection: elector is already running") + var ErrLeaseExpiredLocally = errors.New("leaderelection: lease expired before it could be renewed") + var ErrLeaseLost = errors.New("leaderelection: lease lost") + var ErrNoLease = errors.New("leaderelection: no lease record") + func GenerateIdentity() (string, error) + type Callbacks struct + OnNewLeader func(identity string, fence int64) + OnStartedLeading func(ctx context.Context, fence int64) + OnStoppedLeading func() + type Config struct + Callbacks Callbacks + DisableRelease bool + Identity string + LeaseDuration time.Duration + Logger *slog.Logger + Name string + OperationTimeout time.Duration + Payload []byte + RenewInterval time.Duration + RetryPeriod time.Duration + SafetyMargin time.Duration + Store Store + func (c Config) Validate() error + type ConfigError struct + Field string + Reason string + func (e *ConfigError) Error() string + type Elector struct + func New(cfg Config) (*Elector, error) + func (e *Elector) Fence() (int64, bool) + func (e *Elector) IsLeader() bool + func (e *Elector) Metrics() Metrics + func (e *Elector) Run(ctx context.Context) error + func (e *Elector) Status() Status + type Lease struct + AcquiredAt time.Time + ExpiresAt time.Time + Fence int64 + Holder string + Name string + Now time.Time + Payload []byte + RenewedAt time.Time + func (l Lease) Expired() bool + func (l Lease) HeldBy(identity string) bool + func (l Lease) TTL() time.Duration + type Metrics struct + Election string + HasError bool + HasObservation bool + HasSuccessfulRenewal bool + IsLeader bool + LastSuccessfulRenewalAgeSeconds float64 + LeaderChangesObservedTotal uint64 + LeaderWorkActive bool + LeaderWorkCanceled bool + LeaseLossesTotal uint64 + LeaseRemainingSeconds float64 + LocalExpirationsTotal uint64 + ObservationAgeSeconds float64 + RenewalsAcceptedTotal uint64 + Running bool + Store StoreMetrics + TermsEndedTotal uint64 + TermsStartedTotal uint64 + type OperationMetrics struct + CallsTotal uint64 + CanceledTotal uint64 + DurationSecondsTotal float64 + ErrorsTotal uint64 + ExpectedOutcomesTotal uint64 + InFlight uint64 + LastDurationSeconds float64 + TimeoutsTotal uint64 + type Status struct + Fence int64 + Identity string + IsLeader bool + LastError error + Leader string + LeaderFence int64 + LeaderPayload []byte + ObservedAt time.Time + ValidUntil time.Time + type Store interface + Acquire func(ctx context.Context, name, identity string, ttl time.Duration, payload []byte) (Lease, error) + Inspect func(ctx context.Context, name string) (Lease, error) + Release func(ctx context.Context, name, identity string, fence int64) error + Renew func(ctx context.Context, name, identity string, fence int64, ttl time.Duration, ...) (Lease, error) + type StoreMetrics struct + Acquire OperationMetrics + Inspect OperationMetrics + Release OperationMetrics + Renew OperationMetrics