fix(scheduler): 尽早发现子网ip不足引起的调度失败 (#22131)

This commit is contained in:
Zexi Li
2025-02-19 17:02:38 +08:00
committed by GitHub
parent 29a0d421fc
commit d759f836ce
3 changed files with 40 additions and 8 deletions
@@ -30,6 +30,7 @@ import (
"yunion.io/x/onecloud/pkg/scheduler/algorithm/plugin"
"yunion.io/x/onecloud/pkg/scheduler/api"
"yunion.io/x/onecloud/pkg/scheduler/core"
schedmodels "yunion.io/x/onecloud/pkg/scheduler/models"
)
// NetworkPredicate will filter the current network information with
@@ -315,7 +316,7 @@ func (p *NetworkPredicate) Execute(ctx context.Context, u *core.Unit, c core.Can
getFreePort := func(id string) int {
if _, ok := p.networkFreePortCount[id]; ok {
return p.networkFreePortCount[id] - c.Getter().GetPendingUsage().NetUsage.Get(id)
return p.networkFreePortCount[id] - schedmodels.HostPendingUsageManager.GetNetPendingUsage(id)
}
return c.Getter().GetFreePort(id)
}
+2 -1
View File
@@ -35,6 +35,7 @@ import (
"yunion.io/x/onecloud/pkg/compute/baremetal"
computemodels "yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/scheduler/core"
schedmodels "yunion.io/x/onecloud/pkg/scheduler/models"
o "yunion.io/x/onecloud/pkg/scheduler/options"
"yunion.io/x/onecloud/pkg/util/cgrouputils/cpuset"
)
@@ -792,7 +793,7 @@ func (h *HostDesc) freeStorageSizeOfType(storageType string, mediumType string,
func (h *HostDesc) GetFreePort(netId string) int {
freeCnt := h.BaseHostDesc.GetFreePort(netId)
return freeCnt - h.GetPendingUsage().NetUsage.Get(netId)
return freeCnt - schedmodels.HostPendingUsageManager.GetNetPendingUsage(netId)
}
func reservedResourceCal(
+36 -6
View File
@@ -59,6 +59,10 @@ func (m *SHostPendingUsageManager) GetPendingUsage(hostId string) (*SPendingUsag
return m.getPendingUsage(hostId)
}
func (m *SHostPendingUsageManager) GetNetPendingUsage(netId string) int {
return m.store.GetNetPendingUsage(netId)
}
func (m *SHostPendingUsageManager) getPendingUsage(hostId string) (*SPendingUsage, error) {
pending, err := m.store.GetPendingUsage(hostId)
if err != nil {
@@ -173,6 +177,18 @@ func (self *SHostMemoryPendingUsageStore) DeleteSessionUsage(usage *SessionPendi
self.store.Delete(self.sessionUsageKey(usage.SessionId, usage.Usage.HostId))
}
func (self *SHostMemoryPendingUsageStore) GetNetPendingUsage(id string) int {
total := 0
self.store.Range(func(hostId, usageObj interface{}) bool {
usage, ok := usageObj.(*SPendingUsage)
if ok {
total += usage.NetUsage.Get(id)
}
return true
})
return total
}
type SessionPendingUsage struct {
HostId string
SessionId string
@@ -354,13 +370,27 @@ func NewPendingUsageBySchedInfo(hostId string, req *api.SchedInfo, candidate *sc
u.DiskUsage.Set(backend, osize+size)
}
for _, net := range req.Networks {
id := net.Network
if id == "" {
continue
if candidate != nil && len(candidate.Nets) > 0 {
for _, net := range candidate.Nets {
// 只对建议 network_id 为1个的时候设置 pending_usage
// 多个的情况下只有交给 region 那边自己判断
// 这里只是尽让调度器提前判断出子网是否空闲 ip
if len(net.NetworkIds) != 1 {
continue
}
id := net.NetworkIds[0]
ocount := u.NetUsage.Get(id)
u.NetUsage.Set(id, ocount+1)
}
} else {
for _, net := range req.Networks {
id := net.Network
if id == "" {
continue
}
ocount := u.NetUsage.Get(id)
u.NetUsage.Set(id, ocount+1)
}
ocount := u.NetUsage.Get(id)
u.NetUsage.Set(id, ocount+1)
}
// group add