common

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckDNs = polardbxv1reconcile.NewStepBinder("CheckDNs",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()
		topology := polardbx.Status.SpecSnapshot.Topology
		replicas := int(topology.Nodes.DN.Replicas)

		dnStores, err := rc.GetDNMap()
		if err != nil {
			return flow.Error(err, "Unable to get xstores of DN.")
		}

		lastIndex := 0
		for ; lastIndex < replicas; lastIndex++ {
			if _, ok := dnStores[lastIndex]; !ok {
				break
			}
		}
		if lastIndex != replicas && lastIndex != len(dnStores) {
			helper.TransferPhase(polardbx, polardbxv1polardbx.PhaseFailed)
			return flow.Retry("Found broken DN, transfer into failed.")
		}

		return flow.Pass()
	},
)
View Source
var GenerateRandInStatus = polardbxv1reconcile.NewStepBinder("GenerateRandInStatus",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()
		if len(polardbx.Status.Rand) == 0 {
			polardbx.Status.Rand = rand.String(4)
		}
		return flow.Pass()
	},
)
View Source
var InitializeServiceName = polardbxv1reconcile.NewStepBinder("InitializeServiceName",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()
		if len(polardbx.Spec.ServiceName) == 0 {
			polardbx.Spec.ServiceName = polardbx.Name
			rc.MarkPolarDBXChanged()
		}
		return flow.Pass()
	},
)
View Source
var PersistentPolarDBXCluster = polardbxv1reconcile.NewStepBinder("PersistentPolarDBXCluster",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		if rc.IsPolarDBXChanged() {
			err := rc.UpdatePolarDBX()
			if err != nil {
				return flow.Error(err, "Unable to persistent polardbx.")
			}
		}
		return flow.Pass()
	},
)
View Source
var PersistentStatus = polardbxv1reconcile.NewStepBinder("PersistentStatus",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		if rc.IsPolarDBXStatusChanged() {
			err := rc.UpdatePolarDBXStatus()
			if err != nil {
				return flow.Error(err, "Unable to persistent status.")
			}
		}
		return flow.Pass()
	},
)
View Source
var UpdateDisplayDetailedVersion = polardbxv1reconcile.NewStepBinder("UpdateDisplayDetailedVersion",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()

		mgr, err := rc.GetPolarDBXGroupManager()
		if err != nil {
			return flow.Error(err, "Unable to get group manager.")
		}
		clusterVersion, err := mgr.GetClusterVersion()
		if err != nil {
			return flow.Error(err, "Unable to get cluster version.")
		}
		polardbx.Status.StatusForPrint.DetailedVersion = clusterVersion
		return flow.Pass()
	},
)
View Source
var UpdateDisplayReplicas = polardbxv1reconcile.NewStepBinder("UpdateDisplayReplicas",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()

		statusRef := &polardbx.Status

		if statusRef.ObservedGeneration <= 0 {
			return flow.Pass()
		}

		statusForPrintRef, snapshot := &polardbx.Status.StatusForPrint, polardbx.Status.SpecSnapshot

		cnDeployments, err := rc.GetDeploymentMap(polardbxmeta.RoleCN)
		if err != nil {
			return flow.Error(err, "Unable to get deployments of CN.")
		}
		gmsStore, err := rc.GetGMS()
		if client.IgnoreNotFound(err) != nil {
			return flow.Error(err, "Unable to get xstore of GMS.")
		}
		dnStores, err := rc.GetOrderedDNList()
		if err != nil {
			return flow.Error(err, "Unable to get xstores of DN.")
		}

		statusRef.ReplicaStatus = polardbxv1polardbx.ClusterReplicasStatus{
			GMS: polardbxv1polardbx.ReplicasStatus{Total: 1, Available: int32(countAvailableXStores(gmsStore))},
			CN:  polardbxv1polardbx.ReplicasStatus{Total: snapshot.Topology.Nodes.CN.Replicas, Available: int32(countAvailableReplicasFromDeployments(cnDeployments))},
			DN:  polardbxv1polardbx.ReplicasStatus{Total: snapshot.Topology.Nodes.DN.Replicas, Available: int32(countAvailableXStores(dnStores...))},
			CDC: nil,
		}
		if snapshot.Topology.Nodes.CDC != nil {
			cdcDeployments, err := rc.GetDeploymentMap(polardbxmeta.RoleCDC)
			if err != nil {
				return flow.Error(err, "Unable to get deployments of CDC.")
			}
			statusRef.ReplicaStatus.CDC = &polardbxv1polardbx.ReplicasStatus{
				Available: int32(countAvailableReplicasFromDeployments(cdcDeployments)),
				Total:     snapshot.Topology.Nodes.CDC.Replicas,
			}
		}
		statusForPrintRef.ReplicaStatus = polardbxv1polardbx.ReplicaStatusForPrint{
			GMS: statusRef.ReplicaStatus.GMS.Display(),
			CN:  statusRef.ReplicaStatus.CN.Display(),
			DN:  statusRef.ReplicaStatus.DN.Display(),
			CDC: statusRef.ReplicaStatus.CDC.Display(),
		}

		return flow.Pass()
	},
)
View Source
var UpdateDisplayStorageSize = polardbxv1reconcile.NewStepBinder("UpdateDisplayStorageSize",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()

		gmsStore, err := rc.GetGMS()
		if client.IgnoreNotFound(err) != nil {
			return flow.Error(err, "Unable to get xstore of GMS.")
		}
		dnStores, err := rc.GetOrderedDNList()
		if err != nil {
			return flow.Error(err, "Unable to get xstores of DN.")
		}

		now := time.Now()
		statusForPrintRef := &polardbx.Status.StatusForPrint

		if statusForPrintRef.StorageSizeUpdateTime == nil ||
			statusForPrintRef.StorageSizeUpdateTime.Time.Add(1*time.Minute).Before(now) {
			totalSize := int64(0)
			if !polardbx.Spec.ShareGMS && gmsStore != nil {
				totalSize += getTotalDataSizeOfXStore(gmsStore)
			}
			for _, dnStore := range dnStores {
				totalSize += getTotalDataSizeOfXStore(dnStore)
			}
			statusForPrintRef.StorageSizeUpdateTime = &metav1.Time{
				Time: now,
			}
			statusForPrintRef.StorageSize = unit.ByteCountIEC(totalSize)

			return flow.Continue("Storage size updated!")
		}

		return flow.Pass()
	})
View Source
var UpdateSnapshotAndObservedGeneration = polardbxv1reconcile.NewStepBinder("UpdateSnapshotAndObservedGeneration",
	func(rc *polardbxv1reconcile.Context, flow control.Flow) (reconcile.Result, error) {
		polardbx := rc.MustGetPolarDBX()
		polardbx.Status.SpecSnapshot = &polardbxv1polardbx.SpecSnapshot{
			Topology: *polardbx.Spec.Topology.DeepCopy(),
			Config:   *polardbx.Spec.Config.DeepCopy(),
		}
		polardbx.Status.ObservedGeneration = polardbx.Generation
		return flow.Pass()
	},
)

Functions

func TransferPhaseTo

func TransferPhaseTo(phase polardbxv1polardbx.Phase, requeue bool) control.BindFunc

func TransferStageTo

func TransferStageTo(stage polardbxv1polardbx.Stage, requeue bool) control.BindFunc

func WhenDeletedAndNotDeleting

func WhenDeletedAndNotDeleting(binders ...control.BindFunc) control.BindFunc

Types

This section is empty.

Jump to

Keyboard shortcuts

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