leadership

package
v0.0.0-...-be26699 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2015 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a manifold whose worker wraps a Tracker working on behalf of the dependency identified by AgentName.

Types

type ManifoldConfig

type ManifoldConfig struct {
	AgentName           string
	ApiCallerName       string
	LeadershipGuarantee time.Duration
}

ManifoldConfig defines the names of the manifolds on which a Manifold will depend.

type Ticket

type Ticket interface {

	// Wait returns true if its Tracker is prepared to guarantee leadership
	// for some period from the ticket request. The guaranteed duration depends
	// upon the Tracker.
	Wait() bool

	// Ready returns a channel that will be closed when a result is available
	// to Wait(), and is helpful for clients that want to select rather than
	// block on long-waiting tickets.
	Ready() <-chan struct{}
}

Ticket is used to communicate leadership status to Tracker clients.

type Tracker

type Tracker interface {

	// ServiceName returns the name of the service for which leadership claims
	// are made.
	ServiceName() string

	// ClaimDuration returns the duration for which a Ticket's true Wait result
	// is guaranteed valid.
	ClaimDuration() time.Duration

	// ClaimLeader will return a Ticket which, when Wait()ed for, will return
	// true if leadership is guaranteed for at least the tracker's duration from
	// the time the ticket was issued. Leadership claims should be resolved
	// relatively quickly.
	ClaimLeader() Ticket

	// WaitLeader will return a Ticket which, when Wait()ed for, will block
	// until the tracker attains leadership.
	WaitLeader() Ticket

	// WaitMinion will return a Ticket which, when Wait()ed for, will block
	// until the tracker's future leadership can no longer be guaranteed.
	WaitMinion() Ticket
}

Tracker allows clients to discover current leadership status by attempting to claim it for themselves.

type TrackerWorker

type TrackerWorker interface {
	worker.Worker
	Tracker
}

TrackerWorker embeds the Tracker and worker.Worker interfaces.

func NewTrackerWorker

func NewTrackerWorker(tag names.UnitTag, leadership leadership.LeadershipManager, duration time.Duration) TrackerWorker

NewTrackerWorker returns a TrackerWorker that attempts to claim and retain service leadership for the supplied unit. It will claim leadership for twice the supplied duration, and once it's leader it will renew leadership every time the duration elapses. Thus, successful leadership claims on the resulting Tracker will guarantee leadership for the duration supplied here without generating additional calls to the supplied manager (which may very well be on the other side of a network connection).

Jump to

Keyboard shortcuts

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