leader

package
v0.396.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

type Coordinator[P any] struct {
	// contains filtered or unexported fields
}

Coordinator assigns a single leader for the rest to follow.

P is the protocol that the leader and followers must implement. Callers of Get() will receive a P, abstracting away whether they are interacting with a leader or a follower.

func NewCoordinator

func NewCoordinator[P any](ctx context.Context,
	advertise *url.URL,
	key leases.Key,
	leaser leases.Leaser,
	leaseTTL time.Duration,
	leaderFactory LeaderFactory[P],
	followerFactory FollowerFactory[P]) *Coordinator[P]

func (*Coordinator[P]) Get

func (c *Coordinator[P]) Get() (leaderOrFollower P, err error)

Get returns either a leader or follower

type ErrorFilter added in v0.328.2

type ErrorFilter struct {
	// contains filtered or unexported fields
}

ErrorFilter allows uses of leases to decide if an error might be due to the master falling over, or is something else that will not resolve itself after the TTL

func NewErrorFilter added in v0.328.2

func NewErrorFilter(leaseTTL time.Duration) *ErrorFilter

func (*ErrorFilter) ReportLeaseError added in v0.328.2

func (c *ErrorFilter) ReportLeaseError() bool

ReportLeaseError reports that an operation that relies on the leader being up has failed If this is either the first report or the error is within the lease timeout duration from the time of the first report it will return false, indicating that this may be a transient error If it returns true then the error has persisted over the length of a lease, and is probably serious this will also return true if some operations are succeeding and some are failing, indicating a non-lease related transient error

func (*ErrorFilter) ReportOperationSuccess added in v0.328.2

func (c *ErrorFilter) ReportOperationSuccess()

ReportOperationSuccess reports that an operation that relies on the leader being up has succeeded it is used to decide if an error is transient and will be fixed with a new leader, or if the error is persistent

type FollowerFactory

type FollowerFactory[P any] func(ctx context.Context, leaderURL *url.URL) (P, error)

FollowerFactory is a function that is called whenever we follow a new leader.

If the new leader has the same url as the previous leader, the existing follower will be used.

type LeaderFactory

type LeaderFactory[P any] func(ctx context.Context) (P, error)

LeaderFactory is a function that is called whenever a new leader is acquired.

The context provided is tied to the lease and will be cancelled when the leader is no longer leading.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL