From ae26632e75e90212eec152fbf53f7e9f89176e5a Mon Sep 17 00:00:00 2001 From: Yifan Xiong Date: Wed, 12 May 2021 16:51:49 +0800 Subject: [PATCH] Fix bugs in new v2 test cases Fix bugs in new v2 test cases, including: * calculate leaf cell numbers per pod when creating new PodGroupSchedulingStatus * get cell chain through within cell type (no higher than node) instead of leaf cell type * sort cells by virtual address in cluster view --- pkg/algorithm/config.go | 12 +++++++++--- pkg/algorithm/hived_algorithm.go | 18 +++++++++++++----- pkg/algorithm/sku_scheduler.go | 5 ++++- pkg/algorithm/types_v2.go | 12 +++++++++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/pkg/algorithm/config.go b/pkg/algorithm/config.go index d610c37..0714d1c 100644 --- a/pkg/algorithm/config.go +++ b/pkg/algorithm/config.go @@ -418,11 +418,13 @@ func parseCellChainInfo( map[CellChain]map[CellLevel]int32, map[CellChain]map[CellLevel]api.CellType, map[CellChain]map[api.CellType]CellLevel, + map[string][]CellChain, map[string][]CellChain) { cellLevelToLeafCellNum := map[CellChain]map[CellLevel]int32{} cellLevelToType := map[CellChain]map[CellLevel]api.CellType{} cellTypeToLevel := map[CellChain]map[api.CellType]CellLevel{} + cellTypeToChain := map[string][]CellChain{} leafCellTypeToChain := map[string][]CellChain{} for _, chain := range chains { ce := cellChainElements[api.CellType(chain)] @@ -436,11 +438,13 @@ func parseCellChainInfo( cellLevelToLeafCellNum[chain][ce.level] = ce.leafCellNumber cellLevelToType[chain][ce.level] = ce.cellType cellTypeToLevel[chain][ce.cellType] = ce.level + if !ce.isMultiNodes { + cellTypeToChain[string(ce.cellType)] = append(cellTypeToChain[string(ce.cellType)], chain) + } ce, ok = cellChainElements[ce.childCellType] } } - return cellLevelToLeafCellNum, cellLevelToType, cellTypeToLevel, leafCellTypeToChain - + return cellLevelToLeafCellNum, cellLevelToType, cellTypeToLevel, cellTypeToChain, leafCellTypeToChain } func ParseConfig(sConfig *api.Config) ( @@ -453,6 +457,7 @@ func ParseConfig(sConfig *api.Config) ( physicalPinnedCells map[api.VirtualClusterName]map[api.PinnedCellId]*PhysicalCell, // vc:pinnedCellId:PhysicalCell cellLevelToLeafCellNum map[CellChain]map[CellLevel]int32, // chain:level:leafCellNumber leafCellTypeToChain map[string][]CellChain, // leafCellType:[]chain + cellTypeToChain map[string][]CellChain, // cellType:[]chain cellLevelToType map[CellChain]map[CellLevel]api.CellType, // chain:level:cellType cellTypeToLevel map[CellChain]map[api.CellType]CellLevel, // chain:cellType:level ) { @@ -476,7 +481,8 @@ func ParseConfig(sConfig *api.Config) ( for k := range physicalFullList { cellChains = append(cellChains, k) } - cellLevelToLeafCellNum, cellLevelToType, cellTypeToLevel, leafCellTypeToChain = parseCellChainInfo(cellChainElements, cellChains) + cellLevelToLeafCellNum, cellLevelToType, cellTypeToLevel, cellTypeToChain, leafCellTypeToChain = + parseCellChainInfo(cellChainElements, cellChains) return } diff --git a/pkg/algorithm/hived_algorithm.go b/pkg/algorithm/hived_algorithm.go index a896f99..c6b0ed9 100644 --- a/pkg/algorithm/hived_algorithm.go +++ b/pkg/algorithm/hived_algorithm.go @@ -95,7 +95,11 @@ type HivedAlgorithm struct { // bad nodes in the physical cluster badNodes common.Set + // map each level in a chain to the leaf cell number + leafCellNums map[CellChain]map[CellLevel]int32 // map each leaf cell type to all chains that contain this type + leafCellChains map[string][]CellChain + // map each within cell type to all chains that contain this type cellChains map[string][]CellChain // map each level in a chain to the specific cell type name cellTypes map[CellChain]map[CellLevel]api.CellType @@ -110,7 +114,7 @@ type HivedAlgorithm struct { // NewHivedAlgorithm initializes a HivedAlgorithm from the config file. func NewHivedAlgorithm(sConfig *api.Config) *HivedAlgorithm { fullPcl, freePcl, vcFreeCellNum, nonPinnedFullVcl, nonPinnedFreeVcl, pinnedVcl, pinnedPcl, - leafCellNums, chains, cellTypes, cellLevels := ParseConfig(sConfig) + leafCellNums, leafCellChains, cellChains, cellTypes, cellLevels := ParseConfig(sConfig) h := &HivedAlgorithm{ vcSchedulers: map[api.VirtualClusterName]intraVCScheduler{}, @@ -124,7 +128,9 @@ func NewHivedAlgorithm(sConfig *api.Config) *HivedAlgorithm { vcDoomedBadCells: map[api.VirtualClusterName]map[CellChain]ChainCellList{}, allVCDoomedBadCellNum: map[CellChain]map[CellLevel]int32{}, badNodes: common.NewSet(), - cellChains: chains, + leafCellNums: leafCellNums, + leafCellChains: leafCellChains, + cellChains: cellChains, cellTypes: cellTypes, cellLevels: cellLevels, podGroups: map[string]*PodGroupSchedulingStatus{}, @@ -844,7 +850,7 @@ func (h *HivedAlgorithm) schedulePodGroupForAnyLeafCellType( string) { var failedReason string - for leafCellType := range h.cellChains { + for leafCellType := range h.leafCellChains { klog.Infof("Searching leaf cell type %v", leafCellType) podGroupSchedRequest.podRootGroup.SetCellType(leafCellType) typePhysicalPlacement, typeVirtualPlacement, typeFailedReason := @@ -982,7 +988,8 @@ func (h *HivedAlgorithm) scheduleOpportunisticPodGroup( // createAllocatedPodGroup creates a new pod group and allocate the resources. func (h *HivedAlgorithm) createAllocatedPodGroup(podSchedSpec *apiv2.PodSchedulingSpec, info *apiv2.PodBindingInfo, pod *core.Pod) { klog.Infof("[%v]: Creating new allocated pod group: %v", internal.Key(pod), podSchedSpec.PodRootGroup.Name) - newPodGroupSchedStatus := newPodGroupSchedulingStatus(podSchedSpec, podGroupAllocated) + newPodGroupSchedStatus := newPodGroupSchedulingStatus( + podSchedSpec, h.leafCellNums[CellChain(info.CellChain)], h.cellLevels[CellChain(info.CellChain)], podGroupAllocated) shouldLazyPreempt := false infoIter := info.PodRootGroupBindingInfo.Iterator() @@ -1084,7 +1091,8 @@ func (h *HivedAlgorithm) createPreemptingPodGroup( pod *core.Pod) { klog.Infof("[%v]: Creating new preempting pod group: %v", internal.Key(pod), podSchedSpec.PodRootGroup.Name) - newPodGroupSchedStatus := newPodGroupSchedulingStatus(podSchedSpec, podGroupPreempting) + newPodGroupSchedStatus := newPodGroupSchedulingStatus( + podSchedSpec, map[CellLevel]int32{}, map[api.CellType]CellLevel{}, podGroupPreempting) newPodGroupSchedStatus.physicalPlacement = physicalPlacement newPodGroupSchedStatus.virtualPlacement = virtualPlacement diff --git a/pkg/algorithm/sku_scheduler.go b/pkg/algorithm/sku_scheduler.go index 9c6890b..2355662 100644 --- a/pkg/algorithm/sku_scheduler.go +++ b/pkg/algorithm/sku_scheduler.go @@ -459,7 +459,7 @@ func (cv skuClusterView) Len() int { // 2. cell level (prefer lower) // 3. usedLeafCellNumAtPriority (prefer higher) // 4. usedLeafCellNumHigherPriority (prefer lower) -// 5. cell address (prefer lower) +// 5. cell physical/virtual address (prefer lower) func (cv skuClusterView) Less(i, j int) bool { if cv[i].healthy != cv[j].healthy { return cv[i].healthy @@ -476,6 +476,9 @@ func (cv skuClusterView) Less(i, j int) bool { if cv[i].address != cv[j].address { return cv[i].address < cv[j].address } + if cv[i].cell.GetAddress() != cv[j].cell.GetAddress() { + return cv[i].cell.GetAddress() < cv[j].cell.GetAddress() + } return true } diff --git a/pkg/algorithm/types_v2.go b/pkg/algorithm/types_v2.go index 8fa032e..abed4cc 100644 --- a/pkg/algorithm/types_v2.go +++ b/pkg/algorithm/types_v2.go @@ -86,6 +86,8 @@ func (podGroupSchedStatus *PodGroupSchedulingStatus) DumpPodGroup() apiv2.PodGro func newPodGroupSchedulingStatus( podSchedSpec *apiv2.PodSchedulingSpec, + leafCellNums map[CellLevel]int32, + cellLevel map[api.CellType]CellLevel, state PodGroupState) *PodGroupSchedulingStatus { podGroupSchedStatus := &PodGroupSchedulingStatus{ @@ -121,9 +123,13 @@ func newPodGroupSchedulingStatus( podNumIndex := int32(0) for _, pod := range podGroup.Pods { for i := int32(0); i < pod.PodMinNumber; i++ { - // TODO: need leaf cell number - virtualPlacementQueue[index].podsPlacement[podNumIndex] = make(CellList, pod.CellsPerPod.CellNumber) - physicalPlacementQueue[index].podsPlacement[podNumIndex] = make(CellList, pod.CellsPerPod.CellNumber) + if level, ok := cellLevel[pod.CellsPerPod.CellType]; ok { + virtualPlacementQueue[index].podsPlacement[podNumIndex] = make(CellList, pod.CellsPerPod.CellNumber*leafCellNums[level]) + physicalPlacementQueue[index].podsPlacement[podNumIndex] = make(CellList, pod.CellsPerPod.CellNumber*leafCellNums[level]) + } else { + virtualPlacementQueue[index].podsPlacement[podNumIndex] = make(CellList, pod.CellsPerPod.CellNumber) + physicalPlacementQueue[index].podsPlacement[podNumIndex] = make(CellList, pod.CellsPerPod.CellNumber) + } podNumIndex++ } }