orchestrator

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	PromotionRulePrefer  = "prefer"
	PromotionRuleNeutral = "neutral"
	PromotionRuleMustNot = "must_not"
)
View Source
const (
	DowntimeOwner            = "percona-server-mysql-operator"
	DowntimeReasonSwitchover = "graceful-switchover"

	DowntimeReasonForcePromote = "force-promote"

	// DowntimeReasonLostInRecovery is the downtime orchestrator puts on the
	// failed primary at the end of every master recovery, for a year, whether
	// it promoted a replica or not. Orchestrator does not recover a downtimed
	// instance, so after a failed promotion it never retries
	DowntimeReasonLostInRecovery = "lost-in-recovery"
)
View Source
const (
	AppName = "orchestrator"

	// HandlerStateDir is where orc-handler keeps the marks a failover leaves
	// between hook runs. It sits on the pod's config emptyDir, next to
	// orchestrator's own database, so a container restart keeps both or
	// neither.
	HandlerStateDir = configMountPath + "/orc-handler"

	CredsMountPath = "/etc/orchestrator/orchestrator-users-secret"
)
View Source
const ProblemReplicationLag = "replication_lag"

ProblemReplicationLag is reported for a replica lagging more than ReasonableReplicationLagSeconds.

View Source
const RaftStateLeader = "Leader"
View Source
const RecoveryClaimIdle = 5 * time.Minute

RecoveryClaimIdle is how long the pre-failover hook's claim on a source outlives its last heartbeat. A claim idle for longer belongs to a recovery whose hook is gone, and both the hook's gate and the operator treat that recovery as over.

Variables

View Source
var (
	ErrEmptyResponse          = errors.New("empty response")
	ErrUnableToGetClusterName = errors.New("unable to determine cluster name")
	ErrUnauthorized           = errors.New("unauthorized")
	ErrBadConn                = errors.New("bad connection")
	ErrNoSuchHost             = errors.New("mysql host not found")
	ErrTimeout                = errors.New("timeout")
	ErrContainerNotFound      = errors.New("orchestrator container not found")

	// ErrRecoveryNotAttempted is orchestrator turning a takeover away because
	// another recovery of the same instance holds its place in the audit
	ErrRecoveryNotAttempted = errors.New("recovery not attempted")

	// ErrInstanceUnreachable is orchestrator's own answer that it could not
	// read the instance when asked to refresh it.
	ErrInstanceUnreachable = errors.New("instance unreachable")
)
View Source
var ErrSplitTopology = errors.New("orchestrator sees more than one live cluster")

Functions

func AckRecovery added in v1.3.0

func AckRecovery(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, uid, comment string) error

AckRecovery acknowledges the recovery orchestrator identifies by uid, which ends the active period it holds on the cluster and on the instance it promoted. Until then orchestrator starts no other recovery for either. The comment is what the audit shows as the reason.

func AddPeer added in v0.2.0

func AddPeer(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, peer string) error

func BeginDowntime added in v0.12.0

func BeginDowntime(
	ctx context.Context,
	cliCmd clientcmd.Client,
	pod *corev1.Pod,
	host string,
	port int,
	owner string,
	reason string,
	durationSeconds int,
) error

func ConfigMap added in v0.2.0

func ConfigMap(cr *apiv1.PerconaServerMySQL) (*corev1.ConfigMap, error)

func ConfigMapData added in v0.2.0

func ConfigMapData(cr *apiv1.PerconaServerMySQL) (string, error)

func ConfigMapName added in v0.2.0

func ConfigMapName(cr *apiv1.PerconaServerMySQL) string

func Discover added in v0.4.0

func Discover(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int) error

func EndDowntime added in v0.12.0

func EndDowntime(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int) error

func EnsureNodeIsPrimary added in v0.3.0

func EnsureNodeIsPrimary(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, clusterHint, host string, port int, catchUp time.Duration) (err error)

func ExistingNodes added in v1.0.0

func ExistingNodes(cmap *corev1.ConfigMap) ([]string, error)

func FQDN added in v0.2.0

func FQDN(cr *apiv1.PerconaServerMySQL, idx int) string

func ForceMasterTakeover added in v1.3.0

func ForceMasterTakeover(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, clusterHint, host string, port int32) error

ForceMasterTakeover promotes host even though orchestrator sees no reason to. It is the break-glass path for a cluster left without a writable primary because the pre-failover hook could not recover the transactions stranded on the dead one, so it gives those transactions up.

func ForgetInstance added in v0.8.0

func ForgetInstance(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int) error

func GetReadyPod added in v0.12.0

func GetReadyPod(
	ctx context.Context,
	cl client.Client,
	cluster *apiv1.PerconaServerMySQL,
) (*corev1.Pod, error)

func IsMasterFailover added in v1.3.0

func IsMasterFailover(analysis string) bool

func IsPlannedTakeover added in v1.3.0

func IsPlannedTakeover(command string) bool

func Labels

func Labels(cr *apiv1.PerconaServerMySQL) map[string]string

Labels returns labels of orchestrator

func LiveClaims added in v1.3.0

func LiveClaims(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod) ([]string, error)

LiveClaims returns the recoveries whose pre-failover hook is still in flight on the orchestrator in pod.

func MatchLabels

func MatchLabels(cr *apiv1.PerconaServerMySQL) map[string]string

func Name

Name returns component name

func PodName added in v0.2.0

func PodName(cr *apiv1.PerconaServerMySQL, idx int) string

func PodService added in v0.2.0

func PodService(cr *apiv1.PerconaServerMySQL, t corev1.ServiceType, podName string) *corev1.Service

func RBAC added in v0.8.0

func RaftNodes added in v0.2.0

func RaftNodes(cr *apiv1.PerconaServerMySQL) []string

func RaftState added in v1.3.0

func RaftState(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod) (string, error)

func RegisterCandidate added in v1.3.0

func RegisterCandidate(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int32, promotionRule string) error

RegisterCandidate sets the promotion rule orchestrator applies to an instance when it picks a replica to promote. The registration expires on its own after CandidateInstanceExpireMinutes.

func RemovePeer added in v0.2.0

func RemovePeer(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, peer string) error

func ResolveCluster added in v1.3.0

func ResolveCluster(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, clusterHint string) (string, error)

ResolveCluster returns the name of the one cluster the orchestrator of this cluster holds live instances of. The alias does not do: every primary claims it through DetectClusterAliasQuery, so a primary left outside the topology takes the alias over and a lookup by it lands on either cluster.

func Service

func Service(cr *apiv1.PerconaServerMySQL) *corev1.Service

func ServiceName

func ServiceName(cr *apiv1.PerconaServerMySQL) string

func SetWriteable added in v0.8.0

func SetWriteable(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int) error

func StartReplication

func StartReplication(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int32) error

func StatefulSet

func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash string) *appsv1.StatefulSet

func StopReplication

func StopReplication(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int32) error

func SwitchoverCatchUp added in v1.3.0

func SwitchoverCatchUp(cr *apiv1.PerconaServerMySQL) (time.Duration, error)

SwitchoverCatchUp is the effective ReasonableMaintenanceReplicationLagSeconds. Orchestrator refuses a graceful takeover to a candidate lagging more than this, and waits at most this long for the candidate after freezing the primary.

func SwitchoverDowntime added in v1.3.0

func SwitchoverDowntime(catchUp time.Duration) int

SwitchoverDowntime is how long the old primary is kept downtimed during a graceful switchover, derived from the catch-up wait so the two cannot drift apart.

Types

type BinlogCoordinates added in v1.3.0

type BinlogCoordinates struct {
	LogFile string `json:"LogFile"`
	LogPos  int64  `json:"LogPos"`
}

type Component added in v0.12.0

type Component apiv1.PerconaServerMySQL

func (*Component) Labels added in v0.12.0

func (c *Component) Labels() map[string]string

func (*Component) MatchLabels added in v0.12.0

func (c *Component) MatchLabels() map[string]string

func (*Component) Name added in v0.12.0

func (c *Component) Name() string

func (*Component) Object added in v0.12.0

func (c *Component) Object(ctx context.Context, cl client.Client) (client.Object, error)

func (*Component) PerconaServerMySQL added in v0.12.0

func (c *Component) PerconaServerMySQL() *apiv1.PerconaServerMySQL

func (*Component) PodSpec added in v0.12.0

func (c *Component) PodSpec() *apiv1.PodSpec

type Exposer added in v0.2.0

type Exposer apiv1.PerconaServerMySQL

func (*Exposer) Exposed added in v0.2.0

func (e *Exposer) Exposed() bool

func (*Exposer) MatchLabels added in v0.12.0

func (e *Exposer) MatchLabels() map[string]string

func (*Exposer) Name added in v0.2.0

func (e *Exposer) Name(index string) string

func (*Exposer) SaveOldMeta added in v0.4.0

func (e *Exposer) SaveOldMeta() bool

func (*Exposer) Service added in v0.2.0

func (e *Exposer) Service(name string) *corev1.Service

func (*Exposer) Size added in v0.2.0

func (e *Exposer) Size() int32

type Instance

type Instance struct {
	Key                   InstanceKey       `json:"Key"`
	Alias                 string            `json:"InstanceAlias"`
	ClusterName           string            `json:"ClusterName"`
	MasterKey             InstanceKey       `json:"MasterKey"`
	Replicas              []InstanceKey     `json:"Replicas"`
	ReadOnly              bool              `json:"ReadOnly"`
	IsLastCheckValid      bool              `json:"IsLastCheckValid"`
	Problems              []string          `json:"Problems"`
	IsDowntimed           bool              `json:"IsDowntimed"`
	DowntimeReason        string            `json:"DowntimeReason"`
	DowntimeOwner         string            `json:"DowntimeOwner"`
	DowntimeEndTimestamp  string            `json:"DowntimeEndTimestamp"`
	ElapsedDowntime       time.Duration     `json:"ElapsedDowntime"`
	ExecBinlogCoordinates BinlogCoordinates `json:"ExecBinlogCoordinates"`
	ExecutedGtidSet       string            `json:"ExecutedGtidSet"`
	ReplicationLagSeconds sql.NullInt64     `json:"ReplicationLagSeconds"`
}

func Cluster added in v0.8.0

func Cluster(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, clusterHint string) ([]*Instance, error)

func ClusterPrimary

func ClusterPrimary(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, clusterHint string) (*Instance, error)

func GetInstance added in v1.2.0

func GetInstance(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int) (*Instance, error)

func RefreshInstance added in v1.3.0

func RefreshInstance(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, host string, port int) (*Instance, error)

RefreshInstance has orchestrator read the instance now rather than answer from its last poll. It fails when orchestrator can't reach the instance.

func ReplicasOf added in v1.3.0

func ReplicasOf(instances []*Instance, host string) []*Instance

ReplicasOf returns the instances replicating from host.

type InstanceKey

type InstanceKey struct {
	Hostname string `json:"Hostname"`
	Port     int32  `json:"Port"`
}

func BestCandidate added in v1.3.0

func BestCandidate(instances []*Instance) (InstanceKey, bool)

BestCandidate returns the replica best suited for promotion, whichever instance it currently replicates from. It is the pick for a promotion forced by hand, where the old primary may be gone from the topology already.

func MostUpToDate added in v1.3.0

func MostUpToDate(replicas []*Instance) InstanceKey

MostUpToDate returns the replica with the least to catch up on.

type Recovery added in v1.3.0

type Recovery struct {
	UID      string `json:"UID"`
	Analysis struct {
		FailedKey   InstanceKey `json:"AnalyzedInstanceKey"`
		Analysis    string      `json:"Analysis"`
		CommandHint string      `json:"CommandHint"`
	} `json:"AnalysisEntry"`
	IsActive             bool   `json:"IsActive"`
	IsSuccessful         bool   `json:"IsSuccessful"`
	Acknowledged         bool   `json:"Acknowledged"`
	RecoveryEndTimestamp string `json:"RecoveryEndTimestamp"`
}

Recovery is an entry of orchestrator's recovery audit.

func UnacknowledgedRecoveries added in v1.3.0

func UnacknowledgedRecoveries(ctx context.Context, cliCmd clientcmd.Client, pod *corev1.Pod, clusterHint string) ([]Recovery, error)

UnacknowledgedRecoveries returns the cluster's recoveries nobody has acknowledged yet, newest first.

func (Recovery) Ended added in v1.3.0

func (r Recovery) Ended() bool

Ended reports whether orchestrator got as far as resolving the recovery, promoted or not. A recovery abandoned by its pre-failover hook never does.

func (Recovery) Started added in v1.3.0

func (r Recovery) Started() (time.Time, bool)

Started returns when orchestrator registered the recovery. The uid carries it: the audit's own start timestamp is rewritten whenever an orchestrator rebuilds its database from the raft log.

Jump to

Keyboard shortcuts

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