replication

package
v0.6.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: AGPL-3.0 Imports: 21 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 GeneratePVCFromVolumeClaimTemplates

func GeneratePVCFromVolumeClaimTemplates(sts *appsv1.StatefulSet, vctList []corev1.PersistentVolumeClaimTemplate) map[string]*corev1.PersistentVolumeClaim

GeneratePVCFromVolumeClaimTemplates generates the required pvc object according to the name of statefulSet and volumeClaimTemplates.

func GetPersistentVolumeClaimName

func GetPersistentVolumeClaimName(sts *appsv1.StatefulSet, claimTpl *corev1.PersistentVolumeClaimTemplate, ordinal int) string

GetPersistentVolumeClaimName gets the name of PersistentVolumeClaim for a replicationSet pod with an ordinal. claimTpl must be a PersistentVolumeClaimTemplate from the VolumeClaimsTemplate in the Cluster API.

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,
	component *appsv1alpha1.ClusterComponentSpec,
	componentDef appsv1alpha1.ClusterComponentDefinition) (types.Component, error)

NewReplicationComponent creates a new ReplicationSet object.

func RemoveReplicationSetClusterStatus

func RemoveReplicationSetClusterStatus(cli client.Client,
	ctx context.Context,
	cluster *appsv1alpha1.Cluster,
	stsList []*appsv1.StatefulSet,
	componentReplicas int32) error

RemoveReplicationSetClusterStatus removes replicationSet pod status from cluster.status.component[componentName].ReplicationStatus.

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 ReplicationComponent

type ReplicationComponent struct {
	stateful.StatefulComponent
}

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

func (*ReplicationComponent) GetPhaseWhenPodsNotReady

func (r *ReplicationComponent) GetPhaseWhenPodsNotReady(ctx context.Context,
	componentName string) (appsv1alpha1.ClusterComponentPhase, 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 (*ReplicationComponent) HandleProbeTimeoutWhenPodsReady

func (r *ReplicationComponent) HandleProbeTimeoutWhenPodsReady(ctx context.Context, recorder record.EventRecorder) (bool, error)

HandleProbeTimeoutWhenPodsReady is the implementation of the type Component interface method, and replicationSet does not need to do role probe detection, so it returns false directly.

func (*ReplicationComponent) HandleUpdate

func (r *ReplicationComponent) HandleUpdate(ctx context.Context, obj client.Object) error

HandleUpdate is the implementation of the type Component interface method, handles replicationSet workload Pod updates.

func (*ReplicationComponent) IsRunning

func (r *ReplicationComponent) 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 (*ReplicationComponent) PodIsAvailable

func (r *ReplicationComponent) 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 (*ReplicationComponent) PodsReady

func (r *ReplicationComponent) 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.

type ReplicationRole

type ReplicationRole string
const (
	Primary                ReplicationRole = "primary"
	Secondary              ReplicationRole = "secondary"
	DBClusterFinalizerName                 = "cluster.kubeblocks.io/finalizer"
)

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