Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Fix bugs in new v2 test cases
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abuccts committed May 12, 2021
1 parent 3a7d752 commit ae26632
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
12 changes: 9 additions & 3 deletions pkg/algorithm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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) (
Expand All @@ -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
) {
Expand All @@ -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
}
18 changes: 13 additions & 5 deletions pkg/algorithm/hived_algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{},
Expand All @@ -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{},
Expand Down Expand Up @@ -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 :=
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion pkg/algorithm/sku_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/algorithm/types_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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++
}
}
Expand Down

0 comments on commit ae26632

Please sign in to comment.