leader

package
v0.295.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 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 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