lease

package
v0.0.0-...-56cb166 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

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

View Source
const (
	// MaxSleep is the longest the manager will sleep before checking
	// whether any leases should be expired. If it can see a lease
	// expiring sooner than that it will still wake up earlier.
	MaxSleep = time.Minute
)

Variables

This section is empty.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold builds a dependency.Manifold for running a lease manager.

func NewStore

func NewStore(dbGetter database.DBGetter, logger logger.Logger) lease.Store

NewStore returns a new lease store based on the input config.

func NewWorker

func NewWorker(config ManagerConfig) (worker.Worker, error)

NewWorker wraps NewManager to return worker.Worker for testability.

Types

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 {

	// SecretaryFinder determines validation given a namespace. The
	// secretary returned is responsible for validating lease names
	// and holder names for that namespace.
	SecretaryFinder lease.SecretaryFinder

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

	// Tracer is used to record tracing information as the manager runs.
	Tracer trace.Tracer

	// Logger is used to report debugging/status information as the
	// manager runs.
	Logger 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 ManifoldConfig

type ManifoldConfig struct {
	AgentName      string
	ClockName      string
	DBAccessorName string
	TraceName      string

	Logger               logger.Logger
	LogDir               string
	PrometheusRegisterer prometheus.Registerer
	NewWorker            func(ManagerConfig) (worker.Worker, error)
	NewStore             func(database.DBGetter, logger.Logger) lease.Store
	NewSecretaryFinder   func(string) lease.SecretaryFinder
}

ManifoldConfig holds the resources needed to start the lease manager in a dependency engine.

func (ManifoldConfig) Validate

func (c ManifoldConfig) Validate() error

Validate checks that the config has all the required values.

Jump to

Keyboard shortcuts

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