lease

package
v0.0.0-...-7db8050 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 24 Imported by: 7

Documentation

Overview

Package lease, also known as the manager, manages the leases used by individual Juju workers.

Workers will claim a lease, and they are either attributed (i.e., the workers gets the lease ) or blocked (i.e., the worker is waiting for a lease to become available). In the latter case, the manager will keep track of all the blocked claims. When a worker's lease expires or gets revoked, then the manager will re-attribute it to one of other workers, thus unblocking them and satisfying their claim. In the special case where a worker is upgrading an application, it will ask the manager to "pin" the lease. This means that the lease will not expire or be revoked during the upgrade, and the validity of the lease will get refreshed once the upgrade has completed. The overall effect is that the application unit does not lose leadership during an upgrade.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SecretaryFinder

func SecretaryFinder(controllerUUID string) func(string) (Secretary, error)

SecretaryFinder returns a function to find the correct secretary to use for validation for a specific lease namespace (or an error if the namespace isn't valid).

Types

type LeadershipSecretary

type LeadershipSecretary struct{}

LeadershipSecretary implements Secretary; it checks that leases are application names, and holders are unit names.

func (LeadershipSecretary) CheckDuration

func (LeadershipSecretary) CheckDuration(duration time.Duration) error

CheckDuration is part of the lease.Secretary interface.

func (LeadershipSecretary) CheckHolder

func (LeadershipSecretary) CheckHolder(name string) error

CheckHolder is part of the lease.Secretary interface.

func (LeadershipSecretary) CheckLease

func (LeadershipSecretary) CheckLease(key lease.Key) error

CheckLease is part of the lease.Secretary interface.

type Logger

type Logger interface {
	Tracef(string, ...interface{})
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warningf(string, ...interface{})
	Errorf(string, ...interface{})
}

Logger represents the logging methods we use from a loggo.Logger.

type Manager

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

Manager implements worker.Worker and can be bound to get lease.Checkers and lease.Claimers.

func NewManager

func NewManager(config ManagerConfig) (*Manager, error)

NewManager returns a new *Manager configured as supplied. The caller takes responsibility for killing, and handling errors from, the returned Worker.

func (*Manager) Checker

func (manager *Manager) Checker(namespace, modelUUID string) (lease.Checker, error)

Checker returns a lease.Checker for the specified namespace and model.

func (*Manager) Claimer

func (manager *Manager) Claimer(namespace, modelUUID string) (lease.Claimer, error)

Claimer returns a lease.Claimer for the specified namespace and model.

func (*Manager) Kill

func (manager *Manager) Kill()

Kill is part of the worker.Worker interface.

func (*Manager) Pinner

func (manager *Manager) Pinner(namespace, modelUUID string) (lease.Pinner, error)

Pinner returns a lease.Pinner for the specified namespace and model.

func (*Manager) Reader

func (manager *Manager) Reader(namespace, modelUUID string) (lease.Reader, error)

Reader returns a lease.Reader for the specified namespace and model.

func (*Manager) Report

func (manager *Manager) Report() map[string]interface{}

Report is part of dependency.Reporter

func (*Manager) Revoker

func (manager *Manager) Revoker(namespace, modelUUID string) (lease.Revoker, error)

Revoker returns a lease.Revoker for the specified namespace and model.

func (*Manager) Wait

func (manager *Manager) Wait() error

Wait is part of the worker.Worker interface.

type ManagerConfig

type ManagerConfig struct {

	// Secretary determines validation given a namespace. The
	// secretary returned is responsible for validating lease names
	// and holder names for that namespace.
	Secretary func(namespace string) (Secretary, error)

	// Store is responsible for recording, retrieving, and expiring leases.
	Store lease.Store

	// Logger is used to report debugging/status information as the
	// manager runs.
	Logger Logger

	// Clock is responsible for reporting the passage of time.
	Clock clock.Clock

	// MaxSleep is the longest time the Manager should sleep before
	// refreshing its store's leases and checking for expiries.
	MaxSleep time.Duration

	// EntityUUID is the entity that we are running this Manager for. Used for
	// logging purposes.
	EntityUUID string

	// LogDir is the directory to write a debugging log file in the
	// case that the worker times out waiting to shut down.
	LogDir string

	PrometheusRegisterer prometheus.Registerer
}

ManagerConfig contains the resources and information required to create a Manager.

func (ManagerConfig) Validate

func (config ManagerConfig) Validate() error

Validate returns an error if the configuration contains invalid information or missing resources.

type Secretary

type Secretary interface {

	// CheckLease returns an error if the supplied lease name is not valid.
	CheckLease(key lease.Key) error

	// CheckHolder returns an error if the supplied holder name is not valid.
	CheckHolder(name string) error

	// CheckDuration returns an error if the supplied duration is not valid.
	CheckDuration(duration time.Duration) error
}

Secretary is responsible for validating the sanity of lease and holder names before bothering the manager with them.

type SingularSecretary

type SingularSecretary struct {
	ControllerUUID string
}

SingularSecretary implements Secretary to restrict claims to either a lease for the controller or the specific model it's asking for, holdable only by machine-tag strings.

func (SingularSecretary) CheckDuration

func (s SingularSecretary) CheckDuration(duration time.Duration) error

CheckDuration is part of the lease.Secretary interface.

func (SingularSecretary) CheckHolder

func (s SingularSecretary) CheckHolder(name string) error

CheckHolder is part of the lease.Secretary interface.

func (SingularSecretary) CheckLease

func (s SingularSecretary) CheckLease(key lease.Key) error

CheckLease is part of the lease.Secretary interface.

type Store

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

Store implements lease.Store using a database supporting SQLite-compatible dialects.

func NewStore

func NewStore(cfg StoreConfig) *Store

NewStore returns a reference to a new database-backed lease store.

func (*Store) ClaimLease

func (s *Store) ClaimLease(ctx context.Context, key lease.Key, req lease.Request) error

ClaimLease (lease.Store) claims the lease indicated by the input key, for the holder and duration indicated by the input request. The lease must not already be held, otherwise an error is returned.

func (*Store) ExtendLease

func (s *Store) ExtendLease(ctx context.Context, key lease.Key, req lease.Request) error

ExtendLease (lease.Store) ensures the input lease will be held for at least the requested duration starting from now. If the input holder does not currently hold the lease, an error is returned.

func (*Store) LeaseGroup

func (s *Store) LeaseGroup(ctx context.Context, namespace, modelUUID string) (map[lease.Key]lease.Info, error)

LeaseGroup (lease.Store) returns all leases for the input namespace and model.

func (*Store) Leases

func (s *Store) Leases(ctx context.Context, keys ...lease.Key) (map[lease.Key]lease.Info, error)

Leases (lease.Store) returns all leases in the database, optionally filtering using the input keys.

func (*Store) PinLease

func (s *Store) PinLease(ctx context.Context, key lease.Key, entity string) error

PinLease (lease.Store) adds the input entity into the lease_pin table to indicate that the lease indicated by the input key must not expire, and that this entity requires such behaviour.

func (*Store) Pinned

func (s *Store) Pinned(ctx context.Context) (map[lease.Key][]string, error)

Pinned (lease.Store) returns all leases that are currently pinned, and the entities requiring such behaviour for them.

func (*Store) RevokeLease

func (s *Store) RevokeLease(ctx context.Context, key lease.Key, holder string) error

RevokeLease (lease.Store) deletes the lease from the store, provided it exists and is held by the input holder. If either of these conditions is false, an error is returned.

func (*Store) UnpinLease

func (s *Store) UnpinLease(ctx context.Context, key lease.Key, entity string) error

UnpinLease (lease.Store) removes the record indicated by the input key and entity from the lease pin table, indicating that the entity no longer requires the lease to be pinned. When there are no entities associated with a particular lease, it is determined not to be pinned, and can expire normally.

type StoreConfig

type StoreConfig struct {
	// TrackedDB is the SQL database that backs this lease store.
	TrackedDB coredatabase.TrackedDB

	// Logger is used to emit store-specific diagnostics.
	Logger StoreLogger
}

StoreConfig encapsulates data required to construct a lease store instance.

type StoreLogger

type StoreLogger interface {
	Errorf(string, ...interface{})
}

StoreLogger describes methods for logging lease store concerns.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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