state

package
v0.0.0-...-57dcc05 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: AGPL-3.0 Imports: 13 Imported by: 1

Documentation

Overview

Package upgrade state provides a type for representing the state of an upgrade.

The states are represented as a finite state machine, with the following transitions:

┌──────────────────┐
│      Created     ├─────┐
└─────────┬────────┘     │
          │              │
          │              │
┌─────────▼─────────┐    │
│      Started      ├────┤
└─────────┬─────────┘    │
          │              │    ┌───────────┐
          │              ├────►   Error   │
┌─────────▼─────────┐    │    └───────────┘
│    DBCompleted    ├────┤
└─────────┬─────────┘    │
          │              │
          │              │
┌─────────▼─────────┐    │
│  StepsCompleted   ├────┘
└───────────────────┘

The state machine is represented by the State type, which is an integer type. The constants for the states are exported, and the type is exported so that it can be used in APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerNodeInfo

type ControllerNodeInfo struct {
	// UUID holds the rows UUID.
	UUID string `db:"uuid"`
	// UpgradeInfoUUID holds the UUID of the associated upgrade info.
	UpgradeInfoUUID string `db:"upgrade_info_uuid"`
	// ControllerNodeID holds the controller node ID
	ControllerNodeID string `db:"controller_node_id"`
	// NodeUpgradeStartedAt holds the time the upgrade was started on the node
	NodeUpgradeCompletedAt sql.NullString `db:"node_upgrade_completed_at"`
}

ControllerNodeInfo holds the information about completeness of database upgrade process for a particular controller node

type Count

type Count struct {
	Num int `db:"num"`
}

Count is used to select counts from the database.

type Info

type Info struct {
	// UUID holds the upgrader's ID
	UUID string `db:"uuid"`
	// PreviousVersion holds the previous version
	PreviousVersion string `db:"previous_version"`
	// TargetVersion holds the target version
	TargetVersion string `db:"target_version"`
	// StateIDType holds the type id of the current state of the upgrade.
	StateIDType int `db:"state_type_id"`
}

Info holds the information about database upgrade

func (Info) ToUpgradeInfo

func (i Info) ToUpgradeInfo() (upgrade.Info, error)

ToUpgradeInfo converts an info to an upgrade.Info.

type State

type State struct {
	*domain.StateBase
}

State is used to access the database.

func NewState

func NewState(factory coredatabase.TxnRunnerFactory) *State

NewState creates a state to access the database.

func (*State) ActiveUpgrade

func (st *State) ActiveUpgrade(ctx context.Context) (domainupgrade.UUID, error)

ActiveUpgrade returns the uuid of the active upgrade. The active upgrade is any upgrade that is not in the StepsCompleted state. It returns a NotFound error if there is no active upgrade.

func (*State) AllProvisionedControllersReady

func (st *State) AllProvisionedControllersReady(ctx context.Context, upgradeUUID domainupgrade.UUID) (bool, error)

AllProvisionedControllersReady returns true if and only if all controllers that have been started by the provisioner are ready to start the provided upgrade.

func (*State) CreateUpgrade

func (st *State) CreateUpgrade(ctx context.Context, previousVersion, targetVersion version.Number) (domainupgrade.UUID, error)

CreateUpgrade creates an active upgrade to and from specified versions and returns the upgrade's UUID. If an active upgrade already exists, return an AlreadyExists error

func (*State) SetControllerDone

func (st *State) SetControllerDone(ctx context.Context, upgradeUUID domainupgrade.UUID, controllerID string) error

SetControllerDone marks the supplied controllerID as having completed its upgrades. When SetControllerDone is called by the all provisioned controller, the upgrade itself will be completed.

TODO (jack-w-shaw) Set `statuses`/`statuseshistory` here to status.Available when we complete an upgrade

func (*State) SetControllerReady

func (st *State) SetControllerReady(ctx context.Context, upgradeUUID domainupgrade.UUID, controllerID string) error

SetControllerReady marks the supplied controllerID as being ready to start a provided upgrade. All provisioned controllers need to be ready before an upgrade can start. A controller node is ready for an upgrade if a row corresponding to the controller is present in upgrade_info_controller_node.

func (*State) SetDBUpgradeCompleted

func (st *State) SetDBUpgradeCompleted(ctx context.Context, upgradeUUID domainupgrade.UUID) error

SetDBUpgradeCompleted marks the database upgrade as completed.

func (*State) SetDBUpgradeFailed

func (st *State) SetDBUpgradeFailed(ctx context.Context, upgradeUUID domainupgrade.UUID) error

SetDBUpgradeFailed marks the database upgrade as failed.

func (*State) StartUpgrade

func (st *State) StartUpgrade(ctx context.Context, upgradeUUID domainupgrade.UUID) error

StartUpgrade starts the provided upgrade if the upgrade already exists. If it does not exists it returns a NotFound error. If it's already started, it returns a AlreadyStarted error.

TODO (jack-w-shaw) Set `statuses`/`statuseshistory` here to status.Busy once the table has been added

func (*State) UpgradeInfo

func (st *State) UpgradeInfo(ctx context.Context, upgradeUUID domainupgrade.UUID) (upgrade.Info, error)

UpgradeInfo returns the upgrade info for the provided upgradeUUID. It returns a NotFound error if the upgrade does not exist.

Jump to

Keyboard shortcuts

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