Documentation
¶
Index ¶
- Constants
- Variables
- type Callback
- type LeaderElection
- func (le *LeaderElection) Close()
- func (le *LeaderElection) GetState() State
- func (le *LeaderElection) Init(cfg LeaderElectionConfig)
- func (le *LeaderElection) IsBootstrap() bool
- func (le *LeaderElection) IsFollower() bool
- func (le *LeaderElection) IsLeader() bool
- func (le *LeaderElection) Run(ctx context.Context) error
- type LeaderElectionConfig
- type LeaderElector
- type State
Constants ¶
View Source
const (
DefaultRelinquishInterval time.Duration = 300 * time.Second
)
Variables ¶
View Source
var (
ErrInvalidState = errors.New("invalid election state")
)
Functions ¶
This section is empty.
Types ¶
type LeaderElection ¶
type LeaderElection struct {
Elector LeaderElector
LeaderElectionConfig
// contains filtered or unexported fields
}
func (*LeaderElection) Close ¶ added in v0.1.6
func (le *LeaderElection) Close()
Stop leader election
func (*LeaderElection) GetState ¶ added in v0.1.5
func (le *LeaderElection) GetState() State
Return current state
func (*LeaderElection) Init ¶ added in v0.1.5
func (le *LeaderElection) Init(cfg LeaderElectionConfig)
Initializes leader election
func (*LeaderElection) IsBootstrap ¶ added in v0.1.5
func (le *LeaderElection) IsBootstrap() bool
Returns true if current state is Bootstrap
func (*LeaderElection) IsFollower ¶ added in v0.1.5
func (le *LeaderElection) IsFollower() bool
Returns true if current state is Follower
func (*LeaderElection) IsLeader ¶ added in v0.1.5
func (le *LeaderElection) IsLeader() bool
Returns true if current state is Leader
type LeaderElectionConfig ¶
type LeaderElectionConfig struct {
// Lock identifier
LockId uint
// Duration after which the leader will relinquish
RelinquishInterval time.Duration
// Relinquish as a cron spec. If spec is provided,
// RelinquishInterval will be ignored.
RelinquishIntervalSpec string
// How often will leader check to make sure they are still the leader
// It is important the LeaderCheckInterval is set to a value that is
// lesser than RelinquishInterval or what RelinquishIntervalSpec evaluates to.
// It is also important that LeaderCheckInterval is a factor of RelinquishInterval
// or what RelinquishIntervalSpec evaluates to.
// Failure to comply with above two points will result in delayed relinquish action
// by the leader.
LeaderCheckInterval time.Duration
// How often a follower will check to see if they can take over as a leader
FollowerCheckInterval time.Duration
// Callback once leadership has been acquired or staying on as a leader
LeaderCallback Callback
// Callback once switch to a follower or staying on as a follower
FollowerCallback Callback
}
type LeaderElector ¶ added in v0.1.5
type LeaderElector interface {
// Called by a follower or bootstrap to acquire leadership. A leader calling this will be a no-op
// bool return value must be true if leadership acquisition was successful and false otherwise.
AcquireLeadership(context.Context) (bool, error)
// Called by the leader to make sure they are still the leader. Will return an error if not leader.
// bool return value must be true if we are still the leader and false otherwise.
CheckLeadership(context.Context) (bool, error)
// Called by the leader to relinquish leadership. Will return an error if not leader.
// bool return value must be true if relinquish attempt was successful and false otherwise.
RelinquishLeadership(context.Context) (bool, error)
// Run the election. Will run until passed context is canceled or times out or deadline exceeds
Run(context.Context) error
// Close the election
Close()
}
Click to show internal directories.
Click to hide internal directories.