workers

package
v0.0.0-...-4bd6544 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2016 License: AGPL-3.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 DumbConfig

type DumbConfig struct {
	Factory Factory
	Logger  loggo.Logger
}

DumbConfig holds a DumbWorkers' dependencies.

func (DumbConfig) Validate

func (config DumbConfig) Validate() error

Validate returns an error if config cannot drive a DumbWorkers.

type DumbWorkers

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

DumbWorkers holds references to standard state workers. The workers are not guaranteed to be running; but they are guaranteed to be stopped when the DumbWorkers is stopped.

func NewDumbWorkers

func NewDumbWorkers(config DumbConfig) (_ *DumbWorkers, err error)

NewDumbWorkers returns a worker that will live until Kill()ed, giving access to a set of sub-workers needed by the state package.

These workers may die of their own accord at any time, and will not be replaced; they will also all be stopped before Wait returns.

func (*DumbWorkers) Kill

func (dw *DumbWorkers) Kill()

Kill is part of the worker.Worker interface.

func (*DumbWorkers) LeadershipManager

func (dw *DumbWorkers) LeadershipManager() LeaseManager

LeadershipManager is part of the Workers interface.

func (*DumbWorkers) PresenceWatcher

func (dw *DumbWorkers) PresenceWatcher() PresenceWatcher

PresenceWatcher is part of the Workers interface.

func (*DumbWorkers) SingularManager

func (dw *DumbWorkers) SingularManager() LeaseManager

SingularManager is part of the Workers interface.

func (*DumbWorkers) TxnLogWatcher

func (dw *DumbWorkers) TxnLogWatcher() TxnLogWatcher

TxnLogWatcher is part of the Workers interface.

func (*DumbWorkers) Wait

func (dw *DumbWorkers) Wait() error

Wait is part of the worker.Worker interface.

type DynamicLeaseManager

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

DynamicLeaseManager is a workers.LeaseManager that calls a given function to acquire a fresh LeaseManager for each method call. This enables us to hide the fact that workers returned from RestartManager may become stale.

func (DynamicLeaseManager) Claim

func (d DynamicLeaseManager) Claim(leaseName, holderName string, duration time.Duration) error

Claim is part of the lease.Claimer interface.

func (DynamicLeaseManager) Token

func (d DynamicLeaseManager) Token(leaseName, holderName string) lease.Token

Token is part of the lease.Checker interface.

func (DynamicLeaseManager) Underlying

func (d DynamicLeaseManager) Underlying() LeaseManager

Underlying returns the current underlying LeaseManager.

func (DynamicLeaseManager) WaitUntilExpired

func (d DynamicLeaseManager) WaitUntilExpired(leaseName string) error

WaitUntilExpired is part of the lease.Claimer interface.

type ExposedFailer

type ExposedFailer interface {
	Dead() <-chan struct{}
	Err() error
}

ExposedFailer encapsulates methods for shutdown detection and handling, used widely inside state watcher types.

Would be lovely to remove this dependency -- by adding new watchers to something that tracked watcher and/or state validity, and stopped them automatically -- but that's likely to have impacts reverberating through state and apiserver and deserves its own careful analysis.

type Factory

type Factory interface {
	NewTxnLogWorker() (TxnLogWorker, error)
	NewPresenceWorker() (PresenceWorker, error)
	NewLeadershipWorker() (LeaseWorker, error)
	NewSingularWorker() (LeaseWorker, error)
}

Factory supplies implementations of various workers used in state, and is generally a critical dependency of a Workers implementation such as DumbWorkers or RestartWorkers.

It'll generally just be a thin wrapper over a *State -- this package exists only to paper over worker-lifetime issues that are hard to address in the state package, not really to pave the way to alternate backends or anything.

type LeaseManager

type LeaseManager interface {
	lease.Claimer
	lease.Checker
}

LeaseManager exposes the methods of lease.Manager that are needed by the state package.

type LeaseWorker

type LeaseWorker interface {
	worker.Worker
	LeaseManager
}

LeaseWorker includes the lease.Manager's worker.Worker methods, so that a Workers implementation can manage its lifetime.

type PresenceWatcher

type PresenceWatcher interface {
	ExposedFailer

	// Horrible hack for goosing it into activity. Not clear why
	// this is used by state in place of StartSync, but it is.
	Sync()

	// Presence-reading and -watching.
	Alive(key string) (bool, error)
	Watch(key string, ch chan<- presence.Change)
	Unwatch(key string, ch chan<- presence.Change)
}

PresenceWatcher exposes the methods of presence.Watcher that are needed by the state package.

type PresenceWorker

type PresenceWorker interface {
	worker.Worker
	PresenceWatcher
}

PresenceWorker includes the presence.Watcher's worker.Worker methods, so that a Workers implementation can manage its lifetime.

type RestartConfig

type RestartConfig struct {
	Factory Factory
	Logger  loggo.Logger
	Clock   clock.Clock
	Delay   time.Duration
}

RestartConfig holds a RestartWorkers' dependencies and configuration.

func (RestartConfig) Validate

func (config RestartConfig) Validate() error

Validate returns an error if config cannot drive a RestartWorkers.

type RestartWorkers

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

RestartWorkers wraps a DumbWorkers and restarts/replaces workers as they fail.

func NewRestartWorkers

func NewRestartWorkers(config RestartConfig) (*RestartWorkers, error)

NewRestartWorkers returns a worker that will live until Kill()ed, giving access to a set of sub-workers needed by the state package.

These workers may die of their own accord at any time, and will be replaced after the configured delay; all active workers will be stopped before Wait returns.

func (*RestartWorkers) Kill

func (rw *RestartWorkers) Kill()

Kill is part of the worker.Worker interface.

func (*RestartWorkers) LeadershipManager

func (rw *RestartWorkers) LeadershipManager() LeaseManager

LeadershipManager is part of the Workers interface.

func (*RestartWorkers) PresenceWatcher

func (rw *RestartWorkers) PresenceWatcher() PresenceWatcher

PresenceWatcher is part of the Workers interface.

func (*RestartWorkers) SingularManager

func (rw *RestartWorkers) SingularManager() LeaseManager

SingularManager is part of the Workers interface.

func (*RestartWorkers) TxnLogWatcher

func (rw *RestartWorkers) TxnLogWatcher() TxnLogWatcher

TxnLogWatcher is part of the Workers interface.

func (*RestartWorkers) Wait

func (rw *RestartWorkers) Wait() error

Wait is part of the worker.Worker interface.

type TxnLogWatcher

type TxnLogWatcher interface {
	ExposedFailer

	// horrible hack for goosing it into activity (for tests).
	StartSync()

	// single-document watching
	Watch(coll string, id interface{}, revno int64, ch chan<- watcher.Change)
	Unwatch(coll string, id interface{}, ch chan<- watcher.Change)

	// collection-watching
	WatchCollection(coll string, ch chan<- watcher.Change)
	WatchCollectionWithFilter(coll string, ch chan<- watcher.Change, filter func(interface{}) bool)
	UnwatchCollection(coll string, ch chan<- watcher.Change)
}

TxnLogWatcher exposes the methods of watcher.Watcher that are needed by the state package.

type TxnLogWorker

type TxnLogWorker interface {
	worker.Worker
	TxnLogWatcher
}

TxnLogWorker includes the watcher.Watcher's worker.Worker methods, so that a Workers implementation can manage its lifetime.

type Workers

type Workers interface {
	worker.Worker

	TxnLogWatcher() TxnLogWatcher
	PresenceWatcher() PresenceWatcher
	LeadershipManager() LeaseManager
	SingularManager() LeaseManager
}

Workers doesn't really need to exist -- it could basically just exist in the state package -- but that'd entail duplication of the TxnLogWatcher, PresenceWatcher, and LeaseManager interfaces in both packages to avoid import cycles, and, yuck.

See the DumbWorkers and RestartWorkers types for implementations.

Jump to

Keyboard shortcuts

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