Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// TTL is the time-to-live for the leader lock
TTL time.Duration
// RenewalInterval is how often to renew the leader lock
RenewalInterval time.Duration
// NodeID is the unique identifier for this node (for logging/metrics only)
// If empty, a random ID will be generated
NodeID string
}
Config holds configuration for leader election.
type Elector ¶
type Elector interface {
// Start begins the leader election process
Start(ctx context.Context) error
// Stop gracefully stops the leader election
Stop(ctx context.Context) error
// IsLeader returns true if this node is currently the leader
IsLeader() bool
// OnLeadershipChange registers a callback for guaranteed leadership notification.
// The callback is invoked synchronously when leadership status changes.
// Multiple callbacks can be registered and will be invoked in registration order.
//
// Important: Keep callbacks fast (< 100ms) to avoid delaying leadership renewal.
// For long-running operations, spawn a goroutine within the callback.
OnLeadershipChange(callback LeadershipCallback)
}
Elector defines the interface for leader election implementations.
type LeadershipCallback ¶ added in v0.1.5
LeadershipCallback is a function invoked when leadership status changes. The callback is invoked synchronously - implementations should return quickly (< 100ms) to avoid delaying leadership renewal. Long-running operations should be spawned in a separate goroutine.
type RedisElector ¶
type RedisElector struct {
// contains filtered or unexported fields
}
RedisElector implements leader election using Redis with redsync.
func NewRedisElector ¶
func NewRedisElector( client *redis.Client, log logrus.FieldLogger, keyName string, config *Config, ) (*RedisElector, error)
NewRedisElector creates a new Redis-based leader elector using redsync.
func (*RedisElector) IsLeader ¶
func (e *RedisElector) IsLeader() bool
IsLeader returns true if this node is currently the leader.
func (*RedisElector) OnLeadershipChange ¶ added in v0.1.5
func (e *RedisElector) OnLeadershipChange(callback LeadershipCallback)
OnLeadershipChange registers a callback for guaranteed leadership notification.