Version: v1.3.13 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 2




View Source
const (
	MinPreElectionPause   = 10 * time.Millisecond
	MinMasterHoldInterval = 10 * time.Second

Minimum values for configuration intervals. TODO(pavelkalinnikov): These parameters are specific to the application, so shouldn't be here.


This section is empty.


func HeldInfo

func HeldInfo(held []string, ids []string) string

HeldInfo produces a textual description of the set of held IDs, compared to a complete set of IDs.


type MasterTracker

type MasterTracker struct {
	// contains filtered or unexported fields

MasterTracker tracks the current mastership state across multiple IDs.

func NewMasterTracker

func NewMasterTracker(ids []string, notify func(id string, isMaster bool)) *MasterTracker

NewMasterTracker creates a new MasterTracker instance to track the mastership status for the given set of IDs.

func (*MasterTracker) Count

func (mt *MasterTracker) Count() int

Count returns the number of IDs for which we are currently master.

func (*MasterTracker) Held

func (mt *MasterTracker) Held() []string

Held returns a (sorted) list of the IDs for which we are currently master.

func (*MasterTracker) IDs

func (mt *MasterTracker) IDs() []string

IDs returns a (sorted) list of the IDs that we are currently tracking.

func (*MasterTracker) Set

func (mt *MasterTracker) Set(id string, isMaster bool)

Set changes the tracked mastership status for the given ID. This method should be called exactly once for each state transition.

func (*MasterTracker) String

func (mt *MasterTracker) String() string

String returns a textual decription of the current mastership status.

type Resignation

type Resignation struct {
	ID string
	// contains filtered or unexported fields

Resignation indicates that a master should explicitly resign mastership, and call the Execute() method as soon as no master-related activity is ongoing.

func (*Resignation) Execute

func (r *Resignation) Execute(ctx context.Context)

Execute performs the pending deliberate resignation for an election runner.

type Runner

type Runner struct {
	// Allow the user to store a Cancel function with the runner for convenience.
	Cancel context.CancelFunc
	// contains filtered or unexported fields

Runner controls a continuous election process.

func NewRunner

func NewRunner(id string, cfg *RunnerConfig, tracker *MasterTracker, cancel context.CancelFunc, el election2.Election) *Runner

NewRunner builds a new election Runner instance with the given config. On calling Run(), the provided Election will be continuously monitored, and mastership changes will be notified to the provided MasterTracker instance.

func (*Runner) Run

func (er *Runner) Run(ctx context.Context, pending chan<- Resignation)

Run performs a continuous election process. It runs continuously until the context is canceled or an internal error is encountered.

type RunnerConfig

type RunnerConfig struct {
	// PreElectionPause is the maximum interval to wait before starting a
	// mastership election for a particular log.
	PreElectionPause time.Duration
	// MasterHoldInterval is the minimum interval to hold mastership for.
	MasterHoldInterval time.Duration
	// MasterHoldJitter is the maximum addition to MasterHoldInterval.
	MasterHoldJitter time.Duration

	TimeSource clock.TimeSource

RunnerConfig describes the parameters for an election Runner.

func (*RunnerConfig) ResignDelay added in v1.3.0

func (cfg *RunnerConfig) ResignDelay() time.Duration

ResignDelay returns a randomized delay of how long to keep mastership for.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL