package election
import "github.com/google/trillian/util/election"
Package election provides a generic interface for election of a leader.
Index ¶
- Constants
- func HeldInfo(held []string, ids []string) string
- type MasterTracker
- func NewMasterTracker(ids []string, notify func(id string, isMaster bool)) *MasterTracker
- func (mt *MasterTracker) Count() int
- func (mt *MasterTracker) Held() []string
- func (mt *MasterTracker) IDs() []string
- func (mt *MasterTracker) Set(id string, isMaster bool)
- func (mt *MasterTracker) String() string
- type Resignation
- type Runner
- func NewRunner(id string, cfg *RunnerConfig, tracker *MasterTracker, cancel context.CancelFunc, el election2.Election) *Runner
- func (er *Runner) Run(ctx context.Context, pending chan<- Resignation)
- type RunnerConfig
Constants ¶
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.
Functions ¶
func HeldInfo ¶
HeldInfo produces a textual description of the set of held IDs, compared to a complete set of IDs.
Types ¶
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 ¶
func (cfg *RunnerConfig) ResignDelay() time.Duration
ResignDelay returns a randomized delay of how long to keep mastership for.
Source Files ¶
- Version
- v1.7.1 (latest)
- Published
- Jan 9, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 5 days ago –
Tools for package owners.