utils

package
v0.0.0-...-9e299b5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

* * Copyright 2019. The CloudDB Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *

Index

Constants

View Source
const (
	HashratePerTidb     = 1
	ScalerOut           = 1
	ScalerIn            = 2
	ZeroHashrate        = 0.0
	MinHashraterPerTidb = 0.5
	NormalHashrate1     = 1.0
	NormalHashrate2     = 2.0
	NormalHashrate3     = 4.0
	NormalHashrate4     = 8.0
	NormalHashrate5     = 16.0
)
View Source
const (
	// AnnTiDBLastAutoScalingTimestamp is annotation key of tidbcluster to indicate the last timestamp for tidb auto-scaling
	AnnTiDBLastAutoScalingTimestamp = "tidb.tidb.pingcap.com/last-autoscaling-timestamp"
	// AnnTiKVLastAutoScalingTimestamp is annotation key of tidbclusterto which ordinal is created by tikv auto-scaling
	AnnTiKVLastAutoScalingTimestamp = "tikv.tidb.pingcap.com/last-autoscaling-timestamp"
	// AnnLastSyncingTimestamp records last sync timestamp
	AnnLastSyncingTimestamp = "tidb.pingcap.com/last-syncing-timestamp"
)
View Source
const (
	TP                   string = "tp"
	AP                   string = "ap"
	BIGAP                string = "large"
	RoleInstanceLabelKey string = "bcrds.cmss.com/role"
)

Variables

View Source
var AllScalerOutData = make(map[string]*ScalerData)
View Source
var GMapMutex sync.Mutex
View Source
var MaxHashrate = os.Getenv("MAX_HASHRATE")
View Source
var SplitReplicas = os.Getenv("SPLIT_REPLICAS")
View Source
var TwoPattern = "2"

Functions

func AutoScalerToMidWareScalerOut

func AutoScalerToMidWareScalerOut(tcArr *TClus) error

func CalcMaxPerfResource

func CalcMaxPerfResource(metrics v1alpha1.Metric) int

calcute max hashrate based on metric.

func CallupTidb

func CallupTidb(podList []*corev1.Pod, name, namesp string, scaletype string) error

func ChangeScalerStatus

func ChangeScalerStatus(name string, namesp string)

func CheckStsAutoScalingInterval

func CheckStsAutoScalingInterval(sldb *v1alpha1.ServerlessDB, intervalSeconds int32, memberType tcv1.MemberType) (bool, error)

CheckStsAutoScalingInterval would check whether there is enough interval duration between every two auto-scaling

func CleanHashrate

func CleanHashrate(tc *tcv1.TidbCluster, scaletype string)

func CleanScalerMap

func CleanScalerMap(name string, namesp string)

func CompareResource

func CompareResource(metrics v1alpha1.Metric, expectTotal int) int

caculated resource cannot exceed cluster limit.

func DnsCheck

func DnsCheck(pod *corev1.Pod) error

func FEqual

func FEqual(a, b float64) bool

func FGreater

func FGreater(a, b float64) bool

func FSmaller

func FSmaller(a, b float64) bool

func FilterFailedAndNoHealthInstance

func FilterFailedAndNoHealthInstance(sldb *v1alpha1.ServerlessDB, tc *tcv1.TidbCluster, sldbType tcv1.MemberType) ([]int, []int, []int, error)

func FilterIdx

func FilterIdx(instances []string) ([]int, error)

func FilterNeedReduceTidbReplicas

func FilterNeedReduceTidbReplicas(tc *tcv1.TidbCluster, reduceReplicas int, component string) ([]string, error)

func FilterNeedReduceTidbReplicasIndex

func FilterNeedReduceTidbReplicasIndex(tc *tcv1.TidbCluster, reduceReplica int, component string) ([]int, error)

func GetBigCostPodArray

func GetBigCostPodArray(tc *tcv1.TidbCluster, sldbType tcv1.MemberType) ([]*corev1.Pod, error)

func GetHashrateAndReplicasPerTidb

func GetHashrateAndReplicasPerTidb(sldb *v1alpha1.ServerlessDB, totalHashrate float64, currentHashrate float64, autoFlag bool) (float64, int32)

func GetK8sAllPodArray

func GetK8sAllPodArray(name string, namesp string, sldbType tcv1.MemberType, scalertype string) ([]*corev1.Pod, error)

func GetK8sPodArray

func GetK8sPodArray(tc *tcv1.TidbCluster, sldbType tcv1.MemberType, scalertype string) ([]*corev1.Pod, error)

func GetMaxHashrate

func GetMaxHashrate(sldb *v1alpha1.ServerlessDB) float64

func GetMemory

func GetMemory(hashratePerTidb float64, newMem resource.Quantity) resource.Quantity

func GetNewAnnoAndReplias

func GetNewAnnoAndReplias(sldb *v1alpha1.ServerlessDB, tc *tcv1.TidbCluster, oldTc *tcv1.TidbCluster,
	sldbType tcv1.MemberType) error

func GetPodArray

func GetPodArray(tc *tcv1.TidbCluster, sldbType tcv1.MemberType) ([]*corev1.Pod, error)

func GetSldb

func GetSldb(clus, ns string) (*v1alpha1.ServerlessDB, error)

func GetTcArrayAP

func GetTcArrayAP(sldb *v1alpha1.ServerlessDB) ([]*tcv1.TidbCluster, *tcv1.TidbCluster, error)

func GetTcArrayTP

func GetTcArrayTP(sldb *v1alpha1.ServerlessDB) ([]*tcv1.TidbCluster, error)

func GetTidbStatus

func GetTidbStatus(tcArr *TClus) tcv1.MemberPhase

func HanderAllScalerIn

func HanderAllScalerIn(tcArr *TClus, sldb *v1alpha1.ServerlessDB, sldbType tcv1.MemberType, autoscale bool) error

func HanderAllScalerOut

func HanderAllScalerOut(tcArr *TClus, sldb *v1alpha1.ServerlessDB, sldbType tcv1.MemberType, autoscale bool) error

func IsPodReady

func IsPodReady(pod *corev1.Pod) bool

func ListTidbcluster

func ListTidbcluster(ns string, opt metav1.ListOptions) (*tcv1.TidbClusterList, error)

func MergeSlice

func MergeSlice(slice1 []int, slice2 []int) []int

func OneHashrate

func OneHashrate(tc *tcv1.TidbCluster, scaletype string)

func PendingHander

func PendingHander(sldb *v1alpha1.ServerlessDB, tc *tcv1.TidbCluster, oldTc *tcv1.TidbCluster, sldbType tcv1.MemberType, autoscale bool) error

func PodStatusCheckRollback

func PodStatusCheckRollback(sldb *v1alpha1.ServerlessDB, tc *tcv1.TidbCluster, oldTc *tcv1.TidbCluster, sldbType tcv1.MemberType) (map[string]string, int, error)

func PvcExpand

func PvcExpand(tc *tcv1.TidbCluster)

func RecalculateScale

func RecalculateScale(sldb *v1alpha1.ServerlessDB, tcArr *TClus, autoFlag bool) error

func RecalculateScaleIn

func RecalculateScaleIn(sldb *v1alpha1.ServerlessDB, tcArr *TClus, autoFlag bool) error

func RecalculateScaleOut

func RecalculateScaleOut(sldb *v1alpha1.ServerlessDB, tcArr *TClus, autoFlag bool) error

func ResourceProblemCheck

func ResourceProblemCheck(sldb *v1alpha1.ServerlessDB, tcArr *TClus, sldbType tcv1.MemberType) (bool, error)

func SyncReplicasToMidWare

func SyncReplicasToMidWare(tcArr *TClus, scalertype string) error

func TransHashrateToReplica

func TransHashrateToReplica(hashrate int) int

transfer hashrate to tidb replicas

func UpdateAnno

func UpdateAnno(tc *tcv1.TidbCluster, component string, actualReplica, targetReplica int) (map[string]string, error)

func UpdateLastData

func UpdateLastData(name string, namesp string, data *ScalerData, ty int)

func UpdateOneTcToNewNorms

func UpdateOneTcToNewNorms(Tc *tcv1.TidbCluster, reps int32) error

func UpdateSldbCondStatus

func UpdateSldbCondStatus(sldb *v1alpha1.ServerlessDB) error

func UpdateTC

func UpdateTC(tc *tcv1.TidbCluster, sldbType tcv1.MemberType, auto bool) error

func UpdateTCToNewNorms

func UpdateTCToNewNorms(tcArr *TClus) error

Types

type ChoiceScalerInstance

type ChoiceScalerInstance struct {
	// contains filtered or unexported fields
}

type DBStatus

type DBStatus struct {
	Cluster         string `json:"cluster"`
	Address         string `json:"address"`
	Type            string `json:"type"`
	Status          string `json:"status"`
	LastPing        string `json:"laste_ping"`
	MaxConn         int    `json:"max_conn"`
	IdleConn        int    `json:"idle_conn"`
	CacheConn       int    `json:"cache_conn"`
	PushConnCount   int64  `json:"push_conn_count"`
	PopConnCount    int64  `json:"pop_conn_count"`
	UsingConnsCount int64  `json:"using_conn_count"`
}

type ScalerData

type ScalerData struct {
	ScalerNeedCore  float64
	ScalerCurtime   int64
	FirstExpandTime int64
	ScalerFlag      int
}

func GetLastData

func GetLastData(name string, namesp string) (ScalerData, error)

type SigleTc

type SigleTc struct {
	Tc              tcv1.TidbCluster
	HashratePerTidb float64
	Replicas        int32
}

func GetHashRate

func GetHashRate(tc *tcv1.TidbCluster) (SigleTc, error)

type TClus

type TClus struct {
	OldTc       []SigleTc
	NewTc       []SigleTc
	OldHashRate float64
	NewHashRate float64
}

func CloneMutiRevsionTc

func CloneMutiRevsionTc(sldb *v1alpha1.ServerlessDB, role string) (*TClus, *tcv1.TidbCluster, error)

func ClusterStatusCheck

func ClusterStatusCheck(sldb *v1alpha1.ServerlessDB, sldbType tcv1.MemberType) (*TClus, error)

Jump to

Keyboard shortcuts

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