replication

package
v0.6.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SwitchPhasePrepare    SwitchPhase = "prepare"
	SwitchPhaseElect      SwitchPhase = "election"
	SwitchPhaseDetect     SwitchPhase = "detection"
	SwitchPhaseDecision   SwitchPhase = "decision"
	SwitchPhaseDoAction   SwitchPhase = "doAction"
	SwitchPhaseUpdateRole SwitchPhase = "updateRole"

	SwitchPhaseStatusExecuting SwitchPhaseStatus = "executing"
	SwitchPhaseStatusFailed    SwitchPhaseStatus = "failed"
	SwitchPhaseStatusSucceed   SwitchPhaseStatus = "succeed"
	SwitchPhaseStatusUnknown   SwitchPhaseStatus = "unknown"
)
View Source
const (
	SwitchElectionRoleFilterName   = "SwitchElectionRoleFilter"
	SwitchElectionHealthFilterName = "SwitchElectionHealthFilter"
)
View Source
const (
	KBSwitchPromoteStmtEnvName = "KB_SWITCH_PROMOTE_STATEMENT"
	KBSwitchDemoteStmtEnvName  = "KB_SWITCH_DEMOTE_STATEMENT"
	KBSwitchFollowStmtEnvName  = "KB_SWITCH_FOLLOW_STATEMENT"

	KBSwitchOldPrimaryRoleName = "KB_OLD_PRIMARY_ROLE_NAME"
	KBSwitchNewPrimaryRoleName = "KB_NEW_PRIMARY_ROLE_NAME"

	KBSwitchRoleEndPoint = "KB_SWITCH_ROLE_ENDPOINT"
)

Environment names for switchStatements

View Source
const (
	KBSwitchJobLabelKey                = "kubeblocks.io/switch-job"
	KBSwitchJobLabelValue              = "kb-switch-job"
	KBSwitchJobNamePrefix              = "kb-switch-job"
	KBSwitchJobContainerName           = "switch-job-container"
	KBSwitchJobTTLSecondsAfterFinished = 5
)

Variables

This section is empty.

Functions

func CheckPrimaryIndexChanged

func CheckPrimaryIndexChanged(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	compName string,
	currentPrimaryIndex int32) (bool, int32, error)

CheckPrimaryIndexChanged checks whether primaryIndex has changed and returns current primaryIndex. @return bool - true is primaryIndex inconsistent @return int32 - current primaryIndex; -1 if error @return error

func DefaultRole

func DefaultRole(i int32) string

func HandleReplicationSetHASwitch

func HandleReplicationSetHASwitch(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	clusterCompSpec *appsv1alpha1.ClusterComponentSpec) error

HandleReplicationSetHASwitch handles high-availability switching of a single replication workload under current cluster.

func HandleReplicationSetRoleChangeEvent

func HandleReplicationSetRoleChangeEvent(cli client.Client,
	reqCtx intctrlutil.RequestCtx,
	cluster *appsv1alpha1.Cluster,
	compName string,
	pod *corev1.Pod,
	newRole string) error

HandleReplicationSetRoleChangeEvent handles the role change event of the replication workload when switchPolicy is Noop.

func NewReplicationComponent

func NewReplicationComponent(cli client.Client,
	cluster *appsv1alpha1.Cluster,
	clusterVersion *appsv1alpha1.ClusterVersion,
	synthesizedComponent *component.SynthesizedComponent,
	dag *graph.DAG) *replicationComponent

Types

type HealthDetectResult

type HealthDetectResult bool

type LagDetectResult

type LagDetectResult int32

type ProbeDetectManager

type ProbeDetectManager struct{}

ProbeDetectManager implements the SwitchDetectManager interface with KubeBlocks Probe.

type ReplicationRole

type ReplicationRole string
const (
	Primary   ReplicationRole = "primary"
	Secondary ReplicationRole = "secondary"
)

type ReplicationSet

type ReplicationSet struct {
	stateful.Stateful
}

ReplicationSet is a component object used by Cluster, ClusterComponentDefinition and ClusterComponentSpec

func (*ReplicationSet) GetPhaseWhenPodsNotReady

func (r *ReplicationSet) GetPhaseWhenPodsNotReady(ctx context.Context,
	componentName string) (appsv1alpha1.ClusterComponentPhase, appsv1alpha1.ComponentMessageMap, error)

GetPhaseWhenPodsNotReady is the implementation of the type Component interface method, when the pods of replicationSet are not ready, calculate the component phase is Failed or Abnormal. if return an empty phase, means the pods of component are ready and skips it.

func (*ReplicationSet) GetPhaseWhenPodsReadyAndProbeTimeout

func (r *ReplicationSet) GetPhaseWhenPodsReadyAndProbeTimeout(pods []*corev1.Pod) (appsv1alpha1.ClusterComponentPhase, appsv1alpha1.ComponentMessageMap)

func (*ReplicationSet) HandleHA

func (r *ReplicationSet) HandleHA(ctx context.Context, obj client.Object) ([]graph.Vertex, error)

func (*ReplicationSet) HandleRestart

func (r *ReplicationSet) HandleRestart(ctx context.Context, obj client.Object) ([]graph.Vertex, error)

func (*ReplicationSet) HandleRoleChange

func (r *ReplicationSet) HandleRoleChange(ctx context.Context, obj client.Object) ([]graph.Vertex, error)

func (*ReplicationSet) IsRunning

func (r *ReplicationSet) IsRunning(ctx context.Context, obj client.Object) (bool, error)

IsRunning is the implementation of the type Component interface method, which is used to check whether the replicationSet component is running normally.

func (*ReplicationSet) PodIsAvailable

func (r *ReplicationSet) PodIsAvailable(pod *corev1.Pod, minReadySeconds int32) bool

PodIsAvailable is the implementation of the type Component interface method, Check whether the status of a Pod of the replicationSet is ready, including the role label on the Pod

func (*ReplicationSet) PodsReady

func (r *ReplicationSet) PodsReady(ctx context.Context, obj client.Object) (bool, error)

PodsReady is the implementation of the type Component interface method, which is used to check whether all the pods of replicationSet component is ready.

func (*ReplicationSet) SetComponent

func (r *ReplicationSet) SetComponent(comp types.Component)

type RoleDetectResult

type RoleDetectResult string
const (
	DetectRolePrimary   RoleDetectResult = "primary"
	DetectRoleSecondary RoleDetectResult = "secondary"
)

type Switch

type Switch struct {
	SwitchResource      *SwitchResource
	SwitchInstance      *SwitchInstance
	SwitchStatus        *SwitchStatus
	SwitchDetectManager SwitchDetectManager
	SwitchActionHandler SwitchActionHandler
}

Switch is the main high-availability switching implementation.

type SwitchActionHandler

type SwitchActionHandler interface {
	// contains filtered or unexported methods
}

SwitchActionHandler is a handler interface for performing switching actions

type SwitchActionWithJobHandler

type SwitchActionWithJobHandler struct{}

SwitchActionWithJobHandler implements the SwitchActionHandler interface with executing switch commands by k8s Job.

type SwitchDetectManager

type SwitchDetectManager interface {
	// contains filtered or unexported methods
}

SwitchDetectManager is an interface to implement various detections that high-availability depends on, including health detection, role detection, data delay detection, etc.

type SwitchElectionFilter

type SwitchElectionFilter interface {
	// contains filtered or unexported methods
}

SwitchElectionFilter is an interface used to filter the candidate primary during the election process.

type SwitchElectionHealthFilter

type SwitchElectionHealthFilter struct{}

SwitchElectionHealthFilter implements the SwitchElectionFilter interface and is used to filter unhealthy instances that cannot be selected as candidate primary.

type SwitchElectionRoleFilter

type SwitchElectionRoleFilter struct{}

SwitchElectionRoleFilter implements the SwitchElectionFilter interface and is used to filter the instances which role cannot be elected as candidate primary.

type SwitchInstance

type SwitchInstance struct {
	// OldPrimaryRole stores the old primary role information
	OldPrimaryRole *SwitchRoleInfo
	// CandidatePrimaryRole stores the new candidate primary role information after election, if no new primary is elected, it would be nil
	CandidatePrimaryRole *SwitchRoleInfo
	// SecondariesRole stores the information of secondary roles
	SecondariesRole []*SwitchRoleInfo
}

SwitchInstance is used to record the instance information of switching.

type SwitchPhase

type SwitchPhase string

SwitchPhase defines the phase of switching.

type SwitchPhaseStatus

type SwitchPhaseStatus string

SwitchPhaseStatus defines the status of switching phase.

type SwitchResource

SwitchResource is used to record resources that high-availability switching depends on, such as cluster information, component information, etc.

type SwitchRoleInfo

type SwitchRoleInfo struct {
	// k8s pod obj
	Pod *corev1.Pod
	// HealthDetectInfo stores the results of health detection
	HealthDetectInfo *HealthDetectResult
	// RoleDetectInfo stores the results of kernel role detection
	RoleDetectInfo *RoleDetectResult
	// LagDetectInfo stores the results of data delay detection
	LagDetectInfo *LagDetectResult
}

SwitchRoleInfo is used to record the role information including health detection, role detection, data delay detection info, etc.

type SwitchRoleInfoList

type SwitchRoleInfoList []*SwitchRoleInfo

SwitchRoleInfoList is a sort.Interface that Sorts a list of SwitchRoleInfo based on LagDetectInfo value.

func (SwitchRoleInfoList) Len

func (sl SwitchRoleInfoList) Len() int

Len is the implementation of the sort.Interface, calculate the length of the list of SwitchRoleInfoList.

func (SwitchRoleInfoList) Less

func (sl SwitchRoleInfoList) Less(i, j int) bool

Less is the implementation of the sort.Interface, sort the SwitchRoleInfo with LagDetectInfo.

func (SwitchRoleInfoList) Swap

func (sl SwitchRoleInfoList) Swap(i, j int)

Swap is the implementation of the sort.Interface, exchange two items in SwitchRoleInfoList.

type SwitchStatus

type SwitchStatus struct {
	// SwitchPhase defines the various phases of high-availability switching
	SwitchPhase SwitchPhase
	// SwitchPhaseStatus defines the state of each phase of high-availability switching
	SwitchPhaseStatus SwitchPhaseStatus
	// a brief single-word reason of current SwitchPhase and SwitchPhaseStatus.
	Reason string
	// a brief message explaining of current SwitchPhase and SwitchPhaseStatus.
	Message string
}

SwitchStatus defines the status of high-availability switching.

Jump to

Keyboard shortcuts

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